File tree Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ # json-sql-utility
2+
3+ This module is useful for buidling SQL queries from JSON objects.
4+ Currently only SELECT query is supported.
5+
6+ ## Install
7+ ``` javascript
8+ yarn add json- sql- utility
9+ or
10+ npm i json- sql- utility
11+ ```
12+
13+ ## Usage
14+ Simple example
15+
16+ ``` javascript
17+ import { select } from " json-sql-utility"
18+
19+ const query = select ({
20+ fields: [' A' , ' B' ],
21+ aggregate: [
22+ {
23+ fn: ' count' ,
24+ args: ' D' ,
25+ alias: ' CNT'
26+ }
27+ ],
28+ from: ' STUDENTS' ,
29+ where: [
30+ {
31+ operator: ' equal' ,
32+ field: ' NAME' ,
33+ value: ' Piyush'
34+ },
35+ {
36+ operator: ' =' ,
37+ field: ' ROLL' ,
38+ value: [13 ],
39+ },
40+ {
41+ operator: ' OR' ,
42+ conditions: [
43+ {
44+ operator: ' equal' ,
45+ field: ' A' ,
46+ value: 5 ,
47+ },
48+ {
49+ operator: ' equal' ,
50+ field: ' A' ,
51+ value: 10 ,
52+ }
53+ ]
54+ }
55+ ],
56+ groupBy: [' A' , ' B' , ' C' ],
57+ orderBy: [' A' ],
58+ });
59+
60+ console .log (query);
61+
62+ /*
63+ Will output:
64+
65+ SELECT A, B, count(D) AS CNT FROM STUDENTS
66+ WHERE NAME = "Piyush" AND ROLL = 13 AND (A = 5 OR A = 10)
67+ GROUP BY A, B, C
68+ ORDER BY A
69+
70+ */
71+ ```
You can’t perform that action at this time.
0 commit comments