0.0.15 • Published 4 years ago

jq-lang v0.0.15

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Install jql

npm install jq-lang

JQL = JSON Query Language

JQL translates json to sql code. Syntax is ANSI sql, except offset and limit keywords (which is SQL Server). JQL is heavily influenced by mongo db.

JQL is designed to be integrated into General Endpoint (GE), a data driven http api.

Normalization Conventions

jql has 3 normalization conventions:
1. All tables must have an ID field that is primary key and autoincrement. This convention is mandatory.
2. FKs follow naming convention {tableName}ID.
3. FK lookup tables have a "name" field for display. Use a computed column for names that are composites.

JQL query object

Post body for query contains json object with these fields.

PropertyDescriptionType
fieldstable column names. If not set, returns tableName.*string[]
joinsTables on which inner joins are performed. See join operations belowstring[] or object[]
whereObject containing fields to form where clause. See Where clause operators below.object
orderByarray of strings of field names to order by. '-fieldName' for descending. 'tableName.fieldName' is valid.string or string[]
childrentable name for child records. if children property exists, it will return an additional array of objects for each child table in input array. pulls based on foreign key conventionstring[]
offsetoffset for starting select (requires order by and limit)int
limitlimit the number of rows returned (requires order by and limit) typically used for paging.int

Join Operations

Join operates by default on conventions. Default adds {joinTableName}Name to columns and joins based on naming convention. Use -tableName for left outer join.

jqlsql
joins: "mytable"select mytableName... inner join mytable on mytable.id = mytableID
joins: "-mytable"select mytableName... left outer join mytable on mytable.id = mytableID
joins: [{model:"mytable", fields:"myField1", "myField2"}]select myField1, myField2... inner join mytable on mytable.id = mytableID
joins: [{model:"machine",on:{"machine.ID":"mytable.machineID"}}]inner join machine on machine.ID = mytable.machineID

Where clause operators

JQL has mongo db style where clause operators.

propertyeffect
$nenot equal <>
$gtgreater than >
$gtegreater than or equal to >=
$ltless than <
$lteless than or equal to <=
likesql like operator
Examples
jqlsql
where: { active: 1, deleted: 0}where active =1 and deleted = 0
where: { qty: { $gt: 20 } }where qty > 20
where: { price: { $gt: 1, $lt: 2 }where price > 1 and price < 2
0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago