SQLite
SQLite keeps a graph in a file, with no server: the same tables as Oracle and Postgres, so a file drivine4j or
drivine-python wrote is read and written here, and the other way round. Drivine opens it through Node’s own driver,
node:sqlite, in Node 22.13 or later; nothing else is installed. Node 22 and 24 print
an ExperimentalWarning the first time node:sqlite is loaded. Models, the DSL and the object manager are the same as on
the graph engines; PersistenceManager runs plain SQL, with cursors and transactions, and Cypher, compiled to SQLite’s
SQL as drivine4j compiles it (a cursor runs SQL alone). What Cypher does that SQLite’s JSON functions don’t, Drivine’s
functions registered on each connection do.
Which SQLite. From Drivine 5.0, compiled Cypher needs SQLite 3.53.2 or later. On an older one it is wrong or
refused: a float it computes is written to 15 digits (3.53.0 and 3.53.1 still write 15), 3.49 refuses a CALL that
groups by a variable it imports, and SQLite before 3.47 refuses the -> -1 that last() and a negative list index
compile to. So a Cypher statement is refused there, with a DrivineError that names the SQLite and the Node that
bundles it, before it is compiled. Plain SQL, the schema manager and the object manager, which write SQL, run on SQLite
3.45 or later. The SQLite is the one Node bundles, unless Node was built against the system’s:
| Node line | node:sqlite without a flag from |
SQLite before 3.53.2 | 3.53.2 or later from |
|---|---|---|---|
| 22 | 22.13.0 | 3.47.2 (22.13.0) to 3.51.3 (22.23.3) | 22.23.4 (3.53.4) |
| 23 | 23.4.0 | 3.47.1 to 3.49.1 | none |
| 24 | 24.0.0 | 3.49.1 (24.0.0) to 3.53.1 (24.18.1) | 24.19.0 (3.53.3) |
| 25 | 25.0.0 | 3.50.4 to 3.51.3 | none |
| 26 | 26.0.0 | 3.51.3 (26.0.0) to 3.53.1 (26.3.1) | 26.4.0 (3.53.2) |
Which Node. The SQLite comes with Node, so use a Node whose SQLite writes a float it computes in JSON to 17
significant digits, which read back as it: json_quote(0.1 + 0.2) is 0.30000000000000004. SQLite 3.53.2 does so by
default (3.53.0 and 3.53.1 still write 15), but a build may still write 15, so Drivine asks SQLite rather than reading
its version. Node 22.23.4, 24.22.2 and 26.13, for example, were measured to write 17. A SQLite that writes 15
significant digits, as a build of 3.53.2 may and every one before 3.53.2 does, rounds what it computes, and every value
compiled Cypher gives is JSON: 0.1 + 0.2 comes back as 0.3, 1.0/3 as 0.333333333333333, a value passed through
WITH and multiplied back as 0.999999999999999 where 1.0 is wanted, and a computed float a statement SETs is
stored rounded. Parameters, stored values and Drivine’s own functions, such as pi(), keep their digits. Drivine
detects this at run time: when it first opens a file, it asks SQLite for json_quote(0.1 + 0.2), and warns once where
the answer is rounded and compiled Cypher is not refused; it runs all the same. The warning is a Node process warning,
so it shows whatever DRIVINE_LOG_LEVEL is, and its code is DRIVINE_SQLITE_ROUNDED_FLOATS.
node --disable-warning=DRIVINE_SQLITE_ROUNDED_FLOATS (or the same in NODE_OPTIONS) silences it alone, and
node --no-warnings with every other process warning.
| Node, measured | SQLite | json_quote(0.1 + 0.2) |
|---|---|---|
| 24.7.0 | 3.50.4 | 0.3; compiled Cypher is refused, so not warned of |
| 24.16.0 | 3.53.0 | 0.3; compiled Cypher is refused, so not warned of |
| 22.23.4 | 3.53.4 | 0.30000000000000004 |
| 24.22.2 | 3.53.4 | 0.30000000000000004 |
| 26.13.0 | 3.54.0 | 0.30000000000000004 |
DATABASE_TYPE=SQLITEDATABASE_NAME=./data/graph.db # the path of the file, made if it is not there; the folder must beDATABASE_DEFAULT_GRAPH_PATH=drivine # names the graph's tables; this is the defaultDATABASE_CONNECTION_TIMEOUT=30000 # how long a statement waits for the file's lock, in ms; this is the defaultA SQLite store has no host, port, user or password. :memory: is refused: each pooled connection would open a database
of its own. The tables are made on the first connection, when they are not there, as on Postgres.
How a graph is stored. drivine4j’s layout, so the three libraries read one file:
<graph>_node (nid INTEGER PRIMARY KEY AUTOINCREMENT, labels TEXT, props TEXT, stamp TEXT),
<graph>_edge (eid INTEGER PRIMARY KEY AUTOINCREMENT, src, dst REFERENCES node ON DELETE CASCADE, type, props TEXT), and
<graph>_schema. Labels and properties are JSON text, not SQLite’s binary jsonb. Labels are written sorted, with no
character escaped that JSON does not require, because a label is found by its text, "Label", within labels. The stamp
is a column. Values are held in store layout 2, a moment as a tagged map of its ISO 8601 text, and a graph an earlier
Drivine wrote is judged, as on Oracle.
nid and eid are AUTOINCREMENT keys, so the id of a node or relationship that is deleted is never given to another,
within a statement, a transaction or after it, as on Oracle and Postgres: an element id an application holds names the
element it was read from or nothing. SQLite keeps the greatest id each table has given in its own table
sqlite_sequence; deleting every row, as a test’s cleanup does, leaves it, so ids go on from there. A file whose graph
tables an earlier Drivine made, with INTEGER PRIMARY KEY alone, which gives a new row the id of the last one deleted, is
refused on the provider’s first connection and every one after it, and before an object manager’s first statement over
the graph, with a ReusedIdsError that names the graph and the file. There is no migration: make a new file and save
the graph into it again.
What a transaction gives.
- One writer at a time. A transaction takes the file’s write lock as it begins (
BEGIN IMMEDIATE), so even one that only reads waits for the lock, up to the connection timeout. One that holds the lock longer than five seconds is warned of when it ends, committed, rolled back or released. - A read outside a transaction doesn’t wait for a writer: the journal is a write-ahead log, and a read sees what was committed.
- A save or a delete outside a transaction that finds the file locked is run again, as one turned away as contended is on the other stores.
- Each statement Drivine writes applies whole or not at all: a save is a call of
drivine_write, a function each connection registers, which carries out the save’s steps under a savepoint. - Node’s driver is synchronous, so a connection that finds the file locked waits for it by trying again after a pause, which leaves the rest of the process running. A connection you open yourself on the file has none of this, nor the functions Drivine’s statements call.
Notes:
- A statement you write yourself is SQL; parameters are named
$name, and a statement is bound only the ones it names outside quoted text and comments, so the$tof a JSON path’s'$."$t"'is none. A statement Drivine writes whose text values are each JSON opens with/* drivine:json */, and is read as JSON. - SQLite’s JSON writes an infinity as
9e999, which reads back as the infinity, and holds no NaN: Drivine’s functions, and the rows of a/* drivine:json */statement, take the map{"$numberDouble": "NaN"}, exactly, as NaN, as drivine4j does. So a map a statement writes so is NaN too, equal to nothing; one with another key, or another value, is the map it is. - A predicate you write yourself is SQL over the root’s row: its
props,labelsandstamp, e.g.(n.props ->> 'name') = $name. A property of the root may be written as Cypher writes it,n.name = $name, and is read as that property, as text, as on Postgres. One whose name begins with$,n.`$k`, is read as it is held, under$$k. SQLite’s own->>readstrueas1and a number as a number. - Each connection registers the functions Drivine’s statements call, by drivine4j’s names:
drivine_write,drivine_delete,drivine_lower_copies,drivine_similarity,drivine_epoch(a moment as nanoseconds since the epoch),drivine_lower(a Unicodelower),drivine_regexp_count, andregexp, which SQLite’sREGEXPcalls. - A range index or a uniqueness constraint is a partial index, for the nodes of the label, over the property’s class
and key as store layout 2 holds it (a temporal value’s kind and sort key, any other value as
->>reads it), so a value is equal only to one of its kind. A vector or a full-text index is recorded and not made:loadNearestmeasures every node of the label that holds an embedding of the vector’s size, andloadMatchingreads every node of the label and scores by BM25, as Postgres does. =~andmatchestake Java’s regular expression, matched against the whole value and read as Java reads it withUNICODE_CHARACTER_CLASS: SQLite’sregexpis the shared compiler’s matcher, on every runtime, Node and the browser bundle alike, not JavaScript’sRegExp. So\w,\d,\band\sare Unicode’s, as on drivine4j, a class’s&&is an intersection, and\Q…\E,\Z,\p{…}and inline flags such as(?i)are Java’s (#560, #568, #632). One departure is on purpose, as on drivine4j and drivine-python: a POSIX class,[:alnum:],[:alpha:],[:digit:],[:space:],[:upper:],[:lower:]or[:punct:], is read as Java names it,\p{Alnum}and so on, Unicode’s, so[[:alpha:]]matchesé, where Java reads it as a class of the characters:,a,l,pandh; a full-text search’s patterns, written for Postgres, read alike. A pattern Java can’t compile is refused with Java’s description of the fault (Bad class syntax), without its index. What the matcher can’t match exactly as Java does, it refuses by name (a lookbehind is not supported on this platform; rewrite the pattern without it.), as the compiler’s README lists them:- a lookbehind, and any lookahead but one of literals, classes, alternatives,
$and\zalone, unquantified; - a back reference,
\1or\k<name>; - a possessive quantifier, and an atomic group,
(?>…); \G,\X,\R,\N{…}and\b{g};- a quantifier on what has no width (
^*,(\b)*), and a quantifier on a quantifier (a{2}{3}); - a lazy quantifier on a group but
*?and??((bc)+?); - a capturing group of fixed length in a group repeated (
(?:(a))*a), and a group that can match nothing in a group repeated ((?:a(?:b*)*){2}); - groups repeated within each other more than 3 deep;
(?-U),(?-u)and(?c);- and a pattern of more than 2,000,000 characters.
- a lookbehind, and any lookahead but one of literals, classes, alternatives,
- Text compares and sorts by SQLite’s
BINARYcollation, the order of its code points, so a page of mixed-case text is in the order Neo4j gives (B, a, b), as on Postgres. - A whole number past 2^53 that a statement gives back is refused by Node’s driver; one a save leaves alone keeps its digits.

