@type32/tauri-sqlite-orm 0.1.3 → 0.1.4
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/LICENSE +21 -21
- package/README.md +247 -210
- package/dist/index.d.mts +43 -27
- package/dist/index.d.ts +43 -27
- package/dist/index.js +237 -130
- package/dist/index.mjs +236 -127
- package/package.json +7 -7
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Wilson
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Wilson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,210 +1,247 @@
|
|
|
1
|
-
## tauri-sqlite-orm
|
|
2
|
-
|
|
3
|
-
A Drizzle-like TypeScript ORM tailored for Tauri v2's `@tauri-apps/plugin-sql` (SQLite). Plug-and-play for Nuxt/Tauri apps: define schema in TS, run tracked migrations, and query with a soft-relations API.
|
|
4
|
-
|
|
5
|
-
### Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
Make sure the SQL plugin is registered on the Rust side (see Tauri docs).
|
|
12
|
-
|
|
13
|
-
### Quick start
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import {
|
|
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
|
-
await db
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
),
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
await db
|
|
134
|
-
|
|
135
|
-
.
|
|
136
|
-
.
|
|
137
|
-
.execute();
|
|
138
|
-
|
|
139
|
-
//
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
});
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
- `
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
where: eq(
|
|
182
|
-
orderBy: [asc(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
1
|
+
## tauri-sqlite-orm
|
|
2
|
+
|
|
3
|
+
A Drizzle-like TypeScript ORM tailored for Tauri v2's `@tauri-apps/plugin-sql` (SQLite). Plug-and-play for Nuxt/Tauri apps: define schema in TS, run tracked migrations, and query with a soft-relations API.
|
|
4
|
+
|
|
5
|
+
### Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add @type32/tauri-sqlite-orm @tauri-apps/plugin-sql
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Make sure the SQL plugin is registered on the Rust side (see Tauri docs).
|
|
12
|
+
|
|
13
|
+
### Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
TauriORM,
|
|
18
|
+
defineTable,
|
|
19
|
+
integer,
|
|
20
|
+
text,
|
|
21
|
+
relations,
|
|
22
|
+
} from "tauri-sqlite-orm";
|
|
23
|
+
|
|
24
|
+
const db = new TauriORM("sqlite:app.db");
|
|
25
|
+
|
|
26
|
+
export const users = defineTable("users", {
|
|
27
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
28
|
+
name: text("name").notNull(),
|
|
29
|
+
email: text("email"),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export const posts = defineTable("posts", {
|
|
33
|
+
id: integer("id").primaryKey(),
|
|
34
|
+
content: text("content"),
|
|
35
|
+
randomId: text("random_id").$defaultFn(() => crypto.randomUUID()),
|
|
36
|
+
authorId: integer("author_id"),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const usersRelations = relations(users, ({ many }) => ({
|
|
40
|
+
posts: many(posts),
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
db.configure({ users, posts }, { users: usersRelations });
|
|
44
|
+
await db.migrateConfigured({ name: "init:users,posts" });
|
|
45
|
+
|
|
46
|
+
// Create
|
|
47
|
+
await db
|
|
48
|
+
.insert(users)
|
|
49
|
+
.values({ name: "Dan", email: "dan@example.com" })
|
|
50
|
+
.execute();
|
|
51
|
+
|
|
52
|
+
// Query with relations (join-based when flat)
|
|
53
|
+
const res = await db.query.users.findMany({
|
|
54
|
+
with: { posts: true },
|
|
55
|
+
join: true,
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Schema builder
|
|
60
|
+
|
|
61
|
+
Chainable, Drizzle-style:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import {
|
|
65
|
+
defineTable,
|
|
66
|
+
integer,
|
|
67
|
+
text,
|
|
68
|
+
real,
|
|
69
|
+
blob,
|
|
70
|
+
numeric,
|
|
71
|
+
sql,
|
|
72
|
+
} from "tauri-sqlite-orm";
|
|
73
|
+
|
|
74
|
+
type Data = { foo: string; bar: number };
|
|
75
|
+
|
|
76
|
+
export const example = defineTable("example", {
|
|
77
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
78
|
+
isActive: integer("is_active", { mode: "boolean" }),
|
|
79
|
+
createdAt: integer("created_at", { mode: "timestamp" }).default(
|
|
80
|
+
sql`(strftime('%s','now'))`
|
|
81
|
+
),
|
|
82
|
+
rating: real("rating"),
|
|
83
|
+
status: text("status", { enum: ["active", "inactive"] as const }),
|
|
84
|
+
name: text("name").notNull().default("Anonymous"),
|
|
85
|
+
data: blob("data"),
|
|
86
|
+
jsonField: blob("json_field", { mode: "json" }).$type<Data>(),
|
|
87
|
+
bigCounter: blob("big_counter", { mode: "bigint" }),
|
|
88
|
+
valueNumeric: numeric("value_numeric"),
|
|
89
|
+
valueNumericNum: numeric("value_numeric_num", { mode: "number" }),
|
|
90
|
+
valueNumericBig: numeric("value_numeric_big", { mode: "bigint" }),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Foreign key
|
|
94
|
+
export const posts = defineTable("posts", {
|
|
95
|
+
id: integer("id").primaryKey(),
|
|
96
|
+
userId: integer("user_id")
|
|
97
|
+
.references(() => users.id, { onDelete: "cascade" })
|
|
98
|
+
.notNull(),
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### More data types and modes
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
// JSON stored in TEXT with proper SQLite JSON function support
|
|
106
|
+
const cfg = defineTable("cfg", {
|
|
107
|
+
jsonText: text("json_text", { mode: "json" }).$type<{ foo: string }>(),
|
|
108
|
+
tsMs: integer("ts_ms", { mode: "timestamp_ms" }),
|
|
109
|
+
dataBuf: blob("data_buf", { mode: "buffer" }),
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Tip: Prefer `text(name, { mode: 'json' })` over `blob(name, { mode: 'json' })` to use SQLite JSON functions.
|
|
114
|
+
|
|
115
|
+
### Migrations
|
|
116
|
+
|
|
117
|
+
Tracked simple migrations are part of the ORM instance:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
// one-off for specific tables
|
|
121
|
+
await db.migrate([users, posts], { name: "init:users,posts" });
|
|
122
|
+
|
|
123
|
+
// or using configured schema
|
|
124
|
+
await db.migrateConfigured({ name: "init:users,posts" });
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
DDL emitted respects: primaryKey + autoIncrement, notNull, default(value or sql), references (with onDelete/onUpdate).
|
|
128
|
+
|
|
129
|
+
### CRUD (Drizzle-like builders)
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
// Insert
|
|
133
|
+
await db.insert(users).values({ name: "Alice" }).execute();
|
|
134
|
+
await db
|
|
135
|
+
.insert(users)
|
|
136
|
+
.values([{ name: "A" }, { name: "B" }])
|
|
137
|
+
.execute();
|
|
138
|
+
|
|
139
|
+
// Update
|
|
140
|
+
import { eq } from "tauri-sqlite-orm";
|
|
141
|
+
await db
|
|
142
|
+
.update(users)
|
|
143
|
+
.set({ email: "new@mail.com" })
|
|
144
|
+
.where(eq(users.id, 1))
|
|
145
|
+
.execute();
|
|
146
|
+
|
|
147
|
+
// Delete
|
|
148
|
+
await db.delete(users).where(eq(users.id, 2)).execute();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Runtime defaults and onUpdate
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { defineTable, integer, text, increments } from "tauri-sqlite-orm";
|
|
155
|
+
|
|
156
|
+
export const audit = defineTable("audit", {
|
|
157
|
+
id: increments("id"),
|
|
158
|
+
// Called on insert if value not provided
|
|
159
|
+
createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(
|
|
160
|
+
() => new Date()
|
|
161
|
+
),
|
|
162
|
+
// Called on update when not explicitly set; if no default is provided, also used on insert
|
|
163
|
+
updatedAt: integer("updated_at", { mode: "timestamp" }).$onUpdateFn(
|
|
164
|
+
() => new Date()
|
|
165
|
+
),
|
|
166
|
+
token: text("token").$default(() => crypto.randomUUID()),
|
|
167
|
+
});
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Query API (relations)
|
|
171
|
+
|
|
172
|
+
Auto-generated with `db.configure(tables, relations?)`:
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
// Flat relations with join
|
|
176
|
+
import { asc } from "tauri-sqlite-orm";
|
|
177
|
+
|
|
178
|
+
const usersWithPosts = await db.query.users.findMany({
|
|
179
|
+
with: { posts: true },
|
|
180
|
+
join: true,
|
|
181
|
+
where: (users, { eq }) => eq(users.id, 1),
|
|
182
|
+
orderBy: (users, { asc }) => [asc(users.id)],
|
|
183
|
+
limit: 10,
|
|
184
|
+
offset: 0,
|
|
185
|
+
columns: { id: true, name: true },
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// Nested relations (batched loader)
|
|
189
|
+
const nested = await db.query.users.findMany({
|
|
190
|
+
with: {
|
|
191
|
+
posts: {
|
|
192
|
+
with: { comments: true },
|
|
193
|
+
columns: ["id", "content"],
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
// First row helper
|
|
199
|
+
const firstUser = await db.query.users.findFirst({
|
|
200
|
+
where: (users, { eq }) => eq(users.id, 1),
|
|
201
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Notes:
|
|
205
|
+
|
|
206
|
+
- `where` accepts SQL helpers (eq, lt, gte, like) or object map, or a callback `(table, ops) => SQL`.
|
|
207
|
+
- `orderBy` accepts typed helpers or a callback `(table, { asc, desc }) => [...]`.
|
|
208
|
+
- `columns` accepts string[] or object map of base table columns.
|
|
209
|
+
- `join: true` only for one-level `with` (flat). Nested uses batched selects.
|
|
210
|
+
|
|
211
|
+
### SQL helpers
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
import { eq, ne, gt, gte, lt, lte, like, asc, desc } from "tauri-sqlite-orm";
|
|
215
|
+
db.query.posts.findMany({
|
|
216
|
+
where: (posts, { eq }) => eq(posts.authorId, 1),
|
|
217
|
+
orderBy: (posts, { asc }) => [asc(posts.id)],
|
|
218
|
+
});
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Nuxt + Tauri usage
|
|
222
|
+
|
|
223
|
+
Initialize in a client plugin and ensure a single ORM instance is created:
|
|
224
|
+
|
|
225
|
+
```ts
|
|
226
|
+
// plugins/orm.client.ts
|
|
227
|
+
import { TauriORM } from "tauri-sqlite-orm";
|
|
228
|
+
import { users, posts, usersRelations } from "@/lib/schema";
|
|
229
|
+
|
|
230
|
+
export default defineNuxtPlugin(async () => {
|
|
231
|
+
const db = new TauriORM("sqlite:app.db");
|
|
232
|
+
db.configure({ users, posts }, { users: usersRelations });
|
|
233
|
+
await db.migrateConfigured({ name: "init:users,posts" });
|
|
234
|
+
|
|
235
|
+
return { provide: { db } };
|
|
236
|
+
});
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Roadmap
|
|
240
|
+
|
|
241
|
+
- Aliasing helpers and typed orderBy (asc(users.id)) for findMany
|
|
242
|
+
- Unique(), check(), composite primary/unique constraints
|
|
243
|
+
- Insert returning / batch returning (where feasible)
|
|
244
|
+
|
|
245
|
+
### License
|
|
246
|
+
|
|
247
|
+
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import Database from '@tauri-apps/plugin-sql';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Initializes the database connection. This must be called once at the start of your application.
|
|
5
|
-
* @param dbPath The path to the database file, e.g., 'sqlite:mydatabase.db'
|
|
6
|
-
* @returns The database instance.
|
|
7
|
-
*/
|
|
8
|
-
declare function initDb(dbPath: string): Promise<Database>;
|
|
9
|
-
/**
|
|
10
|
-
* Gets the singleton database instance.
|
|
11
|
-
* @throws If `initDb` has not been called.
|
|
12
|
-
* @returns The database instance.
|
|
13
|
-
*/
|
|
14
|
-
declare function getDb(): Database;
|
|
15
|
-
|
|
16
3
|
type UpdateDeleteAction = "cascade" | "restrict" | "no action" | "set null" | "set default";
|
|
17
4
|
interface SQLExpression {
|
|
18
5
|
raw: string;
|
|
@@ -26,6 +13,7 @@ interface Column<T = any> {
|
|
|
26
13
|
isNotNull?: boolean;
|
|
27
14
|
defaultValue?: T | SQLExpression;
|
|
28
15
|
defaultFn?: () => any;
|
|
16
|
+
onUpdateFn?: () => any;
|
|
29
17
|
references?: {
|
|
30
18
|
table: string;
|
|
31
19
|
column: string;
|
|
@@ -48,29 +36,49 @@ type ColumnBuilder<T> = Column<T> & {
|
|
|
48
36
|
default: (value: T | SQLExpression) => ColumnBuilder<T>;
|
|
49
37
|
$type: <U>() => ColumnBuilder<U>;
|
|
50
38
|
$defaultFn: (fn: () => any) => ColumnBuilder<T>;
|
|
39
|
+
$default: (fn: () => any) => ColumnBuilder<T>;
|
|
40
|
+
$onUpdate: (fn: () => any) => ColumnBuilder<T>;
|
|
41
|
+
$onUpdateFn: (fn: () => any) => ColumnBuilder<T>;
|
|
51
42
|
references: (target: () => Column<any>, actions?: {
|
|
52
43
|
onDelete?: UpdateDeleteAction;
|
|
53
44
|
onUpdate?: UpdateDeleteAction;
|
|
54
45
|
}) => ColumnBuilder<T>;
|
|
55
46
|
};
|
|
56
|
-
|
|
57
|
-
isPrimaryKey?: boolean;
|
|
47
|
+
type TextConfig<TEnum extends string> = {
|
|
58
48
|
enum?: readonly TEnum[];
|
|
59
|
-
|
|
49
|
+
mode?: "json";
|
|
50
|
+
};
|
|
51
|
+
declare function text<TEnum extends string>(name: string, config?: TextConfig<TEnum>): ColumnBuilder<TEnum extends string ? TEnum : string>;
|
|
52
|
+
declare function text<TEnum extends string>(config?: TextConfig<TEnum>): ColumnBuilder<TEnum extends string ? TEnum : string>;
|
|
53
|
+
type IntegerMode = "number" | "boolean" | "timestamp" | "timestamp_ms";
|
|
60
54
|
declare function integer(name: string, config?: {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
mode?: IntegerMode;
|
|
56
|
+
}): ColumnBuilder<number | boolean | Date>;
|
|
57
|
+
declare function integer(config?: {
|
|
58
|
+
mode?: IntegerMode;
|
|
64
59
|
}): ColumnBuilder<number | boolean | Date>;
|
|
65
60
|
declare function real(name: string): ColumnBuilder<number>;
|
|
61
|
+
declare function real(): ColumnBuilder<number>;
|
|
62
|
+
type BlobMode = "json" | "bigint" | "buffer";
|
|
66
63
|
declare function blob(name: string, config?: {
|
|
67
|
-
mode?:
|
|
64
|
+
mode?: BlobMode;
|
|
68
65
|
}): ColumnBuilder<unknown | bigint | Uint8Array>;
|
|
66
|
+
declare function blob(config?: {
|
|
67
|
+
mode?: BlobMode;
|
|
68
|
+
}): ColumnBuilder<unknown | bigint | Uint8Array>;
|
|
69
|
+
type NumericMode = "string" | "number" | "bigint";
|
|
69
70
|
declare function numeric(name: string, config?: {
|
|
70
|
-
mode?:
|
|
71
|
+
mode?: NumericMode;
|
|
72
|
+
}): ColumnBuilder<string | number | bigint>;
|
|
73
|
+
declare function numeric(config?: {
|
|
74
|
+
mode?: NumericMode;
|
|
71
75
|
}): ColumnBuilder<string | number | bigint>;
|
|
72
|
-
declare
|
|
73
|
-
declare
|
|
76
|
+
declare function boolean(name: string): ColumnBuilder<boolean>;
|
|
77
|
+
declare function boolean(): ColumnBuilder<boolean>;
|
|
78
|
+
declare function timestamp(name: string): ColumnBuilder<Date>;
|
|
79
|
+
declare function timestamp(): ColumnBuilder<Date>;
|
|
80
|
+
declare function increments(name: string): ColumnBuilder<number>;
|
|
81
|
+
declare function increments(): ColumnBuilder<number>;
|
|
74
82
|
type SchemaDefinition = Record<string, Column<any>>;
|
|
75
83
|
type InferModel<T extends SchemaDefinition> = {
|
|
76
84
|
[K in keyof T]: T[K]["_dataType"];
|
|
@@ -103,7 +111,8 @@ declare class SelectQueryBuilder<T> {
|
|
|
103
111
|
private _limit;
|
|
104
112
|
private _offset;
|
|
105
113
|
private _eager;
|
|
106
|
-
|
|
114
|
+
private _dbProvider;
|
|
115
|
+
constructor(dbProvider: () => Promise<Database>, fields?: Record<string, Column<any>>);
|
|
107
116
|
from(table: Table<any>): this;
|
|
108
117
|
where(...conditions: SQL[]): this;
|
|
109
118
|
leftJoin(otherTable: Table<any>, on: SQL): this;
|
|
@@ -116,6 +125,9 @@ declare class TauriORM {
|
|
|
116
125
|
query: Record<string, any>;
|
|
117
126
|
private _tables;
|
|
118
127
|
private _relations;
|
|
128
|
+
private _dbPromise;
|
|
129
|
+
constructor(dbUri: string);
|
|
130
|
+
private getDb;
|
|
119
131
|
configureQuery(tables: Record<string, Table<any>>, relations: Record<string, Record<string, RelationConfig>>): void;
|
|
120
132
|
select<T>(fields?: Record<string, Column<any>>): SelectQueryBuilder<T>;
|
|
121
133
|
insert(table: Table<any>): {
|
|
@@ -209,7 +221,6 @@ declare class TauriORM {
|
|
|
209
221
|
preserveData?: boolean;
|
|
210
222
|
}): Promise<void>;
|
|
211
223
|
}
|
|
212
|
-
declare const db: TauriORM;
|
|
213
224
|
type OneConfig = {
|
|
214
225
|
fields?: Column[];
|
|
215
226
|
references?: Column[];
|
|
@@ -238,12 +249,17 @@ type WithSpec = Record<string, boolean | {
|
|
|
238
249
|
with?: WithSpec;
|
|
239
250
|
columns?: string[];
|
|
240
251
|
}>;
|
|
241
|
-
declare function makeQueryAPI(tables: Record<string, Table<any>>, relDefs: Record<string, Record<string, RelationConfig
|
|
252
|
+
declare function makeQueryAPI(tables: Record<string, Table<any>>, relDefs: Record<string, Record<string, RelationConfig>>, dbProvider: () => Promise<Database>): { [K in keyof typeof tables]: {
|
|
242
253
|
findMany: (opts?: {
|
|
243
254
|
with?: WithSpec;
|
|
244
255
|
join?: boolean;
|
|
245
256
|
columns?: string[];
|
|
246
257
|
}) => Promise<any[]>;
|
|
258
|
+
findFirst: (opts?: {
|
|
259
|
+
with?: WithSpec;
|
|
260
|
+
join?: boolean;
|
|
261
|
+
columns?: string[];
|
|
262
|
+
}) => Promise<any | null>;
|
|
247
263
|
}; };
|
|
248
264
|
|
|
249
|
-
export { type Column, type ManyRelation, type OneRelation, type SQL, type SQLExpression, type Table, TauriORM, type UpdateDeleteAction, asc, blob, boolean,
|
|
265
|
+
export { type BlobMode, type Column, type ColumnBuilder, type IntegerMode, type ManyRelation, type NumericMode, type OneRelation, type SQL, type SQLExpression, type Table, TauriORM, type UpdateDeleteAction, asc, blob, boolean, defineTable, desc, eq, gt, gte, increments, integer, like, lt, lte, makeQueryAPI, ne, numeric, real, relations, sql, text, timestamp };
|