@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/dist/index.d.ts
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 };
|