gaql is a query language, comprising a JSON-compiler and resolver.
[![npm][9]][7] [![agpl][2]][1]
gaql is a query language, comprising a JSON-compiler and resolver. It is extensible to support any query and common queries are published with gaql for general operations involving math, logic, time, etc. See example usages in [the unit-tests,][14]
``javascript
import gaql from 'gaql'
import * as core from 'gaql/src/queries/core.js'
import * as logic from 'gaql/src/queries/logic.js'
import * as transform from 'gaql/src/queries/transform.js'
import * as aggregate from 'gaql/src/queries/aggregate.js'
const q = gaql([ core, logic, transform, aggregate ])
const winners = await q
.expr([
{ id: 123, wins: 13, losses: 5, name: 'jim' },
{ id: 456, wins: 16, losses: 2, name: 'jen' },
{ id: 789, wins: 8, losses: 10, name: 'jon' }])
.filter(user => user('wins').gt(user('losses')))
.orderBy(q.desc('wins'))
.map(user => user('name'))
.run()
console.log(winners) // ['jen', 'jim']
`
gaql is modelled after the [ReQL query language][10] used by RethinkDB and, specifically, its interface is modelled after the excellent [rethinkdb-ts javascript driver.][11]
gaql` provides excellent support for resolving complex operations in a small and portable module. A few short-comings listed below are okay for my own usage now, and could be improved later with updates,
* _Error handling at the JSON-compiler could be improved._ If the user chains a "list" operation to an "integer" result, the _compiler_ will not detect the error before it occurs at runtime,
* _Error handling at the resolver could be improved_. Error messages could show specific parts of a query that cause the error,
* _JSON instructions are not heavily-optimized._ Small example; "concatMap" appears in the JSON instructions, rather than, say, a mapped-integer.
[1]: https://www.gnu.org/licenses/agpl.txt "AGPL-v3"
[2]: https://img.shields.io/badge/License-AGPLv3-blue.svg
[9]: https://img.shields.io/npm/v/gaql
[7]: https://www.npmjs.com/package/gaql "npm gaql package"
[14]: https://codeberg.org/bumblehead/gaql/src/branch/main/test "tests"
[10]: https://rethinkdb.com/docs/introduction-to-reql/ "introduction to reql"
[11]: https://github.com/ronzeidman/rebirthdbts "rebirthdbts"