0.0.25-alpha • Published 6 years ago

gremlin-helper v0.0.25-alpha

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

A wrapper around the gremlin client to introduce model validation and other useful functionality to use within a web api.

Features

  • Model schemas
  • Retrieve models in a workable format
  • Mockable for testing

Getting Started

Install from NPM: https://www.npmjs.com/package/gremlin-helper

> npm install --save gremlin gremlin-helper

Create a vertex model

import { Vertex } from 'gremlin-helper';

interface IPerson {
  name: string;
  phone?: string;
}

const PersonVertex = new Vertex<IPerson>({
  label: 'user',
  props: {
    name: {
      type: 'string',
      required: true
    },
    phone: 'string'
  }
});

Add some pre-commit operations

import { Ops } from 'gremlin-helper';

PersonVertex.ops = {
  phone: Ops.merge(
    Ops.validatePhone,
    Ops.formatPhone
  )
}

Create an edge model

import { Edge } from 'gremlin-helper';

const FriendEdge = new Edge({ label: 'friend' })

Create a client

import { createClient } from 'gremlin';
import { Client } from 'gremlin-helper';

const client = new Client(createClient, config);

Create some people

const person1 = await client.addVAsync(PersonVertex, {
  name: 'Person 1',
  phone: '800273 8255'
});

const person2 = await client.addVAsync(PersonVertex, {
  name: 'Person 2'
});

const person3 = await client.addVAsync(PersonVertex, {
  name: 'Person 3'
});

Create some friend edges

// Person 1 friends person 2
await client.addEAsync(FriendEdge, person1.id, person2.id);
// Person 3 friends person 1
await client.addEAsync(FriendEdge, person3.id, person1.id);

Get all of person1 friends

import { QueryBuilder } from 'gremlin-helper';

// Build a query to get all people that have friended, or have been
// friended by person1
const query = new QueryBuilder()
  .getAllV(PersonVertex)
  .hasE(FriendEdge)
  .toOrFrom(PersonVertex, person1.id);

const friends = await client.executeAsync(PersonVertex, query);
0.0.25-alpha

6 years ago

0.0.24-alpha

6 years ago

0.0.23-alpha

6 years ago

0.0.22-alpha

6 years ago

0.0.21-alpha

6 years ago

0.0.20-alpha

6 years ago

0.0.19-alpha

6 years ago

0.0.18-alpha

6 years ago

0.0.17-alpha

6 years ago

0.0.16-alpha

6 years ago

0.0.15-alpha

6 years ago

0.0.14-alpha

6 years ago

0.0.13-alpha

6 years ago

0.0.12-alpha

6 years ago

0.0.11-alpha

6 years ago

0.0.10-alpha

6 years ago

0.0.9-alpha

6 years ago

0.0.8-alpha

6 years ago

0.0.7-alpha

6 years ago

0.0.6-alpha

6 years ago

0.0.5-alpha

6 years ago

0.0.4-alpha

6 years ago

0.0.3-alpha

6 years ago

0.0.2-alpha

6 years ago

0.0.1-alpha

6 years ago