1.4.0 • Published 9 months ago

@faable/faableql v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months 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.4.0

9 months ago

1.3.1

9 months ago

1.3.0

9 months ago

1.2.9

1 year ago

1.2.8

1 year ago

1.2.7

1 year ago

1.2.6

1 year ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year 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