airflow.hooks.dbapi_hook
¶
Module Contents¶
-
class
airflow.hooks.dbapi_hook.
DbApiHook
(*args, **kwargs)[source]¶ Bases:
airflow.hooks.base_hook.BaseHook
Abstract base class for sql hooks.
-
get_first
(self, sql, parameters=None)[source]¶ Executes the sql and returns the first resulting row.
-
run
(self, sql, autocommit=False, parameters=None)[source]¶ Runs a command or a list of commands. Pass a list of sql statements to the sql parameter to get them to execute sequentially
-
get_autocommit
(self, conn)[source]¶ Get autocommit setting for the provided connection. Return True if conn.autocommit is set to True. Return False if conn.autocommit is not set or set to False or conn does not support autocommit.
- Parameters
conn (connection object.) – Connection to get autocommit setting from.
- Returns
connection autocommit setting.
- Return type
-
static
_generate_insert_sql
(table, values, target_fields, replace, **kwargs)[source]¶ Static helper method that generate the INSERT SQL statement. The REPLACE variant is specific to MySQL syntax.
- Parameters
- Returns
The generated INSERT or REPLACE SQL statement
- Return type
-
insert_rows
(self, table, rows, target_fields=None, commit_every=1000, replace=False, **kwargs)[source]¶ A generic way to insert a set of tuples into a table, a new transaction is created every commit_every rows
- Parameters
table (str) – Name of the target table
rows (iterable of tuples) – The rows to insert into the table
target_fields (iterable of strings) – The names of the columns to fill in the table
commit_every (int) – The maximum number of rows to insert in one transaction. Set to 0 to insert all rows in one transaction.
replace (bool) – Whether to replace instead of insert
-