dblite
1.3.0
Simple query interface for SQL databases
|
Public Member Functions | |
def | __del__ (self) |
Closes the database, if open. More... | |
def | __enter__ (self) |
Context manager entry, opens database if not already open, returns Database object. More... | |
def | __exit__ (self, exc_type, exc_val, exc_trace) |
Context manager exit, closes database and any pending transactions if open. More... | |
def | close (self, commit=None) |
Closes the database and any pending transactions, if open. More... | |
def | open (self) |
Opens database connection if not already open. More... | |
def | transaction (self, commit=True, exclusive=None, **kwargs) |
Returns a transaction context manager. 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 | |
row_factory = property | |
The custom row factory, if any, as `function(cursor, row tuple)`. 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... | |
Database instance.
Usable as an auto-closing context manager.
Queries directly on the Database object use autocommit mode.
Note that the database connection is not opened immediately on construction.
def dblite.api.Database.__del__ | ( | self | ) |
def dblite.api.Database.__enter__ | ( | self | ) |
Context manager entry, opens database if not already open, returns Database object.
Reimplemented in dblite.engines.postgres.Database, and dblite.engines.sqlite.Database.
def dblite.api.Database.__exit__ | ( | self, | |
exc_type, | |||
exc_val, | |||
exc_trace | |||
) |
Context manager exit, closes database and any pending transactions if open.
Reimplemented in dblite.engines.postgres.Database, and dblite.engines.sqlite.Database.
def dblite.api.Database.close | ( | self, | |
commit = None |
|||
) |
Closes the database and any pending transactions, if open.
commit | `True` for explicit commit on open transactions, `False` for explicit rollback on open transactions, `None` defaults to `commit` flag from transaction creations |
Reimplemented in dblite.engines.postgres.Database, and dblite.engines.sqlite.Database.
def dblite.api.Database.open | ( | self | ) |
Opens database connection if not already open.
Reimplemented in dblite.engines.postgres.Database, and dblite.engines.sqlite.Database.
def dblite.api.Database.transaction | ( | self, | |
commit = True , |
|||
exclusive = None , |
|||
** | kwargs | ||
) |
Returns a transaction context manager.
Context is breakable by raising Rollback.
Note that parameter `exclusive` defaults to `True` when using SQLite.
commit | whether transaction autocommits at exiting with-block |
exclusive | whether entering a with-block is exclusive over other Transaction instances on this Database; `None` stands for engine default |
kwargs | engine-specific arguments, like `schema="other", lazy=True` for Postgres |
Reimplemented in dblite.engines.sqlite.Database, and dblite.engines.postgres.Database.
|
static |