@type32/tauri-sqlite-orm 0.1.18-1 → 0.1.18-11
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/README.md +0 -156
- package/dist/index.d.mts +195 -73
- package/dist/index.d.ts +195 -73
- package/dist/index.js +661 -191
- package/dist/index.mjs +642 -189
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,159 +16,3 @@ bun add @type32/tauri-sqlite-orm @tauri-apps/plugin-sql
|
|
|
16
16
|
```
|
|
17
17
|
|
|
18
18
|
Make sure the SQL plugin is registered on the Rust side (see Tauri docs).
|
|
19
|
-
|
|
20
|
-
### Quick Start
|
|
21
|
-
|
|
22
|
-
Here’s a quick example to get you started:
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
// src/db/schema.ts
|
|
26
|
-
import { sqliteTable, text, integer } from "@type32/tauri-sqlite-orm";
|
|
27
|
-
|
|
28
|
-
export const users = sqliteTable("users", {
|
|
29
|
-
id: integer("id").primaryKey().autoincrement(),
|
|
30
|
-
name: text("name").notNull(),
|
|
31
|
-
email: text("email").unique(),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
export const posts = sqliteTable("posts", {
|
|
35
|
-
id: integer("id").primaryKey(),
|
|
36
|
-
content: text("content"),
|
|
37
|
-
authorId: integer("author_id").references(() => users.id),
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// src/db/index.ts
|
|
41
|
-
import { TauriORM } from "@type32/tauri-sqlite-orm";
|
|
42
|
-
import Database from "@tauri-apps/plugin-sql";
|
|
43
|
-
import * as schema from "./schema";
|
|
44
|
-
|
|
45
|
-
// Load the database
|
|
46
|
-
const dbInstance = await Database.load("sqlite:app.db");
|
|
47
|
-
|
|
48
|
-
// Create the ORM instance
|
|
49
|
-
export const db = new TauriORM(dbInstance, schema);
|
|
50
|
-
|
|
51
|
-
// Migrate the database if the schema has changed
|
|
52
|
-
await db.migrateIfDirty();
|
|
53
|
-
|
|
54
|
-
// Now you can use the ORM to interact with your database
|
|
55
|
-
const newUser = await db
|
|
56
|
-
.insert(schema.users)
|
|
57
|
-
.values({ name: "John Doe", email: "john.doe@example.com" });
|
|
58
|
-
const allUsers = await db.select(schema.users).execute();
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Documentation
|
|
62
|
-
|
|
63
|
-
- [Getting Started](docs/getting-started.md)
|
|
64
|
-
- [Schema and Types](docs/schema-and-types.md)
|
|
65
|
-
- [CRUD Operations (SELECT)](docs/queries-select.md)
|
|
66
|
-
- [CRUD Operations (INSERT)](docs/crud-insert.md)
|
|
67
|
-
- [CRUD Operations (UPDATE)](docs/crud-update.md)
|
|
68
|
-
- [CRUD Operations (DELETE)](docs/crud-delete.md)
|
|
69
|
-
- [Migrations](docs/migrations.md)
|
|
70
|
-
- [Transactions](docs/transactions.md)
|
|
71
|
-
- [Relations](docs/relations.md)
|
|
72
|
-
|
|
73
|
-
### Schema Definition
|
|
74
|
-
|
|
75
|
-
Define your tables and columns using a chainable, Drizzle-style API.
|
|
76
|
-
|
|
77
|
-
```typescript
|
|
78
|
-
import { sqliteTable, text, integer, boolean } from "@type32/tauri-sqlite-orm";
|
|
79
|
-
|
|
80
|
-
export const users = sqliteTable("users", {
|
|
81
|
-
id: integer("id").primaryKey().autoincrement(),
|
|
82
|
-
name: text("name").notNull(),
|
|
83
|
-
email: text("email").unique(),
|
|
84
|
-
isActive: boolean("is_active").default(true),
|
|
85
|
-
createdAt: integer("created_at", { mode: "timestamp" }).$defaultFn(
|
|
86
|
-
() => new Date()
|
|
87
|
-
),
|
|
88
|
-
});
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### CRUD Operations
|
|
92
|
-
|
|
93
|
-
Perform `CREATE`, `READ`, `UPDATE`, and `DELETE` operations using a type-safe query builder.
|
|
94
|
-
|
|
95
|
-
**SELECT**
|
|
96
|
-
|
|
97
|
-
```typescript
|
|
98
|
-
import { eq, and } from "@type32/tauri-sqlite-orm";
|
|
99
|
-
|
|
100
|
-
// Select all users
|
|
101
|
-
const allUsers = await db.select(users).execute();
|
|
102
|
-
|
|
103
|
-
// Select specific columns
|
|
104
|
-
const userNames = await db.select(users, ["name"]).execute();
|
|
105
|
-
|
|
106
|
-
// Use WHERE conditions
|
|
107
|
-
const activeUsers = await db
|
|
108
|
-
.select(users)
|
|
109
|
-
.where(eq(users.isActive, true))
|
|
110
|
-
.execute();
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
**INSERT**
|
|
114
|
-
|
|
115
|
-
```typescript
|
|
116
|
-
// Insert a single user
|
|
117
|
-
const newUser = await db
|
|
118
|
-
.insert(users)
|
|
119
|
-
.values({ name: "Jane Doe", email: "jane.doe@example.com" });
|
|
120
|
-
|
|
121
|
-
// Insert multiple users
|
|
122
|
-
await db.insert(users).values([
|
|
123
|
-
{ name: "Alice", email: "alice@example.com" },
|
|
124
|
-
{ name: "Bob", email: "bob@example.com" },
|
|
125
|
-
]);
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
**UPDATE**
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
import { eq } from "@type32/tauri-sqlite-orm";
|
|
132
|
-
|
|
133
|
-
// Update a user's email
|
|
134
|
-
await db
|
|
135
|
-
.update(users)
|
|
136
|
-
.set({ email: "new.email@example.com" })
|
|
137
|
-
.where(eq(users.id, 1));
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
**DELETE**
|
|
141
|
-
|
|
142
|
-
```typescript
|
|
143
|
-
import { eq } from "@type32/tauri-sqlite-orm";
|
|
144
|
-
|
|
145
|
-
// Delete a user
|
|
146
|
-
await db.delete(users).where(eq(users.id, 1));
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### Migrations
|
|
150
|
-
|
|
151
|
-
The ORM includes a simple migration system that automatically detects schema changes and applies them to the database.
|
|
152
|
-
|
|
153
|
-
```typescript
|
|
154
|
-
// This will check if the schema has changed and run migrations if it has
|
|
155
|
-
await db.migrateIfDirty();
|
|
156
|
-
|
|
157
|
-
// You can also run migrations manually
|
|
158
|
-
await db.migrate();
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Transactions
|
|
162
|
-
|
|
163
|
-
Run multiple database operations within a transaction to ensure atomicity.
|
|
164
|
-
|
|
165
|
-
```typescript
|
|
166
|
-
await db.transaction(async (tx) => {
|
|
167
|
-
await tx.insert(users).values({ name: "From Transaction" });
|
|
168
|
-
await tx.delete(users).where(eq(users.id, 1));
|
|
169
|
-
});
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### License
|
|
173
|
-
|
|
174
|
-
MIT
|
package/dist/index.d.mts
CHANGED
|
@@ -18,6 +18,123 @@ interface ColumnOptions<TData> {
|
|
|
18
18
|
$onUpdateFn?: () => TData;
|
|
19
19
|
}
|
|
20
20
|
type ExtractColumnType<T extends AnySQLiteColumn> = T extends SQLiteColumn<infer _, infer TType, infer TMode, infer TNotNull, infer THasDefault> ? THasDefault extends true ? TNotNull extends true ? ColumnValueTypes<TType, TMode> : ColumnValueTypes<TType, TMode> | null | undefined : TNotNull extends true ? ColumnValueTypes<TType, TMode> : ColumnValueTypes<TType, TMode> | null | undefined : never;
|
|
21
|
+
type AnySQLiteColumn = SQLiteColumn<any, any, any, any, any, any>;
|
|
22
|
+
type AnyTable = Table<Record<string, AnySQLiteColumn>, string>;
|
|
23
|
+
type InferSelectModel<T extends AnyTable> = {
|
|
24
|
+
[K in keyof T["_"]["columns"]]: ExtractColumnType<T["_"]["columns"][K]>;
|
|
25
|
+
};
|
|
26
|
+
type RelationType = "one" | "many";
|
|
27
|
+
interface RelationConfig {
|
|
28
|
+
type: RelationType;
|
|
29
|
+
foreignTable: AnyTable;
|
|
30
|
+
fields?: AnySQLiteColumn[];
|
|
31
|
+
references?: AnySQLiteColumn[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare class BaseQueryBuilder {
|
|
35
|
+
protected db: Database;
|
|
36
|
+
protected query: string;
|
|
37
|
+
protected params: any[];
|
|
38
|
+
constructor(db: Database);
|
|
39
|
+
where(condition: SQLCondition): this;
|
|
40
|
+
orderBy(column: AnySQLiteColumn | {
|
|
41
|
+
sql: string;
|
|
42
|
+
params: any[];
|
|
43
|
+
}, direction?: "ASC" | "DESC"): this;
|
|
44
|
+
limit(count: number): this;
|
|
45
|
+
offset(count: number): this;
|
|
46
|
+
build(): {
|
|
47
|
+
sql: string;
|
|
48
|
+
params: any[];
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare class SelectQueryBuilder<TTable extends AnyTable, TSelectedColumns extends (keyof TTable["_"]["columns"])[] | undefined = undefined> extends BaseQueryBuilder {
|
|
53
|
+
private table;
|
|
54
|
+
private columns?;
|
|
55
|
+
private isDistinct;
|
|
56
|
+
private groupByColumns;
|
|
57
|
+
private havingCondition;
|
|
58
|
+
private joins;
|
|
59
|
+
private includeRelations;
|
|
60
|
+
constructor(db: Database, table: TTable, columns?: TSelectedColumns | undefined);
|
|
61
|
+
distinct(): this;
|
|
62
|
+
groupBy(...columns: AnySQLiteColumn[]): this;
|
|
63
|
+
having(condition: SQLCondition): this;
|
|
64
|
+
leftJoin<T extends AnyTable>(table: T, condition: SQLCondition, alias?: string): this;
|
|
65
|
+
innerJoin<T extends AnyTable>(table: T, condition: SQLCondition, alias?: string): this;
|
|
66
|
+
include(relations: Record<string, boolean>): this;
|
|
67
|
+
private buildJoins;
|
|
68
|
+
execute(): Promise<any[]>;
|
|
69
|
+
all(): Promise<any[]>;
|
|
70
|
+
get(): Promise<any | undefined>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
declare class UpdateQueryBuilder<T extends AnyTable> extends BaseQueryBuilder {
|
|
74
|
+
private table;
|
|
75
|
+
private updateData;
|
|
76
|
+
private returningColumns;
|
|
77
|
+
constructor(db: Database, table: T);
|
|
78
|
+
set(data: Partial<InferInsertModel<T>>): this;
|
|
79
|
+
returning(...columns: (keyof T["_"]["columns"])[]): this;
|
|
80
|
+
private buildUpdateClause;
|
|
81
|
+
execute(): Promise<T extends AnyTable ? (InferSelectModel<T> & Record<string, any>)[] : never>;
|
|
82
|
+
returningAll(): Promise<InferSelectModel<T>[]>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
declare class InsertQueryBuilder<T extends AnyTable> extends BaseQueryBuilder {
|
|
86
|
+
private table;
|
|
87
|
+
private dataSets;
|
|
88
|
+
private returningColumns;
|
|
89
|
+
private onConflictAction;
|
|
90
|
+
private conflictTarget;
|
|
91
|
+
private updateSet;
|
|
92
|
+
constructor(db: Database, table: T);
|
|
93
|
+
values(data: InferInsertModel<T> | InferInsertModel<T>[]): this;
|
|
94
|
+
returning(...columns: (keyof T["_"]["columns"])[]): this;
|
|
95
|
+
onConflictDoNothing(target?: AnySQLiteColumn | AnySQLiteColumn[]): this;
|
|
96
|
+
onConflictDoUpdate(config: {
|
|
97
|
+
target: AnySQLiteColumn | AnySQLiteColumn[];
|
|
98
|
+
set: Partial<InferInsertModel<T>>;
|
|
99
|
+
}): this;
|
|
100
|
+
private processDefaultValues;
|
|
101
|
+
private buildConflictClause;
|
|
102
|
+
execute(): Promise<T extends AnyTable ? (InferSelectModel<T> & Record<string, any>)[] : never>;
|
|
103
|
+
returningAll(): Promise<InferSelectModel<T>[]>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
declare class DeleteQueryBuilder<T extends AnyTable> extends BaseQueryBuilder {
|
|
107
|
+
private table;
|
|
108
|
+
private returningColumns;
|
|
109
|
+
constructor(db: Database, table: T);
|
|
110
|
+
returning(...columns: (keyof T["_"]["columns"])[]): this;
|
|
111
|
+
execute(): Promise<T extends AnyTable ? (InferSelectModel<T> & Record<string, any>)[] : never>;
|
|
112
|
+
returningAll(): Promise<InferSelectModel<T>[]>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare class WithQueryBuilder {
|
|
116
|
+
private db;
|
|
117
|
+
private ctes;
|
|
118
|
+
constructor(db: Database);
|
|
119
|
+
with(alias: string, query: {
|
|
120
|
+
sql: string;
|
|
121
|
+
params: any[];
|
|
122
|
+
}): this;
|
|
123
|
+
select<T extends AnyTable, C extends (keyof T["_"]["columns"])[] | undefined = undefined>(table: T, columns?: C): SelectQueryBuilder<T, C>;
|
|
124
|
+
insert<T extends AnyTable>(table: T): InsertQueryBuilder<T>;
|
|
125
|
+
update<T extends AnyTable>(table: T): UpdateQueryBuilder<T>;
|
|
126
|
+
delete<T extends AnyTable>(table: T): DeleteQueryBuilder<T>;
|
|
127
|
+
private applyWithClause;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
type RelationsBuilder = {
|
|
131
|
+
one: <U extends AnyTable>(table: U, config?: {
|
|
132
|
+
fields: AnySQLiteColumn[];
|
|
133
|
+
references: AnySQLiteColumn[];
|
|
134
|
+
}) => OneRelation<U>;
|
|
135
|
+
many: <U extends AnyTable>(table: U) => ManyRelation<U>;
|
|
136
|
+
};
|
|
137
|
+
|
|
21
138
|
declare class SQLiteColumn<TName extends string = string, TType extends ColumnDataType = ColumnDataType, TMode extends Mode = "default", TNotNull extends boolean = false, THasDefault extends boolean = false, TAutoincrement extends boolean = false> {
|
|
22
139
|
type: TType;
|
|
23
140
|
options: ColumnOptions<ColumnValueTypes<TType, TMode>>;
|
|
@@ -33,29 +150,19 @@ declare class SQLiteColumn<TName extends string = string, TType extends ColumnDa
|
|
|
33
150
|
notNull(): SQLiteColumn<TName, TType, TMode, true, THasDefault, TAutoincrement>;
|
|
34
151
|
default(value: ColumnValueTypes<TType, TMode>): SQLiteColumn<TName, TType, TMode, TNotNull, true, TAutoincrement>;
|
|
35
152
|
$defaultFn(fn: () => ColumnValueTypes<TType, TMode>): SQLiteColumn<TName, TType, TMode, TNotNull, true, TAutoincrement>;
|
|
36
|
-
primaryKey(): SQLiteColumn<TName, TType, TMode,
|
|
153
|
+
primaryKey(): SQLiteColumn<TName, TType, TMode, true, THasDefault, TAutoincrement>;
|
|
37
154
|
autoincrement(): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, true>;
|
|
38
155
|
unique(): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
|
|
39
156
|
references<T extends AnyTable, K extends keyof T["_"]["columns"] & string>(ref: T, column: K): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
|
|
40
157
|
$onUpdateFn(fn: () => ColumnValueTypes<TType, TMode>): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
|
|
158
|
+
as(alias: string): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
|
|
41
159
|
}
|
|
42
|
-
|
|
43
|
-
declare const integer: <TName extends string, TMode extends Mode = "default">(name: TName, config?: {
|
|
44
|
-
mode?: TMode;
|
|
45
|
-
}) => SQLiteColumn<TName, "INTEGER", "default" | TMode, false, false, false>;
|
|
46
|
-
declare const real: <TName extends string>(name: TName) => SQLiteColumn<TName, "REAL", "default", false, false, false>;
|
|
47
|
-
declare const blob: <TName extends string>(name: TName) => SQLiteColumn<TName, "BLOB", "default", false, false, false>;
|
|
48
|
-
declare const boolean: <TName extends string>(name: TName) => SQLiteColumn<TName, "BOOLEAN", "default", false, false, false>;
|
|
49
|
-
type AnySQLiteColumn = SQLiteColumn<any, any, any, any, any, any>;
|
|
50
|
-
type AnyTable = Table<Record<string, AnySQLiteColumn>, string>;
|
|
51
|
-
type InferSelectModel<T extends AnyTable> = {
|
|
52
|
-
[K in keyof T["_"]["columns"]]: ExtractColumnType<T["_"]["columns"][K]>;
|
|
53
|
-
};
|
|
54
|
-
type RequiredColumns<TColumns extends Record<string, AnySQLiteColumn>> = {
|
|
55
|
-
[K in keyof TColumns]: TColumns[K]["_"]["notNull"] extends true ? TColumns[K]["_"]["hasDefault"] extends true ? never : K : never;
|
|
56
|
-
}[keyof TColumns];
|
|
160
|
+
type IsOptionalOnInsert<C extends AnySQLiteColumn> = C["_"]["notNull"] extends false ? true : C["_"]["hasDefault"] extends true ? true : C["_"]["autoincrement"] extends true ? true : false;
|
|
57
161
|
type OptionalColumns<TColumns extends Record<string, AnySQLiteColumn>> = {
|
|
58
|
-
[K in keyof TColumns]: TColumns[K]
|
|
162
|
+
[K in keyof TColumns]: IsOptionalOnInsert<TColumns[K]> extends true ? K : never;
|
|
163
|
+
}[keyof TColumns];
|
|
164
|
+
type RequiredColumns<TColumns extends Record<string, AnySQLiteColumn>> = {
|
|
165
|
+
[K in keyof TColumns]: IsOptionalOnInsert<TColumns[K]> extends true ? never : K;
|
|
59
166
|
}[keyof TColumns];
|
|
60
167
|
type InferInsertModel<T extends AnyTable> = {
|
|
61
168
|
[K in RequiredColumns<T["_"]["columns"]>]: ExtractColumnType<T["_"]["columns"][K]>;
|
|
@@ -67,6 +174,7 @@ declare class Table<TColumns extends Record<string, AnySQLiteColumn>, TTableName
|
|
|
67
174
|
name: TTableName;
|
|
68
175
|
columns: TColumns;
|
|
69
176
|
};
|
|
177
|
+
relations: Record<string, RelationConfig>;
|
|
70
178
|
constructor(name: TTableName, columns: TColumns);
|
|
71
179
|
}
|
|
72
180
|
declare const sqliteTable: <TTableName extends string, TColumns extends Record<string, AnySQLiteColumn>>(tableName: TTableName, columns: TColumns) => Table<TColumns, TTableName>;
|
|
@@ -74,66 +182,37 @@ type SQLCondition = {
|
|
|
74
182
|
sql: string;
|
|
75
183
|
params: any[];
|
|
76
184
|
};
|
|
77
|
-
declare const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
declare const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
declare const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
protected query: string;
|
|
91
|
-
protected params: any[];
|
|
92
|
-
constructor(db: Database);
|
|
93
|
-
where(condition: SQLCondition): this;
|
|
94
|
-
orderBy(column: AnySQLiteColumn, direction?: "ASC" | "DESC"): this;
|
|
95
|
-
limit(count: number): this;
|
|
96
|
-
offset(count: number): this;
|
|
97
|
-
build(): {
|
|
98
|
-
sql: string;
|
|
99
|
-
params: any[];
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
declare class SelectQueryBuilder<TTable extends AnyTable, TSelectedColumns extends (keyof TTable["_"]["columns"])[] | undefined = undefined> extends BaseQueryBuilder {
|
|
103
|
-
private table;
|
|
104
|
-
private columns?;
|
|
105
|
-
constructor(db: Database, table: TTable, columns?: TSelectedColumns | undefined);
|
|
106
|
-
execute(): Promise<TSelectedColumns extends (keyof TTable["_"]["columns"])[] ? Pick<InferSelectModel<TTable>, TSelectedColumns[number]>[] : InferSelectModel<TTable>[]>;
|
|
107
|
-
}
|
|
108
|
-
declare class InsertQueryBuilder<T extends AnyTable> extends BaseQueryBuilder {
|
|
109
|
-
private table;
|
|
110
|
-
private dataSets;
|
|
111
|
-
constructor(db: Database, table: T);
|
|
112
|
-
values(data: Partial<InferInsertModel<T>> | Partial<InferInsertModel<T>>[]): this;
|
|
113
|
-
execute(): Promise<number>;
|
|
114
|
-
}
|
|
115
|
-
declare class UpdateQueryBuilder<T extends AnyTable> extends BaseQueryBuilder {
|
|
116
|
-
private table;
|
|
117
|
-
private updateData;
|
|
118
|
-
constructor(db: Database, table: T);
|
|
119
|
-
set(data: Partial<InferInsertModel<T>>): this;
|
|
120
|
-
execute(): Promise<number>;
|
|
121
|
-
}
|
|
122
|
-
declare class DeleteQueryBuilder<T extends AnyTable> extends BaseQueryBuilder {
|
|
123
|
-
private table;
|
|
124
|
-
constructor(db: Database, table: T);
|
|
125
|
-
execute(): Promise<number>;
|
|
126
|
-
}
|
|
185
|
+
declare const asc: (column: AnySQLiteColumn) => {
|
|
186
|
+
sql: string;
|
|
187
|
+
params: never[];
|
|
188
|
+
};
|
|
189
|
+
declare const desc: (column: AnySQLiteColumn) => {
|
|
190
|
+
sql: string;
|
|
191
|
+
params: never[];
|
|
192
|
+
};
|
|
193
|
+
declare const sql: <T = unknown>(strings: TemplateStringsArray, ...values: any[]) => {
|
|
194
|
+
sql: string;
|
|
195
|
+
params: any[];
|
|
196
|
+
mapWith?: (value: any) => T;
|
|
197
|
+
};
|
|
127
198
|
declare class TauriORM {
|
|
128
199
|
private db;
|
|
129
200
|
private tables;
|
|
130
|
-
constructor(db: Database, schema?: Record<string, AnyTable
|
|
201
|
+
constructor(db: Database, schema?: Record<string, AnyTable | Record<string, Relation>> | undefined);
|
|
202
|
+
private buildColumnDefinition;
|
|
131
203
|
migrate(): Promise<void>;
|
|
132
204
|
select<T extends AnyTable, C extends (keyof T["_"]["columns"])[] | undefined = undefined>(table: T, columns?: C): SelectQueryBuilder<T, C>;
|
|
133
205
|
insert<T extends AnyTable>(table: T): InsertQueryBuilder<T>;
|
|
134
206
|
update<T extends AnyTable>(table: T): UpdateQueryBuilder<T>;
|
|
135
207
|
delete<T extends AnyTable>(table: T): DeleteQueryBuilder<T>;
|
|
208
|
+
$with(alias: string): {
|
|
209
|
+
as: (query: {
|
|
210
|
+
sql: string;
|
|
211
|
+
params: any[];
|
|
212
|
+
}) => WithQueryBuilder;
|
|
213
|
+
};
|
|
136
214
|
transaction<T>(callback: (tx: TauriORM) => Promise<T>): Promise<T>;
|
|
215
|
+
rollback(): never;
|
|
137
216
|
private ensureSchemaMeta;
|
|
138
217
|
private getSchemaMeta;
|
|
139
218
|
private setSchemaMeta;
|
|
@@ -147,9 +226,52 @@ declare class TauriORM {
|
|
|
147
226
|
}>;
|
|
148
227
|
migrateIfDirty(): Promise<boolean>;
|
|
149
228
|
}
|
|
150
|
-
declare
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
229
|
+
declare class Relation<T extends AnyTable = AnyTable> {
|
|
230
|
+
foreignTable: T;
|
|
231
|
+
constructor(foreignTable: T);
|
|
232
|
+
}
|
|
233
|
+
declare class OneRelation<T extends AnyTable = AnyTable> extends Relation<T> {
|
|
234
|
+
config?: {
|
|
235
|
+
fields: AnySQLiteColumn[];
|
|
236
|
+
references: AnySQLiteColumn[];
|
|
237
|
+
} | undefined;
|
|
238
|
+
constructor(foreignTable: T, config?: {
|
|
239
|
+
fields: AnySQLiteColumn[];
|
|
240
|
+
references: AnySQLiteColumn[];
|
|
241
|
+
} | undefined);
|
|
242
|
+
}
|
|
243
|
+
declare class ManyRelation<T extends AnyTable = AnyTable> extends Relation<T> {
|
|
244
|
+
constructor(foreignTable: T);
|
|
245
|
+
}
|
|
246
|
+
declare const relations: <T extends AnyTable, R extends Record<string, Relation>>(_table: T, relationsCallback: (helpers: RelationsBuilder) => R) => R;
|
|
247
|
+
declare const getTableColumns: <T extends AnyTable>(table: T) => Record<string, AnySQLiteColumn>;
|
|
248
|
+
declare const alias: <T extends AnyTable>(table: T, alias: string) => Table<T["_"]["columns"], T["_"]["name"]>;
|
|
249
|
+
|
|
250
|
+
declare const eq: <T>(column: AnySQLiteColumn, value: T) => SQLCondition;
|
|
251
|
+
declare const and: (...conditions: SQLCondition[]) => SQLCondition;
|
|
252
|
+
declare const or: (...conditions: SQLCondition[]) => SQLCondition;
|
|
253
|
+
declare const not: (condition: SQLCondition) => SQLCondition;
|
|
254
|
+
declare const gt: <T>(column: AnySQLiteColumn, value: T) => SQLCondition;
|
|
255
|
+
declare const gte: <T>(column: AnySQLiteColumn, value: T) => SQLCondition;
|
|
256
|
+
declare const lt: <T>(column: AnySQLiteColumn, value: T) => SQLCondition;
|
|
257
|
+
declare const lte: <T>(column: AnySQLiteColumn, value: T) => SQLCondition;
|
|
258
|
+
declare const like: (column: AnySQLiteColumn, pattern: string) => SQLCondition;
|
|
259
|
+
declare const isNull: (column: AnySQLiteColumn) => SQLCondition;
|
|
260
|
+
declare const isNotNull: (column: AnySQLiteColumn) => SQLCondition;
|
|
261
|
+
declare const inArray: <T>(column: AnySQLiteColumn, values: T[]) => SQLCondition;
|
|
262
|
+
declare const count: (column?: AnySQLiteColumn) => SQLCondition;
|
|
263
|
+
declare const countDistinct: (column: AnySQLiteColumn) => SQLCondition;
|
|
264
|
+
declare const sum: (column: AnySQLiteColumn) => SQLCondition;
|
|
265
|
+
declare const avg: (column: AnySQLiteColumn) => SQLCondition;
|
|
266
|
+
declare const max: (column: AnySQLiteColumn) => SQLCondition;
|
|
267
|
+
declare const min: (column: AnySQLiteColumn) => SQLCondition;
|
|
268
|
+
|
|
269
|
+
declare const text: <TName extends string>(name: TName) => SQLiteColumn<TName, "TEXT", "default", false, false, false>;
|
|
270
|
+
declare const integer: <TName extends string, TMode extends Mode = "default">(name: TName, config?: {
|
|
271
|
+
mode?: TMode;
|
|
272
|
+
}) => SQLiteColumn<TName, "INTEGER", "default" | TMode, false, false, false>;
|
|
273
|
+
declare const real: <TName extends string>(name: TName) => SQLiteColumn<TName, "REAL", "default", false, false, false>;
|
|
274
|
+
declare const blob: <TName extends string>(name: TName) => SQLiteColumn<TName, "BLOB", "default", false, false, false>;
|
|
275
|
+
declare const boolean: <TName extends string>(name: TName) => SQLiteColumn<TName, "BOOLEAN", "default", false, false, false>;
|
|
154
276
|
|
|
155
|
-
export { type AnySQLiteColumn, type AnyTable, type ColumnDataType, type ColumnOptions, DeleteQueryBuilder, type InferInsertModel, type InferSelectModel, InsertQueryBuilder, type Mode, type SQLCondition, SQLiteColumn, SelectQueryBuilder, Table, TauriORM, UpdateQueryBuilder, and, blob, boolean, eq, gt, gte, inArray, integer, isNotNull, isNull, like, lt, lte, or, real, relations, sqliteTable, text };
|
|
277
|
+
export { type AnySQLiteColumn, type AnyTable, BaseQueryBuilder, type ColumnDataType, type ColumnOptions, type ColumnValueTypes, DeleteQueryBuilder, type ExtractColumnType, type InferInsertModel, type InferSelectModel, InsertQueryBuilder, ManyRelation, type Mode, OneRelation, Relation, type RelationConfig, type RelationType, type RelationsBuilder, type SQLCondition, SQLiteColumn, SelectQueryBuilder, Table, TauriORM, UpdateQueryBuilder, WithQueryBuilder, alias, and, asc, avg, blob, boolean, count, countDistinct, desc, eq, getTableColumns, gt, gte, inArray, integer, isNotNull, isNull, like, lt, lte, max, min, not, or, real, relations, sql, sqliteTable, sum, text };
|