inibase 1.0.0-rc.58 → 1.0.0-rc.59
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.
- package/README.md +302 -125
- package/dist/cli.js +9 -19
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -3
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +16 -0
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -42,8 +42,10 @@ const users = await db.get("user", undefined, {
|
|
|
42
42
|
// Get items from "user" table where "favoriteFoods" does not includes "Pizza" or "Burger"
|
|
43
43
|
const users = await db.get("user", { favoriteFoods: "![]Pizza,Burger" });
|
|
44
44
|
```
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
> [!NOTE]
|
|
46
|
+
> Enjoy using Inibase? Consider sponsoring us via [PayPal](https://paypal.me/KarimAmahtil) <br>
|
|
47
|
+
> Your support helps us maintain and improve our services. <br>
|
|
48
|
+
> Thank you! 🫰
|
|
47
49
|
|
|
48
50
|
## Install
|
|
49
51
|
|
|
@@ -53,21 +55,28 @@ If you like Inibase, please sponsor: [GitHub Sponsors](https://github.com/sponso
|
|
|
53
55
|
|
|
54
56
|
## How it works?
|
|
55
57
|
|
|
56
|
-
|
|
58
|
+
`Inibase` organizes data into databases, tables, and columns, each stored in separate files.
|
|
59
|
+
|
|
60
|
+
- **POST**: New data is appended to column files efficiently.
|
|
61
|
+
- **GET**: Data retrieval is optimized by reading files line-by-line.
|
|
62
|
+
- **PUT**: Updates are streamlined, with only the relevant file being modified.
|
|
63
|
+
- **DELETE**: Removes lines from column files for swift deletion.
|
|
64
|
+
|
|
65
|
+
This structure ensures efficient storage, retrieval, and updates, making our system scalable and high-performing for diverse datasets and applications.
|
|
57
66
|
|
|
58
67
|
## Config (.env)
|
|
59
68
|
|
|
60
|
-
The `.env` file supports the following parameters
|
|
69
|
+
The `.env` file supports the following parameters
|
|
61
70
|
|
|
62
71
|
```ini
|
|
63
|
-
#
|
|
72
|
+
# Don't add this line, it's an auto generated secret key, will be using for encrypting the IDs
|
|
64
73
|
INIBASE_SECRET=
|
|
65
74
|
|
|
66
|
-
INIBASE_COMPRESSION=
|
|
67
|
-
INIBASE_CACHE=
|
|
75
|
+
INIBASE_COMPRESSION=false
|
|
76
|
+
INIBASE_CACHE=false
|
|
68
77
|
|
|
69
|
-
# Prepend new items to the beginning of file
|
|
70
|
-
INIBASE_REVERSE=
|
|
78
|
+
# Prepend new items to the beginning of file
|
|
79
|
+
INIBASE_REVERSE=false
|
|
71
80
|
```
|
|
72
81
|
|
|
73
82
|
## Benchmark
|
|
@@ -90,60 +99,94 @@ INIBASE_REVERSE=true
|
|
|
90
99
|
| PUT | 33 ms (10.29 mb) | 312 ms (11.06 mb) | 3539 ms (14.87 mb) |
|
|
91
100
|
| DELETE | 134 ms (13.50 mb) | 1224 ms (16.57 mb) | 7339 ms (11.46 mb) |
|
|
92
101
|
|
|
93
|
-
|
|
102
|
+
> Testing by default with `user` table, with username, email, password fields _so results include password encryption process_
|
|
103
|
+
> To run benchmarks, install *typescript* & *tsx* globally and run `benchmark` `benchmark:bulk` `benchmark:single`
|
|
94
104
|
|
|
95
|
-
##
|
|
105
|
+
## Inibase CLI
|
|
96
106
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
- [x] Criteria
|
|
101
|
-
- [x] Columns
|
|
102
|
-
- [x] Sort (using UNIX commands)
|
|
103
|
-
- [x] POST
|
|
104
|
-
- [x] PUT
|
|
105
|
-
- [x] DELETE
|
|
106
|
-
- [x] SUM
|
|
107
|
-
- [x] MAX
|
|
108
|
-
- [x] MIN
|
|
109
|
-
- [ ] Schema supported types:
|
|
110
|
-
- [x] String
|
|
111
|
-
- [x] Number
|
|
112
|
-
- [x] Boolean
|
|
113
|
-
- [x] Date
|
|
114
|
-
- [x] Email
|
|
115
|
-
- [x] Url
|
|
116
|
-
- [x] Table
|
|
117
|
-
- [x] Object
|
|
118
|
-
- [x] Array
|
|
119
|
-
- [x] Password
|
|
120
|
-
- [x] IP
|
|
121
|
-
- [x] HTML
|
|
122
|
-
- [x] Id
|
|
123
|
-
- [x] JSON
|
|
124
|
-
- [ ] TO-DO:
|
|
125
|
-
- [x] Improve caching
|
|
126
|
-
- [ ] Commenting the code
|
|
127
|
-
- [x] Add property "unique" for schema fields
|
|
128
|
-
- [ ] Add Backup feature (generate a tar.gz)
|
|
129
|
-
- [ ] Add Custom field validation property to schema (using RegEx?)
|
|
130
|
-
- [ ] Features:
|
|
131
|
-
- [ ] Encryption
|
|
132
|
-
- [x] Data Compression
|
|
133
|
-
- [x] Caching System
|
|
134
|
-
- [ ] Suggest [new feature +](https://github.com/inicontent/inibase/discussions/new?category=ideas)
|
|
107
|
+
```shell
|
|
108
|
+
npx inibase -p <databaseFolderPath>
|
|
109
|
+
```
|
|
135
110
|
|
|
111
|
+
<blockquote>
|
|
112
|
+
<details>
|
|
113
|
+
<summary>GET</summary>
|
|
136
114
|
|
|
137
|
-
|
|
115
|
+
```shell
|
|
116
|
+
get <tableName> -w <ID|LineNumber|Criteria> -p <pageNumber> -l <perPage> -c <columnName1> -c <columnName2>
|
|
117
|
+
```
|
|
118
|
+
</details>
|
|
138
119
|
|
|
139
120
|
<details>
|
|
140
121
|
<summary>POST</summary>
|
|
141
122
|
|
|
123
|
+
```shell
|
|
124
|
+
post <tableName> -d <InisonStrigifedData>
|
|
125
|
+
```
|
|
126
|
+
</details>
|
|
127
|
+
|
|
128
|
+
<details>
|
|
129
|
+
<summary>PUT</summary>
|
|
130
|
+
|
|
131
|
+
```shell
|
|
132
|
+
put <tableName> -d <InisonStrigifedData> -w <ID|LineNumber|Criteria>
|
|
133
|
+
```
|
|
134
|
+
</details>
|
|
135
|
+
|
|
136
|
+
<details>
|
|
137
|
+
<summary>DELETE</summary>
|
|
138
|
+
|
|
139
|
+
```shell
|
|
140
|
+
delete <tableName> -w <ID|LineNumber|Criteria>
|
|
141
|
+
```
|
|
142
|
+
</details>
|
|
143
|
+
</blockquote>
|
|
144
|
+
|
|
145
|
+
## Examples
|
|
146
|
+
|
|
147
|
+
<details>
|
|
148
|
+
<summary>Schema</summary>
|
|
149
|
+
<blockquote>
|
|
150
|
+
|
|
151
|
+
<details>
|
|
152
|
+
<summary>Create Schema</summary>
|
|
153
|
+
<blockquote>
|
|
154
|
+
|
|
155
|
+
<details>
|
|
156
|
+
<summary>Using schema.json file</summary>
|
|
157
|
+
<blockquote>
|
|
158
|
+
Inside the table folder
|
|
159
|
+
|
|
160
|
+
1. Create empty folders `.cache` `.tmp`
|
|
161
|
+
2. Create `schema.json` file
|
|
162
|
+
|
|
163
|
+
```jsonc
|
|
164
|
+
[
|
|
165
|
+
{
|
|
166
|
+
// Give a unique ID number for each field
|
|
167
|
+
"id": 1,
|
|
168
|
+
"key": "username",
|
|
169
|
+
"type": "string"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"id": 2,
|
|
173
|
+
"key": "email",
|
|
174
|
+
"type": "email"
|
|
175
|
+
},
|
|
176
|
+
]
|
|
177
|
+
```
|
|
178
|
+
</blockquote>
|
|
179
|
+
</details>
|
|
180
|
+
|
|
181
|
+
<details>
|
|
182
|
+
<summary>Using built-in function</summary>
|
|
183
|
+
<blockquote>
|
|
184
|
+
|
|
142
185
|
```js
|
|
143
186
|
import Inibase from "inibase";
|
|
144
187
|
const db = new Inibase("/databaseName");
|
|
145
188
|
|
|
146
|
-
const
|
|
189
|
+
const userSchema = [
|
|
147
190
|
{
|
|
148
191
|
key: "username",
|
|
149
192
|
type: "string",
|
|
@@ -209,7 +252,128 @@ const user_schema = [
|
|
|
209
252
|
},
|
|
210
253
|
];
|
|
211
254
|
|
|
212
|
-
|
|
255
|
+
await db.setTableSchema("user", userSchema);
|
|
256
|
+
```
|
|
257
|
+
</blockquote>
|
|
258
|
+
</details>
|
|
259
|
+
|
|
260
|
+
</blockquote>
|
|
261
|
+
</details>
|
|
262
|
+
|
|
263
|
+
<details>
|
|
264
|
+
<summary>Add field</summary>
|
|
265
|
+
<blockquote>
|
|
266
|
+
|
|
267
|
+
```js
|
|
268
|
+
import Inibase from "inibase";
|
|
269
|
+
const db = new Inibase("/databaseName");
|
|
270
|
+
|
|
271
|
+
const userSchema = await db.getTableSchema("user");
|
|
272
|
+
const newUserSchema = [...userSchema, {key: "phone2", type: "number", required: false}];
|
|
273
|
+
|
|
274
|
+
await db.setTableSchema("user", newUserSchema);
|
|
275
|
+
```
|
|
276
|
+
</blockquote>
|
|
277
|
+
</details>
|
|
278
|
+
|
|
279
|
+
<details>
|
|
280
|
+
<summary>Update field</summary>
|
|
281
|
+
<blockquote>
|
|
282
|
+
|
|
283
|
+
```js
|
|
284
|
+
import Inibase from "inibase";
|
|
285
|
+
import { setField } from "inibase/utils";
|
|
286
|
+
|
|
287
|
+
const db = new Inibase("/databaseName");
|
|
288
|
+
|
|
289
|
+
const userSchema = await db.getTableSchema("user");
|
|
290
|
+
setField("username", userSchema, {key: "full_name"});
|
|
291
|
+
await db.setTableSchema("user", newUserSchema);
|
|
292
|
+
```
|
|
293
|
+
</blockquote>
|
|
294
|
+
</details>
|
|
295
|
+
|
|
296
|
+
<details>
|
|
297
|
+
<summary>Join Tables</summary>
|
|
298
|
+
<blockquote>
|
|
299
|
+
|
|
300
|
+
```js
|
|
301
|
+
import Inibase from "inibase";
|
|
302
|
+
const db = new Inibase("/databaseName");
|
|
303
|
+
|
|
304
|
+
const productSchema = [
|
|
305
|
+
{
|
|
306
|
+
key: "title",
|
|
307
|
+
type: "string",
|
|
308
|
+
required: true,
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
key: "price",
|
|
312
|
+
type: "number",
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
key: "createdBy",
|
|
316
|
+
type: "table",
|
|
317
|
+
table: "user",
|
|
318
|
+
required: true,
|
|
319
|
+
},
|
|
320
|
+
];
|
|
321
|
+
|
|
322
|
+
await db.setTableSchema("product", productSchema);
|
|
323
|
+
|
|
324
|
+
const productData = [
|
|
325
|
+
{
|
|
326
|
+
title: "Product 1",
|
|
327
|
+
price: 16,
|
|
328
|
+
createdBy: "1d88385d4b1581f8fb059334dec30f4c",
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
title: "Product 2",
|
|
332
|
+
price: 10,
|
|
333
|
+
createdBy: "5011c230aa44481bf7e8dcfe0710474f",
|
|
334
|
+
},
|
|
335
|
+
];
|
|
336
|
+
|
|
337
|
+
const product = await db.post("product", productData);
|
|
338
|
+
// [
|
|
339
|
+
// {
|
|
340
|
+
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
341
|
+
// "title": "Product 1",
|
|
342
|
+
// "price": 16,
|
|
343
|
+
// "createdBy": {
|
|
344
|
+
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
345
|
+
// "username": "user1",
|
|
346
|
+
// "email": "user1@example.com",
|
|
347
|
+
// ...
|
|
348
|
+
// }
|
|
349
|
+
// },
|
|
350
|
+
// {
|
|
351
|
+
// "id": "5011c230aa44481bf7e8dcfe0710474f",
|
|
352
|
+
// "title": "Product 2",
|
|
353
|
+
// "price": 10,
|
|
354
|
+
// "createdBy": {
|
|
355
|
+
// "id": "5011c230aa44481bf7e8dcfe0710474f",
|
|
356
|
+
// "username": "user2",
|
|
357
|
+
// ...
|
|
358
|
+
// }
|
|
359
|
+
// }
|
|
360
|
+
// ]
|
|
361
|
+
```
|
|
362
|
+
</blockquote>
|
|
363
|
+
</details>
|
|
364
|
+
|
|
365
|
+
</blockquote>
|
|
366
|
+
</details>
|
|
367
|
+
|
|
368
|
+
<details>
|
|
369
|
+
<summary>POST</summary>
|
|
370
|
+
<blockquote>
|
|
371
|
+
|
|
372
|
+
```js
|
|
373
|
+
import Inibase from "inibase";
|
|
374
|
+
const db = new Inibase("/databaseName");
|
|
375
|
+
|
|
376
|
+
const userData = [
|
|
213
377
|
{
|
|
214
378
|
username: "user1",
|
|
215
379
|
email: "user1@example.com",
|
|
@@ -244,7 +408,7 @@ const user_data = [
|
|
|
244
408
|
},
|
|
245
409
|
];
|
|
246
410
|
|
|
247
|
-
const users = await db.post("user",
|
|
411
|
+
const users = await db.post("user", userData);
|
|
248
412
|
// [
|
|
249
413
|
// {
|
|
250
414
|
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
@@ -282,79 +446,21 @@ const users = await db.post("user", user_data);
|
|
|
282
446
|
// ]
|
|
283
447
|
```
|
|
284
448
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
```js
|
|
288
|
-
import Inibase from "inibase";
|
|
289
|
-
const db = new Inibase("/databaseName");
|
|
290
|
-
|
|
291
|
-
const product_schema = [
|
|
292
|
-
{
|
|
293
|
-
key: "title",
|
|
294
|
-
type: "string",
|
|
295
|
-
required: true,
|
|
296
|
-
},
|
|
297
|
-
{
|
|
298
|
-
key: "price",
|
|
299
|
-
type: "number",
|
|
300
|
-
},
|
|
301
|
-
{
|
|
302
|
-
key: "createdBy",
|
|
303
|
-
type: "table",
|
|
304
|
-
table: "user",
|
|
305
|
-
required: true,
|
|
306
|
-
},
|
|
307
|
-
];
|
|
308
|
-
|
|
309
|
-
const product_data = [
|
|
310
|
-
{
|
|
311
|
-
title: "Product 1",
|
|
312
|
-
price: 16,
|
|
313
|
-
createdBy: "1d88385d4b1581f8fb059334dec30f4c",
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
title: "Product 2",
|
|
317
|
-
price: 10,
|
|
318
|
-
createdBy: "5011c230aa44481bf7e8dcfe0710474f",
|
|
319
|
-
},
|
|
320
|
-
];
|
|
321
|
-
|
|
322
|
-
const product = await db.post("product", product_data);
|
|
323
|
-
// [
|
|
324
|
-
// {
|
|
325
|
-
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
326
|
-
// "title": "Product 1",
|
|
327
|
-
// "price": 16,
|
|
328
|
-
// "createdBy": {
|
|
329
|
-
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
330
|
-
// "username": "user1",
|
|
331
|
-
// "email": "user1@example.com",
|
|
332
|
-
// ...
|
|
333
|
-
// }
|
|
334
|
-
// },
|
|
335
|
-
// {
|
|
336
|
-
// "id": "5011c230aa44481bf7e8dcfe0710474f",
|
|
337
|
-
// "title": "Product 2",
|
|
338
|
-
// "price": 10,
|
|
339
|
-
// "createdBy": {
|
|
340
|
-
// "id": "5011c230aa44481bf7e8dcfe0710474f",
|
|
341
|
-
// "username": "user2",
|
|
342
|
-
// ...
|
|
343
|
-
// }
|
|
344
|
-
// }
|
|
345
|
-
// ]
|
|
346
|
-
```
|
|
347
|
-
|
|
449
|
+
</blockquote>
|
|
348
450
|
</details>
|
|
349
451
|
|
|
350
452
|
<details>
|
|
351
453
|
<summary>GET</summary>
|
|
454
|
+
<blockquote>
|
|
455
|
+
|
|
456
|
+
<details>
|
|
457
|
+
<summary>GET by ID</summary>
|
|
458
|
+
<blockquote>
|
|
352
459
|
|
|
353
460
|
```js
|
|
354
461
|
import Inibase from "inibase";
|
|
355
462
|
const db = new Inibase("/databaseName");
|
|
356
463
|
|
|
357
|
-
// Get "user" by id
|
|
358
464
|
const user = await db.get("user", "1d88385d4b1581f8fb059334dec30f4c");
|
|
359
465
|
// {
|
|
360
466
|
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
@@ -383,8 +489,18 @@ const user = await db.get("user", "1d88385d4b1581f8fb059334dec30f4c");
|
|
|
383
489
|
// "country": "Sampleland"
|
|
384
490
|
// }
|
|
385
491
|
// }
|
|
492
|
+
```
|
|
493
|
+
</blockquote>
|
|
494
|
+
</details>
|
|
495
|
+
|
|
496
|
+
<details>
|
|
497
|
+
<summary>GET by criteria</summary>
|
|
498
|
+
<blockquote>
|
|
499
|
+
|
|
500
|
+
```js
|
|
501
|
+
import Inibase from "inibase";
|
|
502
|
+
const db = new Inibase("/databaseName");
|
|
386
503
|
|
|
387
|
-
// Get "user" by Criteria: where "favoriteFoods" includes "Pizza"
|
|
388
504
|
const users = await db.get("user", { favoriteFoods: "[]Pizza" });
|
|
389
505
|
// [
|
|
390
506
|
// {
|
|
@@ -416,17 +532,32 @@ const users = await db.get("user", { favoriteFoods: "[]Pizza" });
|
|
|
416
532
|
// },
|
|
417
533
|
// ...
|
|
418
534
|
// ]
|
|
535
|
+
```
|
|
536
|
+
</blockquote>
|
|
537
|
+
</details>
|
|
538
|
+
|
|
539
|
+
<details>
|
|
540
|
+
<summary>GET with columns</summary>
|
|
541
|
+
<blockquote>
|
|
542
|
+
|
|
543
|
+
```js
|
|
544
|
+
import Inibase from "inibase";
|
|
545
|
+
const db = new Inibase("/databaseName");
|
|
419
546
|
|
|
420
547
|
// Get all "user" columns except "username" & "address.street"
|
|
421
548
|
const users = await db.get("user", undefined, {
|
|
422
549
|
columns: ["!username", "!address.street"],
|
|
423
550
|
});
|
|
424
551
|
```
|
|
552
|
+
</blockquote>
|
|
553
|
+
</details>
|
|
425
554
|
|
|
555
|
+
</blockquote>
|
|
426
556
|
</details>
|
|
427
557
|
|
|
428
558
|
<details>
|
|
429
559
|
<summary>PUT</summary>
|
|
560
|
+
<blockquote>
|
|
430
561
|
|
|
431
562
|
```js
|
|
432
563
|
import Inibase from "inibase";
|
|
@@ -441,11 +572,12 @@ await db.put("user", { isActive: false }, "1d88385d4b1581f8fb059334dec30f4c");
|
|
|
441
572
|
// set "isActive" to "true" in table "user" by criteria (where "isActive" is equal to "true")
|
|
442
573
|
await db.put("user", { isActive: false }, { isActive: true });
|
|
443
574
|
```
|
|
444
|
-
|
|
575
|
+
</blockquote>
|
|
445
576
|
</details>
|
|
446
577
|
|
|
447
578
|
<details>
|
|
448
579
|
<summary>DELETE</summary>
|
|
580
|
+
<blockquote>
|
|
449
581
|
|
|
450
582
|
```js
|
|
451
583
|
import Inibase from "inibase";
|
|
@@ -460,11 +592,12 @@ await db.put("user", "1d88385d4b1581f8fb059334dec30f4c");
|
|
|
460
592
|
// delete "user" by criteria (where "isActive" is equal to "false")
|
|
461
593
|
await db.put("user", { isActive: false });
|
|
462
594
|
```
|
|
463
|
-
|
|
595
|
+
</blockquote>
|
|
464
596
|
</details>
|
|
465
597
|
|
|
466
598
|
<details>
|
|
467
599
|
<summary>SUM</summary>
|
|
600
|
+
<blockquote>
|
|
468
601
|
|
|
469
602
|
```js
|
|
470
603
|
import Inibase from "inibase";
|
|
@@ -476,11 +609,12 @@ await db.sum("user", "age");
|
|
|
476
609
|
// get the sum of column "age" by criteria (where "isActive" is equal to "false") in "user" table
|
|
477
610
|
await db.sum("user", ["age", ...], { isActive: false });
|
|
478
611
|
```
|
|
479
|
-
|
|
612
|
+
</blockquote>
|
|
480
613
|
</details>
|
|
481
614
|
|
|
482
615
|
<details>
|
|
483
616
|
<summary>MAX</summary>
|
|
617
|
+
<blockquote>
|
|
484
618
|
|
|
485
619
|
```js
|
|
486
620
|
import Inibase from "inibase";
|
|
@@ -492,11 +626,12 @@ await db.max("user", "age");
|
|
|
492
626
|
// get the biggest number of column "age" by criteria (where "isActive" is equal to "false") in "user" table
|
|
493
627
|
await db.max("user", ["age", ...], { isActive: false });
|
|
494
628
|
```
|
|
495
|
-
|
|
629
|
+
</blockquote>
|
|
496
630
|
</details>
|
|
497
631
|
|
|
498
632
|
<details>
|
|
499
633
|
<summary>MIN</summary>
|
|
634
|
+
<blockquote>
|
|
500
635
|
|
|
501
636
|
```js
|
|
502
637
|
import Inibase from "inibase";
|
|
@@ -508,11 +643,12 @@ await db.min("user", "age");
|
|
|
508
643
|
// get the smallest number of column "age" by criteria (where "isActive" is equal to "false") in "user" table
|
|
509
644
|
await db.min("user", ["age", ...], { isActive: false });
|
|
510
645
|
```
|
|
511
|
-
|
|
646
|
+
</blockquote>
|
|
512
647
|
</details>
|
|
513
648
|
|
|
514
649
|
<details>
|
|
515
650
|
<summary>SORT</summary>
|
|
651
|
+
<blockquote>
|
|
516
652
|
|
|
517
653
|
```js
|
|
518
654
|
import Inibase from "inibase";
|
|
@@ -525,9 +661,50 @@ await db.sort("user", "age");
|
|
|
525
661
|
await db.sort("user", ["age","username"]);
|
|
526
662
|
await db.sort("user", {age: -1, username: "asc"});
|
|
527
663
|
```
|
|
528
|
-
|
|
664
|
+
</blockquote>
|
|
529
665
|
</details>
|
|
530
666
|
|
|
667
|
+
## Roadmap
|
|
668
|
+
|
|
669
|
+
- [x] Actions:
|
|
670
|
+
- [x] GET:
|
|
671
|
+
- [x] Pagination
|
|
672
|
+
- [x] Criteria
|
|
673
|
+
- [x] Columns
|
|
674
|
+
- [x] Sort (using UNIX commands)
|
|
675
|
+
- [x] POST
|
|
676
|
+
- [x] PUT
|
|
677
|
+
- [x] DELETE
|
|
678
|
+
- [x] SUM
|
|
679
|
+
- [x] MAX
|
|
680
|
+
- [x] MIN
|
|
681
|
+
- [ ] Schema supported types:
|
|
682
|
+
- [x] String
|
|
683
|
+
- [x] Number
|
|
684
|
+
- [x] Boolean
|
|
685
|
+
- [x] Date
|
|
686
|
+
- [x] Email
|
|
687
|
+
- [x] Url
|
|
688
|
+
- [x] Table
|
|
689
|
+
- [x] Object
|
|
690
|
+
- [x] Array
|
|
691
|
+
- [x] Password
|
|
692
|
+
- [x] IP
|
|
693
|
+
- [x] HTML
|
|
694
|
+
- [x] Id
|
|
695
|
+
- [x] JSON
|
|
696
|
+
- [ ] TO-DO:
|
|
697
|
+
- [x] Improve caching
|
|
698
|
+
- [ ] Commenting the code
|
|
699
|
+
- [x] Add property "unique" for schema fields
|
|
700
|
+
- [ ] Add Backup feature (generate a tar.gz)
|
|
701
|
+
- [ ] Add Custom field validation property to schema (using RegEx?)
|
|
702
|
+
- [ ] Features:
|
|
703
|
+
- [ ] Encryption
|
|
704
|
+
- [x] Data Compression
|
|
705
|
+
- [x] Caching System
|
|
706
|
+
- [ ] Suggest [new feature +](https://github.com/inicontent/inibase/discussions/new?category=ideas)
|
|
707
|
+
|
|
531
708
|
## License
|
|
532
709
|
|
|
533
|
-
[MIT](./LICENSE)
|
|
710
|
+
[MIT](./LICENSE)
|
package/dist/cli.js
CHANGED
|
@@ -34,7 +34,7 @@ rl.on("line", async (input) => {
|
|
|
34
34
|
const table = splitedInput[1];
|
|
35
35
|
if (!table)
|
|
36
36
|
throw new Error("Please specify table name");
|
|
37
|
-
let { where, page, perPage, columns, data
|
|
37
|
+
let { where, page, perPage, columns, data } = parseArgs({
|
|
38
38
|
args: splitedInput.toSpliced(0, 2),
|
|
39
39
|
options: {
|
|
40
40
|
where: { type: "string", short: "w" },
|
|
@@ -42,7 +42,6 @@ rl.on("line", async (input) => {
|
|
|
42
42
|
perPage: { type: "string", short: "l" },
|
|
43
43
|
columns: { type: "string", short: "c", multiple: true },
|
|
44
44
|
data: { type: "string", short: "d" },
|
|
45
|
-
returnData: { type: "boolean", short: "r" },
|
|
46
45
|
},
|
|
47
46
|
}).values;
|
|
48
47
|
if (where) {
|
|
@@ -66,28 +65,19 @@ rl.on("line", async (input) => {
|
|
|
66
65
|
}));
|
|
67
66
|
break;
|
|
68
67
|
case "post":
|
|
69
|
-
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}, returnData);
|
|
75
|
-
console.log(postReturn !== null && typeof postReturn === "object"
|
|
76
|
-
? "Item(s) Posted Successfully"
|
|
77
|
-
: postReturn);
|
|
78
|
-
}
|
|
68
|
+
console.log(await db.post(table, data, {
|
|
69
|
+
page: Number(page) ?? 1,
|
|
70
|
+
perPage: Number(perPage) ?? 15,
|
|
71
|
+
columns,
|
|
72
|
+
}, true));
|
|
79
73
|
break;
|
|
80
|
-
case "put":
|
|
81
|
-
|
|
74
|
+
case "put":
|
|
75
|
+
console.log(await db.put(table, data, where, {
|
|
82
76
|
page: Number(page) ?? 1,
|
|
83
77
|
perPage: Number(perPage) ?? 15,
|
|
84
78
|
columns,
|
|
85
|
-
},
|
|
86
|
-
console.log(putReturn !== null && typeof putReturn === "object"
|
|
87
|
-
? "Item(s) Updated Successfully"
|
|
88
|
-
: putReturn);
|
|
79
|
+
}, true));
|
|
89
80
|
break;
|
|
90
|
-
}
|
|
91
81
|
case "delete":
|
|
92
82
|
console.log(await db.delete(table, where));
|
|
93
83
|
break;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "dotenv/config";
|
|
1
2
|
import { unlink, rename, mkdir, readdir } from "node:fs/promises";
|
|
2
3
|
import { existsSync, appendFileSync, readFileSync } from "node:fs";
|
|
3
4
|
import { join, parse } from "node:path";
|
|
@@ -1189,9 +1190,9 @@ export default class Inibase {
|
|
|
1189
1190
|
const outputObject = {};
|
|
1190
1191
|
// Extract values for each file, including `id${this.getFileExtension()}`
|
|
1191
1192
|
filesPathes.forEach((fileName, index) => {
|
|
1192
|
-
const
|
|
1193
|
-
if (
|
|
1194
|
-
outputObject[
|
|
1193
|
+
const field = Utils.getField(parse(fileName).name, schema);
|
|
1194
|
+
if (field)
|
|
1195
|
+
outputObject[field.key] = File.decode(splitedFileColumns[index], field?.type, field?.children, this.salt);
|
|
1195
1196
|
});
|
|
1196
1197
|
return outputObject;
|
|
1197
1198
|
});
|
package/dist/utils.d.ts
CHANGED
|
@@ -172,4 +172,8 @@ export declare function FormatObjectCriteriaValue(value: string, isParentArray?:
|
|
|
172
172
|
type ValidKey = number | string;
|
|
173
173
|
export declare const swapKeyValue: <K extends ValidKey, V extends ValidKey>(object: Record<K, V>) => Record<V, K>;
|
|
174
174
|
export declare function getField(keyPath: string, schema: Schema): Field | null;
|
|
175
|
+
export declare function setField(keyPath: string, schema: Schema, field: Omit<Field, "key" | "type"> & {
|
|
176
|
+
key?: string;
|
|
177
|
+
type?: FieldType | FieldType[];
|
|
178
|
+
}): Field | null | undefined;
|
|
175
179
|
export {};
|
package/dist/utils.js
CHANGED
|
@@ -365,3 +365,19 @@ export function getField(keyPath, schema) {
|
|
|
365
365
|
return null;
|
|
366
366
|
return isArrayOfObjects(RETURN) ? RETURN[0] : RETURN;
|
|
367
367
|
}
|
|
368
|
+
export function setField(keyPath, schema, field) {
|
|
369
|
+
const keyPathSplited = keyPath.split(".");
|
|
370
|
+
for (const [index, key] of keyPathSplited.entries()) {
|
|
371
|
+
const foundItem = schema.find((item) => item.key === key);
|
|
372
|
+
if (!foundItem)
|
|
373
|
+
return null;
|
|
374
|
+
if (index === keyPathSplited.length - 1) {
|
|
375
|
+
Object.assign(foundItem, field);
|
|
376
|
+
return foundItem;
|
|
377
|
+
}
|
|
378
|
+
if ((foundItem.type === "array" || foundItem.type === "object") &&
|
|
379
|
+
foundItem.children &&
|
|
380
|
+
isArrayOfObjects(foundItem.children))
|
|
381
|
+
schema = foundItem.children;
|
|
382
|
+
}
|
|
383
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inibase",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.59",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Karim Amahtil",
|
|
6
6
|
"email": "karim.amahtil@gmail.com"
|
|
@@ -73,17 +73,16 @@
|
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/node": "^20.12.11",
|
|
76
|
+
"dotenv": "^16.4.5",
|
|
76
77
|
"tinybench": "^2.6.0"
|
|
77
78
|
},
|
|
78
79
|
"dependencies": {
|
|
79
|
-
"commander": "^12.0.0",
|
|
80
|
-
"dotenv": "^16.4.5",
|
|
81
80
|
"inison": "^1.0.0-rc.2"
|
|
82
81
|
},
|
|
83
82
|
"scripts": {
|
|
84
83
|
"build": "tsc",
|
|
85
|
-
"benchmark": "tsx
|
|
86
|
-
"benchmark:single": "tsx --expose-gc
|
|
87
|
-
"benchmark:bulk": "tsx --expose-gc
|
|
84
|
+
"benchmark": "tsx ./benchmark/index",
|
|
85
|
+
"benchmark:single": "tsx --expose-gc ./benchmark/single",
|
|
86
|
+
"benchmark:bulk": "tsx --expose-gc ./benchmark/bulk"
|
|
88
87
|
}
|
|
89
88
|
}
|