dblite
1.3.0
Simple query interface for SQL databases
|
Transaction context manager, provides convenience methods for queries. More...
Public Member Functions | |
def | __init__ (self, db, commit=True, exclusive=False, schema=None, lazy=False, itersize=None, **__) |
Creates a transaction context manager. 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, and releases database connection back to connection pool. More... | |
def | commit (self) |
Commits pending actions, if any. More... | |
def | execute (self, sql, args=()) |
Executes SQL statement, returns psycopg 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 | rollback (self) |
Rolls back pending actions, if any. More... | |
Public Member Functions inherited from dblite.api.Transaction | |
def | __init__ (self, db, commit=True, exclusive=False, **kwargs) |
Constructs a new transaction. More... | |
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.postgres.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.postgres.Queryable | |
string | ENGINE = "postgres" |
Name of underlying database engine. More... | |
tuple | OPS |
Recognized binary operators for makeSQL() More... | |
Transaction context manager, provides convenience methods for queries.
Supports server-side cursors; those can only be used for making a single query.
Must be closed explicitly if not used as context manager in a with-block. Block can be exited early by raising Rollback.
Definition at line 634 of file postgres.py.
def dblite.engines.postgres.Transaction.__init__ | ( | self, | |
db, | |||
commit = True , |
|||
exclusive = False , |
|||
schema = None , |
|||
lazy = False , |
|||
itersize = None , |
|||
** | __ | ||
) |
Creates a transaction context manager.
Context is breakable by raising Rollback.
db | Database instance |
commit | whether transaction commits automatically at exiting with-block |
exclusive | whether entering a with-block is exclusive over other Transaction instances Database |
schema | search_path to use in this transaction |
lazy | if true, uses a server-side cursor to fetch results from server iteratively in batches instead of all at once, supports one single query only |
itersize | batch size for server-side cursor (defaults to 2000 rows) |
Definition at line 651 of file postgres.py.
def dblite.engines.postgres.Transaction.__enter__ | ( | self | ) |
Context manager entry, opens cursor, returns Transaction object.
Reimplemented from dblite.api.Transaction.
Definition at line 662 of file postgres.py.
def dblite.engines.postgres.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.
Definition at line 675 of file postgres.py.
def dblite.engines.postgres.Transaction.close | ( | self, | |
commit = None |
|||
) |
Closes the transaction, performing commit or rollback as specified, and releases database connection back to connection pool.
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 from dblite.api.Transaction.
Definition at line 698 of file postgres.py.
def dblite.engines.postgres.Transaction.commit | ( | self | ) |
Commits pending actions, if any.
Reimplemented from dblite.api.Transaction.
Definition at line 745 of file postgres.py.
def dblite.engines.postgres.Transaction.execute | ( | self, | |
sql, | |||
args = () |
|||
) |
Executes SQL statement, returns psycopg cursor.
sql | SQL statement to execute, with psycopg-specific parameter bindings, if any |
args | dictionary for %(name)s placeholders, or a sequence for positional s placeholders, or None |
Reimplemented from dblite.api.Queryable.
Definition at line 716 of file postgres.py.
def dblite.engines.postgres.Transaction.executemany | ( | self, | |
sql, | |||
args | |||
) |
Executes the SQL statement against all parameter sequences.
sql | SQL statement to execute, with psycopg-specific parameter bindings |
args | iterable of query parameters, as dictionaries for %(name)s placeholders or sequences for positional s placeholders |
Reimplemented from dblite.api.Queryable.
Definition at line 728 of file postgres.py.
def dblite.engines.postgres.Transaction.executescript | ( | self, | |
sql | |||
) |
Executes the SQL as script of any number of statements.
Reloads internal schema structure from database.
sql | script with one or more SQL statements |
Reimplemented from dblite.api.Queryable.
Definition at line 740 of file postgres.py.
def dblite.engines.postgres.Transaction.rollback | ( | self | ) |
Rolls back pending actions, if any.
Reimplemented from dblite.api.Transaction.
Definition at line 749 of file postgres.py.
|
static |
Whether transaction is currently not open.
Definition at line 755 of file postgres.py.
|
static |
Database engine cursor object, or `None` if closed.
Definition at line 762 of file postgres.py.
|
static |
Returns transaction Database instance.
Definition at line 771 of file postgres.py.