orm-options-generator
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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

Package Sidebar

Install

npm i orm-options-generator

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

10.9 kB

Total Files

15

Last publish

Collaborators

  • mhmdtshref