jQl, see the dedicated jQL reference.
| Argument | Type | Required |
|---|---|---|
name | string | Yes |
version | number | Yes |
Returns a builder with .open(config), plus .isClientMode() and
.requiresLogin() for opting into those modes before opening.
jdb('myapp', 1)
.open({ storage: 'indexeddb' })
.onCreate(function (e, next) {
e.result.createTbl('users', [{ id: { type: 'NUMBER', AUTO_INCREMENT: 1 }, name: { type: 'VARCHAR' } }]);
next();
})
.onUpgrade(function (e, next) {
next();
})
.onSuccess(function (e) {
var db = e.result; // DatabaseInstance
})
.onError(function (e) {
console.error(e.message);
});
onCreate fires the first time a database is opened; onUpgrade
fires when an existing database is opened with a higher version. Both receive
next() to call once setup is done. onSuccess/onError
(or .then(success, error)) resolve with { result, message, type },
where result is the DatabaseInstance you'll use for everything
else.
| Key | Type | Default | Notes |
|---|---|---|---|
storage | string | memory | memory, localstorage, sessionStorage, indexeddb, sql or flatfile. |
live | boolean | false | Auto-sync writes to serviceHost as they happen. |
serviceHost | string | null | Base URL for server sync/API calls. Also what enables db.clientService. |
interceptor | object | null | Hook called for every outgoing request (e.g. to attach auth headers). |
$ajax | null | Custom transport, replacing the built-in XHR wrapper. | |
schemaPath | string | null | Local or remote path to load table schemas from. |
useFrontendOnlySchema | false | true, or { loadData, maximumRetries, ttl }. | |
alwaysCheckSchema | boolean | false | Development-only: re-check schema on every open. |
ignoreSync | boolean | false | Also accepts an array of table names to exclude from syncing. |
enableSocket | boolean | false | Use WebSockets for realtime updates. |
waitApiToLoad | boolean | true | Block opening until custom API mappings resolve. |
key | string | null | Encryption key. |
Marks the connection as client-facing (production) before .open(), disabling
debugging affordances.
jdb('myapp', 1).isClientMode().open({ storage: 'indexeddb' });
Opens in a restricted login mode: the resolved instance only exposes api(),
close() and jQl() until the app authenticates and re-opens
normally.
jdb('myapp', 1).requiresLogin().open({ serviceHost: 'https://api.example.com' });
.open() returns a jDB Promise: .onSuccess(fn),
.onError(fn), .then(success, error), .catch(fn) and
.finally(fn), plus the .onCreate/.onUpgrade event
hooks shown above. Most instance methods (transaction, jQl,
batchTransaction, storeProc().execute) return standard native
Promises instead — check the signature on each method below.
| Argument | Type | Required | Notes |
|---|---|---|---|
name | string | Yes | |
columns | array | No | Array of column definition objects. |
additionalConfig | object | No | Merged onto the table's internal definition (e.g. alias, policies). |
ignoreInstance | boolean | No | Skip building a TableInstance and just return the raw response. |
db.createTbl('users', [{
id: { type: 'NUMBER', AUTO_INCREMENT: 1 },
email: { type: 'VARCHAR' }
}]);
Looks up an existing table. See Table instance below.
| Argument | Type | Notes |
|---|---|---|
table | string | array | A table name, or ["a as x", "b as y"] for a multi-table (join) transaction. |
mode | string | read (default), write/writeonly, or readwrite. |
Read-mode transactions expose select/qsl; write-mode transactions
expose insert/insertReplace/update/delete.
See Transaction instance below.
db.transaction('users', 'writeonly')
.insert({ name: 'Ada' })
.execute()
.then(res => console.log(res));
Runs a query in jDB's own query language. Full syntax, every command, and the field-type system live on the jQL reference page.
| Argument | Type | Notes |
|---|---|---|
transactions | array | Array of { type, data, query, table, hardInsert }, where type is insert, update or delete. |
rollBackOnError | boolean | Default false. |
db.batchTransaction([
{ type: 'insert', table: 'users', data: { name: 'Ada' } },
{ type: 'update', table: 'users', query: { id: 1 }, data: { role: 'admin' } }
], true);
| Argument | Type | Default | Notes |
|---|---|---|---|
table | string | — | "all" for every table. |
type | string | csv | csv, html, jql or json. |
title | string | — |
db.export('users', 'json').initialize();
| Argument | Type | Notes |
|---|---|---|
table | string | Target table for a data-only (non-schema) import. |
isSchema | boolean | Default true. |
handler | object | { logService, onselect }. |
db.import('users', false).selectFile()
.then(res => console.log(res.result.message));
| Key | Type | Notes |
|---|---|---|
table | string | |
force | boolean | |
syncData |
Pushes every table's pending (unsynced) changes to the configured serviceHost
in one request. Resolves immediately with { message: 'Nothing to Sync' } if
there's nothing pending.
| Method | Notes |
|---|---|
.export({ version, server }) | Generates and downloads a versioned JSON schema snapshot, from the server if server is truthy, otherwise from local storage. |
.add({ schemaData }) | Applies a schema definition (create/alter/crud) to the database. |
.getTableModel(tableName, replacerData) | Returns a blank record shaped to the table's columns, with any matching keys from replacerData filled in. |
| Member | Notes |
|---|---|
.logger() | Returns the registered logger resolver. |
.resource() | Returns the database's resource manager snapshot (tables, sync state). |
.usage() | Returns approximate storage usage, formatted as a string (e.g. "12.40 KB"). |
.dataTypes | Getter — the registered column data-type validators. |
.requestMapping | Getter — custom API route mappings for this database. |
| Method | Notes |
|---|---|
.getByRef(tbl, query) | Fetch a single record by reference. |
.getAll(tbl, query, byQueryId) | Fetch every matching record. |
.getOne(tbl, query) | Fetch a single matching record. |
.query(query, replacer, cacheOptions) | Run a server-side query built with QueryBuilder syntax. |
.fetch(query, replacer, cacheOptions) | Like .query, against the fetch endpoint. |
.getNumRows(param, tbl) | Row count for a table. |
.push(tbl, type, data) | Push a local change to the server outside the normal sync cycle. |
| Method | Notes |
|---|---|
.create(name, query) | Registers a jQL query string under name. |
.remove(name) | |
.execute(name, params) → Promise | Runs the registered query, substituting params into any %key% placeholders. |
const proc = db.storeProc();
proc.create('activeAdmins', 'select -* -users -where(role~admin)');
proc.execute('activeAdmins').then(res => console.log(res.getResult()));
| Method | Notes |
|---|---|
.info() | Returns an array describing every table: records, columns, keys, policies, last modified. |
.close(flag) | Closes the database connection; truthy flag also drops it. |
.rename(newName) → Promise | Renames the database, syncing the rename to the server first if it's ever been synced. |
.truncate(syncToServer) → Promise | Empties every table. |
.drop(flag, db, localOnly) | Drops a database; requires a truthy flag. |
.onUpdate(realtimeConfig) | Returns a realtime connector for subscribing to live change events. |
.getConnector(name, config) | Generic connector factory (used internally by sync/onUpdate). |
.api(path, data) → Promise | Calls a registered REST endpoint. path is a route string or a full request descriptor object. |
| Member | Notes |
|---|---|
.columns | Getter — a deep copy of the table's column definitions. |
.getModel(data) | Maps data onto the table's record shape. |
.update(tableData) | Merges tableData onto the table's internal definition. |
.rename(newName) | Renames the table. |
.truncate(flag) | Empties the table; requires a truthy flag. |
.drop(flag) | Drops the table; requires a truthy flag. |
| Method | Notes |
|---|---|
.add.column(name, config) | Adds a column. name can also be an object of { columnName: config } pairs. |
.add.primary(key) | Marks a column as the primary key. |
.add.foreign(key, tableName) | Adds a foreign key relationship. |
.add.index(name, setting) | Adds/updates an index. |
.add.mode(mode) | Grants an additional allowed access mode. |
.drop(columnName) | Drops a column from the table and every existing row. |
.rename(oldName, newName) | Renames a column. |
db.table('users').alter.add.column('fullName', { type: 'VARCHAR', defaultValue: 'Foo Bar' });
db.table('users').alter.drop('fullName');
Write-mode only. data is an object or array of objects.
hardInsert bypasses soft-insert de-duplication.
Upserts by updateRef (defaults to the table's primary key).
updateRecords is an array of [condition, data] pairs — one
update per pair.
query is a condition object; omit it to delete every row.
Read-mode only. definition is { where, join, limit, orderBy, groupBy,
... } — the same shape jQl's select command builds
internally from its clause syntax.
Quick Search Language: returns dynamically generated findBy<Column>(value,
fields) finders for every column on a single-table transaction, or
findByColumn(columnName, value, fields) for a multi-table one.
db.transaction('users').qsl().findByEmail('ada@example.com');
Runs every queued operation on the transaction (insert/update/delete/select calls can be
chained before calling .execute() once). Also available:
.dataProcessing(boolean) to toggle validation/default-value generation before
inserting.