Socket
Book a DemoInstallSign in
Socket

graft-db

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graft-db

```javascript import { MemStore, Repository, BaseTypes } from 'graft-db';

0.0.22
latest
npmnpm
Version published
Weekly downloads
6
50%
Maintainers
1
Weekly downloads
 
Created
Source

Working with state

import { MemStore, Repository, BaseTypes } from 'graft-db';

// create the store where things get persisted
const store = new MemStore();

// create a repository (one repository can have many tags/branches)
let r = new Repository({ store, id: 'myrepo' });

// create/fetch a branch and name
let master = r.latest().checkout('master');
master = master.set('n1', {type: BaseTypes.Node});
master = master.set('n2', {type: BaseTypes.Node});

// update the 'master' tag to point to this state
master = master.commit();

// fetch new metadata into r
r = r.latest();

// checkout another copy of the master branch
let wip = r.latest().checkout('master');
wip.key() === master.key(); // => true

// change wip and commit to master
wip = wip.set('n100', {type: BaseTypes.Node});
wip = wip.commit();

// continue working on master
// and now try to commit
master = master.set('n3', {type: BaseTypes.Node});
master = master.commit(); // fail 'needs rebase' since upstream is ahead

// fix it by pulling latest
master = master.pull();

// or fix it by rebasing from wip
master = master.rebase(wip);

// now can commit
master.commit();

Building a graph (low level)

// create a node to represent a "Person" type
master = master.set('uuid-person', {type: BaseTypes.Node, name: 'Person'});

// create a property to hold the person's name
master = master.set('uuid-person-name', {type: BaseTypes.String, name: 'name', nullable: true});

// create an "instance" of a person node
master = master.set('uuid-jeff', {type: 'uuid-person'});

// store a name
master = master.setString('uuid-jeff-name', 'jeff');
master = master.set('uuid-jeff-name', {type: 'uuid-person-name', value: {
	type: ValueKeyTypes.data,
	id: 'uuid-jeff-name',
}});

Build a graph (high level) - DEPRECATED

// create a node to represent a "Person" type
master = master.setType({
	name: 'Person',
	properties: {
		name: { type: BaseTypes.String, },
	}
});

// create an "instance" of a person node
master = master.setNode({
	type: 'Person',
	values: {
		name: 'jeff',
	}
});

Querying the graph

let result;
[result, mastelr] = master.query(`{
	node(id: 'uuid-jeff') {
		...on Person {
			name
		}
	}
}`); // => {data: { node: { name: 'jeff' } } }

FAQs

Package last updated on 08 Feb 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.