sql.sqlite.schema
import sql.sqlite.schema
sqldoes not re-export this module, so it is reached only by importing it directly.
Introspection for SQLite, which answers through pragmas rather than through catalogue tables.
PRAGMA table_info, index_list, index_info and foreign_key_list
are functions that return result sets, so each of these is an ordinary
query. The one catalogue table SQLite does have, sqlite_master, is
where the list of tables comes from.
SQLite has no schemas. It has attached databases, which the schema
argument here names: nil and 'main' both mean the database the
connection opened, and 'temp' holds temporary tables.
Classes
SqliteSchema
class sql.sqlite.schema.SqliteSchema < SchemaAdapter
Answers introspection questions about a SQLite database.
Constructor
sql.sqlite.schema.SqliteSchema(connection)
Parameters
connection(SqliteConnection)
SqliteSchema.tables()
sql.sqlite.schema.SqliteSchema.tables(schema) -> list[string]
The tables the application created.
SQLite keeps its own bookkeeping in tables whose names begin with
sqlite_, so those are left out.
Parameters
schema(string|nil) — An attached database name.
Returns list[string]
SqliteSchema.views()
sql.sqlite.schema.SqliteSchema.views(schema) -> list[string]
The views.
Parameters
schema(string|nil)
Returns list[string]
SqliteSchema.columns()
sql.sqlite.schema.SqliteSchema.columns(table: string, schema) -> list[dict]
The columns of table, in declaration order.
Parameters
table(string)schema(string|nil)
Returns list[dict]
SqliteSchema.primary_key_columns()
sql.sqlite.schema.SqliteSchema.primary_key_columns(table: string, schema) -> list[string]
The primary key columns, in key order.
table_info reports each key column’s position within the key, so a
composite key comes back in the order it was declared rather than in
column order.
Parameters
table(string)schema(string|nil)
Returns list[string]
SqliteSchema.indexes()
sql.sqlite.schema.SqliteSchema.indexes(table: string, schema) -> list[dict]
The indexes on table.
The implicit index behind a column’s UNIQUE or PRIMARY KEY
declaration is included, as SQLite reports it, since it is a real index
and constrains the table the same way a named one does.
Parameters
table(string)schema(string|nil)
Returns list[dict]
SqliteSchema.foreign_keys()
sql.sqlite.schema.SqliteSchema.foreign_keys(table: string, schema) -> list[dict]
The foreign keys declared on table.
A key spanning several columns is reported by SQLite as one row per column sharing an id, so the rows are gathered back into one entry per key.
Parameters
table(string)schema(string|nil)
Returns list[dict]
2026, Richard Ore and Zuri contributors