You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -12,10 +12,10 @@ Currently, it can only perform select queries.
12
12
13
13
## TODO:
14
14
15
-
- Implement Union queries
16
-
- Insert Query
17
-
- Validate SQL Syntax
18
-
- ?
15
+
-Implement Union queries
16
+
-Insert Query
17
+
-Validate SQL Syntax
18
+
-?
19
19
20
20
## Installation
21
21
@@ -120,185 +120,185 @@ const (
120
120
121
121
In general, the structure of the JSON format used is as follows:
122
122
123
-
-**_table_**: Used to describe the table name, e.g. table_name (string)
123
+
-**_table_**: Used to describe the table name, e.g. table_name (string)
124
124
125
-
-**\*selectFields\*\***:
126
-
Used to select fields from a table, this property uses the **_Array_** type, you can combine **_Array of String_**, and **_Array of Json_**, the example is as follows:
125
+
-**\*selectFields\*\***:
126
+
Used to select fields from a table, this property uses the **_Array_** type, you can combine **_Array of String_**, and **_Array of Json_**, the example is as follows:
127
127
128
-
```json
129
-
{
130
-
"selectFields": [
131
-
"table_1.a",
132
-
{
133
-
"field": "table_1.b",
134
-
"alias": "foo_bar"
135
-
},
136
-
{
137
-
"field": "table_2.a",
138
-
"alias": "baz",
139
-
"subquery": {
140
-
"table": "table_4",
141
-
"selectFields": ["*"],
142
-
"conditions": [
128
+
```json
129
+
{
130
+
"selectFields": [
131
+
"table_1.a",
143
132
{
144
-
"datatype": "number",
145
-
"clause": "a",
146
-
"operator": "=",
147
-
"value": 1
148
-
}
149
-
],
150
-
"limit": 1
151
-
}
152
-
},
153
-
"table_2.b",
154
-
"table_3.a",
155
-
"table_3.b"
156
-
]
157
-
}
158
-
```
133
+
"field": "table_1.b",
134
+
"alias": "foo_bar"
135
+
},
136
+
{
137
+
"field": "table_2.a",
138
+
"alias": "baz",
139
+
"subquery": {
140
+
"table": "table_4",
141
+
"selectFields": ["*"],
142
+
"conditions": [
143
+
{
144
+
"datatype": "number",
145
+
"clause": "a",
146
+
"operator": "=",
147
+
"value": 1
148
+
}
149
+
],
150
+
"limit": 1
151
+
}
152
+
},
153
+
"table_2.b",
154
+
"table_3.a",
155
+
"table_3.b"
156
+
]
157
+
}
158
+
```
159
159
160
-
There you can see there is a subquery, you can use a subquery with the same format as its parent, you can also describe a field with an alias in the selection field.
160
+
There you can see there is a subquery, you can use a subquery with the same format as its parent, you can also describe a field with an alias in the selection field.
161
161
162
-
> **_NOTE:_** If you are using a subquery, you do not need to describe the data type
162
+
> **_NOTE:_** If you are using a subquery, you do not need to describe the data type
163
163
164
-
-**_join_**:
165
-
You can use join to combine multiple tables, an example is as follows:
164
+
- **_join_**:
165
+
You can use join to combine multiple tables, an example is as follows:
166
166
167
-
```json
168
-
{
169
-
"join": [
170
-
{
171
-
"table": "table_2",
172
-
"type": "join",
173
-
"on": {
174
-
"table_2.a": "table_1.a"
175
-
}
176
-
},
177
-
{
178
-
"table": "table_3",
179
-
"type": "left",
180
-
"on": {
181
-
"table_3.a": "table_2.a"
182
-
}
183
-
}
184
-
]
185
-
}
186
-
```
167
+
```json
168
+
{
169
+
"join": [
170
+
{
171
+
"table": "table_2",
172
+
"type": "join",
173
+
"on": {
174
+
"table_2.a": "table_1.a"
175
+
}
176
+
},
177
+
{
178
+
"table": "table_3",
179
+
"type": "left",
180
+
"on": {
181
+
"table_3.a": "table_2.a"
182
+
}
183
+
}
184
+
]
185
+
}
186
+
```
187
187
188
-
-**conditions**:
189
-
Conditions are used for SQL Where clauses. The structure of these conditions is dynamic; you can use a function, subquery, or composite. Consider the following example:
190
-
```json
191
-
{
192
-
"conditions": [
193
-
{
194
-
"datatype": "string",
195
-
"clause": "table_1.a",
196
-
"operator": "=",
197
-
"value": "foo"
198
-
},
199
-
{
200
-
"operand": "and",
201
-
"datatype": "boolean",
202
-
"clause": "table_1.b",
203
-
"operator": "=",
204
-
"value": true
205
-
},
206
-
{
207
-
"operand": "and",
208
-
"datatype": "function",
209
-
"clause": "table_2.a",
210
-
"operator": ">",
211
-
"value": {
212
-
"sqlFunc": {
213
-
"name": "sum",
214
-
"params": [100]
215
-
}
216
-
}
217
-
},
218
-
{
219
-
"operand": "and",
220
-
"clause": "table_2.b",
221
-
"operator": "=",
222
-
"value": {
223
-
"subquery": {
224
-
"table": "table_4",
225
-
"selectFields": ["*"],
226
-
"conditions": [
227
-
{
228
-
"datatype": "number",
229
-
"clause": "a",
188
+
- **conditions**:
189
+
Conditions are used for SQL Where clauses. The structure of these conditions is dynamic; you can use a function, subquery, or composite. Consider the following example:
190
+
```json
191
+
{
192
+
"conditions": [
193
+
{
194
+
"datatype": "string",
195
+
"clause": "table_1.a",
230
196
"operator": "=",
231
-
"value": 1
232
-
}
233
-
],
234
-
"limit": 1
235
-
}
236
-
}
237
-
},
238
-
{
239
-
"operand": "or",
240
-
"composite": [
241
-
{
242
-
"clause": "table_3.a",
243
-
"datatype": "string",
244
-
"operator": "between",
245
-
"value": {
246
-
"from": "2020-01-01",
247
-
"to": "2023-01-01"
197
+
"value": "foo"
198
+
},
199
+
{
200
+
"operand": "and",
201
+
"datatype": "boolean",
202
+
"clause": "table_1.b",
203
+
"operator": "=",
204
+
"value": true
205
+
},
206
+
{
207
+
"operand": "and",
208
+
"datatype": "function",
209
+
"clause": "table_2.a",
210
+
"operator": ">",
211
+
"value": {
212
+
"sqlFunc": {
213
+
"name": "sum",
214
+
"params": [100]
215
+
}
216
+
}
217
+
},
218
+
{
219
+
"operand": "and",
220
+
"clause": "table_2.b",
221
+
"operator": "=",
222
+
"value": {
223
+
"subquery": {
224
+
"table": "table_4",
225
+
"selectFields": ["*"],
226
+
"conditions": [
227
+
{
228
+
"datatype": "number",
229
+
"clause": "a",
230
+
"operator": "=",
231
+
"value": 1
232
+
}
233
+
],
234
+
"limit": 1
235
+
}
236
+
}
237
+
},
238
+
{
239
+
"operand": "or",
240
+
"composite": [
241
+
{
242
+
"clause": "table_3.a",
243
+
"datatype": "string",
244
+
"operator": "between",
245
+
"value": {
246
+
"from": "2020-01-01",
247
+
"to": "2023-01-01"
248
+
}
249
+
},
250
+
{
251
+
"operand": "and",
252
+
"datatype": "string",
253
+
"clause": "table_3.b",
254
+
"operator": "=",
255
+
"value": "2"
256
+
}
257
+
]
248
258
}
249
-
},
250
-
{
251
-
"operand": "and",
252
-
"datatype": "string",
253
-
"clause": "table_3.b",
254
-
"operator": "=",
255
-
"value": "2"
256
-
}
257
259
]
258
-
}
259
-
]
260
-
}
261
-
```
262
-
-**groupBy**:
260
+
}
261
+
```
262
+
- **groupBy**:
263
263
264
-
```json
265
-
{
266
-
"groupBy": {
267
-
"fields": ["table_1.a"]
264
+
```json
265
+
{
266
+
"groupBy": {
267
+
"fields": ["table_1.a"]
268
+
}
268
269
}
269
-
}
270
-
```
270
+
```
271
271
272
-
-**having**
273
-
```json
274
-
{
275
-
"having": [
276
-
{
277
-
"clause": {
278
-
"sqlFunc": {
279
-
"name": "count",
280
-
"isField": true,
281
-
"params": ["table_2.a"]
282
-
}
272
+
- **having**
273
+
```json
274
+
{
275
+
"having": [
276
+
{
277
+
"clause": {
278
+
"sqlFunc": {
279
+
"name": "count",
280
+
"isField": true,
281
+
"params": ["table_2.a"]
282
+
}
283
+
},
284
+
"datatype": "number",
285
+
"operator": ">",
286
+
"value": 10
287
+
}
288
+
]
289
+
}
290
+
```
291
+
**orderBy, limit, offset**:
292
+
```json
293
+
{
294
+
"orderBy": {
295
+
"fields": ["table_1.a", "table_2.a"],
296
+
"sort": "asc"
283
297
},
284
-
"datatype": "number",
285
-
"operator": ">",
286
-
"value": 10
287
-
}
288
-
]
289
-
}
290
-
```
291
-
**orderBy, limit, offset**:
292
-
```json
293
-
{
294
-
"orderBy": {
295
-
"fields": ["table_1.a", "table_2.a"],
296
-
"sort": "asc"
297
-
},
298
-
"limit": 1,
299
-
"offset": 0
300
-
}
301
-
```
298
+
"limit": 1,
299
+
"offset": 0
300
+
}
301
+
```
302
302
303
303
## Convert to Raw Query
304
304
@@ -483,3 +483,16 @@ SELECT table_1.a, table_1.b AS foo_bar, (SELECT * FROM table_4 WHERE a = ? LIMIT
483
483
Param:
484
484
[1 foo true 100 1 2020-01-01 2023-01-01 2 10]
485
485
```
486
+
487
+
## Benchmarking
488
+
489
+
In this benchmarking process, I used a 2020 MacBook Pro M1 with an 8-core processor (arm64) and 8GB of RAM. The following are the benchmark results obtained on my MacBook.
0 commit comments