soul-cli 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,705 @@
1
+ {
2
+ "swagger": "2.0",
3
+ "info": {
4
+ "version": "0.0.1",
5
+ "title": "Soul API",
6
+ "description": "API Documentation for <b>Soul</b>, a simple SQLite RESTful server. "
7
+ },
8
+ "host": "localhost:8000",
9
+ "basePath": "/",
10
+ "tags": [
11
+ {
12
+ "name": "Root",
13
+ "description": "Root endpoints"
14
+ },
15
+ {
16
+ "name": "Tables",
17
+ "description": "Tables endpoints"
18
+ },
19
+ {
20
+ "name": "Rows",
21
+ "description": "Rows endpoints"
22
+ }
23
+ ],
24
+ "schemes": [
25
+ "http",
26
+ "https"
27
+ ],
28
+ "securityDefinitions": {},
29
+ "consumes": [
30
+ "application/json"
31
+ ],
32
+ "produces": [
33
+ "application/json"
34
+ ],
35
+ "paths": {
36
+ "/api/": {
37
+ "get": {
38
+ "tags": [
39
+ "Root"
40
+ ],
41
+ "summary": "Timestamp",
42
+ "description": "Endpoint to return server timestamp",
43
+ "parameters": [],
44
+ "responses": {
45
+ "200": {
46
+ "description": "OK"
47
+ }
48
+ }
49
+ }
50
+ },
51
+ "/api/transaction": {
52
+ "post": {
53
+ "tags": [
54
+ "Root"
55
+ ],
56
+ "summary": "Transaction",
57
+ "description": "Endpoint to run any transaction, e.g. [{ \"query\": \"\" }, { \"statement\": \"\", \"values\": {} }, { \"query\": \"\" }]",
58
+ "parameters": [
59
+ {
60
+ "name": "body",
61
+ "in": "body",
62
+ "required": true,
63
+ "schema": {
64
+ "$ref": "#/definitions/TransactionRequestBody"
65
+ }
66
+ }
67
+ ],
68
+ "responses": {
69
+ "200": {
70
+ "description": "OK"
71
+ },
72
+ "400": {
73
+ "description": "Bad Request"
74
+ }
75
+ }
76
+ }
77
+ },
78
+ "/api/tables/": {
79
+ "get": {
80
+ "tags": [
81
+ "Tables"
82
+ ],
83
+ "summary": "List Tables",
84
+ "description": "Endpoint to list all tables",
85
+ "parameters": [
86
+ {
87
+ "name": "_search",
88
+ "in": "query",
89
+ "required": false,
90
+ "type": "string",
91
+ "description": "Search term"
92
+ },
93
+ {
94
+ "name": "_ordering",
95
+ "in": "query",
96
+ "required": false,
97
+ "type": "string",
98
+ "description": "Ordering term"
99
+ }
100
+ ],
101
+ "responses": {
102
+ "200": {
103
+ "description": "OK"
104
+ },
105
+ "400": {
106
+ "description": "Bad Request"
107
+ }
108
+ }
109
+ },
110
+ "post": {
111
+ "tags": [
112
+ "Tables"
113
+ ],
114
+ "summary": "Create Table",
115
+ "description": "Endpoint to create a table",
116
+ "parameters": [
117
+ {
118
+ "name": "body",
119
+ "in": "body",
120
+ "required": true,
121
+ "schema": {
122
+ "$ref": "#/definitions/CreateTableRequestBody"
123
+ }
124
+ }
125
+ ],
126
+ "responses": {
127
+ "201": {
128
+ "description": "Table created",
129
+ "schema": {
130
+ "$ref": "#/definitions/CreateTableSuccessResponse"
131
+ }
132
+ },
133
+ "400": {
134
+ "description": "Bad request",
135
+ "schema": {
136
+ "$ref": "#/definitions/CreateTableErrorResponse"
137
+ }
138
+ }
139
+ }
140
+ }
141
+ },
142
+ "/api/tables/{name}": {
143
+ "get": {
144
+ "tags": [
145
+ "Tables"
146
+ ],
147
+ "summary": "Get Table Schema",
148
+ "description": "Endpoint to get the schema of a table",
149
+ "parameters": [
150
+ {
151
+ "name": "name",
152
+ "in": "path",
153
+ "required": true,
154
+ "type": "string",
155
+ "description": "Name of the table"
156
+ }
157
+ ],
158
+ "responses": {
159
+ "200": {
160
+ "description": "OK"
161
+ },
162
+ "400": {
163
+ "description": "Bad Request"
164
+ }
165
+ }
166
+ },
167
+ "delete": {
168
+ "tags": [
169
+ "Tables"
170
+ ],
171
+ "summary": "Delete Table",
172
+ "description": "Endpoint to delete a table",
173
+ "parameters": [
174
+ {
175
+ "name": "name",
176
+ "in": "path",
177
+ "required": true,
178
+ "type": "string",
179
+ "description": "Name of the table"
180
+ }
181
+ ],
182
+ "responses": {
183
+ "200": {
184
+ "description": "OK"
185
+ },
186
+ "400": {
187
+ "description": "Bad Request"
188
+ }
189
+ }
190
+ }
191
+ },
192
+ "/api/tables/{name}/rows": {
193
+ "get": {
194
+ "tags": [
195
+ "Rows"
196
+ ],
197
+ "summary": "List Rows",
198
+ "description": "Endpoint to list rows of a table.",
199
+ "parameters": [
200
+ {
201
+ "name": "name",
202
+ "in": "path",
203
+ "required": true,
204
+ "type": "string",
205
+ "description": "Table name."
206
+ },
207
+ {
208
+ "name": "_page",
209
+ "description": "Page number.",
210
+ "in": "query",
211
+ "type": "number",
212
+ "default": 1
213
+ },
214
+ {
215
+ "name": "_limit",
216
+ "description": "Number of rows per page.",
217
+ "in": "query",
218
+ "type": "number",
219
+ "default": 10
220
+ },
221
+ {
222
+ "name": "_ordering",
223
+ "description": "Ordering of rows. e.g. ?_ordering=-age will order rows by age descending.",
224
+ "in": "query",
225
+ "type": "string"
226
+ },
227
+ {
228
+ "name": "_schema",
229
+ "description": "Schema of rows. e.g. ?_schema=name,age will return only name and age fields.",
230
+ "in": "query",
231
+ "type": "string"
232
+ },
233
+ {
234
+ "name": "_extend",
235
+ "description": "Extend rows. e.g. ?_extend=user_id will return user data for each row.",
236
+ "in": "query",
237
+ "type": "string"
238
+ },
239
+ {
240
+ "name": "_search",
241
+ "in": "query",
242
+ "type": "string"
243
+ },
244
+ {
245
+ "name": "filters",
246
+ "in": "query",
247
+ "type": "string"
248
+ }
249
+ ],
250
+ "responses": {
251
+ "200": {
252
+ "description": "OK"
253
+ },
254
+ "400": {
255
+ "description": "Bad Request"
256
+ }
257
+ }
258
+ },
259
+ "post": {
260
+ "tags": [
261
+ "Rows"
262
+ ],
263
+ "summary": "Insert Row",
264
+ "description": "Insert a new row in a table",
265
+ "parameters": [
266
+ {
267
+ "name": "name",
268
+ "in": "path",
269
+ "required": true,
270
+ "type": "string",
271
+ "description": "Table name"
272
+ },
273
+ {
274
+ "name": "body",
275
+ "in": "body",
276
+ "required": true,
277
+ "schema": {
278
+ "$ref": "#/definitions/InsertRowRequestBody"
279
+ }
280
+ }
281
+ ],
282
+ "responses": {
283
+ "201": {
284
+ "description": "Row inserted successfully",
285
+ "schema": {
286
+ "$ref": "#/definitions/InsertRowSuccessResponse"
287
+ }
288
+ },
289
+ "400": {
290
+ "description": "Bad request",
291
+ "schema": {
292
+ "$ref": "#/definitions/InsertRowErrorResponse"
293
+ }
294
+ }
295
+ }
296
+ }
297
+ },
298
+ "/api/tables/{name}/rows/{pk}": {
299
+ "get": {
300
+ "tags": [
301
+ "Rows"
302
+ ],
303
+ "summary": "Retrieve Row",
304
+ "description": "Retrieve a row by primary key",
305
+ "parameters": [
306
+ {
307
+ "name": "name",
308
+ "in": "path",
309
+ "required": true,
310
+ "type": "string",
311
+ "description": "Table name"
312
+ },
313
+ {
314
+ "name": "pk",
315
+ "in": "path",
316
+ "required": true,
317
+ "type": "string",
318
+ "description": "Primary key"
319
+ },
320
+ {
321
+ "name": "_schema",
322
+ "in": "query",
323
+ "description": "Fields to return",
324
+ "required": false,
325
+ "type": "string"
326
+ },
327
+ {
328
+ "name": "_extend",
329
+ "in": "query",
330
+ "description": "Foreign keys to extend",
331
+ "required": false,
332
+ "type": "string"
333
+ },
334
+ {
335
+ "name": "_field",
336
+ "in": "query",
337
+ "description": "If you want to get field by any other field than primary key, use this parameter",
338
+ "required": false,
339
+ "type": "string"
340
+ }
341
+ ],
342
+ "responses": {
343
+ "200": {
344
+ "description": "OK"
345
+ },
346
+ "400": {
347
+ "description": "Bad Request"
348
+ },
349
+ "404": {
350
+ "description": "Not Found"
351
+ }
352
+ }
353
+ },
354
+ "put": {
355
+ "tags": [
356
+ "Rows"
357
+ ],
358
+ "summary": "Update Row",
359
+ "description": "Update a row by primary key",
360
+ "parameters": [
361
+ {
362
+ "name": "name",
363
+ "in": "path",
364
+ "required": true,
365
+ "type": "string",
366
+ "description": "Table name"
367
+ },
368
+ {
369
+ "name": "pk",
370
+ "in": "path",
371
+ "required": true,
372
+ "type": "string",
373
+ "description": "Primary key"
374
+ },
375
+ {
376
+ "name": "body",
377
+ "in": "body",
378
+ "required": true,
379
+ "schema": {
380
+ "$ref": "#/definitions/UpdateRowRequestBody"
381
+ }
382
+ },
383
+ {
384
+ "name": "_field",
385
+ "in": "query",
386
+ "description": "If you want to update row by any other field than primary key, use this parameter",
387
+ "required": false,
388
+ "type": "string"
389
+ },
390
+ {
391
+ "name": "in",
392
+ "in": "query",
393
+ "type": "string"
394
+ },
395
+ {
396
+ "name": "required",
397
+ "in": "query",
398
+ "type": "string"
399
+ },
400
+ {
401
+ "name": "type",
402
+ "in": "query",
403
+ "type": "string"
404
+ },
405
+ {
406
+ "name": "schema",
407
+ "in": "query",
408
+ "type": "string"
409
+ }
410
+ ],
411
+ "responses": {
412
+ "200": {
413
+ "description": "OK"
414
+ },
415
+ "400": {
416
+ "description": "Bad Request"
417
+ }
418
+ }
419
+ },
420
+ "delete": {
421
+ "tags": [
422
+ "Rows"
423
+ ],
424
+ "summary": "Delete Row",
425
+ "description": "Delete a row by primary key",
426
+ "parameters": [
427
+ {
428
+ "name": "name",
429
+ "in": "path",
430
+ "required": true,
431
+ "type": "string",
432
+ "description": "Table name"
433
+ },
434
+ {
435
+ "name": "pk",
436
+ "in": "path",
437
+ "required": true,
438
+ "type": "string",
439
+ "description": "Primary key"
440
+ },
441
+ {
442
+ "name": "_field",
443
+ "in": "query",
444
+ "description": "If you want to delete row by any other field than primary key, use this parameter",
445
+ "required": false,
446
+ "type": "string"
447
+ }
448
+ ],
449
+ "responses": {
450
+ "200": {
451
+ "description": "OK"
452
+ },
453
+ "404": {
454
+ "description": "Not Found"
455
+ }
456
+ }
457
+ }
458
+ }
459
+ },
460
+ "definitions": {
461
+ "Table": {
462
+ "type": "object",
463
+ "properties": {
464
+ "name": {
465
+ "type": "string",
466
+ "example": "users"
467
+ }
468
+ }
469
+ },
470
+ "Row": {
471
+ "type": "object",
472
+ "properties": {}
473
+ },
474
+ "Query": {
475
+ "type": "object",
476
+ "properties": {
477
+ "query": {
478
+ "type": "string",
479
+ "example": "SELECT * FROM users"
480
+ }
481
+ }
482
+ },
483
+ "Statement": {
484
+ "type": "object",
485
+ "properties": {
486
+ "statement": {
487
+ "type": "string",
488
+ "example": "INSERT INTO users (id, firstName, lastName) VALUES (:id, :firstName, :lastName)"
489
+ },
490
+ "values": {
491
+ "type": "object",
492
+ "properties": {
493
+ "id": {
494
+ "type": "number",
495
+ "example": 1
496
+ },
497
+ "firstName": {
498
+ "type": "string",
499
+ "example": "John"
500
+ },
501
+ "lastName": {
502
+ "type": "string",
503
+ "example": "Doe"
504
+ }
505
+ }
506
+ }
507
+ }
508
+ },
509
+ "Transaction": {
510
+ "type": "object",
511
+ "properties": {
512
+ "transaction": {
513
+ "type": "array",
514
+ "items": {
515
+ "$ref": "#/definitions/Statement"
516
+ }
517
+ }
518
+ }
519
+ },
520
+ "ForeignKey": {
521
+ "type": "object",
522
+ "properties": {
523
+ "table": {
524
+ "type": "string",
525
+ "example": "users"
526
+ },
527
+ "column": {
528
+ "type": "string",
529
+ "example": "id"
530
+ },
531
+ "onDelete": {
532
+ "type": "string",
533
+ "example": "CASCADE"
534
+ },
535
+ "onUpdate": {
536
+ "type": "string",
537
+ "example": "CASCADE"
538
+ }
539
+ }
540
+ },
541
+ "Field": {
542
+ "type": "object",
543
+ "properties": {
544
+ "name": {
545
+ "type": "string",
546
+ "example": "user_id"
547
+ },
548
+ "type": {
549
+ "type": "string",
550
+ "example": "INTEGER"
551
+ },
552
+ "default": {
553
+ "type": "number",
554
+ "example": 1
555
+ },
556
+ "notNull": {
557
+ "type": "boolean",
558
+ "example": true
559
+ },
560
+ "unique": {
561
+ "type": "boolean",
562
+ "example": false
563
+ },
564
+ "primaryKey": {
565
+ "type": "boolean",
566
+ "example": false
567
+ },
568
+ "foreignKey": {
569
+ "$ref": "#/definitions/ForeignKey"
570
+ },
571
+ "index": {
572
+ "type": "boolean",
573
+ "example": false
574
+ }
575
+ }
576
+ },
577
+ "Schema": {
578
+ "type": "array",
579
+ "items": {
580
+ "$ref": "#/definitions/Field"
581
+ }
582
+ },
583
+ "CreateTableRequestBody": {
584
+ "type": "object",
585
+ "properties": {
586
+ "name": {
587
+ "type": "string",
588
+ "example": "users"
589
+ },
590
+ "schema": {
591
+ "$ref": "#/definitions/Schema"
592
+ },
593
+ "autoAddCreatedAt": {
594
+ "type": "boolean",
595
+ "example": true
596
+ },
597
+ "autoAddUpdatedAt": {
598
+ "type": "boolean",
599
+ "example": true
600
+ }
601
+ }
602
+ },
603
+ "CreateTableSuccessResponse": {
604
+ "type": "object",
605
+ "properties": {
606
+ "message": {
607
+ "type": "string",
608
+ "example": "Table created"
609
+ },
610
+ "data": {
611
+ "type": "object",
612
+ "properties": {
613
+ "name": {
614
+ "type": "string",
615
+ "example": "users"
616
+ },
617
+ "fields": {
618
+ "type": "array",
619
+ "items": {
620
+ "$ref": "#/definitions/Field"
621
+ }
622
+ }
623
+ }
624
+ }
625
+ }
626
+ },
627
+ "CreateTableErrorResponse": {
628
+ "type": "object",
629
+ "properties": {
630
+ "message": {
631
+ "type": "string",
632
+ "example": "Table not created"
633
+ },
634
+ "error": {
635
+ "type": "string",
636
+ "example": "already_exists"
637
+ },
638
+ "data": {
639
+ "type": "object",
640
+ "properties": {}
641
+ }
642
+ }
643
+ },
644
+ "InsertRowRequestBody": {
645
+ "$ref": "#/definitions/Row"
646
+ },
647
+ "InsertRowSuccessResponse": {
648
+ "type": "object",
649
+ "properties": {
650
+ "message": {
651
+ "type": "string",
652
+ "example": "Row inserted"
653
+ },
654
+ "data": {
655
+ "type": "object",
656
+ "properties": {
657
+ "id": {
658
+ "type": "number",
659
+ "example": 1
660
+ },
661
+ "createdAt": {
662
+ "type": "string",
663
+ "example": "2022-10-10 10:55:29"
664
+ },
665
+ "updatedAt": {
666
+ "type": "string",
667
+ "example": "2022-10-10 10:55:29"
668
+ },
669
+ "firstName": {
670
+ "type": "string",
671
+ "example": "John"
672
+ }
673
+ }
674
+ }
675
+ }
676
+ },
677
+ "InsertRowErrorResponse": {
678
+ "type": "object",
679
+ "properties": {
680
+ "message": {
681
+ "type": "string",
682
+ "example": "Row not inserted"
683
+ },
684
+ "error": {
685
+ "type": "string",
686
+ "example": "not_found"
687
+ }
688
+ }
689
+ },
690
+ "UpdateRowRequestBody": {
691
+ "type": "object",
692
+ "properties": {
693
+ "fields": {
694
+ "type": "array",
695
+ "items": {
696
+ "$ref": "#/definitions/Field"
697
+ }
698
+ }
699
+ }
700
+ },
701
+ "TransactionRequestBody": {
702
+ "$ref": "#/definitions/Transaction"
703
+ }
704
+ }
705
+ }
@@ -0,0 +1,11 @@
1
+ const { createTestTable, insertIntoTestTable } = require('.');
2
+
3
+ const setup = () => {
4
+ console.log('Test suite started');
5
+ console.log('Creating test table...');
6
+ createTestTable();
7
+ console.log('Inserting a row into test table...');
8
+ insertIntoTestTable();
9
+ };
10
+
11
+ module.exports = setup;