glide.sql module¶
-
class
glide.sql.
AssertSQL
(*args, **kwargs)[source]¶ Bases:
glide.sql.SQLNode
-
run
(data, sql, conn, cursor=None, cursor_type=None, params=None, data_check=None, **kwargs)[source]¶ Run a SQL query to check data.
- Parameters
data – Data to pass through on success
sql (str) – SQL query to run. Should return a single row with a “assert” column to indicate success. Truthy values for “assert” will be considered successful, unless data_check is passed in which case it will be compared for equality to the result of that callable.
conn – SQL connection object
cursor (optional) – SQL connection cursor object
cursor_type (optional) – SQL connection cursor type when creating a cursor is necessary
params (tuple or dict, optional) – A tuple or dict of params to pass to the execute method
data_check (callable, optional) – A callable that will be passed the node and data as arguments and is expected to return a value to be compared to the SQL result.
**kwargs – Keyword arguments pushed to the execute method
-
-
class
glide.sql.
BaseSQLNode
(*args, **kwargs)[source]¶ Bases:
glide.flow.SkipFalseNode
Base class for SQL-based nodes, checks for valid connection types on init
-
allowed_conn_types
¶ A list or tuple of connection types that are allowed
- Type
list or tuple
-
allowed_conn_types
= None
-
create_like
(conn, cursor, table, like_table, drop=False)[source]¶ Create a table like another table, optionally trying to drop table first
-
execute
(conn, cursor, sql, params=None, **kwargs)[source]¶ Executes the sql statement and returns an object that can fetch results
- Parameters
conn – A SQL database connection object
cursor – A SQL database cursor
sql (str) – A sql query to execute
params (tuple, optional) – A tuple of params to pass to the execute method of the conn or cursor
**kwargs – kwargs passed through to execute()
- Returns
cursor object that has executed but not fetched a query.
- Return type
cursor
-
executemany
(conn, cursor, sql, rows)[source]¶ Bulk executes the sql statement and returns an object that can fetch results
- Parameters
conn – A SQL database connection object
cursor – A SQL database cursor
sql (str) – A sql query to execute
rows – Rows of data to bulk execute
- Returns
cursor object that has executed but not fetched a query.
- Return type
cursor
-
get_bulk_statement
(conn, stmt_type, table, rows, odku=False)[source]¶ Get a bulk execution SQL statement
- Parameters
conn – A SQL database connection object
stmt_type (str) – Type of SQL statement to use (REPLACE, INSERT, etc.)
table (str) – name of a SQL table
rows – An iterable of dict rows. The first row is used to determine column names.
odku (bool or list, optional) – If true, add ON DUPLICATE KEY UPDATE clause for all columns. If a list then only add it for the specified columns. Note: Backend support for this varies.
- Returns
- Return type
A SQL bulk load query of the given stmt_type
-
-
class
glide.sql.
SQLExecute
(*args, **kwargs)[source]¶ Bases:
glide.sql.SQLNode
-
run
(sql, conn, cursor=None, cursor_type=None, params=None, commit=True, rollback=False, dry_run=False, **kwargs)[source]¶ Perform a generic SQL query execution and push the cursor/execute response.
- Parameters
sql (str) – SQL query to run
conn – SQL connection object
cursor (optional) – SQL connection cursor object
cursor_type (optional) – SQL connection cursor type when creating a cursor is necessary
params (tuple or dict, optional) – A tuple or dict of params to pass to the execute method
commit (bool, optional) – If true try to commit the transaction. If your connection autocommits this will have no effect. If this is a SQLAlchemy connection and you are in a transaction, it will try to get a reference to the current transaction and call commit on that.
rollback (bool, optional) – If true try to rollback the transaction on exceptions. Behavior may vary by backend DB library if you are not currently in a transaction.
**kwargs – Keyword arguments pushed to the execute method
-
-
class
glide.sql.
SQLNode
(*args, **kwargs)[source]¶ Bases:
glide.sql.BaseSQLNode
,glide.sql.SQLCursorPushMixin
A generic SQL node that will behave differently based on the connection type
-
allowed_conn_types
= [<class 'object'>]¶
-
-
class
glide.sql.
SQLTransaction
(*args, **kwargs)[source]¶ Bases:
glide.sql.SQLNode