rdftrees
v1.0.0
Published
You can query data through accessing the properties of the created tree.
Downloads
5
Readme
Querying Data
You can query data through accessing the properties of the created tree.
const trees = new Trees("https://lalasepp.owntech.de/profile/card#me");
trees.create().then(tree => {
console.log(tree.me.role);
//Also works for deeply nested properties
console.log(tree.me.hasEmail.type);
});
Setting Data
You can use the set function that's part of the tree class to set values.
const trees = new Trees("https://lalasepp.owntech.de/profile/card#me");
const { set } = trees;
trees.create().then(tree => {
// Pass any node to set() to get an object with setter methods for it's edges
set(tree.me).role("Software Engineer");
// For setting multiple values do:
set(tree.me).knows([
"https://ludwig.owntech.de/profile/card#me",
"https://bejow.owntech.de/profile/card#me"
]);
// For setting nested values do:
set(tree.me.hasEmail).type("Work");
// or more abbreviated
const email = tree.me.hasEmail;
set(email).type("Work");
});
Comparison to rdflib.js:
Reading and Updating single values (e.g. The job description of a user)
import Trees from "trees";
import rdf from "rdflib";
const newRole = "Software Engineer";
// trees.js
const createAndModifyTree = async () => {
const trees = new Trees("https://lalasepp.owntech.de/profile/card#me");
const { me } = await trees.create();
console.log(me.role);
const { set } = trees;
await set(me).role(newRole);
};
// rdflib.js
const createAndModifyStore = async () => {
const store = rdf.graph();
const fetcher = new rdf.Fetcher();
const updater = new rdf.UpdateManager();
const webId = "https://lalasepp.owntech.de/profile/card#me";
await fetcher.load(webId);
const prevStatements = store.statementsMatching(
rdf.sym(webId),
rdf.sym("http://www.w3.org/2006/vcard/ns#role"),
null
);
console.log(prevStatements[0].object.value);
const newStatement = prevStatements[0];
newStatement.object.value = newRole;
await updater.update(prevStatements, newStatement);
};