Skip to content

holonomy/persons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

persons

store, retrieve, delete, and search foaf:persons using levelgraph-jsonld

methods

var level = require('level');
var db = level('./mydb');
var persons = require('persons')(db, opts);

persons.put(obj, function (err, obj) {

Storing persons is extremely easy:

var manu = {
  "@id": "http://manu.sporny.org#person",
  "name": "Manu Sporny",
  "homepage": "http://manu.sporny.org/"
};

persons.put(manu, function(err, obj) {
  // do something after the obj is inserted
});

persons.get(id, function (err, obj) {

Retrieving a JSON-LD object from the store requires its '@id':

persons.get(manu['@id'], function(err, obj) {
  // obj will be the very same of the manu object
});

persons.del(id, function (err) {

In order to delete an object, you can just pass it's '@id' to the '@del' method:

persons.del(manu['@id'], function(err) {
  // do something after it is deleted!
});

persons.search(constraints, function (err, solution) {

var manu = {
  "@id": "http://manu.sporny.org#person",
  "name": "Manu Sporny",
  "homepage": "http://manu.sporny.org/",
  "knows": [{
    "@id": "https://my-profile.eu/people/deiu/card#me",
    "name": "Andrei Vlad Sambra",
    "based_near": "http://dbpedia.org/resource/Paris"
  }, {
    "@id": "http://melvincarvalho.com/#me",
    "name": "Melvin Carvalho",
    "based_near": "http://dbpedia.org/resource/Honolulu"
  }, {
    "@id": "http://bblfish.net/people/henry/card#me",
    "name": "Henry Story",
    "based_near": "http://dbpedia.org/resource/Paris"
  }, {
    "@id": "http://presbrey.mit.edu/foaf#presbrey",
    "name": "Joe Presbrey",
    "based_near": "http://dbpedia.org/resource/Cambridge"
  }]
};

var paris = 'http://dbpedia.org/resource/Paris';

persons.put(manu, function(){
  persons.search([{
    subject: manu['@id'],
    predicate: 'http://xmlns.com/foaf/0.1/knows',
    object: db.v('webid')
  }, {
    subject: db.v('webid'),
    predicate: 'http://xmlns.com/foaf/0.1/based_near',
    object: paris
  }, {
    subject: db.v('webid'),
    predicate: 'http://xmlns.com/foaf/0.1/name',
    object: db.v('name')
  }
  ], function(err, solution) {
    // solution contains
    // [{
    //   webid: 'http://bblfish.net/people/henry/card#me',
    //   name: '"Henry Story"'
    // }, {
    //   webid: 'https://my-profile.eu/people/deiu/card#me',
    //   name: '"Andrei Vlad Sambra"'
    // }]
  });
});

license

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published