Helper

class networkdisk.sql.helper.Helper(*args, **kwargs)

A class to provide a common interface with the DataBase backend

Parameters:
dialect: Dialect

the SQL dialect used by the BackEnd

dbpath: str or None

If not None, the DB to which to connect.

sql_logger: bool or None or str or callable, default=False

Whether and how to log queries or not.

autocommit: bool, default=False

Whether to automatically commit each queries when not within a transaction.

notransaction: bool, default=False

Whether to forbid context transaction use.

temporary_table_count: int, default=0

The number of temporary tables in the current session.

db: DB-connector or None, default=None

A DB-connector to use (use same session). If not provided, a new connection is obtained from dbpath by the connect method.

Attributes:
dialect: Dialect

the SQL dialect used by the BackEnd

dbpath: str or None

If a string, the path to the db file to which the Helper is connected.

sql_logger: SQLLogger

An object to log query send to the backend

cursor()

Returns a database cursor

The object returned should have the methods execute, executemany and __iter__.

execute(query, args=(), column_map=(), sql_logger=<networkdisk.utils.constants.NotProvidedArg object>, rekey=None, commit=None)

Execute a query

Parameters:
query: Query

a Query object to execute.

sql_logger:

a SQL Logger object to output the resulting query executed. It should be a callable object for printing the query Setting it to None makes the logging to do nothing, namely lambda e: None. Default value is notProvidedArg which is replaced by the sql_logger attribute of self.

commit: bool

A Boolean indication whether to commit or not, after executing the query, if not in an explicit transaction. If its value is None (default), then it is replaced by the self.autocommit.

args:

a mapping from ValueColumn specification to non-encoded value or iterable of values, to replace Placeholders in order

column_map: mapping, default={}

TODO

keykey:

TODO

permutation:

TODO

executemany(query, I=(), column_map=(), args=(), sql_logger=<networkdisk.utils.constants.NotProvidedArg object>, rekey=None, commit=None)

Similar to execute except can be used with an iterable of arguments instead of simply one argument.

A method to optimize bulk-insert

executescript(queries, sql_logger=<networkdisk.utils.constants.NotProvidedArg object>, transaction_control=0, commit=None)

Same as execute method, but uses self.db.executescript rather than self.db.execute for executing the script after having formatted it. This forbid the use of arguments.

class networkdisk.sql.helper.IterableQuery(helper, query, index=None, apply=None)

A object for considering the results of a query as a reiterable.

Parameters:
helperHelper

The helper that describes the DB to connect.

querySelectQuery

The query that produces the results of the iterable.

indexint or None, default=None

Whether to project the result on a single column, specified by the integer index, or not (if None, the default).

apply: iterable function or None, default=None

Whether to modify the results of a query applying a function on Python side.

Notes

The length of the iterable is available through the method len. Since it is not a free operation, we do not override the dunder __len__ that is automatically called by some constructors, such as list.

apply and index parameters are carried away when using composition of iterable query, by taking the one at left.