Module neo4j-ogm

neo4j-ogm

Neo4j OGM for TypeScript / JavaScript

Fetures

  • Type-safe query
  • OGM

Usage

Define models

We use zod to define types.

// create a driver
const driver = neo4j.driver(NEO4J_URI, neo4j.auth.basic(NEO4J_USER, NEO4J_PASSWORD));

// create a DB instance
const db = new DB(driver)
.define("User", {
name: z.string(),
email: z.string(),
FOLLOWS: MANY("User", { since: z.date() }),
POSTS: MANY("Post", { at: z.date() }),
LIKES: MANY("Post", { at: z.date() }),
})
.define("Post", {
title: z.string(),
content: z.string(),
INCLUDES: MANY("Media"),
})
.define("Media", {
url: z.string(),
type: z.string(),
size: z.bigint(),
UPLOADED_BY: ONE("User"),
});

Create nodes

const users = await db.create("User", [
{
name: "Jacob"
email: "hi@jacoblin.cool",
},
{
name: "Alice"
email: "alice@jacoblin.cool",
},
]);

// or if you only want to create one node
const [user] = await db.create("User", {
name: "Jacob"
email: "hi@jacoblin.cool",
});

Create relationships

await jacob.FOLLOWS(alice, { since: new Date() });

Properties

pkg: {
    author: string;
    bugs: {
        url: string;
    };
    dependencies: {
        cuid: string;
        debug: string;
        neo4j-driver: string;
        type-fest: string;
        typed-cypher: string;
        zod: string;
    };
    description: string;
    devDependencies: {
        @jacoblincool/puddle: string;
        @types/debug: string;
        @types/node-fetch: string;
        course-pack: string;
        node-fetch: string;
        ora: string;
        tsup: string;
        typedoc: string;
        typescript: string;
    };
    files: string[];
    homepage: string;
    keywords: never[];
    license: string;
    main: string;
    module: string;
    name: string;
    repository: {
        type: string;
        url: string;
    };
    scripts: {
        build: string;
        build:docs: string;
    };
    typedoc: {
        entryPoint: string;
    };
    types: string;
    version: string;
}

Type declaration

  • author: string
  • bugs: {
        url: string;
    }
    • url: string
  • dependencies: {
        cuid: string;
        debug: string;
        neo4j-driver: string;
        type-fest: string;
        typed-cypher: string;
        zod: string;
    }
    • cuid: string
    • debug: string
    • neo4j-driver: string
    • type-fest: string
    • typed-cypher: string
    • zod: string
  • description: string
  • devDependencies: {
        @jacoblincool/puddle: string;
        @types/debug: string;
        @types/node-fetch: string;
        course-pack: string;
        node-fetch: string;
        ora: string;
        tsup: string;
        typedoc: string;
        typescript: string;
    }
    • @jacoblincool/puddle: string
    • @types/debug: string
    • @types/node-fetch: string
    • course-pack: string
    • node-fetch: string
    • ora: string
    • tsup: string
    • typedoc: string
    • typescript: string
  • files: string[]
  • homepage: string
  • keywords: never[]
  • license: string
  • main: string
  • module: string
  • name: string
  • repository: {
        type: string;
        url: string;
    }
    • type: string
    • url: string
  • scripts: {
        build: string;
        build:docs: string;
    }
    • build: string
    • build:docs: string
  • typedoc: {
        entryPoint: string;
    }
    • entryPoint: string
  • types: string
  • version: string

Generated using TypeDoc