Class DB<Schema>

Type Parameters

Hierarchy

  • DB

Constructors

  • Type Parameters

    Parameters

    • driver: Driver

      The neo4j driver

    • options: {
          database: undefined | string;
      } = {}

      The database to use and the number of sessions to use

      • database: undefined | string

    Returns DB<Schema>

Properties

database: string
defs: Record<keyof Schema, NodeShape<string, readonly string[], Record<string, PropValue | RelationShape<boolean, string, readonly string[], Record<string, PropValue>>>, {}, {}>> = ...
driver: Driver
idgen: (() => string) = cuid

Type declaration

    • (): string
    • This id ($id) generator function, defaults to cuid

      Returns string

log: {
    query: Debugger;
}

Type declaration

  • query: Debugger
sessions: Set<Session> = ...

The underlying sessions

Methods

  • n is returned as a node

    Parameters

    • label: string
    • data: OneOrMany<Record<string, unknown>>

    Returns Promise<QueryResult<{
        n: Node<Integer, Properties, string>;
    }>>

  • n is returned as a node

    Parameters

    • $id: string

    Returns Promise<QueryResult<{
        n: Node<Integer, Properties, string>;
    }>>

  • r is returned as a relation

    Parameters

    • from: string
    • to: string
    • rel: string
    • data: Record<string, unknown>

    Returns Promise<QueryResult<{
        from: unknown;
        r: Relationship<Integer, Properties, string>;
        to: unknown;
    }>>

  • n is returned as a node

    Parameters

    • $id: string
    • data: Record<string, unknown>
    • Optional old: Record<string, unknown>

    Returns Promise<QueryResult<{
        n: Node<Integer, Properties, string>;
    }>>

  • r is returned as a relation

    Parameters

    • $id: string
    • data: Record<string, unknown>
    • Optional old: Record<string, unknown>

    Returns Promise<QueryResult<{
        r: Relationship<Integer, Properties, string>;
    }>>

  • Create a new node

    Returns

    This will always return an array, even if only one node was created

    Type Parameters

    • T extends string | number | symbol

    Parameters

    • type: T
    • data: OneOrMany<{ [ K in string | number | symbol]: Schema[T]["props"][K] extends ZodType<any, ZodTypeDef, any> ? TypeOf<any[any]> : never }>

    Returns Promise<Vertex<Schema, T, Schema[T]>[]>

  • Define a new node (vertex, entity) type

    Returns

    Self, for chaining

    Type Parameters

    • N extends string

    Parameters

    • name: N

      The name of the node type

    Returns DB<Schema & { [ k in string]: NodeShape<N, readonly string[], Record<string, PropValue | RelationShape<boolean, string, readonly string[], Record<string, PropValue>>>, {}, {}> }>

  • Type Parameters

    • N extends string

    • L extends readonly string[]

    Parameters

    • name: N
    • labels: L

    Returns DB<Schema & { [ k in string]: NodeShape<N, L, Record<string, PropValue | RelationShape<boolean, string, readonly string[], Record<string, PropValue>>>, {}, {}> }>

  • Type Parameters

    Parameters

    • name: N
    • props: P

    Returns DB<Schema & { [ k in string]: NodeShape<N, [], P, { [ K in string | number | symbol as P[K] extends PropValue ? K : never]: P[K] extends PropValue ? any[any] : never }, { [ K in string | number | symbol as P[K] extends RelationShape<boolean, string, readonly string[], Record<string, PropValue>> ? K : never]: P[K] extends RelationShape<boolean, string, readonly string[], Record<string, PropValue>> ? any[any] : never }> }>

  • Type Parameters

    • N extends string

    • L extends readonly string[]

    • P extends Record<string, PropValue | RelationShape<boolean, string, readonly string[], Record<string, PropValue>>>

    Parameters

    • name: N
    • labels: L
    • props: P

    Returns DB<Schema & { [ k in string]: NodeShape<N, L, P, { [ K in string | number | symbol as P[K] extends PropValue ? K : never]: P[K] extends PropValue ? any[any] : never }, { [ K in string | number | symbol as P[K] extends RelationShape<boolean, string, readonly string[], Record<string, PropValue>> ? K : never]: P[K] extends RelationShape<boolean, string, readonly string[], Record<string, PropValue>> ? any[any] : never }> }>

  • Type Parameters

    • N extends string | number | symbol

    Parameters

    • node: {
          $id: string;
      }
      • $id: string
    • label: N

    Returns Promise<Vertex<Schema, N, Schema[N]>>

  • Type Parameters

    • N extends string | number | symbol

    Parameters

    • label: N
    • Optional query: {
          limit?: number;
          order?: OneOrMany<[keyof Schema[N]["props"], "ASC" | "DESC"]>;
          where?: Partial<{ [ K in string | number | symbol]: Schema[N]["props"][K] extends ZodType<any, ZodTypeDef, any> ? TypeOf<any[any]> : never }> & {
              $id?: string;
          };
      }
      • Optional limit?: number
      • Optional order?: OneOrMany<[keyof Schema[N]["props"], "ASC" | "DESC"]>
      • Optional where?: Partial<{ [ K in string | number | symbol]: Schema[N]["props"][K] extends ZodType<any, ZodTypeDef, any> ? TypeOf<any[any]> : never }> & {
            $id?: string;
        }

    Returns Promise<Vertex<Schema, N, Schema[N]>[]>

  • Delete all data in the database

    Parameters

    • check: "DELETE ALL DATA"

      string to confirm you want to delete all data

    Returns Promise<void>

  • Run a typed raw query

    Type Parameters

    • Q extends string

    Parameters

    • query: Q

      Query in Cypher

    • Rest ...params: ParamNames<Q>[number] extends never ? [Record<string, unknown>?] : [Params<Q>]

      Parameters to pass to the query

    Returns Promise<QueryResult<keyof Returns<Q> extends never ? {
        [key: string]: unknown;
    } : { [ key in string | number | symbol]: Returns<Q>[key] extends "Node" ? Node<Integer, Properties, string> : Returns<Q>[key] extends "Relationship" ? Relationship<Integer, Properties, string> : unknown }>>

  • Type Parameters

    • N extends string | number | symbol

    Parameters

    • node: Node<Integer, Properties, string>
    • name: N

    Returns Vertex<Schema, N, Schema[N]>

Generated using TypeDoc