JSPM

orm-options-generator

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q21024F
  • License MIT

Helps in converting query params to ORM options

Package Exports

  • orm-options-generator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (orm-options-generator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ORM Options Generator

We are converting query params that comes in the requests into a ORM options like sequelize options.

Supported ORM libraries

Installation

npm install orm-options-generator

Usage

import ORMOptionsGenerator from 'orm-options-generator';
import Post from './models';

const { sequelizeFindOptionsGenerator } = ORMOptionsGenerator;

index = (request, response) => {
    // Get query from request
    const { query } = request;

    // Generate FindOptions to be passed to sequelize model
    const options = sequelizeFindOptionsGenerator(query);
    
    // use options in findAll. Note: `Post` is a sequelize model
    Post.findAll(options)
    .then((posts) => {
        response.status(200).json(posts);
    })
}

Options

Options should be an object contain these properties:

  • [FIELD_NAME]:
    • could contain an object with properties: lt, lte, gt, gte, eq
    • Could contain a value (to find equal)
    • Could contain an array of values (to select equal any of them)
  • and/or
    • Could contain an object with properties. Each property should be an field name (and field name could have values as in [FIELD_NAME] point)
    • Could contain an array, each object should contain properties like previous point (field name, and field name should contain props like [FIELD_NAME])

LICENSE

MIT

Developers

Mohamed Sharif