Skip to content

Commit 4748209

Browse files
committed
Added misc block and converted double quotes to single quotes in output query
1 parent 5f24fab commit 4748209

File tree

4 files changed

+65
-18
lines changed

4 files changed

+65
-18
lines changed

src/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const convertObjValues2List = composeObjValueMapper(arrify);
99

1010
export const select = function select(selectConfigs) {
1111
const arrifiedSelectConfigs = convertObjValues2List(selectConfigs, ['groupBy', 'aggregate', 'fields', 'orderBy']);
12-
const {fields, aggregate, from, where, groupBy, having, orderBy, limit} = arrifiedSelectConfigs;
12+
const {fields, aggregate, from, where, groupBy, having, orderBy, limit, misc} = arrifiedSelectConfigs;
1313

1414
const projectionFields = deriveProjection({fields, groupBy, aggregate});
1515
const whereClause = buildWhereClause.build(where);
@@ -44,6 +44,10 @@ export const select = function select(selectConfigs) {
4444
{
4545
condition: limitClause,
4646
tpl: `LIMIT ${limitClause}`,
47-
}
47+
},
48+
{
49+
condition: misc,
50+
tpl: misc,
51+
},
4852
], ' ');
4953
};

src/quotifyValue.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default value => {
22
if(typeof value === 'string')
3-
return `"${value}"`;
3+
return `'${value}'`;
44
else
55
return value;
66
}

src/test/buildWhereClause.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('testing buildWhereClause module', () => {
1616
}
1717
],
1818
`
19-
A = "5" AND B IN ("5", "10")
19+
A = '5' AND B IN ('5', '10')
2020
`,
2121
],
2222
[
@@ -33,7 +33,7 @@ describe('testing buildWhereClause module', () => {
3333
}
3434
],
3535
`
36-
A != "5" AND B NOT IN ("5", 13)
36+
A != '5' AND B NOT IN ('5', 13)
3737
`,
3838
],
3939
[
@@ -96,14 +96,14 @@ describe('testing buildWhereClause module', () => {
9696
},
9797
],
9898
`
99-
A = "5" AND
100-
B IN (13, "15") AND
99+
A = '5' AND
100+
B IN (13, '15') AND
101101
C IS null AND
102-
X LIKE "% Profit %" AND
102+
X LIKE '% Profit %' AND
103103
D != 6 AND
104-
E NOT IN (6, "Foo") AND
104+
E NOT IN (6, 'Foo') AND
105105
F IS NOT null AND
106-
Y NOT LIKE "_Under"
106+
Y NOT LIKE '_Under'
107107
`,
108108
],
109109
[
@@ -135,7 +135,7 @@ describe('testing buildWhereClause module', () => {
135135
}
136136
],
137137
`
138-
NAME = "Piyush" AND
138+
NAME = 'Piyush' AND
139139
ROLL = 13 AND
140140
(
141141
A = 5 OR A = 10
@@ -190,14 +190,14 @@ describe('testing buildWhereClause module', () => {
190190
]
191191
},
192192
`
193-
a IN ("1", "2") OR
193+
a IN ('1', '2') OR
194194
a IS null OR
195195
(
196196
b IS NOT null AND
197-
c NOT IN ("1", "2") AND
197+
c NOT IN ('1', '2') AND
198198
(
199199
b NOT BETWEEN 15 AND 19 AND
200-
c BETWEEN "1" AND "2"
200+
c BETWEEN '1' AND '2'
201201
)
202202
)
203203
`
@@ -259,7 +259,7 @@ describe('testing buildWhereClause module', () => {
259259
after: '5'
260260
},
261261
`
262-
A BETWEEN "2" AND "5"
262+
A BETWEEN '2' AND '5'
263263
`
264264
],
265265
[

src/test/index.test.js

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('testing json2sql module', () => {
4545
},
4646
`
4747
SELECT A, B, count(D) AS CNT FROM STUDENTS
48-
WHERE NAME = "Piyush" AND ROLL = 13 AND (A = 5 OR A = 10)
48+
WHERE NAME = 'Piyush' AND ROLL = 13 AND (A = 5 OR A = 10)
4949
GROUP BY A, B, C
5050
ORDER BY A
5151
`,
@@ -84,9 +84,9 @@ describe('testing json2sql module', () => {
8484
`
8585
SELECT dept, loc, uniq(name) AS UniquesNames
8686
FROM Students
87-
WHERE dept IN ("Eng", "HM")
87+
WHERE dept IN ('Eng', 'HM')
8888
GROUP BY dept, loc
89-
HAVING uniq(name) NOT LIKE "%Piyush%"
89+
HAVING uniq(name) NOT LIKE '%Piyush%'
9090
ORDER BY name desc
9191
`
9292
],
@@ -101,6 +101,49 @@ describe('testing json2sql module', () => {
101101
LIMIT 100
102102
`
103103
],
104+
[
105+
{
106+
from: 'imaginary',
107+
fields: '*',
108+
misc: [
109+
'some random text',
110+
'at end',
111+
]
112+
},
113+
`
114+
SELECT * FROM imaginary
115+
some random textat end
116+
`,
117+
],
118+
[
119+
{
120+
from: 'imaginary',
121+
fields: '*',
122+
misc: 'some random text'
123+
},
124+
`
125+
SELECT * FROM imaginary
126+
some random text
127+
`,
128+
],
129+
[
130+
{
131+
from: 'imaginary',
132+
fields: '*',
133+
misc: {
134+
joinChar: ' ',
135+
tpl: [
136+
'some random text',
137+
'at end',
138+
]
139+
}
140+
},
141+
`
142+
SELECT * FROM imaginary
143+
some random text at end
144+
`,
145+
],
146+
104147

105148
])('testing using it.each', (received, expected) => {
106149
expect(select(received)).toBeSimilarWith(expected);

0 commit comments

Comments
 (0)