Skip to content

bpmn-server / SqliteDocumentStore

Class: SqliteDocumentStore#

An IDocumentStore on a SQLite file (Node's built-in node:sqlite, Node 22.5 or later): no database server, for small installs, demos and desktop use. Several servers may share one file.

One table per collection, (_id TEXT PRIMARY KEY, doc TEXT), the document as JSON. A query's plain equalities (id, name, items.id, ...) narrow the rows in SQL; DocumentQuery then decides, so queries mean exactly what they mean on the in-memory store. Unique indexes are SQLite expression indexes (a document with none of an index's fields is not in it, as on the in-memory store); other indexes are not needed by that pre-filter and are not made. Writes run in BEGIN IMMEDIATE transactions, the file in WAL mode, so one writer at a time and readers never blocked.

database (MongoDB's database name) is ignored: the file is the database.

Implements#

Table of contents#

Constructors#

Properties#

Methods#

Constructors#

constructor#

• new SqliteDocumentStore(filename, options?): SqliteDocumentStore

Parameters#

Name Type Description
filename string the database file (made when missing), or :memory:
options SqliteOptions -

Returns#

SqliteDocumentStore

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:47

Properties#

db#

• Private db: any = null

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:43


tables#

• Private Readonly tables: Set\<string>

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:44


filename#

• Readonly filename: string

the database file (made when missing), or :memory:

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:47


options#

• Private Readonly options: SqliteOptions = {}

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:47

Methods#

open#

▸ open(): any

Returns#

any

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:49


table#

▸ table(collection): string

The collection's table, made on first use.

Parameters#

Name Type
collection string

Returns#

string

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:69


write#

▸ write\<T>(fn): T

Runs fn in a write transaction: all of it, or none.

Type parameters#

Name
T

Parameters#

Name Type
fn () => T

Returns#

T

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:79


prefilter#

▸ prefilter(query): Object

SQL that keeps every row the query may match (a superset), from its plain equalities on strings and numbers at a path of one or two parts; a value that is an array or an object (a date) is kept for DocumentQuery to decide.

Parameters#

Name Type
query StorageQuery

Returns#

Object

Name Type
where string
params any[]

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:98


matching#

▸ matching(collection, query): { _id: string ; doc: any }[]

The rows matching query, in insertion order, as documents.

Parameters#

Name Type
collection string
query StorageQuery

Returns#

{ _id: string ; doc: any }[]

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:120


run#

▸ run(sql, params): any

Parameters#

Name Type
sql string
params any[]

Returns#

any

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:131


find#

▸ find(database, collection, query, projection?, sort?): Promise\<any[]>

Documents of collection matching query, projected and sorted. database names the logical database (MongoDB's db name; ignored by single-database adapters).

Parameters#

Name Type Default value
database string undefined
collection string undefined
query StorageQuery undefined
projection Record\<string, any> null
sort Record\<string, -1 | 1> null

Returns#

Promise\<any[]>

Implementation of#

IDocumentStore.find

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:142


count#

▸ count(database, collection, query): Promise\<number>

How many documents of collection match query. Optional: without it, callers count what find returns.

Parameters#

Name Type
database string
collection string
query StorageQuery

Returns#

Promise\<number>

Implementation of#

IDocumentStore.count

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:147


insert#

▸ insert(database, collection, documents): Promise\<number>

Inserts all of documents, or none: a unique-index conflict throws a DuplicateKeyError; any other failure throws as it is. Returns how many were inserted.

Parameters#

Name Type
database string
collection string
documents any[]

Returns#

Promise\<number>

Implementation of#

IDocumentStore.insert

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:153


update#

▸ update(database, collection, query, update, options?): Promise\<number>

Updates the first document matching query ($set fields, or replaces it); { upsert: true } inserts when none matches. Returns how many were modified.

Parameters#

Name Type
database string
collection string
query StorageQuery
update Record\<string, any>
options Object
options.upsert? boolean

Returns#

Promise\<number>

Implementation of#

IDocumentStore.update

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:164


remove#

▸ remove(database, collection, query): Promise\<{ deletedCount: number }>

Removes every document matching query; returns { deletedCount }.

Parameters#

Name Type
database string
collection string
query StorageQuery

Returns#

Promise\<{ deletedCount: number }>

Implementation of#

IDocumentStore.remove

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:181


createIndex#

▸ createIndex(database, collection, index, options?): Promise\<string>

Declares an index; { unique: true } makes insert refuse a second document with the same values. Idempotent.

Parameters#

Name Type
database string
collection string
index Record\<string, -1 | 1>
options Object
options.unique? boolean

Returns#

Promise\<string>

Implementation of#

IDocumentStore.createIndex

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:193


close#

▸ close(): Promise\<void>

Releases connections. Idempotent.

Returns#

Promise\<void>

Implementation of#

IDocumentStore.close

Defined in#

packages/bpmn-server/src/datastore/SqliteDocumentStore.ts:205

Comments