graft-db
```javascript import { MemStore, Repository, BaseTypes } from 'graft-db';
Last updated 2 years ago by chrisfarms .
ISC · Original npm · Tarball · package.json
$ cnpm install graft-db 
SYNC missed versions from official npm registry.

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' } } }

Current Tags

  • 0.0.22                                ...           latest (2 years ago)

18 Versions

  • 0.0.22                                ...           2 years ago
  • 0.0.19                                ...           2 years ago
  • 0.0.18                                ...           3 years ago
  • 0.0.17                                ...           3 years ago
  • 0.0.16                                ...           3 years ago
  • 0.0.15                                ...           3 years ago
  • 0.0.14                                ...           3 years ago
  • 0.0.13                                ...           3 years ago
  • 0.0.12                                ...           3 years ago
  • 0.0.10                                ...           3 years ago
  • 0.0.9                                ...           3 years ago
  • 0.0.7                                ...           3 years ago
  • 0.0.6                                ...           3 years ago
  • 0.0.5                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (20)
Dev Dependencies (20)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |