Class GraphEdgeCollection<T>

Represents a EdgeCollection of edges in a Graph.

Type Parameters

  • T extends Record<string, any> = any

    Type to use for document data. Defaults to any.

Hierarchy

  • GraphEdgeCollection

Implements

Accessors

Methods

  • Retrieves the edge matching the given key or id.

    Throws an exception when passed a edge or _id from a different collection, or if the edge does not exist.

    Example

    const graph = db.graph("some-graph");
    const collection = graph.edgeCollection("friends")
    try {
    const edge = await collection.edge("abc123");
    console.log(edge);
    } catch (e: any) {
    console.error("Could not find edge");
    }

    Example

    const graph = db.graph("some-graph");
    const collection = graph.edgeCollection("friends")
    const edge = await collection.edge("abc123", { graceful: true });
    if (edge) {
    console.log(edge);
    } else {
    console.error("Edge does not exist");
    }

    Parameters

    Returns Promise<Edge<T>>

  • Retrieves the edge matching the given key or id.

    Throws an exception when passed a edge or _id from a different collection, or if the edge does not exist.

    Example

    const graph = db.graph("some-graph");
    const collection = graph.edgeCollection("friends")
    try {
    const edge = await collection.edge("abc123", false);
    console.log(edge);
    } catch (e: any) {
    console.error("Could not find edge");
    }

    Example

    const graph = db.graph("some-graph");
    const collection = graph.edgeCollection("friends")
    const edge = await collection.edge("abc123", true);
    if (edge) {
    console.log(edge);
    } else {
    console.error("Edge does not exist");
    }

    Parameters

    • selector: DocumentSelector

      Document _key, _id or object with either of those properties (e.g. a edge from this collection).

    • graceful: boolean

      If set to true, null is returned instead of an exception being thrown if the edge does not exist.

    Returns Promise<Edge<T>>

  • Checks whether a edge matching the given key or id exists in this collection.

    Throws an exception when passed a edge or _id from a different collection.

    Example

    const graph = db.graph("some-graph");
    const collection = graph.edgeCollection("friends")
    const exists = await collection.edgeExists("abc123");
    if (!exists) {
    console.log("Edge does not exist");
    }

    Parameters

    • selector: DocumentSelector

      Document _key, _id or object with either of those properties (e.g. a edge from this collection).

    Returns Promise<boolean>

  • Removes an existing edge from the collection.

    Throws an exception when passed a edge or _id from a different collection.

    Example

    const db = new Database();
    const collection = db.collection("friends");
    const doc = await collection.edge("musadir");
    await collection.remove(doc);
    // edge with key "musadir" deleted

    Parameters

    Returns Promise<DocumentMetadata & { old?: Edge<T> }>

  • Replaces an existing edge in the collection.

    Throws an exception when passed a edge or _id from a different collection.

    Example

    const db = new Database();
    const collection = db.collection("friends");
    await collection.save(
    {
    _key: "musadir",
    _from: "users/rana",
    _to: "users/mudasir",
    active: true,
    best: true
    }
    );
    const result = await collection.replace(
    "musadir",
    { active: false },
    { returnNew: true }
    );
    console.log(result.new.active, result.new.best); // false undefined

    Parameters

    Returns Promise<DocumentMetadata & { new?: Edge<T>; old?: Edge<T> }>

  • Updates an existing edge in the collection.

    Throws an exception when passed a edge or _id from a different collection.

    Example

    const db = new Database();
    const collection = db.collection("friends");
    await collection.save(
    {
    _key: "musadir",
    _from: "users/rana",
    _to: "users/mudasir",
    active: true,
    best: true
    }
    );
    const result = await collection.update(
    "musadir",
    { active: false },
    { returnNew: true }
    );
    console.log(result.new.active, result.new.best); // false true

    Parameters

    Returns Promise<DocumentMetadata & { new?: Edge<T>; old?: Edge<T> }>

Generated using TypeDoc