Skip to content

Database

Public surface (database): list · describe · query

Failures throw MobileLockerDatabaseError. See Errors for DatabaseErrorCode.

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(
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_id

Named 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(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[]
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)