synology_apm_repo.sdk.storage.table module¶
Schema-tolerant SQLite table access: declare the columns a query needs and
whether each is required, and Table.create introspects the real table
(PRAGMA table_info, once per connection). A missing optional column reads back as
None for every row instead of raising no such column, which differs
across connector versions.
- class synology_apm_repo.sdk.storage.table.Column(name, required=True)¶
Bases:
objectOne column a
Tableexpects;required=Falsefor a column only some connector-version schemas have.
- class synology_apm_repo.sdk.storage.table.Table(name, columns)¶
Bases:
objectA schema-tolerant view of one real SQLite table.
Introspects
PRAGMA table_info(name)increate(once per connection, seesqlite.table_columns). A missing required column raisesDataCorruptError; a missing optional one is left out of theSELECTand backfilled asNonein every row.Build with
await Table.create(conn, name, columns), notTable(...): introspection is a query and__init__can’t be async.- Variables:
name – The table name.
columns – The declared
Columns.
- async classmethod create(conn, name, columns, *, index_hints=())¶
Introspect
name’s real schema and return aTablebound toconn.- Parameters:
- Raises:
DataCorruptError – The table is missing or lacks a required column.
- async static exists_in(conn, name)¶
Whether
nameexists with at least one column. Call beforecreatefor a table some repository shapes lack entirely (e.g.file_meta);createraises for a missing table.
- property columns_present: frozenset[str]¶
The table’s actual column set, independent of the declared columns, for callers that pick a column by heuristic because its name varies across repositories.
- async select(where='', params=(), *, order_by=None, limit=None, offset=0)¶
Run
SELECT <present columns> FROM <name> [WHERE <where>] [ORDER BY <order_by>] [LIMIT ? OFFSET ?]and yield each row as{column_name: value}, with every declared-but-absent optional column backfilled asNone.- Parameters:
where (str) – Literal SQL written by the caller, never untrusted input; pass values through
params.params (Sequence[object]) – Values for the
?placeholders inwhere.order_by (str | None) – Literal SQL
ORDER BYfragment.limit (int | None) – Row cap;
Noneis uncapped but still honorsoffset(viaLIMIT -1).offset (int) – Rows to skip.
- async select_one(where='', params=())¶
The first row
select(where, params)yields, orNone.
- synology_apm_repo.sdk.storage.table.as_int(value)¶
Narrow one of
Table.select’sobject | Nonevalues toint.- Raises:
DataCorruptError –
valueis not anint.
- synology_apm_repo.sdk.storage.table.as_str(value)¶
Narrow one of
Table.select’s values tostr.- Raises:
DataCorruptError –
valueis not astr.
- synology_apm_repo.sdk.storage.table.sql_placeholders(n)¶
A comma-joined list of
n"?"placeholders forIN (...).nmust be positive: an emptyIN ()is invalid SQL.