gws.lib.sqlitex

Convenience wrapper for the SQLite driver.

This wrapper accepts a database path and optionally an “init” DDL script. It executes queries given in a text form.

Each query runs on its own connection, which is closed immediately afterwards.

If a query fails with “no such table”, the wrapper runs the “init” script and repeats the query once. The script can contain multiple statements.

A query that fails with a recoverable error is repeated on a new connection.

Source code: gws.lib.sqlitex

Package Contents

gws.lib.sqlitex.BUSY_TIMEOUT = 5.0

Time in seconds to wait for a lock before giving up.

exception gws.lib.sqlitex.Error

Generic GWS error.

gws.lib.sqlitex.MAX_ATTEMPTS = 3

How many times to repeat a query that failed with a recoverable error.

class gws.lib.sqlitex.Object(db_path: str, init_ddl: str = '', uid_column: str = 'uid')
dbPath
initDDL = ''
uidName = 'uid'
delete(table_name: str, uid)

Delete a record by uid from a table.

execute(stmt: str, **params)

Execute a text DML statement.

insert(table_name: str, rec: dict)

Insert a new record (dict) into a table.

select(stmt: str, **params) list[dict]

Execute a text select statement.

update(table_name: str, rec: dict, uid)

Update a record (dict) in a table.

gws.lib.sqlitex.SLEEP_TIME = 0.1

Time in seconds to wait between the attempts.