inibase 1.0.0-rc.0 → 1.0.0-rc.11
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 +45 -62
- package/file.ts +325 -103
- package/index.test.ts +247 -0
- package/index.ts +893 -627
- package/package.json +7 -6
- package/tsconfig.json +2 -1
- package/utils.server.ts +79 -0
- package/utils.ts +166 -64
package/README.md
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-

|
|
1
|
+
[](https://github.com/inicontent/inibase)
|
|
2
2
|
|
|
3
|
-
# Inibase
|
|
3
|
+
# Inibase :pencil:
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.org/package/inibase) [](https://www.npmjs.org/package/inibase) [](./LICENSE) [](https://github.com/inicontent/inibase/pulse) [](https://github.com/inicontent/inibase)
|
|
6
6
|
|
|
7
7
|
> File-based relational database, simple to use and can handle large data :fire:
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
- **Lightweight** 🪶 (~
|
|
11
|
+
- **Lightweight** 🪶 (~80kb)
|
|
12
12
|
- **Minimalist** :white_circle:
|
|
13
13
|
- **TypeScript** :large_blue_diamond:
|
|
14
14
|
- **Super-Fast** :turtle:
|
|
15
15
|
- **Suitable for large data** :page_with_curl:
|
|
16
16
|
- **Safe** :lock:
|
|
17
|
+
- **Easy to use** :hourglass:
|
|
17
18
|
- **...** and much more :rocket:
|
|
18
19
|
|
|
19
20
|
## Usage
|
|
20
21
|
|
|
21
22
|
```js
|
|
22
23
|
import Inibase from "inibase";
|
|
23
|
-
const db = new Inibase("
|
|
24
|
+
const db = new Inibase("database_name");
|
|
24
25
|
|
|
25
26
|
// Get all items from "user" table
|
|
26
27
|
const users = await db.get("user");
|
|
@@ -29,12 +30,12 @@ const users = await db.get("user");
|
|
|
29
30
|
const users = await db.get("user", undefined, { page: 2, per_page: 15 });
|
|
30
31
|
|
|
31
32
|
// Get only required columns to improve speed
|
|
32
|
-
const users = await
|
|
33
|
-
columns: ["username", "address.street", "hobbies
|
|
33
|
+
const users = await db.get("user", undefined, {
|
|
34
|
+
columns: ["username", "address.street", "hobbies.name"],
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
// Get items from "user" table where "favoriteFoods" does not includes "Pizza"
|
|
37
|
-
const users = await
|
|
38
|
+
const users = await db.get("user", { favoriteFoods: "![]Pizza" });
|
|
38
39
|
```
|
|
39
40
|
|
|
40
41
|
If you like Inibase, please sponsor: [GitHub Sponsors](https://github.com/sponsors/inicontent) || [Paypal](https://paypal.me/KarimAmahtil).
|
|
@@ -49,19 +50,17 @@ Become a sponsor and have your company logo here 👉 [GitHub Sponsors](https://
|
|
|
49
50
|
## Install
|
|
50
51
|
|
|
51
52
|
```js
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
<npm|pnpm> install inibase
|
|
54
|
+
```
|
|
54
55
|
|
|
55
|
-
|
|
56
|
-
pnpm add inibase
|
|
56
|
+
## How it works?
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
yarn add inibase
|
|
60
|
-
```
|
|
58
|
+
To semplify the idea, each database has tables, each table has columns, each column will be stored in a seperated file. When POSTing new data, it will be appended to each columns file as new line. When GETing data, the file will be readed line-by-line so it can handle large data (without consuming a lot of resources)
|
|
61
59
|
|
|
62
60
|
## Examples
|
|
63
61
|
|
|
64
|
-
|
|
62
|
+
<details>
|
|
63
|
+
<summary>POST</summary>
|
|
65
64
|
|
|
66
65
|
```js
|
|
67
66
|
import Inibase from "inibase";
|
|
@@ -268,7 +267,10 @@ const product = await db.post("product", product_data);
|
|
|
268
267
|
// ]
|
|
269
268
|
```
|
|
270
269
|
|
|
271
|
-
|
|
270
|
+
</details>
|
|
271
|
+
|
|
272
|
+
<details>
|
|
273
|
+
<summary>GET</summary>
|
|
272
274
|
|
|
273
275
|
```js
|
|
274
276
|
import Inibase from "inibase";
|
|
@@ -336,9 +338,17 @@ const users = await db.get("user", { favoriteFoods: "[]Pizza" });
|
|
|
336
338
|
// },
|
|
337
339
|
// ...
|
|
338
340
|
// ]
|
|
341
|
+
|
|
342
|
+
// Get all "user" columns except "username" & "address.street"
|
|
343
|
+
const users = await db.get("user", undefined, {
|
|
344
|
+
columns: ["!username", "!address.street"],
|
|
345
|
+
});
|
|
339
346
|
```
|
|
340
347
|
|
|
341
|
-
|
|
348
|
+
</details>
|
|
349
|
+
|
|
350
|
+
<details>
|
|
351
|
+
<summary>PUT</summary>
|
|
342
352
|
|
|
343
353
|
```js
|
|
344
354
|
import Inibase from "inibase";
|
|
@@ -354,7 +364,10 @@ await db.put("user", { isActive: false }, "1d88385d4b1581f8fb059334dec30f4c");
|
|
|
354
364
|
await db.put("user", { isActive: false }, { isActive: true });
|
|
355
365
|
```
|
|
356
366
|
|
|
357
|
-
|
|
367
|
+
</details>
|
|
368
|
+
|
|
369
|
+
<details>
|
|
370
|
+
<summary>DELETE</summary>
|
|
358
371
|
|
|
359
372
|
```js
|
|
360
373
|
import Inibase from "inibase";
|
|
@@ -370,45 +383,7 @@ await db.put("user", "1d88385d4b1581f8fb059334dec30f4c");
|
|
|
370
383
|
await db.put("user", { isActive: false });
|
|
371
384
|
```
|
|
372
385
|
|
|
373
|
-
|
|
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
|
-
```
|
|
386
|
+
</details>
|
|
412
387
|
|
|
413
388
|
## Roadmap
|
|
414
389
|
|
|
@@ -417,7 +392,7 @@ type Schema = Field[];
|
|
|
417
392
|
- [x] Pagination
|
|
418
393
|
- [x] Criteria
|
|
419
394
|
- [x] Columns
|
|
420
|
-
- [ ] Order
|
|
395
|
+
- [ ] Order By
|
|
421
396
|
- [x] POST
|
|
422
397
|
- [x] PUT
|
|
423
398
|
- [x] DELETE
|
|
@@ -431,9 +406,17 @@ type Schema = Field[];
|
|
|
431
406
|
- [x] Table
|
|
432
407
|
- [x] Object
|
|
433
408
|
- [x] Array
|
|
434
|
-
- [
|
|
435
|
-
- [
|
|
436
|
-
- [
|
|
409
|
+
- [x] Password
|
|
410
|
+
- [x] IP
|
|
411
|
+
- [x] HTML
|
|
412
|
+
- [x] Id
|
|
413
|
+
- [ ] TO-DO:
|
|
414
|
+
- [ ] Improve caching
|
|
415
|
+
- [ ] Commenting the code
|
|
416
|
+
- [ ] Features:
|
|
417
|
+
- [ ] Encryption
|
|
418
|
+
- [ ] Compress data
|
|
419
|
+
- [ ] Suggest [new feature +](https://github.com/inicontent/inibase/discussions/new?category=ideas)
|
|
437
420
|
|
|
438
421
|
## License
|
|
439
422
|
|