npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gverse

v1.2.7

Published

Object Graph Mapper for Dgraph

Downloads

315

Readme

Gverse

Note: This project is looking for maintainers. If you're interested, please create an issue. 🙏

Object Graph Mapper for Dgraph

GitHub CircleCI npm type definitions GitHub package.json version

Gverse is an Object Graph Mapper (OGM) for the Dgraph, the high-performance open-source Graph Database. Gverse is written in TypeScript and supports TypeScript 3 and JavaScript ES6.

What's an OGM?

An OGM enables developers to work with their graph models through idiomatic objects provided by their native programming language. It is similar in concept to Object-Relational Mapping (ORM) libraries such as TypeORM, Sequelize or Hibernate. See Gverse vs ORMs).

Features

  • Simple API for working with graphs vertices (nodes) and edges (links)
  • Strongly typed classes and predicates (attributes) when using TypeScript
  • Automatically marshal and unmarshal JavaScript objects to and from Graph vertices
  • Support for custom marshaling and unmarshaling methods
  • Support for directed and undirected edges
  • Support for transactions and batch updates
  • Before and after hooks for create, update and delete operations
  • Query options for ordering and pagination
Compatibility with Dgraph

The current version of Gverse supports Dgraph version 1.2.x.

For compatibility with Dgraph 1.0.x, use Gverse version 1.0.2. You can specify the version in your packages.json.

Getting started

Here's a quick start guide to get you up and running.

Install Dgraph

Make sure you have Dgraph installed and running. This guide assumes you have Dgraph running on default ports (8080 for HTTP and 9080 gRPC).

Set up your TypeScript or JavaScript ES6 environments

Gverse requires ES6 with class properties plugin or TypeScript ≥ 2.0.

Install the Gverse package

npm install gverse

or if you prefer, yarn add gverse. The package includes TypeScript types.

Create a Gverse graph session

import Gverse from "gverse"

const graph = new Gverse.Graph(
  new Gverse.Connection({ host: "localhost", port: 9080 })
)

Defining the Dgraph-types for vertices

const indices = `
      name: string @index(exact) @lang .
      owner: [uid] .
      repos: [uid] .
      contributors: [uid] .
      repositories: [uid] .
    `
const types = `
      type User {
        name
        repositories
      }
      type Repository {
        name
        contributors
        owner
      }
    `
await graph.applySchema(indices + types)

Define a vertex class

class User extends Gverse.Vertex {
  type = "User"
  name: string = ""
}

Create the vertex on the graph

const user = new User()
user.name = "Zak"
await graph.create(user)

Load a vertex from the graph

const user = (await graph.get(uid)) as User
console.log(user.name) // = "Zak"

For detailed examples, please see the integration tests under ./test/integration.

Defining edges (links to other vertices)

class Repo {
  type: "Repository"
  name: string
  owner: User
  contributors: User[]
  _edges: {
    owner: Edge.toVertex(User),
    contributors: Edge.toVertices(User)
  }
}

Edges can be directed or undirected (reversible), and can have a cardinality of one or many. For detailed examples, please see the integration tests under ./test/integration.

Running upsert (query with mutation)

The graph.newTransaction().upsert method enables you to execute upsert block having a query and a mutation:

const query = `{vertex as var(func: eq(name,"John"))}`
const values = {
  uid: "uid(vertex)",
  name: "Smith"
}
await graph.newTransaction().upsert(query, values)

An optional parameter condition can be used to run a conditional upsert:

const condition = `eq(len(vertex), 1)`
await graph.newTransaction().upsert(query, values, condition)

Running Tests

Test coverage for Gverse comes from integration tests. Docker and Docker-Compose are required for running integration tests.

./run-integration-tests.sh

Gverse OGM vs Traditional ORMs

Gverse has some fundamental differences to popular ORMs. It's helpful to understand the key differences:

  • Gverse works with vertices and edges in a Graph structure instead of tables, columns and rows in RDBMS like MySQL, Postgres, Oracle, or documents in MongoDB, CouchDB, etc. (learn more).
  • Gverse schema supports dynamic typing. You do not need to define and migrate schemas. Predicates (attributes) can be added as needed, with their data types inferred by value.
  • A schema definition is required for any type that is part of a query or filter function. Both the type and the index needs to be defined and applied. .
  • Advanced graph queries in Gverse are written using GraphQL± (a variant of GraphQL).