@faable/faableql
TypeScript icon, indicating that this package has built-in type declarations

1.2.8 • Public • Published

FaableQL is a query syntax with MongoDB support

Usage

Convert the following FaableQL query status:published order:created to a valid mongodb query.

const config = {...}
const fql = create_faableql(config)
const query = fql(`status:published type:article`)

results in.

{
  "$and": [
    { "status": { "$eq": "published" } },
    { "type": { "$eq": "article" } }
  ]
}

Use cases:

  • As a cli flag. ie: mycli --filter status:published
  • To filter results in a single query param. ie: GET /publications?q=status:published

Install

With NPM:

 npm install @faable/faableql

With Yarn:

 yarn add @faable/faableql

Getting Started

Configure fields that can be queried in MongoDB:

const fields = [{ name: "label", db: "labels" }];
param description
name field name in FaableQL string
db MongoDB field name

Create fql instance configured with defined fields.

import { create_faableql } from "@faable/faableql";

const fql = create_faableql(fields);

Convert a FaableQL query to MongoDB:

const query = "label:optimus label:prime";

// Process FaableQL query
const mongodb_query = fql(query);

mongodb_query will be converted to:

{
  "$and": [{ "labels": { "$eq": "optimus" } }, { "labels": { "$eq": "prime" } }]
}

use mongoose to get results filtered by your query

const docs = await Model.find(mongodb_query);

Syntax

Query = FieldTerm { whitespace FieldTerm }
FieldTerm = name Operator value

Operators

Avaliable operators

Operator Description MongoDB
: Equal {<db_field>:{$eq:<value>}}
!: Not equal {<db_field>:{$ne:<value>}}

Package Sidebar

Install

npm i @faable/faableql

Weekly Downloads

248

Version

1.2.8

License

MIT

Unpacked Size

15 kB

Total Files

18

Last publish

Collaborators

  • boyander