aiosqliteObj.py

Version 1.2.9 · Source: modules/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 APIReturn 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.

ObjectConstruction / important attributesMethods and results
DatabaseDatabase(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.
TableNormally 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.
ColumnRead 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.
NewColumnYour 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.
IndexUsually 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.
DatabaseManagerDatabaseManager(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.
TableManagerReturned 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

class TableNotSet(Exception)

Source line 66

Exception raised when a table is not set.

Construct: TableNotSet()

Declared functions, properties, and nested objects:

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__(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__(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__(self, given, table)

Source line 80

ParameterPassing conventionDefault / required
givenpositional or keywordrequired
tablepositional or keywordrequired
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__(self, table)

Source line 84

ParameterPassing conventionDefault / required
tablepositional or keywordrequired
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__(self, query, trc)

Source line 88

ParameterPassing conventionDefault / required
querypositional or keywordrequired
trcpositional or keywordrequired
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__(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__(self, value1, value2)

Source line 146

ParameterPassing conventionDefault / required
value1positional or keywordrequired
value2positional or keywordrequired
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__(self, value)

Source line 150

ParameterPassing conventionDefault / required
valuepositional or keywordrequired
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__(self, value)

Source line 153

ParameterPassing conventionDefault / required
valuepositional or keywordrequired
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__(self, value)

Source line 156

ParameterPassing conventionDefault / required
valuepositional or keywordrequired
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__(self, value)

Source line 159

ParameterPassing conventionDefault / required
valuepositional or keywordrequired
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:

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__(self, name, tbl_name, sql, db)

Source line 223

ParameterPassing conventionDefault / required
namepositional or keywordrequired
tbl_namepositional or keywordrequired
sqlpositional or keywordrequired
dbpositional or keywordrequired
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

ParameterPassing conventionDefault / required
otherpositional or keywordrequired
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__(self, name, datatype, not_null=0, dflt_value=None, primary_key=0, autoincrement=0)

Source line 264

ParameterPassing conventionDefault / required
namepositional or keywordrequired
datatypepositional or keywordrequired
not_nullpositional or keyword0
dflt_valuepositional or keywordNone
primary_keypositional or keyword0
autoincrementpositional or keyword0
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__(self, table, cid, name, datatype, not_null=0, dflt_value=None, primary_key=0)

Source line 292

ParameterPassing conventionDefault / required
tablepositional or keywordrequired
cidpositional or keywordrequired
namepositional or keywordrequired
datatypepositional or keywordrequired
not_nullpositional or keyword0
dflt_valuepositional or keywordNone
primary_keypositional or keyword0
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

ParameterPassing conventionDefault / required
otherpositional or keywordrequired
Column.from_row(table, i)

Source line 315

ParameterPassing conventionDefault / required
tablepositional or keywordrequired
ipositional or keywordrequired
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__(self, func)

Source line 364

ParameterPassing conventionDefault / required
funcpositional or keywordrequired
AsyncProperty.__await__(self)

Source line 367

No caller-supplied parameters are declared.

AsyncProperty.__get__(self, instance, owner)

Source line 369

ParameterPassing conventionDefault / required
instancepositional or keywordrequired
ownerpositional or keywordrequired
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__(self, db, await_timeout=5)

Source line 374

ParameterPassing conventionDefault / required
dbpositional or keywordrequired
await_timeoutpositional or keyword5
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

ParameterPassing conventionDefault / required
keypositional or keywordrequired

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

ParameterPassing conventionDefault / required
keypositional or keywordrequired
valuepositional or keywordrequired
async Pragmas.set(self, key, value)

Source line 473

ParameterPassing conventionDefault / required
keypositional or keywordrequired
valuepositional or keywordrequired

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__(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.
ParameterPassing conventionDefault / required
filenamepositional or keywordrequired
kwargsextra 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

ParameterPassing conventionDefault / required
valuepositional or keywordrequired
async Database.col_exists(self, col_name, table)

Source line 580

ParameterPassing conventionDefault / required
col_namepositional or keywordrequired
tablepositional or keywordrequired

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

ParameterPassing conventionDefault / required
columnspositional or keyword'*'
dict_modepositional or keywordTrue
tablepositional or keywordNone
limitpositional or keywordNone

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

ParameterPassing conventionDefault / required
selectpositional or keywordrequired
orderDictpositional or keywordNone
op_andpositional or keywordTrue
limitpositional or keywordNone
case_insensitivepositional or keywordFalse
columnspositional or keyword'*'
countpositional or keywordFalse
dict_modepositional or keywordTrue
tablepositional or keywordNone

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.
ParameterPassing conventionDefault / required
tablepositional or keywordNone

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.
ParameterPassing conventionDefault / required
tablepositional or keywordNone

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
ParameterPassing conventionDefault / required
index_namepositional or keywordrequired
tablepositional or keywordrequired
columnspositional or keywordrequired
uniquepositional or keywordFalse

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

ParameterPassing conventionDefault / required
updatepositional or keywordrequired
wherepositional or keywordrequired
op_andpositional or keywordTrue
tablepositional or keywordNone

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

ParameterPassing conventionDefault / required
insertpositional or keywordrequired
tablepositional or keywordNone

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

ParameterPassing conventionDefault / required
tablepositional or keywordNone

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

ParameterPassing conventionDefault / required
columnpositional or keywordrequired
tablepositional or keywordNone

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.
ParameterPassing conventionDefault / required
column_namepositional or keywordrequired
tablepositional or keywordNone

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.
ParameterPassing conventionDefault / required
tablepositional or keywordrequired
columnspositional 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

ParameterPassing conventionDefault / required
tablepositional or keywordNone

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.
ParameterPassing conventionDefault / required
deletepositional or keywordrequired
op_andpositional or keywordTrue
tablepositional or keywordNone

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.
ParameterPassing conventionDefault / required
querypositional or keywordrequired
parameterspositional or keywordNone

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.
ParameterPassing conventionDefault / required
to_filepositional or keywordNone

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.
ParameterPassing conventionDefault / required
tablepositional or keywordNone

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
ParameterPassing conventionDefault / required
tablepositional or keywordNone
max_lenpositional or keyword100
condensedpositional or keywordTrue
row_rangepositional or keywordNone
to_body_toppositional or keyword''
to_body_bottompositional or keyword''
to_headpositional or keyword''
own_rowspositional or keywordNone
table_onlypositional or keywordFalse

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.
ParameterPassing conventionDefault / required
tablepositional or keywordNone
dict_modepositional or keywordTrue

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

ParameterPassing conventionDefault / required
requestpositional or keywordrequired
per_pagepositional or keyword50
max_lenpositional or keyword100
tablepositional or keywordNone
own_rowspositional or keywordNone

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__(self, r, db)

Source line 1711

ParameterPassing conventionDefault / required
rpositional or keywordrequired
dbpositional or keywordrequired
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.
ParameterPassing conventionDefault / required
distinctpositional or keywordNone

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

ParameterPassing conventionDefault / required
otherpositional or keywordrequired
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__(self, db, name)

Source line 1756

ParameterPassing conventionDefault / required
dbpositional or keywordrequired
namepositional or keywordrequired
TableManager.add_column(self, name, datatype, not_null=0, dflt_value=None, primary_key=0, autoincrement=0, matches=[])

Source line 1760

ParameterPassing conventionDefault / required
namepositional or keywordrequired
datatypepositional or keywordrequired
not_nullpositional or keyword0
dflt_valuepositional or keywordNone
primary_keypositional or keyword0
autoincrementpositional or keyword0
matchespositional or keyword[]
TableManager.get_column(self, name)

Source line 1766

ParameterPassing conventionDefault / required
namepositional or keywordrequired
async TableManager.initialize(self, dbm, override=False)

Source line 1770

ParameterPassing conventionDefault / required
dbmpositional or keywordrequired
overridepositional or keywordFalse

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__(self, db, verbose=False)

Source line 1804

ParameterPassing conventionDefault / required
dbpositional or keywordrequired
verbosepositional or keywordFalse
DatabaseManager.add_table(self, name)

Source line 1809

ParameterPassing conventionDefault / required
namepositional or keywordrequired
DatabaseManager.get_table(self, name)

Source line 1813

ParameterPassing conventionDefault / required
namepositional or keywordrequired
DatabaseManager.add_index(self, table, column_names, index_name=None, unique=False)

Source line 1817

ParameterPassing conventionDefault / required
tablepositional or keywordrequired
column_namespositional or keywordrequired
index_namepositional or keywordNone
uniquepositional or keywordFalse
async DatabaseManager.initialize(self, override=False)

Source line 1833

ParameterPassing conventionDefault / required
overridepositional or keywordFalse

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__(self, v_str)

Source line 1873

ParameterPassing conventionDefault / required
v_strpositional or keywordrequired
Version.__lt__(self, other)

Source line 1909

ParameterPassing conventionDefault / required
otherpositional or keywordrequired
Version.__gt__(self, other)

Source line 1923

ParameterPassing conventionDefault / required
otherpositional or keywordrequired
Version.__eq__(self, other: object) -> bool

Source line 1925

ParameterPassing conventionDefault / required
other: objectpositional or keywordrequired

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.