sjql

Query SynoGraph with JSON objects

Usage no npm install needed!

<script type="module">
  import sjql from 'https://cdn.skypack.dev/sjql';
</script>

README

SJQL - SynoGraph JSON Query Language

Query the SynoGraph using pure JSON objects, using the simple json-predicate syntax.

Usage

const path = require('path');
const SynoGraph = require('synograph').PersistentGraph;
SynoGraph.start(path.join(__dirname, 'data')).then(g => {
    require('./models')(g);
    console.log(JSON.stringify(jsonQuery(g, {
        query: [
            'text', // first step is always a string
            'posted', // mid-steps can either be a `string` or a `{of: String, filter: Object}` object
            {type: 'Person', filter: {
                path: '/name',
                op: 'starts',
                value: 'A'
            }} // either a `string` (of an ID), an `array<string>` (array of IDs) or a `{type: String, filter: Object, limit: Integer}` object.
        ],
        unique: true // default is true
    }), null, 2));
    // equivalent to:
    console.log(JSON.stringify(
        g.select('text').of('posted').ofAny(g.nodeTypes.Person.find(p => p.name.startsWith('A'))).get(), 
    null, 2));
});