sqlite-zod-orm 3.9.0 → 3.11.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/dist/index.js +242 -72
- package/package.json +1 -1
- package/src/builder.ts +399 -0
- package/src/context.ts +9 -0
- package/src/crud.ts +44 -3
- package/src/database.ts +53 -3
- package/src/helpers.ts +11 -0
- package/src/index.ts +1 -1
- package/src/iqo.ts +198 -0
- package/src/proxy.ts +276 -0
- package/src/query.ts +23 -736
- package/src/types.ts +26 -3
package/src/types.ts
CHANGED
|
@@ -19,7 +19,6 @@ export const asZodObject = (s: z.ZodType<any>) => s as unknown as z.ZodObject<an
|
|
|
19
19
|
/** Index definition: single column or composite columns */
|
|
20
20
|
export type IndexDef = string | string[];
|
|
21
21
|
|
|
22
|
-
/** Options for the Database constructor */
|
|
23
22
|
export type DatabaseOptions<R extends RelationsConfig = RelationsConfig> = {
|
|
24
23
|
indexes?: Record<string, IndexDef[]>;
|
|
25
24
|
/**
|
|
@@ -42,6 +41,24 @@ export type DatabaseOptions<R extends RelationsConfig = RelationsConfig> = {
|
|
|
42
41
|
* `.on()` will throw. Default: `true`.
|
|
43
42
|
*/
|
|
44
43
|
reactive?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Auto-add `createdAt` and `updatedAt` TEXT columns to every table.
|
|
46
|
+
* `createdAt` is set on insert, `updatedAt` on insert + update.
|
|
47
|
+
* Default: `false`.
|
|
48
|
+
*/
|
|
49
|
+
timestamps?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Enable soft deletes. Adds a `deletedAt` TEXT column to every table.
|
|
52
|
+
* `delete()` sets `deletedAt` instead of removing the row.
|
|
53
|
+
* Use `.withTrashed()` on queries to include soft-deleted rows.
|
|
54
|
+
* Default: `false`.
|
|
55
|
+
*/
|
|
56
|
+
softDeletes?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Log every SQL query to the console. Useful for debugging.
|
|
59
|
+
* Default: `false`.
|
|
60
|
+
*/
|
|
61
|
+
debug?: boolean;
|
|
45
62
|
};
|
|
46
63
|
|
|
47
64
|
export type Relationship = {
|
|
@@ -144,6 +161,12 @@ export type UpdateBuilder<T> = {
|
|
|
144
161
|
exec: () => number;
|
|
145
162
|
};
|
|
146
163
|
|
|
164
|
+
/** Fluent delete builder */
|
|
165
|
+
export type DeleteBuilder<T> = {
|
|
166
|
+
where: (conditions: Record<string, any>) => DeleteBuilder<T>;
|
|
167
|
+
exec: () => number;
|
|
168
|
+
};
|
|
169
|
+
|
|
147
170
|
/** Nav-aware entity accessor for a specific table */
|
|
148
171
|
export type NavEntityAccessor<
|
|
149
172
|
S extends SchemaMap,
|
|
@@ -155,7 +178,7 @@ export type NavEntityAccessor<
|
|
|
155
178
|
update: ((id: number, data: Partial<Omit<z.input<S[Table & keyof S]>, 'id'>>) => NavEntity<S, R, Table> | null)
|
|
156
179
|
& ((data: Partial<Omit<z.input<S[Table & keyof S]>, 'id'>>) => UpdateBuilder<NavEntity<S, R, Table>>);
|
|
157
180
|
upsert: (conditions?: Partial<z.infer<S[Table & keyof S]>>, data?: Partial<z.infer<S[Table & keyof S]>>) => NavEntity<S, R, Table>;
|
|
158
|
-
delete: (id: number) => void;
|
|
181
|
+
delete: ((id: number) => void) & (() => DeleteBuilder<NavEntity<S, R, Table>>);
|
|
159
182
|
select: (...cols: (keyof z.infer<S[Table & keyof S]> & string)[]) => QueryBuilder<NavEntity<S, R, Table>>;
|
|
160
183
|
on: ((event: 'insert' | 'update', callback: (row: NavEntity<S, R, Table>) => void | Promise<void>) => () => void) &
|
|
161
184
|
((event: 'delete', callback: (row: { id: number }) => void | Promise<void>) => () => void);
|
|
@@ -185,7 +208,7 @@ export type EntityAccessor<S extends z.ZodType<any>> = {
|
|
|
185
208
|
insertMany: (rows: EntityData<S>[]) => AugmentedEntity<S>[];
|
|
186
209
|
update: ((id: number, data: Partial<EntityData<S>>) => AugmentedEntity<S> | null) & ((data: Partial<EntityData<S>>) => UpdateBuilder<AugmentedEntity<S>>);
|
|
187
210
|
upsert: (conditions?: Partial<InferSchema<S>>, data?: Partial<InferSchema<S>>) => AugmentedEntity<S>;
|
|
188
|
-
delete: (id: number) => void;
|
|
211
|
+
delete: ((id: number) => void) & (() => DeleteBuilder<AugmentedEntity<S>>);
|
|
189
212
|
select: (...cols: (keyof InferSchema<S> & string)[]) => QueryBuilder<AugmentedEntity<S>>;
|
|
190
213
|
on: ((event: 'insert' | 'update', callback: (row: AugmentedEntity<S>) => void | Promise<void>) => () => void) &
|
|
191
214
|
((event: 'delete', callback: (row: { id: number }) => void | Promise<void>) => () => void);
|