-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.ts
79 lines (77 loc) · 1.57 KB
/
db.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Schema, SqliteBruv } from "./src/index.ts";
// Example usage:
export const user = new Schema<{
name: string;
username: string;
location: string;
age: number;
createdAt: Date;
}>({
name: "users",
columns: {
name: { type: "TEXT", required: true },
username: { type: "TEXT", required: true, unique: true },
age: { type: "INTEGER", required: true },
location: {
type: "TEXT",
required: true,
default() {
return "earth";
},
},
createdAt: {
type: "DATETIME",
default() {
return "CURRENT_TIMESTAMP";
},
},
},
});
export const works = new Schema<{
name: string;
user: string;
createdAt: Date;
rating: number;
}>({
name: "works",
columns: {
name: {
// unique: true,
type: "TEXT",
required: true,
},
user: {
type: "TEXT",
required: true,
target: "users",
},
rating: {
type: "INTEGER",
default() {
return "1";
},
check: ["1", "1.5", "2", "2.5", "3", "3.5", "4", "4.5", "5"],
},
createdAt: {
type: "DATETIME",
default() {
return "CURRENT_TIMESTAMP";
},
},
},
});
export const db = new SqliteBruv({
schema: [user, works],
// QueryMode: true,
TursoConfig: {
url: process.env.TURSO_URL!,
authToken: process.env.TURSO_AUTH_TOKEN!,
},
// D1Config: {
// accountId: process.env.CFAccountId!,
// databaseId: process.env.D1databaseId!,
// apiKey: process.env.CFauthorizationToken!,
// },
// localFile: "sample.sqlite",
logging: true,
});