Skip to content

database

const database: {
list: Promise<string[]>;
describe: Promise<DatabaseTableDescription>;
query: Promise<DatabaseQueryResult>;
};

Defined in: domains/database.ts:79

list(): Promise<string[]>;

List the SQLite database files available to the current presentation.

Promise<string[]>

Array of database file path strings.

Returns an empty array outside the Mobile Locker app.

MobileLockerDatabaseError on network failure or server error.

describe(database, table): Promise<DatabaseTableDescription>;

Describe the schema of a table in a SQLite database.

In local development, falls back to sql.js and reads the schema directly from the database file via PRAGMA table_info.

Parameter Type Description
database string Path to the .sqlite file (relative to the presentation root).
table string Name of the table to inspect.

Promise<DatabaseTableDescription>

A DatabaseTableDescription with name, sql, and columns.

MobileLockerDatabaseError with code InvalidPath if the table does not exist.

const schema = await mobilelocker.database.describe('data/products.sqlite', 'products')
console.log(schema.columns.map(c => c.name))
query(
path,
sql,
parameters?): Promise<DatabaseQueryResult>;

Execute a SQL SELECT query against a SQLite database embedded in the presentation.

In local development, falls back to sql.js and fetches the database file directly. Only SELECT statements are permitted — write operations throw WriteNotPermitted.

Parameter Type Default value Description
path string undefined Path to the .sqlite file (relative to the presentation root).
sql string undefined A SQL SELECT statement, optionally with ? or :name placeholders.
parameters Record<string, unknown> | unknown[] [] Positional array or named object of bind parameters.

Promise<DatabaseQueryResult>

A DatabaseQueryResult with rows, rows_affected, and last_insert_row_id.

MobileLockerDatabaseError with codes InvalidPath, WriteNotPermitted, NotReady, QueryFailed, or NotConnected.

const result = await mobilelocker.database.query(
'data/products.sqlite',
'SELECT * FROM products WHERE category = ?',
['widgets']
)
result.rows.forEach(row => console.log(row.name))