@type32/tauri-sqlite-orm 0.1.3 → 0.1.5

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.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,34 +36,105 @@ 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
- declare function text<TEnum extends string>(name: string, config?: {
57
- isPrimaryKey?: boolean;
47
+ type TextConfig<TEnum extends string> = {
58
48
  enum?: readonly TEnum[];
59
- }): ColumnBuilder<TEnum extends string ? TEnum : string>;
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
- isPrimaryKey?: boolean;
62
- mode?: "number" | "boolean" | "timestamp";
63
- autoIncrement?: boolean;
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?: "json" | "bigint";
64
+ mode?: BlobMode;
65
+ }): ColumnBuilder<unknown | bigint | Uint8Array>;
66
+ declare function blob(config?: {
67
+ mode?: BlobMode;
68
68
  }): ColumnBuilder<unknown | bigint | Uint8Array>;
69
+ type NumericMode = "string" | "number" | "bigint";
69
70
  declare function numeric(name: string, config?: {
70
- mode?: "string" | "number" | "bigint";
71
+ mode?: NumericMode;
72
+ }): ColumnBuilder<string | number | bigint>;
73
+ declare function numeric(config?: {
74
+ mode?: NumericMode;
71
75
  }): ColumnBuilder<string | number | bigint>;
72
- declare const boolean: (name: string) => ColumnBuilder<boolean>;
73
- declare const timestamp: (name: string) => ColumnBuilder<Date>;
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>;
82
+ type UniqueSpec = {
83
+ name?: string;
84
+ columns: string[];
85
+ };
86
+ type PrimaryKeySpec = {
87
+ name?: string;
88
+ columns: string[];
89
+ };
90
+ type CheckSpec = {
91
+ name: string;
92
+ expr: SQLExpression | {
93
+ raw: string;
94
+ };
95
+ };
96
+ type ForeignKeySpec = {
97
+ name?: string;
98
+ columns: string[];
99
+ foreignTable: string;
100
+ foreignColumns: string[];
101
+ onDelete?: UpdateDeleteAction;
102
+ onUpdate?: UpdateDeleteAction;
103
+ };
104
+ type IndexSpec = {
105
+ name: string;
106
+ columns: string[];
107
+ unique?: boolean;
108
+ where?: SQLExpression;
109
+ };
110
+ declare function unique(name?: string): {
111
+ on: (...cols: Column<any>[]) => UniqueSpec;
112
+ };
113
+ declare function primaryKey(opts: {
114
+ name?: string;
115
+ columns: Column<any>[];
116
+ }): PrimaryKeySpec;
117
+ declare function check(name: string, expr: SQLExpression): CheckSpec;
118
+ declare function foreignKey(opts: {
119
+ name?: string;
120
+ columns: Column<any>[];
121
+ foreignColumns: Column<any>[];
122
+ onDelete?: UpdateDeleteAction;
123
+ onUpdate?: UpdateDeleteAction;
124
+ }): ForeignKeySpec;
125
+ declare function index(name: string): {
126
+ on: (...cols: Column<any>[]) => IndexSpec;
127
+ where: (expr: SQLExpression) => IndexSpec;
128
+ };
129
+ declare function uniqueIndex(name: string): {
130
+ on: (...cols: Column<any>[]) => IndexSpec;
131
+ where: (expr: SQLExpression) => IndexSpec;
132
+ };
74
133
  type SchemaDefinition = Record<string, Column<any>>;
75
134
  type InferModel<T extends SchemaDefinition> = {
76
135
  [K in keyof T]: T[K]["_dataType"];
77
136
  };
78
- declare function defineTable<T extends SchemaDefinition>(tableName: string, schema: T): any & InferModel<T>;
137
+ declare function defineTable<T extends SchemaDefinition>(tableName: string, schema: T, extras?: (t: any) => Array<UniqueSpec | PrimaryKeySpec | CheckSpec | ForeignKeySpec | IndexSpec>): any & InferModel<T>;
79
138
  type Table<T extends SchemaDefinition> = ReturnType<typeof defineTable<T>>;
80
139
 
81
140
  interface SQL {
@@ -84,6 +143,11 @@ interface SQL {
84
143
  bindings: any[];
85
144
  };
86
145
  }
146
+ declare function raw(strings: TemplateStringsArray, ...values: any[]): SQL;
147
+ declare function getQualifiedName(column: Column): string;
148
+ declare const and: (...conditions: SQL[]) => SQL;
149
+ declare const or: (...conditions: SQL[]) => SQL;
150
+ declare const not: (condition: SQL) => SQL;
87
151
  declare const eq: (column: Column, value: any) => SQL;
88
152
  declare const ne: (column: Column, value: any) => SQL;
89
153
  declare const gt: (column: Column, value: number | Date) => SQL;
@@ -91,6 +155,36 @@ declare const gte: (column: Column, value: number | Date) => SQL;
91
155
  declare const lt: (column: Column, value: number | Date) => SQL;
92
156
  declare const lte: (column: Column, value: number | Date) => SQL;
93
157
  declare const like: (column: Column<string>, value: string) => SQL;
158
+ declare const ilike: (column: Column<string>, value: string | Column) => SQL;
159
+ declare const notIlike: (column: Column<string>, value: string | Column) => SQL;
160
+ declare const isNull: (column: Column) => SQL;
161
+ declare const isNotNull: (column: Column) => SQL;
162
+ declare const between: (column: Column, from: number | string | Date | Column, to: number | string | Date | Column) => SQL;
163
+ declare const notBetween: (column: Column, from: number | string | Date | Column, to: number | string | Date | Column) => SQL;
164
+ declare const inArray: (column: Column, valuesOrQuery: any[] | SQL | {
165
+ toSQL: () => {
166
+ clause: string;
167
+ bindings: any[];
168
+ };
169
+ }) => SQL;
170
+ declare const notInArray: (column: Column, valuesOrQuery: any[] | SQL | {
171
+ toSQL: () => {
172
+ clause: string;
173
+ bindings: any[];
174
+ };
175
+ }) => SQL;
176
+ declare const exists: (subquery: SQL | {
177
+ toSQL: () => {
178
+ clause: string;
179
+ bindings: any[];
180
+ };
181
+ }) => SQL;
182
+ declare const notExists: (subquery: SQL | {
183
+ toSQL: () => {
184
+ clause: string;
185
+ bindings: any[];
186
+ };
187
+ }) => SQL;
94
188
  declare const asc: (column: Column) => string;
95
189
  declare const desc: (column: Column) => string;
96
190
 
@@ -102,41 +196,103 @@ declare class SelectQueryBuilder<T> {
102
196
  private _orderBy;
103
197
  private _limit;
104
198
  private _offset;
105
- private _eager;
106
- constructor(fields?: Record<string, Column<any>>);
199
+ private _groupBy;
200
+ private _having;
201
+ private _distinct;
202
+ private _dbProvider;
203
+ constructor(dbProvider: () => Promise<Database>, fields?: Record<string, Column<any>>);
204
+ distinct(): this;
205
+ select(fields: Record<string, Column<any> | SQL>): this;
107
206
  from(table: Table<any>): this;
108
- where(...conditions: SQL[]): this;
207
+ where(...conditions: (SQL | undefined)[]): this;
109
208
  leftJoin(otherTable: Table<any>, on: SQL): this;
110
- orderBy(...clauses: string[]): this;
209
+ groupBy(...exprs: (Column | string)[]): this;
210
+ having(...conditions: SQL[]): this;
211
+ orderBy(...clauses: (string | Column<any> | SQL)[]): this;
111
212
  limit(value: number): this;
112
213
  offset(value: number): this;
113
214
  execute(): Promise<T[]>;
215
+ iterator(): Promise<AsyncIterableIterator<T>>;
114
216
  }
115
217
  declare class TauriORM {
116
218
  query: Record<string, any>;
117
219
  private _tables;
118
220
  private _relations;
221
+ private _dbPromise;
222
+ constructor(dbUri: string);
223
+ private getDb;
119
224
  configureQuery(tables: Record<string, Table<any>>, relations: Record<string, Record<string, RelationConfig>>): void;
120
225
  select<T>(fields?: Record<string, Column<any>>): SelectQueryBuilder<T>;
226
+ selectDistinct<T>(fields?: Record<string, Column<any>>): SelectQueryBuilder<T>;
121
227
  insert(table: Table<any>): {
122
228
  _table: any;
123
229
  _rows: Record<string, any>[];
230
+ _selectSql: {
231
+ clause: string;
232
+ bindings: any[];
233
+ } | null;
234
+ _conflict: null | {
235
+ kind: "doNothing";
236
+ target?: string | string[];
237
+ where?: SQL;
238
+ } | {
239
+ kind: "doUpdate";
240
+ target: string | string[];
241
+ targetWhere?: SQL;
242
+ set: Record<string, any>;
243
+ setWhere?: SQL;
244
+ };
245
+ _returning: null | "__RETURNING_ID__" | Record<string, Column<any>>;
124
246
  values(rowOrRows: Record<string, any> | Record<string, any>[]): /*elided*/ any;
125
- execute(): Promise<void>;
247
+ select(qb: {
248
+ toSQL?: () => {
249
+ clause: string;
250
+ bindings: any[];
251
+ };
252
+ } | SQL): /*elided*/ any;
253
+ returning(fields?: Record<string, Column<any>>): any;
254
+ $returningId(): any;
255
+ onConflictDoNothing(opts?: {
256
+ target?: Column<any> | Column<any>[];
257
+ where?: SQL;
258
+ }): /*elided*/ any;
259
+ onConflictDoUpdate(opts: {
260
+ target: Column<any> | Column<any>[];
261
+ targetWhere?: SQL;
262
+ set: Record<string, any>;
263
+ setWhere?: SQL;
264
+ }): /*elided*/ any;
265
+ execute(): Promise<any>;
266
+ _buildConflictClause(): string;
267
+ _executeWithReturning(db: any, query: string, bindings: any[]): Promise<any>;
126
268
  };
127
269
  update(table: Table<any>): {
128
270
  _table: any;
129
271
  _data: Record<string, any> | null;
130
272
  _where: Record<string, any> | SQL | null;
273
+ _orderBy: Array<string | SQL>;
274
+ _limit: number | null;
275
+ _from: Table<any> | null;
276
+ _returning: null | Record<string, Column<any>>;
131
277
  set(data: Record<string, any>): /*elided*/ any;
132
278
  where(cond: Record<string, any> | SQL): /*elided*/ any;
133
- execute(): Promise<void>;
279
+ orderBy(...clauses: (string | Column<any> | SQL)[]): /*elided*/ any;
280
+ limit(n: number): /*elided*/ any;
281
+ from(tbl: Table<any>): /*elided*/ any;
282
+ returning(fields?: Record<string, Column<any>>): any;
283
+ execute(): Promise<unknown>;
134
284
  };
135
285
  delete(table: Table<any>): {
136
286
  _table: any;
137
287
  _where: Record<string, any> | SQL | null;
288
+ _orderBy: Array<string | SQL>;
289
+ _limit: number | null;
290
+ _returning: null | Record<string, Column<any>>;
138
291
  where(cond: Record<string, any> | SQL): /*elided*/ any;
139
- execute(): Promise<void>;
292
+ orderBy(...clauses: (string | Column<any> | SQL)[]): /*elided*/ any;
293
+ limit(n: number): /*elided*/ any;
294
+ returning(fields?: Record<string, Column<any>>): any;
295
+ execute(): Promise<unknown>;
140
296
  };
141
297
  run(query: string, bindings?: any[]): Promise<void>;
142
298
  private generateCreateTableSql;
@@ -209,7 +365,6 @@ declare class TauriORM {
209
365
  preserveData?: boolean;
210
366
  }): Promise<void>;
211
367
  }
212
- declare const db: TauriORM;
213
368
  type OneConfig = {
214
369
  fields?: Column[];
215
370
  references?: Column[];
@@ -238,12 +393,17 @@ type WithSpec = Record<string, boolean | {
238
393
  with?: WithSpec;
239
394
  columns?: string[];
240
395
  }>;
241
- declare function makeQueryAPI(tables: Record<string, Table<any>>, relDefs: Record<string, Record<string, RelationConfig>>): { [K in keyof typeof tables]: {
396
+ declare function makeQueryAPI(tables: Record<string, Table<any>>, relDefs: Record<string, Record<string, RelationConfig>>, dbProvider: () => Promise<Database>): { [K in keyof typeof tables]: {
242
397
  findMany: (opts?: {
243
398
  with?: WithSpec;
244
399
  join?: boolean;
245
400
  columns?: string[];
246
401
  }) => Promise<any[]>;
402
+ findFirst: (opts?: {
403
+ with?: WithSpec;
404
+ join?: boolean;
405
+ columns?: string[];
406
+ }) => Promise<any | null>;
247
407
  }; };
248
408
 
249
- export { type Column, type ManyRelation, type OneRelation, type SQL, type SQLExpression, type Table, TauriORM, type UpdateDeleteAction, asc, blob, boolean, db, defineTable, desc, eq, getDb, gt, gte, initDb, integer, like, lt, lte, makeQueryAPI, ne, numeric, real, relations, sql, text, timestamp };
409
+ export { type BlobMode, type CheckSpec, type Column, type ColumnBuilder, type ForeignKeySpec, type IndexSpec, type IntegerMode, type ManyRelation, type NumericMode, type OneRelation, type PrimaryKeySpec, type SQL, type SQLExpression, type Table, TauriORM, type UniqueSpec, type UpdateDeleteAction, and, asc, between, blob, boolean, check, defineTable, desc, eq, exists, foreignKey, getQualifiedName, gt, gte, ilike, inArray, increments, index, integer, isNotNull, isNull, like, lt, lte, makeQueryAPI, ne, not, notBetween, notExists, notIlike, notInArray, numeric, or, primaryKey, raw, real, relations, sql, text, timestamp, unique, uniqueIndex };
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,34 +36,105 @@ 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
- declare function text<TEnum extends string>(name: string, config?: {
57
- isPrimaryKey?: boolean;
47
+ type TextConfig<TEnum extends string> = {
58
48
  enum?: readonly TEnum[];
59
- }): ColumnBuilder<TEnum extends string ? TEnum : string>;
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
- isPrimaryKey?: boolean;
62
- mode?: "number" | "boolean" | "timestamp";
63
- autoIncrement?: boolean;
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?: "json" | "bigint";
64
+ mode?: BlobMode;
65
+ }): ColumnBuilder<unknown | bigint | Uint8Array>;
66
+ declare function blob(config?: {
67
+ mode?: BlobMode;
68
68
  }): ColumnBuilder<unknown | bigint | Uint8Array>;
69
+ type NumericMode = "string" | "number" | "bigint";
69
70
  declare function numeric(name: string, config?: {
70
- mode?: "string" | "number" | "bigint";
71
+ mode?: NumericMode;
72
+ }): ColumnBuilder<string | number | bigint>;
73
+ declare function numeric(config?: {
74
+ mode?: NumericMode;
71
75
  }): ColumnBuilder<string | number | bigint>;
72
- declare const boolean: (name: string) => ColumnBuilder<boolean>;
73
- declare const timestamp: (name: string) => ColumnBuilder<Date>;
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>;
82
+ type UniqueSpec = {
83
+ name?: string;
84
+ columns: string[];
85
+ };
86
+ type PrimaryKeySpec = {
87
+ name?: string;
88
+ columns: string[];
89
+ };
90
+ type CheckSpec = {
91
+ name: string;
92
+ expr: SQLExpression | {
93
+ raw: string;
94
+ };
95
+ };
96
+ type ForeignKeySpec = {
97
+ name?: string;
98
+ columns: string[];
99
+ foreignTable: string;
100
+ foreignColumns: string[];
101
+ onDelete?: UpdateDeleteAction;
102
+ onUpdate?: UpdateDeleteAction;
103
+ };
104
+ type IndexSpec = {
105
+ name: string;
106
+ columns: string[];
107
+ unique?: boolean;
108
+ where?: SQLExpression;
109
+ };
110
+ declare function unique(name?: string): {
111
+ on: (...cols: Column<any>[]) => UniqueSpec;
112
+ };
113
+ declare function primaryKey(opts: {
114
+ name?: string;
115
+ columns: Column<any>[];
116
+ }): PrimaryKeySpec;
117
+ declare function check(name: string, expr: SQLExpression): CheckSpec;
118
+ declare function foreignKey(opts: {
119
+ name?: string;
120
+ columns: Column<any>[];
121
+ foreignColumns: Column<any>[];
122
+ onDelete?: UpdateDeleteAction;
123
+ onUpdate?: UpdateDeleteAction;
124
+ }): ForeignKeySpec;
125
+ declare function index(name: string): {
126
+ on: (...cols: Column<any>[]) => IndexSpec;
127
+ where: (expr: SQLExpression) => IndexSpec;
128
+ };
129
+ declare function uniqueIndex(name: string): {
130
+ on: (...cols: Column<any>[]) => IndexSpec;
131
+ where: (expr: SQLExpression) => IndexSpec;
132
+ };
74
133
  type SchemaDefinition = Record<string, Column<any>>;
75
134
  type InferModel<T extends SchemaDefinition> = {
76
135
  [K in keyof T]: T[K]["_dataType"];
77
136
  };
78
- declare function defineTable<T extends SchemaDefinition>(tableName: string, schema: T): any & InferModel<T>;
137
+ declare function defineTable<T extends SchemaDefinition>(tableName: string, schema: T, extras?: (t: any) => Array<UniqueSpec | PrimaryKeySpec | CheckSpec | ForeignKeySpec | IndexSpec>): any & InferModel<T>;
79
138
  type Table<T extends SchemaDefinition> = ReturnType<typeof defineTable<T>>;
80
139
 
81
140
  interface SQL {
@@ -84,6 +143,11 @@ interface SQL {
84
143
  bindings: any[];
85
144
  };
86
145
  }
146
+ declare function raw(strings: TemplateStringsArray, ...values: any[]): SQL;
147
+ declare function getQualifiedName(column: Column): string;
148
+ declare const and: (...conditions: SQL[]) => SQL;
149
+ declare const or: (...conditions: SQL[]) => SQL;
150
+ declare const not: (condition: SQL) => SQL;
87
151
  declare const eq: (column: Column, value: any) => SQL;
88
152
  declare const ne: (column: Column, value: any) => SQL;
89
153
  declare const gt: (column: Column, value: number | Date) => SQL;
@@ -91,6 +155,36 @@ declare const gte: (column: Column, value: number | Date) => SQL;
91
155
  declare const lt: (column: Column, value: number | Date) => SQL;
92
156
  declare const lte: (column: Column, value: number | Date) => SQL;
93
157
  declare const like: (column: Column<string>, value: string) => SQL;
158
+ declare const ilike: (column: Column<string>, value: string | Column) => SQL;
159
+ declare const notIlike: (column: Column<string>, value: string | Column) => SQL;
160
+ declare const isNull: (column: Column) => SQL;
161
+ declare const isNotNull: (column: Column) => SQL;
162
+ declare const between: (column: Column, from: number | string | Date | Column, to: number | string | Date | Column) => SQL;
163
+ declare const notBetween: (column: Column, from: number | string | Date | Column, to: number | string | Date | Column) => SQL;
164
+ declare const inArray: (column: Column, valuesOrQuery: any[] | SQL | {
165
+ toSQL: () => {
166
+ clause: string;
167
+ bindings: any[];
168
+ };
169
+ }) => SQL;
170
+ declare const notInArray: (column: Column, valuesOrQuery: any[] | SQL | {
171
+ toSQL: () => {
172
+ clause: string;
173
+ bindings: any[];
174
+ };
175
+ }) => SQL;
176
+ declare const exists: (subquery: SQL | {
177
+ toSQL: () => {
178
+ clause: string;
179
+ bindings: any[];
180
+ };
181
+ }) => SQL;
182
+ declare const notExists: (subquery: SQL | {
183
+ toSQL: () => {
184
+ clause: string;
185
+ bindings: any[];
186
+ };
187
+ }) => SQL;
94
188
  declare const asc: (column: Column) => string;
95
189
  declare const desc: (column: Column) => string;
96
190
 
@@ -102,41 +196,103 @@ declare class SelectQueryBuilder<T> {
102
196
  private _orderBy;
103
197
  private _limit;
104
198
  private _offset;
105
- private _eager;
106
- constructor(fields?: Record<string, Column<any>>);
199
+ private _groupBy;
200
+ private _having;
201
+ private _distinct;
202
+ private _dbProvider;
203
+ constructor(dbProvider: () => Promise<Database>, fields?: Record<string, Column<any>>);
204
+ distinct(): this;
205
+ select(fields: Record<string, Column<any> | SQL>): this;
107
206
  from(table: Table<any>): this;
108
- where(...conditions: SQL[]): this;
207
+ where(...conditions: (SQL | undefined)[]): this;
109
208
  leftJoin(otherTable: Table<any>, on: SQL): this;
110
- orderBy(...clauses: string[]): this;
209
+ groupBy(...exprs: (Column | string)[]): this;
210
+ having(...conditions: SQL[]): this;
211
+ orderBy(...clauses: (string | Column<any> | SQL)[]): this;
111
212
  limit(value: number): this;
112
213
  offset(value: number): this;
113
214
  execute(): Promise<T[]>;
215
+ iterator(): Promise<AsyncIterableIterator<T>>;
114
216
  }
115
217
  declare class TauriORM {
116
218
  query: Record<string, any>;
117
219
  private _tables;
118
220
  private _relations;
221
+ private _dbPromise;
222
+ constructor(dbUri: string);
223
+ private getDb;
119
224
  configureQuery(tables: Record<string, Table<any>>, relations: Record<string, Record<string, RelationConfig>>): void;
120
225
  select<T>(fields?: Record<string, Column<any>>): SelectQueryBuilder<T>;
226
+ selectDistinct<T>(fields?: Record<string, Column<any>>): SelectQueryBuilder<T>;
121
227
  insert(table: Table<any>): {
122
228
  _table: any;
123
229
  _rows: Record<string, any>[];
230
+ _selectSql: {
231
+ clause: string;
232
+ bindings: any[];
233
+ } | null;
234
+ _conflict: null | {
235
+ kind: "doNothing";
236
+ target?: string | string[];
237
+ where?: SQL;
238
+ } | {
239
+ kind: "doUpdate";
240
+ target: string | string[];
241
+ targetWhere?: SQL;
242
+ set: Record<string, any>;
243
+ setWhere?: SQL;
244
+ };
245
+ _returning: null | "__RETURNING_ID__" | Record<string, Column<any>>;
124
246
  values(rowOrRows: Record<string, any> | Record<string, any>[]): /*elided*/ any;
125
- execute(): Promise<void>;
247
+ select(qb: {
248
+ toSQL?: () => {
249
+ clause: string;
250
+ bindings: any[];
251
+ };
252
+ } | SQL): /*elided*/ any;
253
+ returning(fields?: Record<string, Column<any>>): any;
254
+ $returningId(): any;
255
+ onConflictDoNothing(opts?: {
256
+ target?: Column<any> | Column<any>[];
257
+ where?: SQL;
258
+ }): /*elided*/ any;
259
+ onConflictDoUpdate(opts: {
260
+ target: Column<any> | Column<any>[];
261
+ targetWhere?: SQL;
262
+ set: Record<string, any>;
263
+ setWhere?: SQL;
264
+ }): /*elided*/ any;
265
+ execute(): Promise<any>;
266
+ _buildConflictClause(): string;
267
+ _executeWithReturning(db: any, query: string, bindings: any[]): Promise<any>;
126
268
  };
127
269
  update(table: Table<any>): {
128
270
  _table: any;
129
271
  _data: Record<string, any> | null;
130
272
  _where: Record<string, any> | SQL | null;
273
+ _orderBy: Array<string | SQL>;
274
+ _limit: number | null;
275
+ _from: Table<any> | null;
276
+ _returning: null | Record<string, Column<any>>;
131
277
  set(data: Record<string, any>): /*elided*/ any;
132
278
  where(cond: Record<string, any> | SQL): /*elided*/ any;
133
- execute(): Promise<void>;
279
+ orderBy(...clauses: (string | Column<any> | SQL)[]): /*elided*/ any;
280
+ limit(n: number): /*elided*/ any;
281
+ from(tbl: Table<any>): /*elided*/ any;
282
+ returning(fields?: Record<string, Column<any>>): any;
283
+ execute(): Promise<unknown>;
134
284
  };
135
285
  delete(table: Table<any>): {
136
286
  _table: any;
137
287
  _where: Record<string, any> | SQL | null;
288
+ _orderBy: Array<string | SQL>;
289
+ _limit: number | null;
290
+ _returning: null | Record<string, Column<any>>;
138
291
  where(cond: Record<string, any> | SQL): /*elided*/ any;
139
- execute(): Promise<void>;
292
+ orderBy(...clauses: (string | Column<any> | SQL)[]): /*elided*/ any;
293
+ limit(n: number): /*elided*/ any;
294
+ returning(fields?: Record<string, Column<any>>): any;
295
+ execute(): Promise<unknown>;
140
296
  };
141
297
  run(query: string, bindings?: any[]): Promise<void>;
142
298
  private generateCreateTableSql;
@@ -209,7 +365,6 @@ declare class TauriORM {
209
365
  preserveData?: boolean;
210
366
  }): Promise<void>;
211
367
  }
212
- declare const db: TauriORM;
213
368
  type OneConfig = {
214
369
  fields?: Column[];
215
370
  references?: Column[];
@@ -238,12 +393,17 @@ type WithSpec = Record<string, boolean | {
238
393
  with?: WithSpec;
239
394
  columns?: string[];
240
395
  }>;
241
- declare function makeQueryAPI(tables: Record<string, Table<any>>, relDefs: Record<string, Record<string, RelationConfig>>): { [K in keyof typeof tables]: {
396
+ declare function makeQueryAPI(tables: Record<string, Table<any>>, relDefs: Record<string, Record<string, RelationConfig>>, dbProvider: () => Promise<Database>): { [K in keyof typeof tables]: {
242
397
  findMany: (opts?: {
243
398
  with?: WithSpec;
244
399
  join?: boolean;
245
400
  columns?: string[];
246
401
  }) => Promise<any[]>;
402
+ findFirst: (opts?: {
403
+ with?: WithSpec;
404
+ join?: boolean;
405
+ columns?: string[];
406
+ }) => Promise<any | null>;
247
407
  }; };
248
408
 
249
- export { type Column, type ManyRelation, type OneRelation, type SQL, type SQLExpression, type Table, TauriORM, type UpdateDeleteAction, asc, blob, boolean, db, defineTable, desc, eq, getDb, gt, gte, initDb, integer, like, lt, lte, makeQueryAPI, ne, numeric, real, relations, sql, text, timestamp };
409
+ export { type BlobMode, type CheckSpec, type Column, type ColumnBuilder, type ForeignKeySpec, type IndexSpec, type IntegerMode, type ManyRelation, type NumericMode, type OneRelation, type PrimaryKeySpec, type SQL, type SQLExpression, type Table, TauriORM, type UniqueSpec, type UpdateDeleteAction, and, asc, between, blob, boolean, check, defineTable, desc, eq, exists, foreignKey, getQualifiedName, gt, gte, ilike, inArray, increments, index, integer, isNotNull, isNull, like, lt, lte, makeQueryAPI, ne, not, notBetween, notExists, notIlike, notInArray, numeric, or, primaryKey, raw, real, relations, sql, text, timestamp, unique, uniqueIndex };