inibase 1.0.0-rc.26 → 1.0.0-rc.27
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 +59 -40
- package/dist/config.d.ts +4 -0
- package/dist/config.js +4 -0
- package/dist/file.d.ts +22 -16
- package/dist/file.js +395 -261
- package/dist/index.d.ts +11 -12
- package/dist/index.js +213 -130
- package/dist/utils.server.d.ts +2 -0
- package/dist/utils.server.js +30 -0
- package/package.json +3 -5
package/README.md
CHANGED
|
@@ -4,17 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.org/package/inibase) [](./LICENSE) [](https://github.com/inicontent/inibase/pulse) [](https://github.com/inicontent/inibase)
|
|
6
6
|
|
|
7
|
-
>
|
|
7
|
+
> A file-based & memory-efficient, serverless relational database management system :fire:
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
11
|
- **Lightweight** 🪶
|
|
12
|
-
- **Minimalist** :white_circle:
|
|
12
|
+
- **Minimalist** :white_circle: (but powerful)
|
|
13
13
|
- **TypeScript** :large_blue_diamond:
|
|
14
|
-
- **Super-Fast** :zap:
|
|
15
|
-
- **
|
|
16
|
-
- **Suitable for large data** :page_with_curl:
|
|
17
|
-
- **
|
|
14
|
+
- **Super-Fast** :zap: (built-in caching system)
|
|
15
|
+
- **Built-in form-validation** included :sunglasses:
|
|
16
|
+
- **Suitable for large data** :page_with_curl: (tested with 200K row)
|
|
17
|
+
- **Support Compression** :eight_spoked_asterisk: (using built-in nodejs zlib)
|
|
18
|
+
- **Support Table Joins** :link:
|
|
19
|
+
- **Low memory-usage** :chart_with_downwards_trend: (3-5mb)
|
|
20
|
+
- **Safe** :lock: (no sql or javascript injections)
|
|
18
21
|
- **Easy to use** :bread:
|
|
19
22
|
- **...** and much more :rocket:
|
|
20
23
|
|
|
@@ -35,8 +38,8 @@ const users = await db.get("user", undefined, {
|
|
|
35
38
|
columns: ["username", "address.street", "hobbies.name"],
|
|
36
39
|
});
|
|
37
40
|
|
|
38
|
-
// Get items from "user" table where "favoriteFoods" does not includes "Pizza"
|
|
39
|
-
const users = await db.get("user", { favoriteFoods: "![]Pizza" });
|
|
41
|
+
// Get items from "user" table where "favoriteFoods" does not includes "Pizza" or "Burger"
|
|
42
|
+
const users = await db.get("user", { favoriteFoods: "![]Pizza,Burger" });
|
|
40
43
|
```
|
|
41
44
|
|
|
42
45
|
If you like Inibase, please sponsor: [GitHub Sponsors](https://github.com/sponsors/inicontent) || [Paypal](https://paypal.me/KarimAmahtil).
|
|
@@ -49,7 +52,7 @@ If you like Inibase, please sponsor: [GitHub Sponsors](https://github.com/sponso
|
|
|
49
52
|
|
|
50
53
|
## How it works?
|
|
51
54
|
|
|
52
|
-
To simplify the idea, each database has tables, each table has columns, each column will be stored in a seperated file. When
|
|
55
|
+
To simplify the idea, each database has tables, each table has columns, each column will be stored in a seperated file. When **POST**ing new data, it will be appended to the _head_ of each file as new line. When **GET**ing data, the file will be readed line-by-line so it can handle large data (without consuming a lot of resources), when **PUT**ing(updating) in a specific column, only one file will be opened and updated
|
|
53
56
|
|
|
54
57
|
## Benchmark
|
|
55
58
|
|
|
@@ -71,6 +74,45 @@ To simplify the idea, each database has tables, each table has columns, each col
|
|
|
71
74
|
| PUT | 33 ms (10.29 mb) | 312 ms (11.06 mb) | 3539 ms (14.87 mb) |
|
|
72
75
|
| DELETE | 134 ms (13.50 mb) | 1224 ms (16.57 mb) | 7339 ms (11.46 mb) |
|
|
73
76
|
|
|
77
|
+
|
|
78
|
+
## Roadmap
|
|
79
|
+
|
|
80
|
+
- [x] Actions:
|
|
81
|
+
- [x] GET:
|
|
82
|
+
- [x] Pagination
|
|
83
|
+
- [x] Criteria
|
|
84
|
+
- [x] Columns
|
|
85
|
+
- [ ] Order By
|
|
86
|
+
- [x] POST
|
|
87
|
+
- [x] PUT
|
|
88
|
+
- [x] DELETE
|
|
89
|
+
- [x] SUM
|
|
90
|
+
- [x] MAX
|
|
91
|
+
- [x] MIN
|
|
92
|
+
- [ ] Schema supported types:
|
|
93
|
+
- [x] String
|
|
94
|
+
- [x] Number
|
|
95
|
+
- [x] Boolean
|
|
96
|
+
- [x] Date
|
|
97
|
+
- [x] Email
|
|
98
|
+
- [x] Url
|
|
99
|
+
- [x] Table
|
|
100
|
+
- [x] Object
|
|
101
|
+
- [x] Array
|
|
102
|
+
- [x] Password
|
|
103
|
+
- [x] IP
|
|
104
|
+
- [x] HTML
|
|
105
|
+
- [x] Id
|
|
106
|
+
- [ ] TO-DO:
|
|
107
|
+
- [x] Improve caching
|
|
108
|
+
- [x] Commenting the code
|
|
109
|
+
- [ ] Features:
|
|
110
|
+
- [ ] Encryption
|
|
111
|
+
- [x] Data Compression
|
|
112
|
+
- [x] Caching System
|
|
113
|
+
- [ ] Suggest [new feature +](https://github.com/inicontent/inibase/discussions/new?category=ideas)
|
|
114
|
+
|
|
115
|
+
|
|
74
116
|
## Examples
|
|
75
117
|
|
|
76
118
|
<details>
|
|
@@ -447,40 +489,17 @@ await db.min("user", ["age", ...], { isActive: false });
|
|
|
447
489
|
|
|
448
490
|
</details>
|
|
449
491
|
|
|
492
|
+
## Config
|
|
450
493
|
|
|
494
|
+
The `.env` file supports the following parameters (make sure to run command with flag --env-file=.env)
|
|
451
495
|
|
|
452
|
-
|
|
496
|
+
```ini
|
|
497
|
+
# Auto generated secret key, will be using for encrypting the IDs
|
|
498
|
+
INIBASE_SECRET=
|
|
453
499
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
- [x] Criteria
|
|
458
|
-
- [x] Columns
|
|
459
|
-
- [ ] Order By
|
|
460
|
-
- [x] POST
|
|
461
|
-
- [x] PUT
|
|
462
|
-
- [x] DELETE
|
|
463
|
-
- [ ] Schema supported types:
|
|
464
|
-
- [x] String
|
|
465
|
-
- [x] Number
|
|
466
|
-
- [x] Boolean
|
|
467
|
-
- [x] Date
|
|
468
|
-
- [x] Email
|
|
469
|
-
- [x] Url
|
|
470
|
-
- [x] Table
|
|
471
|
-
- [x] Object
|
|
472
|
-
- [x] Array
|
|
473
|
-
- [x] Password
|
|
474
|
-
- [x] IP
|
|
475
|
-
- [x] HTML
|
|
476
|
-
- [x] Id
|
|
477
|
-
- [ ] TO-DO:
|
|
478
|
-
- [ ] Improve caching
|
|
479
|
-
- [ ] Commenting the code
|
|
480
|
-
- [ ] Features:
|
|
481
|
-
- [ ] Encryption
|
|
482
|
-
- [ ] Compress data
|
|
483
|
-
- [ ] Suggest [new feature +](https://github.com/inicontent/inibase/discussions/new?category=ideas)
|
|
500
|
+
INIBASE_COMPRESSION=true
|
|
501
|
+
INIBASE_CACHE=true
|
|
502
|
+
```
|
|
484
503
|
|
|
485
504
|
## License
|
|
486
505
|
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
package/dist/file.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { ComparisonOperator, FieldType } from "./index.js";
|
|
3
|
+
export declare const write: (filePath: string, data: any, disableCompression?: boolean) => Promise<void>;
|
|
4
|
+
export declare const read: (filePath: string, disableCompression?: boolean) => Promise<string>;
|
|
3
5
|
/**
|
|
4
6
|
* Checks if a file or directory exists at the specified path.
|
|
5
7
|
*
|
|
@@ -41,7 +43,8 @@ export declare const decode: (input: string | null | number, fieldType?: FieldTy
|
|
|
41
43
|
* 1. Record of line numbers and their decoded content or null if no lines are read.
|
|
42
44
|
* 2. Total count of lines processed.
|
|
43
45
|
*/
|
|
44
|
-
export declare
|
|
46
|
+
export declare function get(filePath: string, lineNumbers?: number | number[], fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[], secretKey?: string | Buffer): Promise<Record<number, string | number | boolean | null | (string | number | boolean | (string | number | boolean)[] | null)[]> | null>;
|
|
47
|
+
export declare function get(filePath: string, lineNumbers: undefined | number | number[], fieldType: undefined | FieldType | FieldType[], fieldChildrenType: undefined | FieldType | FieldType[], secretKey: undefined | string | Buffer, readWholeFile: true): Promise<[
|
|
45
48
|
Record<number, string | number | boolean | null | (string | number | boolean | (string | number | boolean)[] | null)[]> | null,
|
|
46
49
|
number
|
|
47
50
|
]>;
|
|
@@ -57,7 +60,7 @@ export declare const get: (filePath: string, lineNumbers?: number | number[], fi
|
|
|
57
60
|
*/
|
|
58
61
|
export declare const replace: (filePath: string, replacements: string | number | boolean | null | (string | number | boolean | null)[] | Record<number, string | boolean | number | null | (string | boolean | number | null)[]>) => Promise<string[]>;
|
|
59
62
|
/**
|
|
60
|
-
* Asynchronously appends data to a file.
|
|
63
|
+
* Asynchronously appends data to the beginning of a file.
|
|
61
64
|
*
|
|
62
65
|
* @param filePath - Path of the file to append to.
|
|
63
66
|
* @param data - Data to append. Can be a string, number, or an array of strings/numbers.
|
|
@@ -75,15 +78,6 @@ export declare const append: (filePath: string, data: string | number | (string
|
|
|
75
78
|
* Note: Creates a temporary file during the process and replaces the original file with it after removing lines.
|
|
76
79
|
*/
|
|
77
80
|
export declare const remove: (filePath: string, linesToDelete: number | number[]) => Promise<string[]>;
|
|
78
|
-
/**
|
|
79
|
-
* Asynchronously counts the number of lines in a file.
|
|
80
|
-
*
|
|
81
|
-
* @param filePath - Path of the file to count lines in.
|
|
82
|
-
* @returns Promise<number>. The number of lines in the file.
|
|
83
|
-
*
|
|
84
|
-
* Note: Reads through the file line by line to count the total number of lines.
|
|
85
|
-
*/
|
|
86
|
-
export declare const count: (filePath: string) => Promise<number>;
|
|
87
81
|
/**
|
|
88
82
|
* Asynchronously searches a file for lines matching specified criteria, using comparison and logical operators.
|
|
89
83
|
*
|
|
@@ -104,9 +98,19 @@ export declare const count: (filePath: string) => Promise<number>;
|
|
|
104
98
|
* Note: Decodes each line for comparison and can handle complex queries with multiple conditions.
|
|
105
99
|
*/
|
|
106
100
|
export declare const search: (filePath: string, operator: ComparisonOperator | ComparisonOperator[], comparedAtValue: string | number | boolean | null | (string | number | boolean | null)[], logicalOperator?: "and" | "or", fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[], limit?: number, offset?: number, readWholeFile?: boolean, secretKey?: string | Buffer) => Promise<[
|
|
107
|
-
Record<number, string | number | boolean | (string | number | boolean | null)[]
|
|
108
|
-
number
|
|
101
|
+
Record<number, string | number | boolean | null | (string | number | boolean | null)[]> | null,
|
|
102
|
+
number,
|
|
103
|
+
Set<number> | null
|
|
109
104
|
]>;
|
|
105
|
+
/**
|
|
106
|
+
* Asynchronously counts the number of lines in a file.
|
|
107
|
+
*
|
|
108
|
+
* @param filePath - Path of the file to count lines in.
|
|
109
|
+
* @returns Promise<number>. The number of lines in the file.
|
|
110
|
+
*
|
|
111
|
+
* Note: Reads through the file line by line to count the total number of lines.
|
|
112
|
+
*/
|
|
113
|
+
export declare const count: (filePath: string) => Promise<number>;
|
|
110
114
|
/**
|
|
111
115
|
* Asynchronously calculates the sum of numerical values from specified lines in a file.
|
|
112
116
|
*
|
|
@@ -150,11 +154,10 @@ export declare const min: (filePath: string, lineNumbers?: number | number[]) =>
|
|
|
150
154
|
*/
|
|
151
155
|
export declare const sort: (filePath: string, sortDirection: 1 | -1 | "asc" | "desc", lineNumbers?: number | number[], _lineNumbersPerChunk?: number) => Promise<void>;
|
|
152
156
|
export default class File {
|
|
153
|
-
static get:
|
|
157
|
+
static get: typeof get;
|
|
154
158
|
static remove: (filePath: string, linesToDelete: number | number[]) => Promise<string[]>;
|
|
155
|
-
static search: (filePath: string, operator: ComparisonOperator | ComparisonOperator[], comparedAtValue: string | number | boolean | (string | number | boolean | null)[] | null, logicalOperator?: "and" | "or" | undefined, fieldType?: FieldType | FieldType[] | undefined, fieldChildrenType?: FieldType | FieldType[] | undefined, limit?: number | undefined, offset?: number | undefined, readWholeFile?: boolean | undefined, secretKey?: string | Buffer | undefined) => Promise<[Record<number, string | number | boolean | (string | number | boolean | null)[] | null> | null, number]>;
|
|
159
|
+
static search: (filePath: string, operator: ComparisonOperator | ComparisonOperator[], comparedAtValue: string | number | boolean | (string | number | boolean | null)[] | null, logicalOperator?: "and" | "or" | undefined, fieldType?: FieldType | FieldType[] | undefined, fieldChildrenType?: FieldType | FieldType[] | undefined, limit?: number | undefined, offset?: number | undefined, readWholeFile?: boolean | undefined, secretKey?: string | Buffer | undefined) => Promise<[Record<number, string | number | boolean | (string | number | boolean | null)[] | null> | null, number, Set<number> | null]>;
|
|
156
160
|
static replace: (filePath: string, replacements: string | number | boolean | (string | number | boolean | null)[] | Record<number, string | number | boolean | (string | number | boolean | null)[] | null> | null) => Promise<string[]>;
|
|
157
|
-
static count: (filePath: string) => Promise<number>;
|
|
158
161
|
static encode: (input: string | number | boolean | (string | number | boolean | null)[] | null, secretKey?: string | Buffer | undefined) => string | number | boolean | null;
|
|
159
162
|
static decode: (input: string | number | null, fieldType?: FieldType | FieldType[] | undefined, fieldChildrenType?: FieldType | FieldType[] | undefined, secretKey?: string | Buffer | undefined) => string | number | boolean | (string | number | boolean | null)[] | null;
|
|
160
163
|
static isExists: (path: string) => Promise<boolean>;
|
|
@@ -162,4 +165,7 @@ export default class File {
|
|
|
162
165
|
static min: (filePath: string, lineNumbers?: number | number[] | undefined) => Promise<number>;
|
|
163
166
|
static max: (filePath: string, lineNumbers?: number | number[] | undefined) => Promise<number>;
|
|
164
167
|
static append: (filePath: string, data: string | number | (string | number)[]) => Promise<string[]>;
|
|
168
|
+
static count: (filePath: string) => Promise<number>;
|
|
169
|
+
static write: (filePath: string, data: any, disableCompression?: boolean) => Promise<void>;
|
|
170
|
+
static read: (filePath: string, disableCompression?: boolean) => Promise<string>;
|
|
165
171
|
}
|