1.2.9 • Published 3 days ago

@faable/faableql v1.2.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 days ago

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" }];
paramdescription
namefield name in FaableQL string
dbMongoDB 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

OperatorDescriptionMongoDB
:Equal{<db_field>:{$eq:<value>}}
!:Not equal{<db_field>:{$ne:<value>}}
1.2.9

3 days ago

1.2.8

18 days ago

1.2.7

18 days ago

1.2.6

19 days ago

1.2.5

19 days ago

1.2.4

19 days ago

1.2.3

3 months ago

1.2.2

4 months ago

1.2.0

5 months ago

1.2.1

5 months ago

1.1.5

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago