aiosqliteObj.py
Async SQLite queries, column and table metadata, declarative schema management, and index reconciliation.
Setup and connection lifecycle
Install aiosqlite and make aiosqliteObj.py available on the import path. Import also invokes pmblue_update.self_update(adv_info=True). If the updater is absent, a requests bootstrap downloads it from the legacy HTTP URL and writes it to the working directory.
Database(filename, **kwargs) creates a wrapper; the connection opens lazily through await db.get_connection() or cursor-based methods. Database operations are coroutines. Establish the connection before calling update() or commit(), which directly use db.conn.
Constructor settings include table, only_connection=True, auto_commit_threshold=None, and auto_vacuum_threshold=None. The default caches table/column metadata assuming this wrapper owns the connection. Automatic commit/vacuum thresholds are disabled by default. Explicitly await db.commit() after writes. await db.close() commits an open transaction before closing.
Working async example
import asyncio
import aiosqliteObj as sql
async def main():
db = sql.Database("contacts.db")
try:
await db.get_connection()
if await db.get_table("contacts") is None:
await db.create_table("contacts", [
sql.NewColumn("id", "INTEGER", primary_key=True),
sql.NewColumn("name", "TEXT"),
sql.NewColumn("city", "TEXT"),
])
await db.set_table("contacts")
contact_id = await db.insert({"name": "Ada", "city": "London"})
await db.commit()
rows = await db.select({"id": contact_id}, columns=["id", "name"])
print(rows)
print(await db.select({"city": ["London", "Oxford"]}, count=True))
finally:
await db.close()
asyncio.run(main())
Queries, filters, and results
| Awaited API | Return and behavior |
|---|---|
select_all(columns="*", dict_mode=True, table=None, limit=None) | List of dictionaries, or underlying rows with dict_mode=False. A list/tuple of column names is validated and quoted; a string is used as a SQL expression. |
select(filters, ..., columns="*", count=False, ...) | List of matching rows. count=True returns an integer count; count="column" counts distinct values. A raw SELECT string is also accepted. |
insert(values, table=None) | Returns the inserted row ID; dictionary input is the clearest form. None entries are omitted rather than explicitly inserted as NULL. |
update(values, where, op_and=True, table=None), delete(filters, ...) | Return affected-row counts. Explicitly commit unless an automatic threshold applies. |
execute(query, parameters=None), cursor() | Return an aiosqlite cursor; await its fetchone(), fetchall(), and other coroutine methods. |
get_table(name), tables(), columns(table) | Table metadata (or None), a table collection, and Column metadata respectively. Table.row_count(distinct=None) and Table.columns() are async. Newly created tables may appear as name strings in the cached table list until reopened. |
Dictionary filters use bound parameters for common scalar, list/tuple, LIKE, and BETWEEN values. Helpers are between, like, contains, case_insensitive, and is_not. List and tuple filters produce IN; empty lists match no rows, and is_not([]) matches all rows. Set op_and=False to combine filters with OR. Use a single orderDict field because the current builder retains only the final ordering expression.
rows = await db.select({"city": sql.contains("don")}, columns=["name"])
rows = await db.select({"id": sql.is_not([1, 2])})
cursor = await db.execute("SELECT * FROM contacts WHERE city IS NULL")
rows_with_null = await cursor.fetchall()
Use explicit SQL IS NULL for NULL filters: the current select type check for None does not match its helper's type-name format. Negated BETWEEN also has special handwritten SQL; use an explicit bound query when exact range semantics matter. Table names, column-expression strings, and raw SQL remain caller-controlled SQL.
Schema and indexes
NewColumn(name, datatype, not_null=0, dflt_value=None, primary_key=0, autoincrement=0) defines columns for create_table() and add_column(). Read Column metadata from columns(). create_index(name, table, columns, unique=False) returns an Index and commits; indexes() lists indexes, and await index.drop() removes one. remove_column() selects a direct SQLite ALTER or a table-copy fallback according to SQLite version.
DatabaseManager stores a desired schema. Add a table, its columns, then indexes; initialize() creates missing tables/columns and reconciles indexes. Existing indexes with the same name but different table, columns, or uniqueness are dropped and recreated. Missing-column cache invalidation allows a newly added column to receive an index during the same initialization pass.
manager = sql.DatabaseManager(db, verbose=True)
contacts = manager.add_table("contacts")
contacts.add_column("id", "INTEGER", primary_key=True)
contacts.add_column("name", "TEXT")
contacts.add_column("city", "TEXT")
manager.add_index("contacts", ["city"], index_name="idx_contacts_city")
await manager.initialize()
await db.commit()
The manager is a schema reconciliation tool, so declare every column and index you intend to keep. With override=False, unlisted columns/indexes trigger terminal prompts; override=True removes them without prompting. It does not generally migrate changed definitions of existing columns. Table-copy column removal can lose table features not represented by its Column objects. Keep schema operations explicit when preserving constraints and indexes matters.
Pragmas, maintenance, and reporting
await db.pragmas["page_count"] reads a supported pragma. await db.pragmas.size and await db.pragmas.max_size calculate byte sizes. await db.pragmas.set("max_page_count", value) waits for the write; assignment via db.pragmas[key] = value schedules a task. Supported reads include page size/count, freelist count, encoding, change counting, maximum page count, and journal mode. Journal mode reads return one of the JournalMode nested classes.
vacuum(to_file=None) commits an open transaction before compaction. Exports to_csv, to_html, to_dict, and request_pagination are async and produce materialized report data. HTML generation does not provide a general escaping guarantee.
Compatibility notes
The primary class is Database, whereas the synchronous module uses sqliteObj. This is not an interchangeable async replacement: schema arguments and close/commit behavior differ. Use the default row factory; the constructor's current row_factory validation rejects callable values even though the property setter accepts them. The journal-mode setter also checks a module name inconsistent with this module's own JournalMode; use a trusted raw PRAGMA if needed.
Schema mutations may commit independently, and close() commits pending changes. For an explicit rollback use the underlying connection's await db.conn.rollback() before closing. Error types include TableNotSet, NoTables, TableNotFound, ColumnNotFound, HasPrimaryKey, and ModuleOperationError.
Objects, relationships, and attributes
Database owns the aiosqlite connection. It creates Table, Column, and Index metadata objects; a DatabaseManager instead holds your intended schema as TableManager and NewColumn objects. Defining the manager's objects is synchronous and only changes Python state. Awaiting initialize() applies the definitions to SQLite.
| Object | Construction / important attributes | Methods and results |
|---|---|---|
Database | Database(filename, table=None, only_connection=True, ...). Exposes filename, conn, connected, table, total_changes, row_factory, and boolean in_transaction. | await get_connection() returns the native connection; query/maintenance methods are async. Accessing properties is synchronous. |
Table | Normally from await db.get_table(name). Has db, name, tbl_name, rootpage, and original CREATE sql. | str(table) is the table name. await table.row_count(distinct=None) returns an integer. await table.columns() returns Column objects. |
Column | Read from SQLite. Has table, id, name, SQL type, boolean not_null/primary_key, and default_value. | str(column) gives the name; is_int_primary_key is a boolean property; new_column() produces a NewColumn description. |
NewColumn | Your requested schema, with name, type, not_null, default_value, primary_key, and autoincrement. | statement() returns column-definition SQL. NewColumn.int_primary_key() returns an autoincrementing integer id definition. It does not execute SQL by itself. |
Index | Usually from indexes() or create_index(). Has name, table/tbl_name, columns, unique, sql, and db. | str(index) returns its name; await index.drop() executes DROP INDEX. Index column parsing is designed for the module's simple column indexes. |
DatabaseManager | DatabaseManager(db, verbose=False); shares the supplied Database. | add_table(name) returns a TableManager; add_index(table, column_names, index_name=None, unique=False) returns a planned Index. await initialize(override=False) returns None. |
TableManager | Returned by manager.add_table(name); holds db, name, and the planned column definitions. | add_column(...) returns a NewColumn. get_column(name) returns it or None. Its matches argument is currently accepted but not used. |
dflt_value is included directly in SQL, so textual SQL defaults need SQL quoting, for example dflt_value="'pending'". primary_key, not_null, and autoincrement are boolean-like flags. SQLite still enforces combinations such as AUTOINCREMENT requiring an integer primary key.
Argument rules for mutations
In await db.update(values, where), values maps columns to replacements and where selects rows. where={} or None updates all rows. await db.delete({}) deletes all rows. A raw update condition string must include WHERE; raw strings passed to select/delete are full SQL statements. For arbitrary SQL, prefer await db.execute(sql, parameters) with a tuple or list of bound values.
Worked example: declare and inspect a schema
The schema lives in a temporary file. Reopening after initialization also refreshes the wrapper's table metadata so this example receives Table objects even for newly created tables.
import asyncio
import os
import tempfile
import aiosqliteObj as sql
async def main():
with tempfile.TemporaryDirectory() as directory:
path = os.path.join(directory, "tasks.db")
db = sql.Database(path)
try:
manager = sql.DatabaseManager(db)
tasks = manager.add_table("tasks")
tasks.add_column("id", "INTEGER", primary_key=True)
tasks.add_column("title", "TEXT", not_null=True)
tasks.add_column("status", "TEXT", dflt_value="'pending'")
manager.add_index("tasks", "status")
await manager.initialize()
await db.commit()
finally:
await db.close()
db = sql.Database(path, table="tasks")
try:
await db.get_connection()
row_id = await db.insert({"title": "Write documentation"})
await db.commit()
table = await db.get_table("tasks")
print(table.name, await table.row_count())
for column in await table.columns():
print(column.name, column.type, column.default_value)
for index in await db.indexes():
print(index.name, index.columns, index.unique)
print(await db.select({"id": row_id}))
finally:
await db.close()
asyncio.run(main())
Worked example: rollback a group of async writes
Since close() commits an outstanding transaction, rollback must happen before closing when an operation fails. Leave automatic commit/vacuum thresholds disabled for the group, and avoid helpers such as create_index that commit independently inside it.
import asyncio
import sqlite3
import aiosqliteObj as sql
async def main():
db = sql.Database(":memory:")
try:
await db.execute("CREATE TABLE users (name TEXT UNIQUE)")
await db.commit()
try:
await db.execute("INSERT INTO users VALUES (?)", ("Ada",))
await db.execute("INSERT INTO users VALUES (?)", ("Ada",))
await db.commit()
except sqlite3.IntegrityError:
await db.conn.rollback()
cursor = await db.execute("SELECT COUNT(*) FROM users")
print((await cursor.fetchone())[0]) # 0
finally:
await db.close()
asyncio.run(main())
Complete source API
Generated from modules/aiosqliteObj.py; version 1.2.9. Includes public functions, classes, directly declared methods, properties, and Python protocol methods. Conditional APIs may require optional dependencies. Inherited members and dynamically assigned attributes are explained in the guide where relevant.
Signatures and docstrings are extracted without importing or running the module. A property or AsyncProperty decorator changes how a member is accessed; see its decorators and the guide.
Classes and objects
TableNotSetHasPrimaryKeyNoTablesColumnNotFoundTableNotFoundModuleOperationErrorWhatTheFuckAreYouDoingbetweenlikecontainscase_insensitiveis_notJournalModeJournalMode.DeleteJournalMode.TruncateJournalMode.PersistJournalMode.MemoryJournalMode.WALJournalMode.OffIndexNewColumnColumnAsyncPropertyPragmasDatabaseTableTableManagerDatabaseManagerVersion
class TableNotSet(Exception)
Source line 66
Exception raised when a table is not set.
Construct: TableNotSet()
Declared functions, properties, and nested objects:
TableNotSet.__init__— method
TableNotSet.__init__(self)
Source line 68
No caller-supplied parameters are declared.
class HasPrimaryKey(Exception)
Source line 70
Exception raised when there is an attempt to add a column as primary key to a table that already has a primary key column.
Construct: HasPrimaryKey()
Declared functions, properties, and nested objects:
HasPrimaryKey.__init__— method
HasPrimaryKey.__init__(self)
Source line 72
No caller-supplied parameters are declared.
class NoTables(Exception)
Source line 74
Exception raised when there are no tables.
Construct: NoTables()
Declared functions, properties, and nested objects:
NoTables.__init__— method
NoTables.__init__(self)
Source line 76
No caller-supplied parameters are declared.
class ColumnNotFound(Exception)
Source line 78
Exception raised when a column provided is not found.
Construct: ColumnNotFound(given, table)
Declared functions, properties, and nested objects:
ColumnNotFound.__init__— method
ColumnNotFound.__init__(self, given, table)
Source line 80
| Parameter | Passing convention | Default / required |
|---|---|---|
given | positional or keyword | required |
table | positional or keyword | required |
class TableNotFound(Exception)
Source line 82
Exception raised when a table is not found.
Construct: TableNotFound(table)
Declared functions, properties, and nested objects:
TableNotFound.__init__— method
TableNotFound.__init__(self, table)
Source line 84
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | required |
class ModuleOperationError(Exception)
Source line 86
Exception raised when this module messes up essentially. When there is an error with an exection, the query that caused the error, and the exception itself, are returned.
Construct: ModuleOperationError(query, trc)
Declared functions, properties, and nested objects:
ModuleOperationError.__init__— method
ModuleOperationError.__init__(self, query, trc)
Source line 88
| Parameter | Passing convention | Default / required |
|---|---|---|
query | positional or keyword | required |
trc | positional or keyword | required |
class WhatTheFuckAreYouDoing(Exception)
Source line 90
Exception raised when you become a psychopath, and have both a pair of 2 single quotes, and a pair of 2 double quotes, in a string. Either do sqliteObj.exact = False, or just stop.
Construct: WhatTheFuckAreYouDoing()
Declared functions, properties, and nested objects:
WhatTheFuckAreYouDoing.__init__— method
WhatTheFuckAreYouDoing.__init__(self)
Source line 93
No caller-supplied parameters are declared.
class between
Source line 145
Construct: between(value1, value2)
Fields assigned by the constructor: value1, value2. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
between.__init__— method
between.__init__(self, value1, value2)
Source line 146
| Parameter | Passing convention | Default / required |
|---|---|---|
value1 | positional or keyword | required |
value2 | positional or keyword | required |
class like
Source line 149
Construct: like(value)
Fields assigned by the constructor: value. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
like.__init__— method
like.__init__(self, value)
Source line 150
| Parameter | Passing convention | Default / required |
|---|---|---|
value | positional or keyword | required |
class contains
Source line 152
Construct: contains(value)
Fields assigned by the constructor: value. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
contains.__init__— method
contains.__init__(self, value)
Source line 153
| Parameter | Passing convention | Default / required |
|---|---|---|
value | positional or keyword | required |
class case_insensitive
Source line 155
Construct: case_insensitive(value)
Fields assigned by the constructor: value. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
case_insensitive.__init__— method
case_insensitive.__init__(self, value)
Source line 156
| Parameter | Passing convention | Default / required |
|---|---|---|
value | positional or keyword | required |
class is_not
Source line 158
Construct: is_not(value)
Fields assigned by the constructor: value. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
is_not.__init__— method
is_not.__init__(self, value)
Source line 159
| Parameter | Passing convention | Default / required |
|---|---|---|
value | positional or keyword | required |
class JournalMode
Source line 186
Represents a Journal mode.
No constructor is declared here. Some utility classes group functions for direct class access; use the call style shown in the guide.
Declared functions, properties, and nested objects:
JournalMode.Delete— nested classJournalMode.Truncate— nested classJournalMode.Persist— nested classJournalMode.Memory— nested classJournalMode.WAL— nested classJournalMode.Off— nested class
class JournalMode.Delete
Source line 188
This is the default mode. Here at the conclusion of a transaction, the journal file is deleted.
No constructor is declared here. Some utility classes group functions for direct class access; use the call style shown in the guide.
class JournalMode.Truncate
Source line 192
The journal file is truncated to a length of zero bytes.
No constructor is declared here. Some utility classes group functions for direct class access; use the call style shown in the guide.
class JournalMode.Persist
Source line 195
The journal file is left in place, but the header is overwritten to indicate the journal is no longer valid.
No constructor is declared here. Some utility classes group functions for direct class access; use the call style shown in the guide.
class JournalMode.Memory
Source line 199
The journal record is held in memory, rather than on disk.
No constructor is declared here. Some utility classes group functions for direct class access; use the call style shown in the guide.
class JournalMode.WAL
Source line 202
Get info here: https://sqlite.org/wal.html
No constructor is declared here. Some utility classes group functions for direct class access; use the call style shown in the guide.
class JournalMode.Off
Source line 205
No journal record is kept.
No constructor is declared here. Some utility classes group functions for direct class access; use the call style shown in the guide.
class Index
Source line 222
Construct: Index(name, tbl_name, sql, db)
Fields assigned by the constructor: columns, db, name, sql, table, tbl_name, unique. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
Index.__init__— methodIndex.__repr__— methodIndex.__str__— methodIndex.__eq__— methodIndex.drop— async method
Index.__init__(self, name, tbl_name, sql, db)
Source line 223
| Parameter | Passing convention | Default / required |
|---|---|---|
name | positional or keyword | required |
tbl_name | positional or keyword | required |
sql | positional or keyword | required |
db | positional or keyword | required |
Index.__repr__(self)
Source line 244
No caller-supplied parameters are declared.
Index.__str__(self)
Source line 247
No caller-supplied parameters are declared.
Index.__eq__(self, other)
Source line 250
| Parameter | Passing convention | Default / required |
|---|---|---|
other | positional or keyword | required |
async Index.drop(self)
Source line 258
Drop this index from the database.
No caller-supplied parameters are declared.
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
class NewColumn
Source line 263
Construct: NewColumn(name, datatype, not_null=0, dflt_value=None, primary_key=0, autoincrement=0)
Fields assigned by the constructor: autoincrement, default_value, name, not_null, primary_key, type. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
NewColumn.__init__— methodNewColumn.__repr__— methodNewColumn.statement— methodNewColumn.int_primary_key— method
NewColumn.__init__(self, name, datatype, not_null=0, dflt_value=None, primary_key=0, autoincrement=0)
Source line 264
| Parameter | Passing convention | Default / required |
|---|---|---|
name | positional or keyword | required |
datatype | positional or keyword | required |
not_null | positional or keyword | 0 |
dflt_value | positional or keyword | None |
primary_key | positional or keyword | 0 |
autoincrement | positional or keyword | 0 |
NewColumn.__repr__(self)
Source line 271
No caller-supplied parameters are declared.
NewColumn.statement(self)
Source line 277
No caller-supplied parameters are declared.
NewColumn.int_primary_key()
Source line 288
No caller-supplied parameters are declared.
class Column
Source line 291
Construct: Column(table, cid, name, datatype, not_null=0, dflt_value=None, primary_key=0)
Fields assigned by the constructor: default_value, id, name, not_null, primary_key, table, type. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
Column.__init__— methodColumn.__repr__— methodColumn.__str__— methodColumn.__eq__— methodColumn.from_row— methodColumn.is_int_primary_key— propertyColumn.new_column— method
Column.__init__(self, table, cid, name, datatype, not_null=0, dflt_value=None, primary_key=0)
Source line 292
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | required |
cid | positional or keyword | required |
name | positional or keyword | required |
datatype | positional or keyword | required |
not_null | positional or keyword | 0 |
dflt_value | positional or keyword | None |
primary_key | positional or keyword | 0 |
Column.__repr__(self)
Source line 300
No caller-supplied parameters are declared.
Column.__str__(self)
Source line 306
No caller-supplied parameters are declared.
Column.__eq__(self, other)
Source line 308
| Parameter | Passing convention | Default / required |
|---|---|---|
other | positional or keyword | required |
Column.from_row(table, i)
Source line 315
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | required |
i | positional or keyword | required |
Column.is_int_primary_key(self)
Source line 325
Decorators: @property
No caller-supplied parameters are declared.
Column.new_column(self)
Source line 327
No caller-supplied parameters are declared.
class AsyncProperty
Source line 363
Construct: AsyncProperty(func)
Fields assigned by the constructor: coro, func. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
AsyncProperty.__init__— methodAsyncProperty.__await__— methodAsyncProperty.__get__— method
AsyncProperty.__init__(self, func)
Source line 364
| Parameter | Passing convention | Default / required |
|---|---|---|
func | positional or keyword | required |
AsyncProperty.__await__(self)
Source line 367
No caller-supplied parameters are declared.
AsyncProperty.__get__(self, instance, owner)
Source line 369
| Parameter | Passing convention | Default / required |
|---|---|---|
instance | positional or keyword | required |
owner | positional or keyword | required |
class Pragmas
Source line 373
Construct: Pragmas(db, await_timeout=5)
Fields assigned by the constructor: await_timeout, db. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
Pragmas.__init__— methodPragmas.size— decorated property (see guide)Pragmas.max_size— decorated property (see guide)Pragmas.__getitem__— async methodPragmas.__setitem__— methodPragmas.set— async methodPragmas.__await__— method
Pragmas.__init__(self, db, await_timeout=5)
Source line 374
| Parameter | Passing convention | Default / required |
|---|---|---|
db | positional or keyword | required |
await_timeout | positional or keyword | 5 |
async Pragmas.size(self)
Source line 380
Decorators: @AsyncProperty
No caller-supplied parameters are declared.
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Pragmas.max_size(self)
Source line 385
Decorators: @AsyncProperty
No caller-supplied parameters are declared.
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Pragmas.__getitem__(self, key)
Source line 389
| Parameter | Passing convention | Default / required |
|---|---|---|
key | positional or keyword | required |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
Pragmas.__setitem__(self, key, value)
Source line 433
| Parameter | Passing convention | Default / required |
|---|---|---|
key | positional or keyword | required |
value | positional or keyword | required |
async Pragmas.set(self, key, value)
Source line 473
| Parameter | Passing convention | Default / required |
|---|---|---|
key | positional or keyword | required |
value | positional or keyword | required |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
Pragmas.__await__(self)
Source line 475
No caller-supplied parameters are declared.
class Database
Source line 492
Construct: Database(filename, **kwargs)
Fields assigned by the constructor: auto_commit_threshold, auto_vacuum_threshold, conn, connected, filename, table, total_changes. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
Database.__init__— methodDatabase.get_connection— async methodDatabase.pragmas— propertyDatabase.row_factory— propertyDatabase.row_factory— property setterDatabase.col_exists— async methodDatabase.select_all— async methodDatabase.select— async methodDatabase.get_table— async methodDatabase.set_table— async methodDatabase.tables— async methodDatabase.indexes— async methodDatabase.create_index— async methodDatabase.update— async methodDatabase.insert— async methodDatabase.columns— async methodDatabase.add_column— async methodDatabase.remove_column— async methodDatabase.create_table— async methodDatabase.drop_table— async methodDatabase.delete— async methodDatabase.commit— async methodDatabase.cursor— async methodDatabase.execute— async methodDatabase.vacuum— async methodDatabase.in_transaction— propertyDatabase.close— async methodDatabase.to_csv— async methodDatabase.to_html— async methodDatabase.to_dict— async methodDatabase.request_pagination— async method
Database.__init__(self, filename, **kwargs)
Source line 493
Represents sqlite db. table - Table to set as default on initialization. auto_vacuum_threshold - amt of net removed rows for auto vacuum to happen. auto_commit_threshold - amt of rows to wait for changes to before auto committing.
| Parameter | Passing convention | Default / required |
|---|---|---|
filename | positional or keyword | required |
kwargs | extra keyword arguments (**kwargs) | optional collection |
async Database.get_connection(self)
Source line 546
No caller-supplied parameters are declared.
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
Database.pragmas(self)
Source line 561
Decorators: @property
No caller-supplied parameters are declared.
Database.row_factory(self)
Source line 569
Decorators: @property
No caller-supplied parameters are declared.
Database.row_factory(self, value)
Source line 572
Decorators: @row_factory.setter
| Parameter | Passing convention | Default / required |
|---|---|---|
value | positional or keyword | required |
async Database.col_exists(self, col_name, table)
Source line 580
| Parameter | Passing convention | Default / required |
|---|---|---|
col_name | positional or keyword | required |
table | positional or keyword | required |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.select_all(self, columns='*', dict_mode=True, table=None, limit=None)
Source line 611
| Parameter | Passing convention | Default / required |
|---|---|---|
columns | positional or keyword | '*' |
dict_mode | positional or keyword | True |
table | positional or keyword | None |
limit | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.select(self, select, orderDict=None, op_and=True, limit=None, case_insensitive=False, columns='*', count=False, dict_mode=True, table=None)
Source line 654
| Parameter | Passing convention | Default / required |
|---|---|---|
select | positional or keyword | required |
orderDict | positional or keyword | None |
op_and | positional or keyword | True |
limit | positional or keyword | None |
case_insensitive | positional or keyword | False |
columns | positional or keyword | '*' |
count | positional or keyword | False |
dict_mode | positional or keyword | True |
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.get_table(self, table=None)
Source line 810
Get a table from its name.
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.set_table(self, table=None)
Source line 817
Sets the default table to perform commands on. If table is not provided, it sets table to the first table in the database.
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.tables(self)
Source line 832
No caller-supplied parameters are declared.
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.indexes(self)
Source line 851
No caller-supplied parameters are declared.
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.create_index(self, index_name, table, columns, unique=False)
Source line 861
Creates an index on the specified table and columns.
Args:
index_name: Name of the index to create
table: Table name or Table object
columns: List of column names to index
unique: If True, create a unique index
| Parameter | Passing convention | Default / required |
|---|---|---|
index_name | positional or keyword | required |
table | positional or keyword | required |
columns | positional or keyword | required |
unique | positional or keyword | False |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.update(self, update, where, op_and=True, table=None)
Source line 894
| Parameter | Passing convention | Default / required |
|---|---|---|
update | positional or keyword | required |
where | positional or keyword | required |
op_and | positional or keyword | True |
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.insert(self, insert, table=None)
Source line 1015
| Parameter | Passing convention | Default / required |
|---|---|---|
insert | positional or keyword | required |
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.columns(self, table=None)
Source line 1091
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.add_column(self, column, table=None)
Source line 1116
| Parameter | Passing convention | Default / required |
|---|---|---|
column | positional or keyword | required |
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.remove_column(self, column_name, table=None)
Source line 1139
Removes a column from the specified table. This is a workaround since SQLite does not support dropping columns directly.
| Parameter | Passing convention | Default / required |
|---|---|---|
column_name | positional or keyword | required |
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.create_table(self, table, columns=(NewColumn('id', 'INTEGER', not_null=1, primary_key=1, autoincrement=1),))
Source line 1183
Creates a new table.
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | required |
columns | positional or keyword | (NewColumn('id', 'INTEGER', not_null=1, primary_key=1, autoincrement=1),) |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.drop_table(self, table=None)
Source line 1218
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.delete(self, delete, op_and=True, table=None)
Source line 1238
Deletes the selected rows in the selected table. delete and op_and have same purpose in this case as in `Database.select` table - Uses default table if not set.
| Parameter | Passing convention | Default / required |
|---|---|---|
delete | positional or keyword | required |
op_and | positional or keyword | True |
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.commit(self)
Source line 1340
Commits changes.
No caller-supplied parameters are declared.
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.cursor(self)
Source line 1347
Creates a cursor.
No caller-supplied parameters are declared.
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.execute(self, query, parameters=None)
Source line 1353
Executes a command.
| Parameter | Passing convention | Default / required |
|---|---|---|
query | positional or keyword | required |
parameters | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.vacuum(self, to_file=None)
Source line 1361
Vacuums the database, making the file smaller. to_file - If set to the path to a new file, it will create a new, vacuumed version of this database seperate from the current database.
| Parameter | Passing convention | Default / required |
|---|---|---|
to_file | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
Database.in_transaction(self)
Source line 1381
Decorators: @property
Whether connection is in a transaction
No caller-supplied parameters are declared.
async Database.close(self)
Source line 1387
Closes the connection if one exists. Will commit if in transaction.
No caller-supplied parameters are declared.
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.to_csv(self, table=None)
Source line 1397
Converts selected table to csv.
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.to_html(self, table=None, max_len=100, condensed=True, row_range=None, to_body_top='', to_body_bottom='', to_head='', own_rows=None, table_only=False)
Source line 1436
Convert a table to html representation. max_len - integer determining the max length of the text displayed in each row condensed - True means txt is minimized, while False would result in more formatted and indented html row_range - If set to a range object, it will only display rows selected by that range to_body_top - String to be included at top of <body> in the html to_body_bottom - String to be included at bottom of <body> in the html to_head - String to be included in the <head> of the html table_only - If True, will not include the name of the table as a heading
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | None |
max_len | positional or keyword | 100 |
condensed | positional or keyword | True |
row_range | positional or keyword | None |
to_body_top | positional or keyword | '' |
to_body_bottom | positional or keyword | '' |
to_head | positional or keyword | '' |
own_rows | positional or keyword | None |
table_only | positional or keyword | False |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.to_dict(self, table=None, dict_mode=True)
Source line 1579
Convert database to a dictionary. If table is not specified, then the dict includes all tables as seperate keys. if `dict_mode` is True, then the rows will be added as dictionaries. If not, they will be added as lists.
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | None |
dict_mode | positional or keyword | True |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Database.request_pagination(self, request, per_page=50, max_len=100, table=None, own_rows=None)
Source line 1610
| Parameter | Passing convention | Default / required |
|---|---|---|
request | positional or keyword | required |
per_page | positional or keyword | 50 |
max_len | positional or keyword | 100 |
table | positional or keyword | None |
own_rows | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
class Table
Source line 1709
Represents a table in a database.
Construct: Table(r, db)
Fields assigned by the constructor: db, name, rootpage, sql, tbl_name. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
Table.__init__— methodTable.row_count— async methodTable.columns— async methodTable.__eq__— methodTable.__int__— methodTable.__str__— methodTable.__repr__— method
Table.__init__(self, r, db)
Source line 1711
| Parameter | Passing convention | Default / required |
|---|---|---|
r | positional or keyword | required |
db | positional or keyword | required |
async Table.row_count(self, distinct=None)
Source line 1722
Get amount of rows in table. Can set distinct to the name of a column for it to only count rows where that columns value is unique.
| Parameter | Passing convention | Default / required |
|---|---|---|
distinct | positional or keyword | None |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
async Table.columns(self)
Source line 1733
`Column`s in this table
No caller-supplied parameters are declared.
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
Table.__eq__(self, other)
Source line 1736
| Parameter | Passing convention | Default / required |
|---|---|---|
other | positional or keyword | required |
Table.__int__(self)
Source line 1743
No caller-supplied parameters are declared.
Table.__str__(self)
Source line 1745
No caller-supplied parameters are declared.
Table.__repr__(self)
Source line 1747
No caller-supplied parameters are declared.
class TableManager
Source line 1755
Construct: TableManager(db, name)
Fields assigned by the constructor: db, name. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
TableManager.__init__— methodTableManager.add_column— methodTableManager.get_column— methodTableManager.initialize— async method
TableManager.__init__(self, db, name)
Source line 1756
| Parameter | Passing convention | Default / required |
|---|---|---|
db | positional or keyword | required |
name | positional or keyword | required |
TableManager.add_column(self, name, datatype, not_null=0, dflt_value=None, primary_key=0, autoincrement=0, matches=[])
Source line 1760
| Parameter | Passing convention | Default / required |
|---|---|---|
name | positional or keyword | required |
datatype | positional or keyword | required |
not_null | positional or keyword | 0 |
dflt_value | positional or keyword | None |
primary_key | positional or keyword | 0 |
autoincrement | positional or keyword | 0 |
matches | positional or keyword | [] |
TableManager.get_column(self, name)
Source line 1766
| Parameter | Passing convention | Default / required |
|---|---|---|
name | positional or keyword | required |
async TableManager.initialize(self, dbm, override=False)
Source line 1770
| Parameter | Passing convention | Default / required |
|---|---|---|
dbm | positional or keyword | required |
override | positional or keyword | False |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
class DatabaseManager
Source line 1803
Construct: DatabaseManager(db, verbose=False)
Fields assigned by the constructor: db, verbose. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
DatabaseManager.__init__— methodDatabaseManager.add_table— methodDatabaseManager.get_table— methodDatabaseManager.add_index— methodDatabaseManager.initialize— async method
DatabaseManager.__init__(self, db, verbose=False)
Source line 1804
| Parameter | Passing convention | Default / required |
|---|---|---|
db | positional or keyword | required |
verbose | positional or keyword | False |
DatabaseManager.add_table(self, name)
Source line 1809
| Parameter | Passing convention | Default / required |
|---|---|---|
name | positional or keyword | required |
DatabaseManager.get_table(self, name)
Source line 1813
| Parameter | Passing convention | Default / required |
|---|---|---|
name | positional or keyword | required |
DatabaseManager.add_index(self, table, column_names, index_name=None, unique=False)
Source line 1817
| Parameter | Passing convention | Default / required |
|---|---|---|
table | positional or keyword | required |
column_names | positional or keyword | required |
index_name | positional or keyword | None |
unique | positional or keyword | False |
async DatabaseManager.initialize(self, override=False)
Source line 1833
| Parameter | Passing convention | Default / required |
|---|---|---|
override | positional or keyword | False |
Declared with async def. Normal calls return an awaitable, or an async generator if the body yields. Decorated properties may be accessed differently; follow the object guide.
class Version
Source line 1872
Construct: Version(v_str)
Fields assigned by the constructor: extra, major, minor, patch, raw, short. Some assignments may be conditional; see the object guide for meaning and lifecycle.
Declared functions, properties, and nested objects:
Version.__init__— methodVersion.__lt__— methodVersion.__gt__— methodVersion.__eq__— methodVersion.__str__— methodVersion.__repr__— method
Version.__init__(self, v_str)
Source line 1873
| Parameter | Passing convention | Default / required |
|---|---|---|
v_str | positional or keyword | required |
Version.__lt__(self, other)
Source line 1909
| Parameter | Passing convention | Default / required |
|---|---|---|
other | positional or keyword | required |
Version.__gt__(self, other)
Source line 1923
| Parameter | Passing convention | Default / required |
|---|---|---|
other | positional or keyword | required |
Version.__eq__(self, other: object) -> bool
Source line 1925
| Parameter | Passing convention | Default / required |
|---|---|---|
other: object | positional or keyword | required |
Return annotation: bool.
Version.__str__(self)
Source line 1930
No caller-supplied parameters are declared.
Version.__repr__(self)
Source line 1932
No caller-supplied parameters are declared.