dblite
1.3.0
Simple query interface for SQL databases
|
Abstract base for Database and Transaction. More...
Public Member Functions | |
def | delete (self, table, where=(), **kwargs) |
Convenience wrapper for database DELETE, returns affected row count. More... | |
def | execute (self, sql, args=()) |
Executes the SQL statement and returns database cursor. More... | |
def | executemany (self, sql, args) |
Executes the SQL statement against all parameter sequences. More... | |
def | executescript (self, sql) |
Executes the SQL as script of any number of statements. More... | |
def | fetchall (self, table, cols="*", where=(), group=(), order=(), limit=(), **kwargs) |
Convenience wrapper for database SELECT and fetch all. More... | |
def | fetchone (self, table, cols="*", where=(), group=(), order=(), limit=(), **kwargs) |
Convenience wrapper for database SELECT and fetch one. More... | |
def | insert (self, table, values=(), **kwargs) |
Convenience wrapper for database INSERT, returns inserted row ID. More... | |
def | insertmany (self, table, rows=(), **kwargs) |
Convenience wrapper for database multiple INSERTs, returns list of inserted row IDs. More... | |
def | makeSQL (self, action, table, cols="*", where=(), group=(), order=(), limit=(), values=(), kwargs=None) |
Returns (SQL statement string, parameter dict). More... | |
def | quote (cls, value, force=False) |
Returns identifier in quotes and proper-escaped for queries, if value needs quoting (has non-alphanumerics, starts with number, or is reserved). More... | |
def | select (self, table, cols="*", where=(), group=(), order=(), limit=(), **kwargs) |
Convenience wrapper for database SELECT, returns database cursor. More... | |
def | update (self, table, values, where=(), **kwargs) |
Convenience wrapper for database UPDATE, returns affected row count. More... | |
Static Public Attributes | |
ENGINE = None | |
Underlying database engine, "sqlite" for SQLite3 and "postgres" for PostgreSQL. More... | |
Properties | |
closed = property | |
Whether currently not open. More... | |
cursor = property | |
Database engine cursor object, or `None` if closed. More... | |
Abstract base for Database and Transaction.
def dblite.api.Queryable.delete | ( | self, | |
table, | |||
where = () , |
|||
** | kwargs | ||
) |
def dblite.api.Queryable.execute | ( | self, | |
sql, | |||
args = () |
|||
) |
Executes the SQL statement and returns database cursor.
sql | SQL statement to execute, with engine-specific parameter bindings, if any |
args | query parameters, as tuple or dictionary |
Reimplemented in dblite.engines.postgres.Transaction, dblite.engines.sqlite.Transaction, dblite.engines.postgres.Database, and dblite.engines.sqlite.Database.
def dblite.api.Queryable.executemany | ( | self, | |
sql, | |||
args | |||
) |
Executes the SQL statement against all parameter sequences.
sql | SQL statement to execute, with engine-specific parameter bindings |
args | iterable of query parameters, as dictionaries for named placeholders or sequences for positional placeholders |
Reimplemented in dblite.engines.postgres.Transaction, dblite.engines.sqlite.Transaction, dblite.engines.postgres.Database, and dblite.engines.sqlite.Database.
def dblite.api.Queryable.executescript | ( | self, | |
sql | |||
) |
Executes the SQL as script of any number of statements.
Note that in SQLite, the statements are executed outside of transaction, and any pending transaction will be committed first.
sql | script with one or more SQL statements |
Reimplemented in dblite.engines.postgres.Transaction, dblite.engines.sqlite.Transaction, dblite.engines.postgres.Database, and dblite.engines.sqlite.Database.
def dblite.api.Queryable.fetchall | ( | self, | |
table, | |||
cols = "*" , |
|||
where = () , |
|||
group = () , |
|||
order = () , |
|||
limit = () , |
|||
** | kwargs | ||
) |
def dblite.api.Queryable.fetchone | ( | self, | |
table, | |||
cols = "*" , |
|||
where = () , |
|||
group = () , |
|||
order = () , |
|||
limit = () , |
|||
** | kwargs | ||
) |
def dblite.api.Queryable.insert | ( | self, | |
table, | |||
values = () , |
|||
** | kwargs | ||
) |
Convenience wrapper for database INSERT, returns inserted row ID.
Keyword arguments are added to VALUES.
Reimplemented in dblite.engines.postgres.Queryable, and dblite.engines.sqlite.Queryable.
def dblite.api.Queryable.insertmany | ( | self, | |
table, | |||
rows = () , |
|||
** | kwargs | ||
) |
Convenience wrapper for database multiple INSERTs, returns list of inserted row IDs.
Keyword arguments are added to VALUES of every single row, overriding individual row values.
Reimplemented in dblite.engines.postgres.Queryable, and dblite.engines.sqlite.Queryable.
def dblite.api.Queryable.makeSQL | ( | self, | |
action, | |||
table, | |||
cols = "*" , |
|||
where = () , |
|||
group = () , |
|||
order = () , |
|||
limit = () , |
|||
values = () , |
|||
kwargs = None |
|||
) |
Returns (SQL statement string, parameter dict).
Reimplemented in dblite.engines.postgres.Queryable, and dblite.engines.sqlite.Queryable.
def dblite.api.Queryable.quote | ( | cls, | |
value, | |||
force = False |
|||
) |
Returns identifier in quotes and proper-escaped for queries, if value needs quoting (has non-alphanumerics, starts with number, or is reserved).
value | the value to quote, returned as-is if not string |
force | whether to quote value even if not required |
Reimplemented in dblite.engines.postgres.Queryable, and dblite.engines.sqlite.Queryable.
def dblite.api.Queryable.select | ( | self, | |
table, | |||
cols = "*" , |
|||
where = () , |
|||
group = () , |
|||
order = () , |
|||
limit = () , |
|||
** | kwargs | ||
) |
def dblite.api.Queryable.update | ( | self, | |
table, | |||
values, | |||
where = () , |
|||
** | kwargs | ||
) |
|
static |
|
static |
|
static |