dblite
1.3.0
Simple query interface for SQL databases
|
Convenience wrapper around sqlite3.Connection. More...
Public Member Functions | |
def | __init__ (self, opts=":memory:", **kwargs) |
Creates a new Database instance for SQLite. 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 | 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. More... | |
def | open (self) |
Opens the database connection, if not already open. More... | |
def | transaction (self, commit=True, exclusive=True, **kwargs) |
Returns a transaction context manager. More... | |
Public Member Functions inherited from dblite.api.Database | |
def | __del__ (self) |
Closes the database, 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... | |
Public Attributes | |
connection | |
path | |
Static Public Attributes | |
MUTEX = collections.defaultdict(threading.RLock) | |
Mutexes for exclusive actions, as {Database instance: lock}. More... | |
ROW_FACTORY = None | |
Registered row factory. More... | |
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... | |
Properties | |
closed = property | |
Whether database is currently not open. More... | |
cursor = property | |
Database engine cursor object, or `None` if closed. More... | |
row_factory = property | |
The custom row factory, if any, as `function(cursor, row tuple)`. More... | |
Properties inherited from dblite.api.Database | |
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... | |
Convenience wrapper around sqlite3.Connection.
Queries directly on the Database object use autocommit mode.
def dblite.engines.sqlite.Database.__init__ | ( | self, | |
opts = ":memory:" , |
|||
** | kwargs | ||
) |
def dblite.engines.sqlite.Database.__enter__ | ( | self | ) |
Context manager entry, opens database if not already open, returns Database object.
Reimplemented from dblite.api.Database.
def dblite.engines.sqlite.Database.__exit__ | ( | self, | |
exc_type, | |||
exc_val, | |||
exc_trace | |||
) |
Context manager exit, closes database and any pending transactions if open.
Reimplemented from dblite.api.Database.
def dblite.engines.sqlite.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 from dblite.api.Database.
def dblite.engines.sqlite.Database.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.Database.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.Database.executescript | ( | self, | |
sql | |||
) |
Executes the SQL as script of any number of statements.
sql | script with one or more SQL statements |
Reimplemented from dblite.api.Queryable.
def dblite.engines.sqlite.Database.open | ( | self | ) |
Opens the database connection, if not already open.
Reimplemented from dblite.api.Database.
def dblite.engines.sqlite.Database.transaction | ( | self, | |
commit = True , |
|||
exclusive = True , |
|||
** | kwargs | ||
) |
Returns a transaction context manager.
Context is breakable by raising Rollback.
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 `detect_types=sqlite3.PARSE_COLNAMES` |
Reimplemented from dblite.api.Database.
|
static |
|
static |
|
static |
|
static |
|
static |