Documentation/SQLiteDatabase
classWORKER

SQLiteDatabase

js/foo_uie_jsplitter.js:4097

SQLite database returned by utils.OpenDatabase.
All operations are synchronous. Use a Worker for large imports, maintenance, or expensive queries when blocking the panel UI would be undesirable.
Parameter arrays are positional and must contain exactly as many values as the SQL statement requires. Booleans are stored as SQLite integers 0/1. Query results map SQLite NULL to null, INTEGER/REAL to number, TEXT to string, and BLOB to Uint8Array.
Database operations report SQL, binding, transaction-state, and closed-handle errors as JavaScript exceptions. Close is idempotent and does not throw.

propertyWORKERreadonly

IsOpen

js/foo_uie_jsplitter.js:4213
IsOpen: boolean = false

Indicates whether the database is open.

methodWORKER

Begin

js/foo_uie_jsplitter.js:4118
Begin()

Starts a deferred transaction by executing BEGIN TRANSACTION.

Throws

Error —

If a SQLite/database error occurs, including when the database is closed or the transaction cannot be started.

Example

try {
    db.Exec('CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY, name TEXT)');
    db.Begin();
    db.Exec('INSERT INTO items(name) VALUES (?)', ['Alpha']);
    db.Exec('INSERT INTO items(name) VALUES (?)', ['Beta']);
    db.Commit();
} catch (e) {
    try {
        db.Rollback();
    } catch (rollbackError) {
        console.log(`Rollback failed: ${rollbackError.message}`);
    }
    throw e;
}
methodWORKER

Close

js/foo_uie_jsplitter.js:4109
Close()

Closes the database. Calling Close more than once is allowed.
This method does not throw; any SQLite close status is not exposed to script code.

Returns

boolean —

true after the database has been closed.

methodWORKER

Commit

js/foo_uie_jsplitter.js:4142
Commit()

Commits the current transaction by executing COMMIT.

Throws

Error —

If a SQLite/database error occurs, including when the database is closed or no transaction can be committed.

methodWORKER

Exec

js/foo_uie_jsplitter.js:4158
Exec(sql, parameters)

Executes one or more SQL statements. Result rows, if any, are discarded.
When multiple statements are supplied, parameter values are consumed in SQLite parameter-index order across the statements. The total parameter count must match exactly.

Parameters

NameTypeDescription
sqlstring

SQL text to execute.

parametersoptionalArray<*>

Positional parameter values. Supported element types: null, boolean, number, string, ArrayBuffer, and typed-array views.

Throws

Error —

If an SQL, parameter, binding, or database error occurs, including an invalid parameter array/count or when the database is closed.

Example

db.Exec(
    'CREATE TABLE IF NOT EXISTS items (id INTEGER PRIMARY KEY, name TEXT);' +
    'INSERT INTO items(name) VALUES (?);',
    ['Example']
);
methodWORKER

Prepare

js/foo_uie_jsplitter.js:4197
Prepare(sql)

Prepares exactly one SQL statement for repeated execution. The returned statement owns its native SQLite handle. It is finalized automatically when the JavaScript object is destroyed, so calling Close is not required for normal use. Call Close only when the native statement should be released immediately.

Parameters

NameTypeDescription
sqlstring

SQL statement to prepare.

Returns

SQLiteStatement —

Prepared statement.

Throws

Error —

If the SQL cannot be prepared, the input does not contain exactly one SQL statement, or the database is closed.

Example

const insert = db.Prepare('INSERT INTO items(name, score) VALUES (?, ?)');
insert.Run(['Alpha', 10]);
insert.Run(['Beta', 20]);
methodWORKER

Query

js/foo_uie_jsplitter.js:4176
Query(sql, parameters)

Executes exactly one SQL statement and returns all rows as plain JavaScript objects keyed by column name.
SQLite NULL becomes null, INTEGER/REAL become number, TEXT becomes string, and BLOB becomes Uint8Array. The query must produce unique column names; use SQL aliases when selecting duplicate names.

Parameters

NameTypeDescription
sqlstring

SQL query to execute.

parametersoptionalArray<*>

Positional parameter values. Supported element types: null, boolean, number, string, ArrayBuffer, and typed-array views.

Returns

Array<Object> —

Query rows. Returns an empty array when the query produces no rows.

Throws

Error —

If an SQL, parameter, binding, result-conversion, or database error occurs; multiple SQL statements are supplied; result column names are duplicated; or the database is closed.

Example

const rows = db.Query(
    'SELECT artist, COUNT(*) AS plays FROM history WHERE played_at >= ? GROUP BY artist ORDER BY plays DESC',
    [Date.now() - 30 * 24 * 60 * 60 * 1000]
);
for (const row of rows) {
    console.log(`${row.artist}: ${row.plays}`);
}
methodWORKER

Rollback

js/foo_uie_jsplitter.js:4150
Rollback()

Rolls back the current transaction by executing ROLLBACK.

Throws

Error —

If a SQLite/database error occurs, including when the database is closed or no transaction can be rolled back.