dblite
1.3.0
Simple query interface for SQL databases
|
Transaction context manager, breakable by raising Rollback. More...
Public Member Functions | |
def | __init__ (self, db, commit=True, exclusive=True, **__) |
Creates a new transaction. More... | |
def | __enter__ (self) |
Context manager entry, opens cursor, returns Transaction object. More... | |
def | __exit__ (self, exc_type, exc_val, exc_trace) |
Context manager exit, closes cursor, commits or rolls back as specified on creation. More... | |
def | close (self, commit=None) |
Closes the transaction, performing commit or rollback as specified. More... | |
def | commit (self) |
Commits pending actions, if any. More... | |
def | execute (self, sql, args=()) |
Executes the SQL statement and returns sqlite3.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, outside of transaction. More... | |
def | rollback (self) |
Rolls back pending actions, if any. More... | |
Public Member Functions inherited from dblite.api.Transaction | |
def | __del__ (self) |
Closes the transaction, if open. More... | |
Public Member Functions inherited from dblite.api.Queryable | |
def | delete (self, table, where=(), **kwargs) |
Convenience wrapper for database DELETE, returns affected row count. 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 | 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... | |
Public Member Functions inherited from dblite.engines.sqlite.Queryable | |
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... | |
Properties | |
closed = property | |
Whether transaction is currently not open. More... | |
cursor = property | |
Database engine cursor object, or `None` if closed. More... | |
database = property | |
Returns transaction Database instance. More... | |
Properties inherited from dblite.api.Transaction | |
database = property | |
Returns transaction Database instance. More... | |
Properties inherited from dblite.api.Queryable | |
closed = property | |
Whether currently not open. More... | |
cursor = property | |
Database engine cursor object, or `None` if closed. More... | |
Additional Inherited Members | |
Static Public Attributes inherited from dblite.api.Queryable | |
ENGINE = None | |
Underlying database engine, "sqlite" for SQLite3 and "postgres" for PostgreSQL. More... | |
Static Public Attributes inherited from dblite.engines.sqlite.Queryable | |
string | ENGINE = "sqlite" |
Name of underlying database engine. More... | |
list | OPS |
Recognized binary operators for makeSQL() More... | |
Transaction context manager, breakable by raising Rollback.
Note that in SQLite, a single connection has one shared transaction state, so it is highly recommended to use exclusive Transaction instances for any action queries, as concurrent transactions can interfere with one another otherwise.
def dblite.engines.sqlite.Transaction.__init__ | ( | self, | |
db, | |||
commit = True , |
|||
exclusive = True , |
|||
** | __ | ||
) |
Creates a new transaction.
db | Database instance |
commit | whether transaction commits automatically at exiting with-block |
exclusive | whether entering a with-block is exclusive over other Transaction instances on this Database |
Reimplemented from dblite.api.Transaction.
def dblite.engines.sqlite.Transaction.__enter__ | ( | self | ) |
Context manager entry, opens cursor, returns Transaction object.
Reimplemented from dblite.api.Transaction.
def dblite.engines.sqlite.Transaction.__exit__ | ( | self, | |
exc_type, | |||
exc_val, | |||
exc_trace | |||
) |
Context manager exit, closes cursor, commits or rolls back as specified on creation.
Reimplemented from dblite.api.Transaction.
def dblite.engines.sqlite.Transaction.close | ( | self, | |
commit = None |
|||
) |
Closes the transaction, performing commit or rollback as specified.
commit | `True` for final commit, `False` for rollback, `None` for auto-commit, if any |
Reimplemented from dblite.api.Transaction.
def dblite.engines.sqlite.Transaction.commit | ( | self | ) |
Commits pending actions, if any.
Reimplemented from dblite.api.Transaction.
def dblite.engines.sqlite.Transaction.execute | ( | self, | |
sql, | |||
args = () |
|||
) |
Executes the SQL statement and returns sqlite3.Cursor.
sql | SQL statement to execute, with SQLite-specific parameter bindings, if any |
args | dictionary for :name placeholders, or a sequence for positional ? placeholders |
Reimplemented from dblite.api.Queryable.
def dblite.engines.sqlite.Transaction.executemany | ( | self, | |
sql, | |||
args | |||
) |
Executes the SQL statement against all parameter sequences.
sql | SQL statement to execute, with SQLite-specific parameter bindings |
args | iterable of query parameters, as dictionaries for :name placeholders or sequences for positional ? placeholders |
Reimplemented from dblite.api.Queryable.
def dblite.engines.sqlite.Transaction.executescript | ( | self, | |
sql | |||
) |
Executes the SQL as script of any number of statements, outside of transaction.
Any pending transaction will be committed first.
sql | script with one or more SQL statements |
Reimplemented from dblite.api.Queryable.
def dblite.engines.sqlite.Transaction.rollback | ( | self | ) |
Rolls back pending actions, if any.
Reimplemented from dblite.api.Transaction.
|
static |
|
static |
|
static |