inibase 1.0.0-rc.3 → 1.0.0-rc.5

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/index.test.ts ADDED
@@ -0,0 +1,248 @@
1
+ import Inibase, { Schema, Data } from "./index";
2
+ import { join } from "node:path";
3
+ // import os from "os";
4
+ // Create a new instance of Inibase with the database path
5
+ const db = new Inibase("inibase", join("..", "inicontent", "databases"));
6
+
7
+ // test with edited schema
8
+ const schema_1: Schema = [
9
+ {
10
+ key: "username",
11
+ type: "string",
12
+ required: true,
13
+ },
14
+ {
15
+ key: "email",
16
+ type: "string",
17
+ required: true,
18
+ },
19
+ {
20
+ key: "age",
21
+ type: "number",
22
+ required: true,
23
+ },
24
+ {
25
+ key: "isActive",
26
+ type: "boolean",
27
+ },
28
+ {
29
+ key: "hobbies",
30
+ type: "array",
31
+ children: [
32
+ {
33
+ key: "name",
34
+ type: "string",
35
+ },
36
+ {
37
+ key: "level",
38
+ type: "string",
39
+ },
40
+ ],
41
+ },
42
+ {
43
+ key: "favoriteFoods",
44
+ type: "array",
45
+ children: "string",
46
+ },
47
+ {
48
+ key: "address",
49
+ type: "object",
50
+ children: [
51
+ {
52
+ key: "street",
53
+ type: "string",
54
+ },
55
+ {
56
+ key: "city",
57
+ type: "string",
58
+ },
59
+ {
60
+ key: "country",
61
+ type: "string",
62
+ },
63
+ ],
64
+ },
65
+ ];
66
+
67
+ const data_1: Data = [
68
+ {
69
+ id: 1,
70
+ username: "user1",
71
+ email: "user1@example.com",
72
+ age: 25,
73
+ isActive: true,
74
+ hobbies: [
75
+ { name: "Reading", level: "Intermediate" },
76
+ { name: "Cooking", level: "Beginner" },
77
+ ],
78
+ favoriteFoods: ["Pizza", "Sushi", "Chocolate"],
79
+ address: {
80
+ street: "123 Main St",
81
+ city: "Exampleville",
82
+ country: "Sampleland",
83
+ },
84
+ },
85
+ {
86
+ id: 2,
87
+ username: "user2",
88
+ email: "user2@example.com",
89
+ age: 30,
90
+ isActive: false,
91
+ hobbies: [
92
+ { name: "Gardening", level: "Advanced" },
93
+ { name: "Photography", level: "Intermediate" },
94
+ ],
95
+ favoriteFoods: ["Burgers", null, "Salad"],
96
+ address: {
97
+ street: "456 Elm Rd",
98
+ city: "Testington",
99
+ country: "Demo Country",
100
+ },
101
+ },
102
+ {
103
+ id: 3,
104
+ username: "user3",
105
+ email: "user3@example.com",
106
+ age: 22,
107
+ isActive: true,
108
+ hobbies: [
109
+ { name: "Painting", level: "Beginner" },
110
+ { name: "Hiking", level: null },
111
+ ],
112
+ favoriteFoods: ["Pasta", "Fruit", "Cakes"],
113
+ address: {
114
+ street: "789 Oak Ave",
115
+ city: "Sampletown",
116
+ country: "Testland",
117
+ },
118
+ },
119
+ ];
120
+
121
+ const schema_2: Schema = [
122
+ {
123
+ key: "title",
124
+ type: "string",
125
+ required: true,
126
+ },
127
+ {
128
+ key: "price",
129
+ type: "number",
130
+ },
131
+ {
132
+ key: "user",
133
+ type: "table",
134
+ required: true,
135
+ },
136
+ ];
137
+
138
+ const data_2 = [
139
+ {
140
+ title: "Product 1",
141
+ price: 16,
142
+ user: 1,
143
+ },
144
+ {
145
+ title: "Product 2",
146
+ price: 10,
147
+ user: 2,
148
+ },
149
+ ];
150
+
151
+ const schema_3: Schema = [
152
+ {
153
+ key: "orderN",
154
+ type: "number",
155
+ },
156
+ {
157
+ key: "isActive",
158
+ type: "boolean",
159
+ },
160
+ {
161
+ key: "products",
162
+ type: "array",
163
+ children: [
164
+ {
165
+ key: "name",
166
+ type: "string",
167
+ },
168
+ {
169
+ key: "variants",
170
+ type: "array",
171
+ children: [
172
+ {
173
+ key: "name",
174
+ type: "string",
175
+ },
176
+ {
177
+ key: "price",
178
+ type: "number",
179
+ },
180
+ ],
181
+ },
182
+ ],
183
+ },
184
+ ];
185
+
186
+ const data_3 = {
187
+ orderN: 5,
188
+ isActive: true,
189
+ products: [
190
+ {
191
+ name: "Product 1",
192
+ variants: [
193
+ {
194
+ name: "Variant 1",
195
+ price: 10,
196
+ },
197
+ {
198
+ name: "Variant 2",
199
+ price: 15,
200
+ },
201
+ ],
202
+ },
203
+ {
204
+ name: "Product 2",
205
+ variants: [
206
+ {
207
+ name: "Variant 3",
208
+ price: 78,
209
+ },
210
+ {
211
+ name: "Variant 4",
212
+ price: 456,
213
+ },
214
+ ],
215
+ },
216
+ ],
217
+ };
218
+
219
+ try {
220
+ // const DATA = await db.post("user", data_1);
221
+ // const DATA = await db.get("user", { favoriteFoods: "![]Pizza" });
222
+ // db.setTableSchema("user", schema_1);
223
+ // const DATA = await db.get("product", "4", {
224
+ // columns: [
225
+ // "title",
226
+ // "user",
227
+ // "user.username",
228
+ // "user.address.street",
229
+ // "user.hobbies.*.name",
230
+ // ],
231
+ // });
232
+ // return os.platform();
233
+ // const DATA = await db.get("user", {
234
+ // "hobbies.*.name": "*Reading,",
235
+ // });
236
+ // db.setTableSchema("order", schema_3);
237
+ const DATA = await db.get("product", "7a6f37d12fac6d4dd082a69e92fc1f07", {
238
+ columns: [
239
+ "!user.favoriteFoods",
240
+ "!user.username",
241
+ "*",
242
+ "!user.hobbies.*.name",
243
+ ],
244
+ });
245
+ console.log(JSON.stringify(DATA, null, 4));
246
+ } catch (er) {
247
+ console.log(er);
248
+ }