1.0.16 • Published 7 years ago

chirql v1.0.16

Weekly downloads
5
License
MIT
Repository
-
Last release
7 years ago

#ChirQL

###Simple, graph-oriented query language.

Build Status Code Climate codecov npm version

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.

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago