dblite  1.3.0
Simple query interface for SQL databases
dblite.engines.sqlite.Transaction Class Reference

Transaction context manager, breakable by raising Rollback. More...

Inheritance diagram for dblite.engines.sqlite.Transaction:
Inheritance graph

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...
 

Detailed Description

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.

Definition at line 418 of file sqlite.py.

Constructor & Destructor Documentation

◆ __init__()

def dblite.engines.sqlite.Transaction.__init__ (   self,
  db,
  commit = True,
  exclusive = True,
**  __ 
)

Creates a new transaction.

Parameters
dbDatabase instance
commitwhether transaction commits automatically at exiting with-block
exclusivewhether entering a with-block is exclusive over other Transaction instances on this Database

Reimplemented from dblite.api.Transaction.

Definition at line 427 of file sqlite.py.

Member Function Documentation

◆ __enter__()

def dblite.engines.sqlite.Transaction.__enter__ (   self)

Context manager entry, opens cursor, returns Transaction object.

Reimplemented from dblite.api.Transaction.

Definition at line 435 of file sqlite.py.

◆ __exit__()

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.

Definition at line 447 of file sqlite.py.

◆ close()

def dblite.engines.sqlite.Transaction.close (   self,
  commit = None 
)

Closes the transaction, performing commit or rollback as specified.

Parameters
commit`True` for final commit, `False` for rollback, `None` for auto-commit, if any

Reimplemented from dblite.api.Transaction.

Definition at line 466 of file sqlite.py.

◆ commit()

def dblite.engines.sqlite.Transaction.commit (   self)

Commits pending actions, if any.

Reimplemented from dblite.api.Transaction.

Definition at line 511 of file sqlite.py.

◆ execute()

def dblite.engines.sqlite.Transaction.execute (   self,
  sql,
  args = () 
)

Executes the SQL statement and returns sqlite3.Cursor.

Parameters
sqlSQL statement to execute, with SQLite-specific parameter bindings, if any
argsdictionary for :name placeholders, or a sequence for positional ? placeholders

Reimplemented from dblite.api.Queryable.

Definition at line 482 of file sqlite.py.

◆ executemany()

def dblite.engines.sqlite.Transaction.executemany (   self,
  sql,
  args 
)

Executes the SQL statement against all parameter sequences.

Parameters
sqlSQL statement to execute, with SQLite-specific parameter bindings
argsiterable of query parameters, as dictionaries for :name placeholders or sequences for positional ? placeholders

Reimplemented from dblite.api.Queryable.

Definition at line 493 of file sqlite.py.

◆ executescript()

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.

Parameters
sqlscript with one or more SQL statements

Reimplemented from dblite.api.Queryable.

Definition at line 505 of file sqlite.py.

◆ rollback()

def dblite.engines.sqlite.Transaction.rollback (   self)

Rolls back pending actions, if any.

Reimplemented from dblite.api.Transaction.

Definition at line 517 of file sqlite.py.

Property Documentation

◆ closed

dblite.engines.sqlite.Transaction.closed = property
static

Whether transaction is currently not open.

Definition at line 525 of file sqlite.py.

◆ cursor

dblite.engines.sqlite.Transaction.cursor = property
static

Database engine cursor object, or `None` if closed.

Definition at line 532 of file sqlite.py.

◆ database

dblite.engines.sqlite.Transaction.database = property
static

Returns transaction Database instance.

Definition at line 542 of file sqlite.py.


The documentation for this class was generated from the following file: