Db Sql¶
Base classes to wrap various SQL based databases in dffml.db abstraction.
- class dffml.db.sql.SQLDatabaseContext(parent: BaseDatabase)[source]¶
- create_table_query(table_name: str, cols: Dict[str, str], *args, **kwargs) None [source]¶
Creates a create query. Table with name
table_name
will be created if it doesn’t exist.
- insert_query(table_name: str, data: Dict[str, Any], *args, **kwargs) None [source]¶
Creates insert query. Keys in
data
dict correspond to the columns intable_name
.
- lookup_query(table_name: str, cols: Optional[List[str]] = None, conditions: Optional[Union[List[List[Condition]], List[List[Tuple[str]]]]] = None) Tuple[str, Tuple[Any]] [source]¶
Creates a query string and tuple of parameters used as bindings.
- classmethod make_condition_expression(conditions)[source]¶
Returns a dict with keys ‘expression’,’values’ if conditions is not empty else returns None
example:
Input : conditions = [ [["firstName", "=", "John"], ["lastName", "=", "Miles"]], [["age", "<", "38"]], ] Output : { 'expression': '((firstName = ? ) OR (lastName = ? )) AND ((age < ? ))', 'values': ['John', 'Miles', '38'] }
- remove_query(table_name: str, conditions: Optional[Union[List[List[Condition]], List[List[Tuple[str]]]]] = None)[source]¶
Creates a delete query to remove rows from
table_name
(satisfyingconditions
if provided).- Parameters:
table_name (str) – Name of the table.
conditions (Conditions, optional) – Nested array of conditions to satisfy, becomes
WHERE
.
- Returns:
query (str) –
DELETE
queryparameters (tuple) – Variables to bind