Database
Public surface (database): list · describe · query
Failures throw MobileLockerDatabaseError. See Errors for DatabaseErrorCode.
List databases
Section titled “List databases”list(): Promise<string[]>// Outside Mobile Locker → []import mobilelocker from '@mobilelocker/javascript-sdk'
const databases = await mobilelocker.database.list()// e.g. ['products.sqlite', 'search/fts.db']Query (SELECT only)
Section titled “Query (SELECT only)”query( path: string, sql: string, parameters?: unknown[] | Record<string, unknown>, // default []): Promise<DatabaseQueryResult>// { rows, rows_affected, last_insert_row_id }Positional parameters:
const result = await mobilelocker.database.query( 'products.sqlite', 'SELECT * FROM products WHERE category = ?', ['widgets'],)// result.rows// result.rows_affected — 0 for SELECT// result.last_insert_row_idNamed parameters (:name placeholders; keys normalized for the host):
const result = await mobilelocker.database.query( 'products.sqlite', 'SELECT * FROM products WHERE category = :category AND approved = :approved', { category: 'oncology', approved: 1 },)In local development, queries fall back to sql.js (loads the file via fetch).
Describe a table
Section titled “Describe a table”describe(database: string, table: string): Promise<DatabaseTableDescription>// { name, sql, columns: DatabaseColumnInfo[] }// columns: { cid, name, type, not_null, default_value, primary_key }const description = await mobilelocker.database.describe('products.sqlite', 'products')// description.name, description.sql, description.columns[]Constraints
Section titled “Constraints”| Rule | Code |
|---|---|
| SELECT only — writes not allowed | WriteNotPermitted (write_not_permitted) |
| Path / table not allowed or missing | InvalidPath (invalid_database_path) |
| DB still copying/opening | NotReady (databases_not_ready) |
| SQL execution failed | QueryFailed (query_failed) |
API reference
Section titled “API reference”- Module:
database - Types:
DatabaseQueryResult,DatabaseTableDescription,DatabaseColumnInfo