1.4.1 • Published 1 year ago
@faable/faableql v1.4.1
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/faableqlWith Yarn:
yarn add @faable/faableqlGetting 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 valueOperators
Avaliable operators
| Operator | Description | MongoDB |
|---|---|---|
: | Equal | {<db_field>:{$eq:<value>}} |
!: | Not equal | {<db_field>:{$ne:<value>}} |
1.4.1
1 year ago
1.4.0
1 year ago
1.3.1
1 year ago
1.3.0
1 year ago
1.2.9
2 years ago
1.2.8
2 years ago
1.2.7
2 years ago
1.2.6
2 years ago
1.2.5
2 years ago
1.2.4
2 years ago
1.2.3
2 years ago
1.2.2
2 years ago
1.2.0
2 years ago
1.2.1
2 years ago
1.1.5
2 years ago
1.1.4
2 years ago
1.1.3
2 years ago
1.1.2
2 years ago
1.1.1
2 years ago
1.1.0
2 years ago
1.0.2
2 years ago
1.0.1
2 years ago