1.0.16 • Published 7 years ago
chirql v1.0.16
#ChirQL
###Simple, graph-oriented query language.
Installation:
npm i chirql --save
Syntax
wrap everything in outer braces:
{
//include query criteria here
}
get an individual property by its predicate:
{
rdf:type
}
get a value property by it's predicate:
{
<rdfs:label>
}
constrain results by object id/value:
{
rdf:type(lib:Painter) // ?s rdf:type http://test.tester.org/library#Painter
<rdfs:label>(Pablo Picasso) // ?s rdfs:label "Pablo Picasso"^^<http://www.w3.org/2001/XMLSchema#string>
}
constrain results by root id value:
(ins:individualID){
rdf:type
rdfs:label
}
supports nesting:
{
rdf:type(lib:GreatGrandparent)
hasChild {
rdf:type(lib:Grandparent)
hasChild {
rdf:type(lib:Parent)
hasChild {
rdf:type(lib:Child)
}
}
}
}
####Usage
ChirQL = require('chirql')
//optional namespace-prefix handler
namespaces = [
{ prefix: 'lib:', namespace: 'http://test.tester.org/library#' },
{ prefix: 'ins:', namespace: 'http://test.tester.org/instance#' },
]
chirQLr = new ChirQL('YOUR_DATABASE_QUERY_LANGUAGE', 'http://your.database.url', namespaces)
chirQLr.runQuery("
{
<lib:hasName(Pablo Picasso)>
<lib:hasAge>
lib:hasSpouse {
<lib:hasName>(OlgaKhoklova)
<lib:hasAge>
lib:hasProfession
}
}
").then((res)->
//do something
)
####Sequence
This query gets transpiled into the specified query language (currently, only sparql is supported),
eg:
select ?root,?prop1,?prop2,?prop3,?prop4 where {
?root lib:hasName "Picasso"^^<http://www.w3.org/2001/XMLSchema#string> .
?root lib:hasAge ?prop1 .
?root lib:hasSpouse ?prop2 .
ins:OlgaKhoklova lib:hasName "OlgaKhoklova"^^<http://www.w3.org/2001/XMLSchema#string> .
ins:OlgaKhoklova lib:hasAge ?prop3 .
ins:OlgaKhoklova lib:hasProfession ?prop4 .
}
Finally the results are serialised into an object matching the construction of the initial chirql query
eg:
[{
'lib:hasName' : ['Pablo Picasso']
'lib:hasAge' : ['65']
'lib:hasSpouse' : [{
'lib:hasName' : ['Olga Khokhlova']
'lib:hasAge' : ['53']
'lib:hasProfession' : ['lib:BalletDancer']
}]
}]
}]
#TODO:
implement Cypher query manager
add features for limit, sortby, etc.