Skip to content
liberation-dataPublic

Repository files navigation

Drivine: graph database client for TypeScript, Python and the JVM

Docs: drivine.org, for TypeScript, Python, and Kotlin & Java.

Watch: Drivine, graph RAG on any database (4:26)
▶ Watch Drivine in four and a half minutes: graph RAG on any database (4:26, with captions)

Drivine is a graph database client for Node.js and TypeScript, with a NestJS module, and no need for one. It supports Neo4j, Memgraph, FalkorDB, Oracle (SQL/PGQ), Postgres and SQLite as graph stores, plus Amazon Neptune through the low-level API. It gives you two ways to work with a graph:

  1. PersistenceManager: a low-level API where you write the queries yourself. This is the classic Drivine approach.
  2. Object manager (StatelessGraphObjectManager): a high-level API that maps decorated classes, with a typed query DSL whose references come from the classes themselves.

A Cypher statement runs on every store: on Postgres, Oracle and SQLite, Drivine compiles it to SQL.

SQLite keeps a graph in one file, through Node's own node:sqlite (Node 22.13 or later), in the tables drivine4j and drivine-python read. A transaction there gives one writer at a time: it takes the file's write lock as it begins, so even one that only reads waits for the lock, up to the busy timeout. Reads outside a transaction don't wait for a writer; saves and deletes outside one are retried when contended; each statement Drivine writes applies whole or not at all; and a connection you open on the file yourself has none of this. Use a Node whose SQLite writes a computed float to 17 significant digits, as Node 22.23.4, 24.22.2 and 26.13 were measured to, for example: one that writes 15 rounds a float it computes in compiled Cypher. Drivine detects it at run time and warns once, as a process warning that node --disable-warning=DRIVINE_SQLITE_ROUNDED_FLOATS silences. See SQLite.

On Python or the JVM? drivine-python (pip install drivine) is Drivine's Python twin, and drivine4j (org.drivine:drivine4j) its Java and Kotlin twin. The three share a storage format.

Installation

npm install @liberation-data/drivine

Drivine needs reflect-metadata and neo4j-driver as peer dependencies, and NestJS (6 to 11) only for its module. Enable experimentalDecorators and emitDecoratorMetadata in tsconfig.json.

Quick Start

Connections come from the environment, or a .env file that Drivine loads:

DATABASE_TYPE=NEO4J          # NEO4J, MEMGRAPH, FALKORDB, ORACLE, NEPTUNE or POSTGRES
DATABASE_HOST=localhost
DATABASE_PORT=7687
DATABASE_USER=neo4j
DATABASE_PASSWORD=password

Then, without Nest, make the factories once and hand the managers to your classes:

import {
    DatabaseRegistry,
    GraphObjectManagerFactory,
    PersistenceManagerFactory,
    StatelessGraphObjectManager,
    Transactional
} from '@liberation-data/drivine';

DatabaseRegistry.buildOrResolveFromEnv();
const persistenceManagers = new PersistenceManagerFactory();
const graphObjectManagers = new GraphObjectManagerFactory(persistenceManagers);

export class PersonService {
    constructor(readonly gom: StatelessGraphObjectManager = graphObjectManagers.get()) {}

    async leads(): Promise<PersonCareer[]> {
        return this.gom.loadAll(PersonCareer, (q) => ({ where: q.person.bio.containsIgnoreCase('lead') }));
    }

    @Transactional()
    async hire(person: Person): Promise<void> {
        await this.gom.save(person);
    }
}

With Nest, register DrivineModule.withOptions(…) from @liberation-data/drivine/nest and inject the managers. The guide covers both, and the decorators behind Person and PersonCareer.

Documentation

  • The guide on drivine.org, a page per section, beside drivine-python's and drivine4j's.
  • The same guide on GitHub, in docs/.
  • RELEASING.md: how a release is made.

Contributing

Questions go to StackOverflow, with the Drivine tag, and bugs and feature requests to GitHub issues. To build and test from source, see Building from Source. Please follow the code of conduct.

License

Copyright (c) 2022 Jasper Blues. Drivine is free software, under the Apache License, Version 2.0. See LICENSE and the licence section.

Releases

Packages

Used by

Contributors

Languages