5.3.1 • Published 4 years ago

mega-nice-criteria v5.3.1

Weekly downloads
39
License
-
Repository
github
Last release
4 years ago

Mega Nice Criteria

Simple data structures to describe criteria for CRUD operations and which can be easily serialized for example to JSON.

Install

npm install mega-nice-criteria

Overview

ReadCriteria

import { ReadCriteria } from 'mega-nice-criteria'

let criteria: ReadCriteria = {
  id: 1,
  name: { operator: 'LIKE', value: '%ert%' },
  job: [ 'student', 'teacher' ],
  age: [{ operator: '>', value: 20 }, { operator: '<', value: 30 }],
  limit: 10,
  offset: 5,
  // order by one field
  orderBy: 'job',
  // ordery by mulitpe fields
  orderBy: [ 'job', 'age' ],
  // order by one field and specify the direction explicitly
  orderBy: {
    field: 'job',
    direction: 'DESC'
  },
  // order by multiple fields and specify their directions explicitly
  orderBy: [
    {
      field: 'job',
      direction: 'DESC'
    },
    {
      field: 'age',
      direction: 'DESC'
    }
  ]
}  

Describes a query looking like this in SQL.

... WHERE id = 1 AND name LIKE '%ert%' AND job IN ('student', 'teacher') AND age > 20 AND age < 30

InsertCriteria

import { InsertCriteria } from 'mega-nice-criteria'

let criteria: InsertCriteria = {
  name: 'Josa',
  job: 'Tree cutter',
  age: 36
}

Describes a query looking like this in SQL.

INSERT INTO table (name, job, age) VALUES ('Josa', 'Tree cutter', 36)

UpdateCriteria

import { UpdateCriteria } from 'mega-nice-criteria'

let criteria: UpdateCriteria = {
  id: 4,
  set: {
    name: 'Josa',
    job: 'Tree cutter',
    age: 36
  }
}

Describes a query looking like this in SQL.

UPDATE table SET name = 'Josa', job = 'Tree cutter', age = '36' WHERE id = 4

DeleteCriteria

import { DeleteCriteria } from 'mega-nice-criteria'

let criteria: DeleteCriteria = {
  id: 4
}

Describes a query looking like this in SQL.

DELETE FROM table WHERE id = 4
5.3.1

4 years ago

5.3.0

4 years ago

5.2.0

4 years ago

5.1.0

4 years ago

5.0.0

4 years ago

4.0.1

4 years ago

4.0.2

4 years ago

4.0.0

4 years ago

3.0.0

4 years ago