inibase 1.0.0-rc.0
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/LICENSE +21 -0
- package/README.md +440 -0
- package/file.ts +322 -0
- package/index.ts +1244 -0
- package/package.json +37 -0
- package/tsconfig.json +6 -0
- package/utils.ts +110 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Inibase
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Inibase
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.org/package/inibase) [](https://nodejs.org/) [](./LICENSE) [](https://github.com/inicontent/inibase/pulse) [](https://github.com/inicontent/inibase)
|
|
6
|
+
|
|
7
|
+
> File-based relational database, simple to use and can handle large data :fire:
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Lightweight** 🪶 (~50kb)
|
|
12
|
+
- **Minimalist** :white_circle:
|
|
13
|
+
- **TypeScript** :large_blue_diamond:
|
|
14
|
+
- **Super-Fast** :turtle:
|
|
15
|
+
- **Suitable for large data** :page_with_curl:
|
|
16
|
+
- **Safe** :lock:
|
|
17
|
+
- **...** and much more :rocket:
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
import Inibase from "inibase";
|
|
23
|
+
const db = new Inibase("/database_name");
|
|
24
|
+
|
|
25
|
+
// Get all items from "user" table
|
|
26
|
+
const users = await db.get("user");
|
|
27
|
+
|
|
28
|
+
// Read page 2 content
|
|
29
|
+
const users = await db.get("user", undefined, { page: 2, per_page: 15 });
|
|
30
|
+
|
|
31
|
+
// Get only required columns to improve speed
|
|
32
|
+
const users = await InibaseDB.get("user", undefined, {
|
|
33
|
+
columns: ["username", "address.street", "hobbies.*.name"],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Get items from "user" table where "favoriteFoods" does not includes "Pizza"
|
|
37
|
+
const users = await InibaseDB.get("user", { favoriteFoods: "![]Pizza" });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
If you like Inibase, please sponsor: [GitHub Sponsors](https://github.com/sponsors/inicontent) || [Paypal](https://paypal.me/KarimAmahtil).
|
|
41
|
+
|
|
42
|
+
## Sponsors
|
|
43
|
+
|
|
44
|
+
<br>
|
|
45
|
+
<br>
|
|
46
|
+
|
|
47
|
+
Become a sponsor and have your company logo here 👉 [GitHub Sponsors](https://github.com/sponsors/inicontent) || [paypal](https://paypal.me/KarimAmahtil).
|
|
48
|
+
|
|
49
|
+
## Install
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
// npm
|
|
53
|
+
npm install inibase
|
|
54
|
+
|
|
55
|
+
// pnpm
|
|
56
|
+
pnpm add inibase
|
|
57
|
+
|
|
58
|
+
// yarn
|
|
59
|
+
yarn add inibase
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Examples
|
|
63
|
+
|
|
64
|
+
#### POST
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
import Inibase from "inibase";
|
|
68
|
+
const db = new Inibase("/database_name");
|
|
69
|
+
|
|
70
|
+
const user_schema = [
|
|
71
|
+
{
|
|
72
|
+
key: "username",
|
|
73
|
+
type: "string",
|
|
74
|
+
required: true,
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "email",
|
|
78
|
+
type: "string",
|
|
79
|
+
required: true,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
key: "age",
|
|
83
|
+
type: "number",
|
|
84
|
+
required: true,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
key: "isActive",
|
|
88
|
+
type: "boolean",
|
|
89
|
+
// required: false
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
key: "hobbies",
|
|
93
|
+
type: "array",
|
|
94
|
+
children: [
|
|
95
|
+
{
|
|
96
|
+
key: "name",
|
|
97
|
+
type: "string",
|
|
98
|
+
// required: false
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
key: "level",
|
|
102
|
+
type: "string",
|
|
103
|
+
// required: false
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
key: "favoriteFoods",
|
|
109
|
+
type: "array",
|
|
110
|
+
children: "string",
|
|
111
|
+
// required: false
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
key: "address",
|
|
115
|
+
type: "object",
|
|
116
|
+
children: [
|
|
117
|
+
{
|
|
118
|
+
key: "street",
|
|
119
|
+
type: "string",
|
|
120
|
+
// required: false
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
key: "city",
|
|
124
|
+
type: "string",
|
|
125
|
+
// required: false
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
key: "country",
|
|
129
|
+
type: "string",
|
|
130
|
+
// required: false
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
const user_data = [
|
|
137
|
+
{
|
|
138
|
+
username: "user1",
|
|
139
|
+
email: "user1@example.com",
|
|
140
|
+
age: 25,
|
|
141
|
+
isActive: true,
|
|
142
|
+
hobbies: [
|
|
143
|
+
{ name: "Reading", level: "Intermediate" },
|
|
144
|
+
{ name: "Cooking", level: "Beginner" },
|
|
145
|
+
],
|
|
146
|
+
favoriteFoods: ["Pizza", "Sushi", "Chocolate"],
|
|
147
|
+
address: {
|
|
148
|
+
street: "123 Main St",
|
|
149
|
+
city: "Exampleville",
|
|
150
|
+
country: "Sampleland",
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
username: "user2",
|
|
155
|
+
email: "user2@example.com",
|
|
156
|
+
age: 30,
|
|
157
|
+
isActive: false,
|
|
158
|
+
hobbies: [
|
|
159
|
+
{ name: "Gardening", level: "Advanced" },
|
|
160
|
+
{ name: "Photography", level: "Intermediate" },
|
|
161
|
+
],
|
|
162
|
+
favoriteFoods: ["Burgers", null, "Salad"],
|
|
163
|
+
address: {
|
|
164
|
+
street: "456 Elm Rd",
|
|
165
|
+
city: "Testington",
|
|
166
|
+
country: "Demo Country",
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
|
|
171
|
+
const users = await db.post("user", user_data);
|
|
172
|
+
// [
|
|
173
|
+
// {
|
|
174
|
+
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
175
|
+
// "username": "user1",
|
|
176
|
+
// "email": "user1@example.com",
|
|
177
|
+
// "age": 25,
|
|
178
|
+
// "isActive": true,
|
|
179
|
+
// "hobbies": {
|
|
180
|
+
// "name": [
|
|
181
|
+
// "Reading",
|
|
182
|
+
// "Cooking"
|
|
183
|
+
// ],
|
|
184
|
+
// "level": [
|
|
185
|
+
// "Intermediate",
|
|
186
|
+
// "Beginner"
|
|
187
|
+
// ]
|
|
188
|
+
// },
|
|
189
|
+
// "favoriteFoods": [
|
|
190
|
+
// "Pizza",
|
|
191
|
+
// "Sushi",
|
|
192
|
+
// "Chocolate"
|
|
193
|
+
// ],
|
|
194
|
+
// "address": {
|
|
195
|
+
// "street": "123 Main St",
|
|
196
|
+
// "city": "Exampleville",
|
|
197
|
+
// "country": "Sampleland"
|
|
198
|
+
// }
|
|
199
|
+
// },
|
|
200
|
+
// {
|
|
201
|
+
// "id": "5011c230aa44481bf7e8dcfe0710474f",
|
|
202
|
+
// "username": "user2",
|
|
203
|
+
// ...
|
|
204
|
+
// },
|
|
205
|
+
// ...
|
|
206
|
+
// ]
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Link two tables: "product" with "user"
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
import Inibase from "inibase";
|
|
213
|
+
const db = new Inibase("/database_name");
|
|
214
|
+
|
|
215
|
+
const product_schema = [
|
|
216
|
+
{
|
|
217
|
+
key: "title",
|
|
218
|
+
type: "string",
|
|
219
|
+
required: true,
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
key: "price",
|
|
223
|
+
type: "number",
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
key: "user",
|
|
227
|
+
type: "table",
|
|
228
|
+
required: true,
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
const product_data = [
|
|
233
|
+
{
|
|
234
|
+
title: "Product 1",
|
|
235
|
+
price: 16,
|
|
236
|
+
user: "1d88385d4b1581f8fb059334dec30f4c",
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
title: "Product 2",
|
|
240
|
+
price: 10,
|
|
241
|
+
user: "5011c230aa44481bf7e8dcfe0710474f",
|
|
242
|
+
},
|
|
243
|
+
];
|
|
244
|
+
|
|
245
|
+
const product = await db.post("product", product_data);
|
|
246
|
+
// [
|
|
247
|
+
// {
|
|
248
|
+
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
249
|
+
// "title": "Product 1",
|
|
250
|
+
// "price": 16,
|
|
251
|
+
// "user": {
|
|
252
|
+
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
253
|
+
// "username": "user1",
|
|
254
|
+
// "email": "user1@example.com",
|
|
255
|
+
// ...
|
|
256
|
+
// }
|
|
257
|
+
// },
|
|
258
|
+
// {
|
|
259
|
+
// "id": "5011c230aa44481bf7e8dcfe0710474f",
|
|
260
|
+
// "title": "Product 2",
|
|
261
|
+
// "price": 10,
|
|
262
|
+
// "user": {
|
|
263
|
+
// "id": "5011c230aa44481bf7e8dcfe0710474f",
|
|
264
|
+
// "username": "user2",
|
|
265
|
+
// ...
|
|
266
|
+
// }
|
|
267
|
+
// }
|
|
268
|
+
// ]
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
#### GET
|
|
272
|
+
|
|
273
|
+
```js
|
|
274
|
+
import Inibase from "inibase";
|
|
275
|
+
const db = new Inibase("/database_name");
|
|
276
|
+
|
|
277
|
+
// Get "user" by id
|
|
278
|
+
const user = await db.get("user", "1d88385d4b1581f8fb059334dec30f4c");
|
|
279
|
+
// {
|
|
280
|
+
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
281
|
+
// "username": "user1",
|
|
282
|
+
// "email": "user1@example.com",
|
|
283
|
+
// "age": 25,
|
|
284
|
+
// "isActive": true,
|
|
285
|
+
// "hobbies": {
|
|
286
|
+
// "name": [
|
|
287
|
+
// "Reading",
|
|
288
|
+
// "Cooking"
|
|
289
|
+
// ],
|
|
290
|
+
// "level": [
|
|
291
|
+
// "Intermediate",
|
|
292
|
+
// "Beginner"
|
|
293
|
+
// ]
|
|
294
|
+
// },
|
|
295
|
+
// "favoriteFoods": [
|
|
296
|
+
// "Pizza",
|
|
297
|
+
// "Sushi",
|
|
298
|
+
// "Chocolate"
|
|
299
|
+
// ],
|
|
300
|
+
// "address": {
|
|
301
|
+
// "street": "123 Main St",
|
|
302
|
+
// "city": "Exampleville",
|
|
303
|
+
// "country": "Sampleland"
|
|
304
|
+
// }
|
|
305
|
+
// }
|
|
306
|
+
|
|
307
|
+
// Get "user" by Criteria: where "favoriteFoods" includes "Pizza"
|
|
308
|
+
const users = await db.get("user", { favoriteFoods: "[]Pizza" });
|
|
309
|
+
// [
|
|
310
|
+
// {
|
|
311
|
+
// "id": "1d88385d4b1581f8fb059334dec30f4c",
|
|
312
|
+
// "username": "user1",
|
|
313
|
+
// "email": "user1@example.com",
|
|
314
|
+
// "age": 25,
|
|
315
|
+
// "isActive": true,
|
|
316
|
+
// "hobbies": {
|
|
317
|
+
// "name": [
|
|
318
|
+
// "Reading",
|
|
319
|
+
// "Cooking"
|
|
320
|
+
// ],
|
|
321
|
+
// "level": [
|
|
322
|
+
// "Intermediate",
|
|
323
|
+
// "Beginner"
|
|
324
|
+
// ]
|
|
325
|
+
// },
|
|
326
|
+
// "favoriteFoods": [
|
|
327
|
+
// "Pizza",
|
|
328
|
+
// "Sushi",
|
|
329
|
+
// "Chocolate"
|
|
330
|
+
// ],
|
|
331
|
+
// "address": {
|
|
332
|
+
// "street": "123 Main St",
|
|
333
|
+
// "city": "Exampleville",
|
|
334
|
+
// "country": "Sampleland"
|
|
335
|
+
// }
|
|
336
|
+
// },
|
|
337
|
+
// ...
|
|
338
|
+
// ]
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
#### PUT
|
|
342
|
+
|
|
343
|
+
```js
|
|
344
|
+
import Inibase from "inibase";
|
|
345
|
+
const db = new Inibase("/database_name");
|
|
346
|
+
|
|
347
|
+
// set "isActive" to "false" for all items in table "user"
|
|
348
|
+
await db.put("user", { isActive: false });
|
|
349
|
+
|
|
350
|
+
// set "isActive" to "true" for specific "user" by id
|
|
351
|
+
await db.put("user", { isActive: false }, "1d88385d4b1581f8fb059334dec30f4c");
|
|
352
|
+
|
|
353
|
+
// set "isActive" to "true" in table "user" by criteria (where "isActive" is equal to "true")
|
|
354
|
+
await db.put("user", { isActive: false }, { isActive: true });
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
#### DELETE
|
|
358
|
+
|
|
359
|
+
```js
|
|
360
|
+
import Inibase from "inibase";
|
|
361
|
+
const db = new Inibase("/database_name");
|
|
362
|
+
|
|
363
|
+
// delete all items in "user" table
|
|
364
|
+
await db.delete("user");
|
|
365
|
+
|
|
366
|
+
// delete a specific "user" by id
|
|
367
|
+
await db.put("user", "1d88385d4b1581f8fb059334dec30f4c");
|
|
368
|
+
|
|
369
|
+
// delete "user" by criteria (where "isActive" is equal to "false")
|
|
370
|
+
await db.put("user", { isActive: false });
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## Typescript
|
|
374
|
+
|
|
375
|
+
#### Schema
|
|
376
|
+
|
|
377
|
+
```js
|
|
378
|
+
type FieldType =
|
|
379
|
+
| "string"
|
|
380
|
+
| "number"
|
|
381
|
+
| "boolean"
|
|
382
|
+
| "date"
|
|
383
|
+
| "email"
|
|
384
|
+
| "url"
|
|
385
|
+
| "table"
|
|
386
|
+
| "object"
|
|
387
|
+
| "array";
|
|
388
|
+
type Field =
|
|
389
|
+
| {
|
|
390
|
+
id?: string | number | null | undefined,
|
|
391
|
+
key: string,
|
|
392
|
+
type: Exclude<FieldType, "array" | "object">,
|
|
393
|
+
required?: boolean,
|
|
394
|
+
}
|
|
395
|
+
| {
|
|
396
|
+
id?: string | number | null | undefined,
|
|
397
|
+
key: string,
|
|
398
|
+
type: "array",
|
|
399
|
+
required?: boolean,
|
|
400
|
+
children: FieldType | FieldType[] | Schema,
|
|
401
|
+
}
|
|
402
|
+
| {
|
|
403
|
+
id?: string | number | null | undefined,
|
|
404
|
+
key: string,
|
|
405
|
+
type: "object",
|
|
406
|
+
required?: boolean,
|
|
407
|
+
children: Schema,
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
type Schema = Field[];
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## Roadmap
|
|
414
|
+
|
|
415
|
+
- [x] Actions:
|
|
416
|
+
- [x] GET:
|
|
417
|
+
- [x] Pagination
|
|
418
|
+
- [x] Criteria
|
|
419
|
+
- [x] Columns
|
|
420
|
+
- [ ] Order
|
|
421
|
+
- [x] POST
|
|
422
|
+
- [x] PUT
|
|
423
|
+
- [x] DELETE
|
|
424
|
+
- [ ] Schema supported types:
|
|
425
|
+
- [x] String
|
|
426
|
+
- [x] Number
|
|
427
|
+
- [x] Boolean
|
|
428
|
+
- [x] Date
|
|
429
|
+
- [x] Email
|
|
430
|
+
- [x] Url
|
|
431
|
+
- [x] Table
|
|
432
|
+
- [x] Object
|
|
433
|
+
- [x] Array
|
|
434
|
+
- [ ] Password
|
|
435
|
+
- [ ] IP
|
|
436
|
+
- [ ] Suggest [new feature +](https://github.com/inicontent/inibase/discussions/new?category=ideas)
|
|
437
|
+
|
|
438
|
+
## License
|
|
439
|
+
|
|
440
|
+
[MIT](./LICENSE)
|