@inflector/optima 1.0.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/test/Schema.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { Int, Text, Table, Json, string, number, Email, Uuid } from "../src/schema";
2
+
3
+
4
+ // Users table for a social media app
5
+ export const Users = Table("Users", {
6
+ ID: Uuid().primaryKey().default(Bun.randomUUIDv7),
7
+ Username: Text()
8
+ .validate((val) => val.length >= 3)
9
+ .notnull(),
10
+ Email: Email()
11
+ .notnull(),
12
+ Password: Text().notnull(),
13
+ Profile: Json({
14
+ bio: string(),
15
+ avatarUrl: string(),
16
+ location: string(),
17
+ }),
18
+ });
19
+
20
+ export const Posts = Table("Posts", {
21
+ ID: Int().primaryKey(),
22
+ UserID: Int()
23
+ .notnull()
24
+ .reference(({ one }) => one(Users.ID)),
25
+ Content: Text().notnull(),
26
+ CreatedAt: Text().notnull(),
27
+ });
28
+
29
+ export const Likes = Table("Likes", {
30
+ ID: Int().primaryKey(),
31
+ UserID: Int()
32
+ .notnull()
33
+ .reference(({ one }) => one(Users.ID)),
34
+ PostID: Int()
35
+ .notnull()
36
+ .reference(({ one }) => one(Posts.ID)),
37
+ CreatedAt: Text().notnull(),
38
+ });
39
+
package/test/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { OptimaDB } from "../src/index";
2
+ import * as Tables from "./Schema";
3
+
4
+ const DB = await OptimaDB.Open("a.db", Tables);
5
+ console.time("Get");
6
+ await DB.transaction(async () => {
7
+ await DB.Tables.Users.Add({
8
+ Email: "ilies@ilies.dev",
9
+ Password: "1032003ilies",
10
+ Profile: { avatarUrl: "" , bio: "" , location: "" },
11
+ Username: "Ilies",
12
+ });
13
+ });
14
+ console.timeEnd("Get");
15
+ const User = await DB.Tables.Users.Get();
16
+ console.dir(User.length, { depth: null });
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Node",
6
+ "outDir": "dist",
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "declaration": true,
11
+ "strict": false
12
+ },
13
+ "include": ["src"],
14
+ "exclude": ["dist","test"]
15
+ }