mql-to-jql

1.5.0 • Public • Published

mql-to-jql

Node.js Test Runner GitHub code size in bytes GitHub package.json version GitHub

Convert mql syntax to jql to query ejdb databases

Installation

npm install --save mql-to-jql

Example usage

const convert = require('mql-to-jql/convert')
const createQuery = require('mql-to-jql/createQuery')

const db = await EJDB2.open('./example.db', { truncate: true });
const query = convert({
  fields: [
    'firstName',
    'lastName'
  ],

 // The following equality operators are implemented:
 // '$eq', '$ne', '$gt', '$gte', '$lt', '$lte', '$exists', '$null', '$in', '$nin'
  query: {
    $or: [
      { a: 1 },
      { a: 5 },
    ]
  },

  order: [
    'asc(firstName)',
    'desc(lastName)'
  ],

  limit: 10,
  skip: 100
});

/*
You can use query by sending it straight to ejdb.
query === {
  mql: '(/[[* = :?] = :?] or /[[* = :?] = :?])',
  values: ['a', 1, 'a', 5]
}
*/

// OR you can use the createQuery helper to do it for you
const q = createQuery(db, 'testCollection', query);
const records = await q.list();

console.log(records);

License

This project is licensed under the terms of the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i mql-to-jql

Weekly Downloads

0

Version

1.5.0

License

MIT

Unpacked Size

18.6 kB

Total Files

17

Last publish

Collaborators

  • markwylde