Code Monkey home page Code Monkey logo

giraffe's Introduction

Giraffe

A simple node & browser graph database

Travis CI Version NPM Downloads LICENSE

Install

npm install --save giraffe

Use

import Giraffe from 'giraffe';

const db = new Giraffe();

export default db;

Methods

  • new Giraffe(data, callback)

    • data: Object Optional
      • Should be in the shape of { nodes: [], edges: [] }
      • Labels are created dynamically based on data passed in
      • Nodes and Edges are checked for their correct shape.
    • callback: Function Optional
      • Can be passed first if no data is supplied
      • Callback is called just before returning on each Database Method
    • Create the DB instance
  • .create(label, data)

    • label: String || Array Optional
    • data: Object
    • label is type checked and coerced into a Array within the Node constructor
  • .remove(nodes)

    • nodes: Array Array of Nodes to be removed from graph
      • this is automatically converted to an Array if a single node is passed in.
  • .edge([ from ], [ to ], label, properties)

    • from Array Array of Nodes where edge originates
    • to: Array Array of Nodes where edge goes
    • label: String Optional
    • properties: Object Optional
  • .query(label, properties)

    • label: String Optional
    • properties: Object Optional
      • you can search for an edge with the property key _edges
    • An empty query returns all nodes
    • Queries return only their immediate relationships
  • .update([ nodes ], [ labels ], data)

    • nodes: Array (or single) node to be updated
    • labels: Array (or single) label to be added to Nodes.
    • data: Object Data set to be merged with previous data, any duplicate keys will be overwritten.
    • edge labels cannot be updated, an error will be thrown

Internal Structure

Database

{
  /**
   * All relationships with additional properties
   */
  edges: [],

  /**
   * All nodes with properties
   */
  nodes: [],

  /**
   * Dynamic key:value store for tracking known node and edge labels
   */
  labels: {
    nodes: {
      [label]: [/* Array of Node ids */]
    },
    edges: {
      [label]: [/* Array of Edge ids */]
    }

  }
}

Callback

The callback passed to your DB instance is called before the return statement of every method. That is to say db.create returns the created Node, but just before that return you callback is fired.

The calls are all identical it is called with the Type of request and the modified, added, or removed data.

method type data
Create 'create' Node
Remove 'remove' Array[Node]
Edge 'edge' Array[Edge]
Query 'query' Array[Query Result]
Update 'update' Array[Updated Nodes / Edges]

Node

{
  identity: <UUID />,
  properties: Object,
  labels: Array,
  edges: Array,
}

Node information

  • properties is the object passed into the db.create method.
  • edges is an array of Edge identity's before a query, after a query it is an array of references to the Node's they represent

Edge

{
  identity: <UUID />,
  from: <Node Identity /> || <Node />,
  through: <Node Identity /> || <Node />,
  label: String,
  properties: Object
}

Edge information

  • properties is the object passed into the db.edge method.
  • from and through are stored in the DB as from.identity and through.identity.
  • When db.query returns from and through are references to the Node's they represent

Coming Features

Checkout out the TODO Project on Github.

  1. Complex Queries.
  2. Investigate Typescript.

giraffe's People

Contributors

tbremer avatar

Stargazers

Richard Borcsik avatar Gurumurthi V Ramanan avatar Stone Penn avatar RB (Archive) avatar Egor Rudinsky avatar Loren Carvalho avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.