0.3.6 • Published 2 months ago

@bitovi/sequelize-querystring-parser v0.3.6

Weekly downloads
-
License
MIT
Repository
-
Last release
2 months ago

sequelize-querystring-parser

This library builds on top of @bitovi/querystring-parser to transform CRUD-related querystrings into structured data for the Sequelize ORM.

Installation

npm install @bitovi/sequelize-querystring-parser

If you do not plan to use this library with Sequelize, please install @bitovi/querystring-parser.

Usage

const querystringParser = require("@bitovi/sequelize-querystring-parser");

Sort Parameters

References:

const result = querystringParser.parse("sort=-date,name");
console.log(result);
// {
//   orm: "sequelize",
//   data: {
//     order: [["date", "DESC"],["name","ASC"]]
//  },
//   errors: [],
// };

Pagination Parameters

References:

const result = querystringParser.parse("page[number]=1&page[size]=10");
console.log(result);
// {
//   orm: "sequelize",
//   data: {
//     offset: 0,
//     limit: 10
//  },
//   errors: []
// };

Fields Parameters

References:

const result = querystringParser.parse("fields[]=id,name");
console.log(result);
// {
//   orm: "sequelize",
//   data: {
//     attributes: ["id","name"]
//  },
//   errors: []
// };

Include Parameters

References:

const result = querystringParser.parse("include=pets,dogs");
console.log(result);
// {
//   orm: "sequelize",
//   data: {
//     include: [
//       { association: "pets", include: [] },
//       { association: "dogs", include: [] }
//     ]
//  },
//   errors: []
// };

Filter Parameters

References:

const result = querystringParser.parse("filter=and(any('age','10','20'),equals('name','mike'))");
console.log(result);
// {
//   orm: "sequelize",
//   data: {
//     where: {
//       [Symbol(and)] : [
//         {
//           age: {
//             [Symbol(in)]: [10, 20]
//           }
//         },
//         {
//           name: {
//             [Symbol(eq)]: "mike"
//           }
//         }
//       ]
//     }
//  },
//   errors: []
// };

Note: Database Validations should be done before or after passing the query to the library before the database call is made.

Note: The Symbol() calls use the Op imported from the Sequelize library, not the Javascript Symbol class.

Example

A more practical example on how to use this library in your project can be found here

Further Documentation

This library builds on @bitovi/querystring-parser. See its documentation for more on using querystring-parser.

0.3.6

2 months ago

0.3.5

2 months ago

0.3.4

2 months ago

0.3.3

4 months ago

0.3.2

5 months ago

0.3.0

5 months ago

0.3.1

5 months ago

0.2.16

5 months ago

0.2.15

5 months ago

0.2.14

5 months ago

0.2.13

5 months ago

0.2.12

5 months ago

0.2.11

5 months ago

0.2.10

5 months ago

0.1.10

10 months ago

0.1.11

10 months ago

0.1.12

10 months ago

0.1.14

9 months ago

0.1.15

9 months ago

0.2.1-pre.0

9 months ago

0.2.1

9 months ago

0.2.0

9 months ago

0.2.7

8 months ago

0.1.16

9 months ago

0.2.6

8 months ago

0.1.17

9 months ago

0.2.9

7 months ago

0.1.18

9 months ago

0.2.8

7 months ago

0.1.9

10 months ago

0.2.3

9 months ago

0.2.2

9 months ago

0.2.5

8 months ago

0.2.4

8 months ago

0.1.8

11 months ago

0.1.7

11 months ago

0.1.6

1 year ago

0.1.3

2 years ago

0.1.2

2 years ago