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=False, **kwargs) |
Constructs a new transaction. More... | |
def | __del__ (self) |
Closes the transaction, if open. More... | |
def | __enter__ (self) |
Context manager entry, returns Transaction object. More... | |
def | __exit__ (self, exc_type, exc_val, exc_trace) |
Context manager exit, propagates raised errors except Rollback. 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 | rollback (self) |
Rolls back pending actions, if any. 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 | 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... | |
Properties | |
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... | |
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.api.Transaction.__init__ | ( | self, | |
db, | |||
commit = True , |
|||
exclusive = False , |
|||
** | kwargs | ||
) |
Constructs a new transaction.
Note that parameter `exclusive` defaults to `True` when using SQLite.
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 |
kwargs | engine-specific arguments, like `schema="other", lazy=True` for Postgres |
Reimplemented in dblite.engines.sqlite.Transaction.
def dblite.api.Transaction.__del__ | ( | self | ) |
def dblite.api.Transaction.__enter__ | ( | self | ) |
Context manager entry, returns Transaction object.
Reimplemented in dblite.engines.postgres.Transaction, and dblite.engines.sqlite.Transaction.
def dblite.api.Transaction.__exit__ | ( | self, | |
exc_type, | |||
exc_val, | |||
exc_trace | |||
) |
Context manager exit, propagates raised errors except Rollback.
Reimplemented in dblite.engines.postgres.Transaction, and dblite.engines.sqlite.Transaction.
def dblite.api.Transaction.close | ( | self, | |
commit = None |
|||
) |
Closes the transaction, performing commit or rollback as specified.
Required if not using transaction as context manager in a with-block.
commit | `True` for explicit commit, `False` for explicit rollback, `None` defaults to `commit` flag from creation |
Reimplemented in dblite.engines.postgres.Transaction, and dblite.engines.sqlite.Transaction.
def dblite.api.Transaction.commit | ( | self | ) |
Commits pending actions, if any.
Reimplemented in dblite.engines.postgres.Transaction, and dblite.engines.sqlite.Transaction.
def dblite.api.Transaction.rollback | ( | self | ) |
Rolls back pending actions, if any.
Reimplemented in dblite.engines.postgres.Transaction, and dblite.engines.sqlite.Transaction.
|
static |