drizzle-orm 0.29.3 → 0.29.4-0a94f2e
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 +29 -141
- package/alias.cjs.map +1 -1
- package/alias.js.map +1 -1
- package/aws-data-api/pg/session.cjs +2 -2
- package/aws-data-api/pg/session.cjs.map +1 -1
- package/aws-data-api/pg/session.d.cts +3 -3
- package/aws-data-api/pg/session.d.ts +3 -3
- package/aws-data-api/pg/session.js +4 -4
- package/aws-data-api/pg/session.js.map +1 -1
- package/d1/session.cjs +3 -3
- package/d1/session.cjs.map +1 -1
- package/d1/session.d.cts +1 -1
- package/d1/session.d.ts +1 -1
- package/d1/session.js +4 -4
- package/d1/session.js.map +1 -1
- package/libsql/session.cjs +1 -1
- package/libsql/session.cjs.map +1 -1
- package/libsql/session.js +1 -1
- package/libsql/session.js.map +1 -1
- package/neon-http/driver.cjs +13 -1
- package/neon-http/driver.cjs.map +1 -1
- package/neon-http/driver.d.cts +8 -3
- package/neon-http/driver.d.ts +8 -3
- package/neon-http/driver.js +13 -5
- package/neon-http/driver.js.map +1 -1
- package/neon-http/session.cjs +46 -28
- package/neon-http/session.cjs.map +1 -1
- package/neon-http/session.d.cts +16 -12
- package/neon-http/session.d.ts +16 -12
- package/neon-http/session.js +47 -29
- package/neon-http/session.js.map +1 -1
- package/neon-serverless/session.cjs +12 -12
- package/neon-serverless/session.cjs.map +1 -1
- package/neon-serverless/session.d.cts +5 -5
- package/neon-serverless/session.d.ts +5 -5
- package/neon-serverless/session.js +13 -13
- package/neon-serverless/session.js.map +1 -1
- package/node-postgres/session.cjs +12 -12
- package/node-postgres/session.cjs.map +1 -1
- package/node-postgres/session.d.cts +5 -5
- package/node-postgres/session.d.ts +5 -5
- package/node-postgres/session.js +13 -13
- package/node-postgres/session.js.map +1 -1
- package/package.json +15 -3
- package/pg-core/db.cjs +14 -1
- package/pg-core/db.cjs.map +1 -1
- package/pg-core/db.js +14 -1
- package/pg-core/db.js.map +1 -1
- package/pg-core/query-builders/delete.cjs +11 -10
- package/pg-core/query-builders/delete.cjs.map +1 -1
- package/pg-core/query-builders/delete.d.cts +8 -6
- package/pg-core/query-builders/delete.d.ts +8 -6
- package/pg-core/query-builders/delete.js +11 -10
- package/pg-core/query-builders/delete.js.map +1 -1
- package/pg-core/query-builders/insert.cjs +15 -14
- package/pg-core/query-builders/insert.cjs.map +1 -1
- package/pg-core/query-builders/insert.d.cts +8 -6
- package/pg-core/query-builders/insert.d.ts +8 -6
- package/pg-core/query-builders/insert.js +15 -14
- package/pg-core/query-builders/insert.js.map +1 -1
- package/pg-core/query-builders/query.cjs +1 -0
- package/pg-core/query-builders/query.cjs.map +1 -1
- package/pg-core/query-builders/query.d.cts +9 -6
- package/pg-core/query-builders/query.d.ts +9 -6
- package/pg-core/query-builders/query.js +1 -0
- package/pg-core/query-builders/query.js.map +1 -1
- package/pg-core/query-builders/raw.cjs +53 -0
- package/pg-core/query-builders/raw.cjs.map +1 -0
- package/pg-core/query-builders/raw.d.cts +22 -0
- package/pg-core/query-builders/raw.d.ts +22 -0
- package/pg-core/query-builders/raw.js +29 -0
- package/pg-core/query-builders/raw.js.map +1 -0
- package/pg-core/query-builders/refresh-materialized-view.cjs +1 -0
- package/pg-core/query-builders/refresh-materialized-view.cjs.map +1 -1
- package/pg-core/query-builders/refresh-materialized-view.d.cts +10 -6
- package/pg-core/query-builders/refresh-materialized-view.d.ts +10 -6
- package/pg-core/query-builders/refresh-materialized-view.js +1 -0
- package/pg-core/query-builders/refresh-materialized-view.js.map +1 -1
- package/pg-core/query-builders/select.cjs +86 -85
- package/pg-core/query-builders/select.cjs.map +1 -1
- package/pg-core/query-builders/select.d.cts +5 -4
- package/pg-core/query-builders/select.d.ts +5 -4
- package/pg-core/query-builders/select.js +86 -85
- package/pg-core/query-builders/select.js.map +1 -1
- package/pg-core/query-builders/select.types.cjs.map +1 -1
- package/pg-core/query-builders/select.types.d.cts +2 -2
- package/pg-core/query-builders/select.types.d.ts +2 -2
- package/pg-core/query-builders/update.cjs +9 -8
- package/pg-core/query-builders/update.cjs.map +1 -1
- package/pg-core/query-builders/update.d.cts +7 -5
- package/pg-core/query-builders/update.d.ts +7 -5
- package/pg-core/query-builders/update.js +9 -8
- package/pg-core/query-builders/update.js.map +1 -1
- package/pg-core/session.cjs +14 -5
- package/pg-core/session.cjs.map +1 -1
- package/pg-core/session.d.cts +7 -2
- package/pg-core/session.d.ts +7 -2
- package/pg-core/session.js +12 -3
- package/pg-core/session.js.map +1 -1
- package/pg-proxy/session.cjs +2 -2
- package/pg-proxy/session.cjs.map +1 -1
- package/pg-proxy/session.d.cts +1 -1
- package/pg-proxy/session.d.ts +1 -1
- package/pg-proxy/session.js +2 -2
- package/pg-proxy/session.js.map +1 -1
- package/planetscale-serverless/driver.cjs +18 -0
- package/planetscale-serverless/driver.cjs.map +1 -1
- package/planetscale-serverless/driver.d.cts +2 -1
- package/planetscale-serverless/driver.d.ts +2 -1
- package/planetscale-serverless/driver.js +18 -0
- package/planetscale-serverless/driver.js.map +1 -1
- package/planetscale-serverless/session.cjs.map +1 -1
- package/planetscale-serverless/session.d.cts +3 -4
- package/planetscale-serverless/session.d.ts +3 -4
- package/planetscale-serverless/session.js.map +1 -1
- package/postgres-js/session.cjs +11 -11
- package/postgres-js/session.cjs.map +1 -1
- package/postgres-js/session.d.cts +5 -5
- package/postgres-js/session.d.ts +5 -5
- package/postgres-js/session.js +12 -12
- package/postgres-js/session.js.map +1 -1
- package/runnable-query.cjs.map +1 -1
- package/runnable-query.d.cts +0 -2
- package/runnable-query.d.ts +0 -2
- package/sql/sql.cjs +0 -8
- package/sql/sql.cjs.map +1 -1
- package/sql/sql.d.cts +1 -1
- package/sql/sql.d.ts +1 -1
- package/sql/sql.js +0 -8
- package/sql/sql.js.map +1 -1
- package/sqlite-core/db.cjs +53 -43
- package/sqlite-core/db.cjs.map +1 -1
- package/sqlite-core/db.d.cts +3 -0
- package/sqlite-core/db.d.ts +3 -0
- package/sqlite-core/db.js +53 -43
- package/sqlite-core/db.js.map +1 -1
- package/sqlite-core/query-builders/delete.cjs +20 -16
- package/sqlite-core/query-builders/delete.cjs.map +1 -1
- package/sqlite-core/query-builders/delete.d.cts +3 -3
- package/sqlite-core/query-builders/delete.d.ts +3 -3
- package/sqlite-core/query-builders/delete.js +20 -16
- package/sqlite-core/query-builders/delete.js.map +1 -1
- package/sqlite-core/query-builders/insert.cjs +23 -19
- package/sqlite-core/query-builders/insert.cjs.map +1 -1
- package/sqlite-core/query-builders/insert.d.cts +1 -1
- package/sqlite-core/query-builders/insert.d.ts +1 -1
- package/sqlite-core/query-builders/insert.js +23 -19
- package/sqlite-core/query-builders/insert.js.map +1 -1
- package/sqlite-core/query-builders/query.cjs +8 -4
- package/sqlite-core/query-builders/query.cjs.map +1 -1
- package/sqlite-core/query-builders/query.js +8 -4
- package/sqlite-core/query-builders/query.js.map +1 -1
- package/sqlite-core/query-builders/raw.cjs +9 -17
- package/sqlite-core/query-builders/raw.cjs.map +1 -1
- package/sqlite-core/query-builders/raw.d.cts +10 -6
- package/sqlite-core/query-builders/raw.d.ts +10 -6
- package/sqlite-core/query-builders/raw.js +9 -17
- package/sqlite-core/query-builders/raw.js.map +1 -1
- package/sqlite-core/query-builders/select.cjs +78 -74
- package/sqlite-core/query-builders/select.cjs.map +1 -1
- package/sqlite-core/query-builders/select.d.cts +7 -7
- package/sqlite-core/query-builders/select.d.ts +7 -7
- package/sqlite-core/query-builders/select.js +78 -74
- package/sqlite-core/query-builders/select.js.map +1 -1
- package/sqlite-core/query-builders/update.cjs +17 -13
- package/sqlite-core/query-builders/update.cjs.map +1 -1
- package/sqlite-core/query-builders/update.d.cts +1 -1
- package/sqlite-core/query-builders/update.d.ts +1 -1
- package/sqlite-core/query-builders/update.js +17 -13
- package/sqlite-core/query-builders/update.js.map +1 -1
- package/vercel-postgres/session.cjs +6 -6
- package/vercel-postgres/session.cjs.map +1 -1
- package/vercel-postgres/session.d.cts +4 -4
- package/vercel-postgres/session.d.ts +4 -4
- package/vercel-postgres/session.js +7 -7
- package/vercel-postgres/session.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
package/sqlite-core/db.js
CHANGED
|
@@ -17,9 +17,10 @@ class BaseSQLiteDatabase {
|
|
|
17
17
|
this.session = session;
|
|
18
18
|
this._ = schema ? { schema: schema.schema, tableNamesMap: schema.tableNamesMap } : { schema: void 0, tableNamesMap: {} };
|
|
19
19
|
this.query = {};
|
|
20
|
+
const query = this.query;
|
|
20
21
|
if (this._.schema) {
|
|
21
22
|
for (const [tableName, columns] of Object.entries(this._.schema)) {
|
|
22
|
-
|
|
23
|
+
query[tableName] = new RelationalQueryBuilder(
|
|
23
24
|
resultKind,
|
|
24
25
|
schema.fullSchema,
|
|
25
26
|
this._.schema,
|
|
@@ -36,33 +37,33 @@ class BaseSQLiteDatabase {
|
|
|
36
37
|
query;
|
|
37
38
|
/**
|
|
38
39
|
* Creates a subquery that defines a temporary named result set as a CTE.
|
|
39
|
-
*
|
|
40
|
+
*
|
|
40
41
|
* It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
|
|
41
|
-
*
|
|
42
|
+
*
|
|
42
43
|
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
|
|
43
|
-
*
|
|
44
|
+
*
|
|
44
45
|
* @param alias The alias for the subquery.
|
|
45
|
-
*
|
|
46
|
+
*
|
|
46
47
|
* Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
|
|
47
|
-
*
|
|
48
|
+
*
|
|
48
49
|
* @example
|
|
49
|
-
*
|
|
50
|
+
*
|
|
50
51
|
* ```ts
|
|
51
52
|
* // Create a subquery with alias 'sq' and use it in the select query
|
|
52
53
|
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
|
|
53
|
-
*
|
|
54
|
+
*
|
|
54
55
|
* const result = await db.with(sq).select().from(sq);
|
|
55
56
|
* ```
|
|
56
|
-
*
|
|
57
|
+
*
|
|
57
58
|
* To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
|
|
58
|
-
*
|
|
59
|
+
*
|
|
59
60
|
* ```ts
|
|
60
61
|
* // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
|
|
61
62
|
* const sq = db.$with('sq').as(db.select({
|
|
62
63
|
* name: sql<string>`upper(${users.name})`.as('name'),
|
|
63
64
|
* })
|
|
64
65
|
* .from(users));
|
|
65
|
-
*
|
|
66
|
+
*
|
|
66
67
|
* const result = await db.with(sq).select({ name: sq.name }).from(sq);
|
|
67
68
|
* ```
|
|
68
69
|
*/
|
|
@@ -81,19 +82,19 @@ class BaseSQLiteDatabase {
|
|
|
81
82
|
}
|
|
82
83
|
/**
|
|
83
84
|
* Incorporates a previously defined CTE (using `$with`) into the main query.
|
|
84
|
-
*
|
|
85
|
+
*
|
|
85
86
|
* This method allows the main query to reference a temporary named result set.
|
|
86
|
-
*
|
|
87
|
+
*
|
|
87
88
|
* See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
|
|
88
|
-
*
|
|
89
|
+
*
|
|
89
90
|
* @param queries The CTEs to incorporate into the main query.
|
|
90
|
-
*
|
|
91
|
+
*
|
|
91
92
|
* @example
|
|
92
|
-
*
|
|
93
|
+
*
|
|
93
94
|
* ```ts
|
|
94
95
|
* // Define a subquery 'sq' as a CTE using $with
|
|
95
96
|
* const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
|
|
96
|
-
*
|
|
97
|
+
*
|
|
97
98
|
* // Incorporate the CTE 'sq' into the main query and select from it
|
|
98
99
|
* const result = await db.with(sq).select().from(sq);
|
|
99
100
|
* ```
|
|
@@ -117,7 +118,16 @@ class BaseSQLiteDatabase {
|
|
|
117
118
|
distinct: true
|
|
118
119
|
});
|
|
119
120
|
}
|
|
120
|
-
|
|
121
|
+
function update(table) {
|
|
122
|
+
return new SQLiteUpdateBuilder(table, self.session, self.dialect);
|
|
123
|
+
}
|
|
124
|
+
function insert(into) {
|
|
125
|
+
return new SQLiteInsertBuilder(into, self.session, self.dialect);
|
|
126
|
+
}
|
|
127
|
+
function delete_(from) {
|
|
128
|
+
return new SQLiteDeleteBase(from, self.session, self.dialect);
|
|
129
|
+
}
|
|
130
|
+
return { select, selectDistinct, update, insert, delete: delete_ };
|
|
121
131
|
}
|
|
122
132
|
select(fields) {
|
|
123
133
|
return new SQLiteSelectBuilder({ fields: fields ?? void 0, session: this.session, dialect: this.dialect });
|
|
@@ -132,24 +142,24 @@ class BaseSQLiteDatabase {
|
|
|
132
142
|
}
|
|
133
143
|
/**
|
|
134
144
|
* Creates an update query.
|
|
135
|
-
*
|
|
145
|
+
*
|
|
136
146
|
* Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
|
|
137
|
-
*
|
|
147
|
+
*
|
|
138
148
|
* Use `.set()` method to specify which values to update.
|
|
139
|
-
*
|
|
140
|
-
* See docs: {@link https://orm.drizzle.team/docs/update}
|
|
141
|
-
*
|
|
149
|
+
*
|
|
150
|
+
* See docs: {@link https://orm.drizzle.team/docs/update}
|
|
151
|
+
*
|
|
142
152
|
* @param table The table to update.
|
|
143
|
-
*
|
|
153
|
+
*
|
|
144
154
|
* @example
|
|
145
|
-
*
|
|
155
|
+
*
|
|
146
156
|
* ```ts
|
|
147
157
|
* // Update all rows in the 'cars' table
|
|
148
158
|
* await db.update(cars).set({ color: 'red' });
|
|
149
|
-
*
|
|
159
|
+
*
|
|
150
160
|
* // Update rows with filters and conditions
|
|
151
161
|
* await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
|
|
152
|
-
*
|
|
162
|
+
*
|
|
153
163
|
* // Update with returning clause
|
|
154
164
|
* const updatedCar: Car[] = await db.update(cars)
|
|
155
165
|
* .set({ color: 'red' })
|
|
@@ -162,22 +172,22 @@ class BaseSQLiteDatabase {
|
|
|
162
172
|
}
|
|
163
173
|
/**
|
|
164
174
|
* Creates an insert query.
|
|
165
|
-
*
|
|
175
|
+
*
|
|
166
176
|
* Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
|
|
167
|
-
*
|
|
168
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert}
|
|
169
|
-
*
|
|
177
|
+
*
|
|
178
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert}
|
|
179
|
+
*
|
|
170
180
|
* @param table The table to insert into.
|
|
171
|
-
*
|
|
181
|
+
*
|
|
172
182
|
* @example
|
|
173
|
-
*
|
|
183
|
+
*
|
|
174
184
|
* ```ts
|
|
175
185
|
* // Insert one row
|
|
176
186
|
* await db.insert(cars).values({ brand: 'BMW' });
|
|
177
|
-
*
|
|
187
|
+
*
|
|
178
188
|
* // Insert multiple rows
|
|
179
189
|
* await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
|
|
180
|
-
*
|
|
190
|
+
*
|
|
181
191
|
* // Insert with returning clause
|
|
182
192
|
* const insertedCar: Car[] = await db.insert(cars)
|
|
183
193
|
* .values({ brand: 'BMW' })
|
|
@@ -189,22 +199,22 @@ class BaseSQLiteDatabase {
|
|
|
189
199
|
}
|
|
190
200
|
/**
|
|
191
201
|
* Creates a delete query.
|
|
192
|
-
*
|
|
193
|
-
* Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
|
|
194
|
-
*
|
|
202
|
+
*
|
|
203
|
+
* Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
|
|
204
|
+
*
|
|
195
205
|
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
196
|
-
*
|
|
206
|
+
*
|
|
197
207
|
* @param table The table to delete from.
|
|
198
|
-
*
|
|
208
|
+
*
|
|
199
209
|
* @example
|
|
200
|
-
*
|
|
210
|
+
*
|
|
201
211
|
* ```ts
|
|
202
212
|
* // Delete all rows in the 'cars' table
|
|
203
213
|
* await db.delete(cars);
|
|
204
|
-
*
|
|
214
|
+
*
|
|
205
215
|
* // Delete rows with filters and conditions
|
|
206
216
|
* await db.delete(cars).where(eq(cars.color, 'green'));
|
|
207
|
-
*
|
|
217
|
+
*
|
|
208
218
|
* // Delete with returning clause
|
|
209
219
|
* const deletedCar: Car[] = await db.delete(cars)
|
|
210
220
|
* .where(eq(cars.id, 1))
|
package/sqlite-core/db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/sqlite-core/db.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { ColumnsSelection, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteAsyncDialect, SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';\nimport {\n\tQueryBuilder,\n\tSQLiteDeleteBase,\n\tSQLiteInsertBuilder,\n\tSQLiteSelectBuilder,\n\tSQLiteUpdateBuilder,\n} from '~/sqlite-core/query-builders/index.ts';\nimport type {\n\tDBResult,\n\tResult,\n\tSQLiteSession,\n\tSQLiteTransaction,\n\tSQLiteTransactionConfig,\n} from '~/sqlite-core/session.ts';\nimport type { SQLiteTable } from '~/sqlite-core/table.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport { SQLiteRaw } from './query-builders/raw.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\n\nexport class BaseSQLiteDatabase<\n\tTResultKind extends 'sync' | 'async',\n\tTRunResult,\n\tTFullSchema extends Record<string, unknown> = Record<string, never>,\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'BaseSQLiteDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\tprivate resultKind: TResultKind,\n\t\t/** @internal */\n\t\treadonly dialect: { sync: SQLiteSyncDialect; async: SQLiteAsyncDialect }[TResultKind],\n\t\t/** @internal */\n\t\treadonly session: SQLiteSession<TResultKind, TRunResult, TFullSchema, TSchema>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t) {\n\t\tthis._ = schema\n\t\t\t? { schema: schema.schema, tableNamesMap: schema.tableNamesMap }\n\t\t\t: { schema: undefined, tableNamesMap: {} };\n\t\tthis.query = {} as typeof this['query'];\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\tthis.query[tableName as keyof TSchema] = new RelationalQueryBuilder(\n\t\t\t\t\tresultKind,\n\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\tthis._.schema,\n\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\tschema!.fullSchema[tableName] as SQLiteTable,\n\t\t\t\t\tcolumns,\n\t\t\t\t\tdialect,\n\t\t\t\t\tsession as SQLiteSession<any, any, any, any> as any,\n\t\t\t\t) as this['query'][keyof TSchema];\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t * \n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t * \n\t * @param alias The alias for the subquery.\n\t * \n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t * \n\t * @example\n\t * \n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t * \n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t * \n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t * \n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t * \n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder());\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t * \n\t * This method allows the main query to reference a temporary named result set.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t * \n\t * @param queries The CTEs to incorporate into the main query.\n\t * \n\t * @example\n\t * \n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t * \n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\tfunction select(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;\n\t\tfunction select(\n\t\t\tfields?: SelectedFields,\n\t\t): SQLiteSelectBuilder<SelectedFields | undefined, TResultKind, TRunResult> {\n\t\t\treturn new SQLiteSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\tfunction selectDistinct(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): SQLiteSelectBuilder<SelectedFields | undefined, TResultKind, TRunResult> {\n\t\t\treturn new SQLiteSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\treturn { select, selectDistinct };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t * \n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t * \n\t * Use `.from()` method to specify which table to select from.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t * \n\t * @param fields The selection object.\n\t * \n\t * @example\n\t * \n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t * \n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({ \n\t * id: cars.id, \n\t * brand: cars.brand \n\t * })\n\t * .from(cars);\n\t * ```\n\t * \n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t * \n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;\n\tselect<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;\n\tselect(fields?: SelectedFields): SQLiteSelectBuilder<SelectedFields | undefined, TResultKind, TRunResult> {\n\t\treturn new SQLiteSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t * \n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t * \n\t * Use `.from()` method to specify which table to select from.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t * \n\t * @param fields The selection object.\n\t * \n\t * @example\n\t * \n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t * \n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;\n\tselectDistinct(\n\t\tfields?: SelectedFields,\n\t): SQLiteSelectBuilder<SelectedFields | undefined, TResultKind, TRunResult> {\n\t\treturn new SQLiteSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t * \n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t * \n\t * Use `.set()` method to specify which values to update.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/update} \n\t * \n\t * @param table The table to update.\n\t * \n\t * @example\n\t * \n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t * \n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t * \n\t * // Update with returning clause\n\t * const updatedCar: Car[] = await db.update(cars)\n\t * .set({ color: 'red' })\n\t * .where(eq(cars.id, 1))\n\t * .returning();\n\t * ```\n\t */\n\tupdate<TTable extends SQLiteTable>(table: TTable): SQLiteUpdateBuilder<TTable, TResultKind, TRunResult> {\n\t\treturn new SQLiteUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t * \n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/insert} \n\t * \n\t * @param table The table to insert into.\n\t * \n\t * @example\n\t * \n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t * \n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t * \n\t * // Insert with returning clause\n\t * const insertedCar: Car[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning();\n\t * ```\n\t */\n\tinsert<TTable extends SQLiteTable>(into: TTable): SQLiteInsertBuilder<TTable, TResultKind, TRunResult> {\n\t\treturn new SQLiteInsertBuilder(into, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t * \n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted. \n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t * \n\t * @param table The table to delete from.\n\t * \n\t * @example\n\t * \n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t * \n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t * \n\t * // Delete with returning clause\n\t * const deletedCar: Car[] = await db.delete(cars)\n\t * .where(eq(cars.id, 1))\n\t * .returning();\n\t * ```\n\t */\n\tdelete<TTable extends SQLiteTable>(from: TTable): SQLiteDeleteBase<TTable, TResultKind, TRunResult> {\n\t\treturn new SQLiteDeleteBase(from, this.session, this.dialect);\n\t}\n\n\trun(query: SQLWrapper): DBResult<TResultKind, TRunResult> {\n\t\tconst sql = query.getSQL();\n\t\tif (this.resultKind === 'async') {\n\t\t\treturn new SQLiteRaw(\n\t\t\t\tasync () => this.session.run(sql),\n\t\t\t\t() => sql,\n\t\t\t\t'run',\n\t\t\t\tthis.dialect as SQLiteAsyncDialect,\n\t\t\t\tthis.session.extractRawRunValueFromBatchResult.bind(this.session),\n\t\t\t) as DBResult<TResultKind, TRunResult>;\n\t\t}\n\t\treturn this.session.run(sql) as DBResult<TResultKind, TRunResult>;\n\t}\n\n\tall<T = unknown>(query: SQLWrapper): DBResult<TResultKind, T[]> {\n\t\tconst sql = query.getSQL();\n\t\tif (this.resultKind === 'async') {\n\t\t\treturn new SQLiteRaw(\n\t\t\t\tasync () => this.session.all(sql),\n\t\t\t\t() => sql,\n\t\t\t\t'all',\n\t\t\t\tthis.dialect as SQLiteAsyncDialect,\n\t\t\t\tthis.session.extractRawAllValueFromBatchResult.bind(this.session),\n\t\t\t) as any;\n\t\t}\n\t\treturn this.session.all(sql) as DBResult<TResultKind, T[]>;\n\t}\n\n\tget<T = unknown>(query: SQLWrapper): DBResult<TResultKind, T> {\n\t\tconst sql = query.getSQL();\n\t\tif (this.resultKind === 'async') {\n\t\t\treturn new SQLiteRaw(\n\t\t\t\tasync () => this.session.get(sql),\n\t\t\t\t() => sql,\n\t\t\t\t'get',\n\t\t\t\tthis.dialect as SQLiteAsyncDialect,\n\t\t\t\tthis.session.extractRawGetValueFromBatchResult.bind(this.session),\n\t\t\t) as DBResult<TResultKind, T>;\n\t\t}\n\t\treturn this.session.get(sql) as DBResult<TResultKind, T>;\n\t}\n\n\tvalues<T extends unknown[] = unknown[]>(query: SQLWrapper): DBResult<TResultKind, T[]> {\n\t\tconst sql = query.getSQL();\n\t\tif (this.resultKind === 'async') {\n\t\t\treturn new SQLiteRaw(\n\t\t\t\tasync () => this.session.values(sql),\n\t\t\t\t() => sql,\n\t\t\t\t'values',\n\t\t\t\tthis.dialect as SQLiteAsyncDialect,\n\t\t\t\tthis.session.extractRawValuesValueFromBatchResult.bind(this.session),\n\t\t\t) as any;\n\t\t}\n\t\treturn this.session.values(sql) as DBResult<TResultKind, T[]>;\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (tx: SQLiteTransaction<TResultKind, TRunResult, TFullSchema, TSchema>) => Result<TResultKind, T>,\n\t\tconfig?: SQLiteTransactionConfig,\n\t): Result<TResultKind, T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type SQLiteWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tTResultKind extends 'sync' | 'async',\n\tTRunResult,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends BaseSQLiteDatabase<\n\t\tTResultKind,\n\t\tTRunResult,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): SQLiteWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst run: Q['run'] = (...args: [any]) => primary.run(...args);\n\tconst all: Q['all'] = (...args: [any]) => primary.all(...args);\n\tconst get: Q['get'] = (...args: [any]) => primary.get(...args);\n\tconst values: Q['values'] = (...args: [any]) => primary.values(...args);\n\tconst transaction: Q['transaction'] = (...args: [any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\trun,\n\t\tall,\n\t\tget,\n\t\tvalues,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAG3B,SAAS,6BAA6B;AAGtC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AASP,SAAS,oBAAoB;AAE7B,SAAS,8BAA8B;AACvC,SAAS,iBAAiB;AAInB,MAAM,mBAKX;AAAA,EAcD,YACS,YAEC,SAEA,SACT,QACC;AANO;AAEC;AAEA;AAGT,SAAK,IAAI,SACN,EAAE,QAAQ,OAAO,QAAQ,eAAe,OAAO,cAAc,IAC7D,EAAE,QAAQ,QAAW,eAAe,CAAC,EAAE;AAC1C,SAAK,QAAQ,CAAC;AACd,QAAI,KAAK,EAAE,QAAQ;AAClB,iBAAW,CAAC,WAAW,OAAO,KAAK,OAAO,QAAQ,KAAK,EAAE,MAAM,GAAG;AACjE,aAAK,MAAM,SAA0B,IAAI,IAAI;AAAA,UAC5C;AAAA,UACA,OAAQ;AAAA,UACR,KAAK,EAAE;AAAA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,SACA,UACA,aAAmC,MAAM,SAAS,KAAK,MAAM,KAAK,OAAO,IAAI,SAAS,MAAM,CAAC,MAClE;AAC3B,QAAM,SAAsB,IAAI,SAAa,WAAW,QAAQ,EAAE,OAAO,GAAG,IAAI;AAChF,QAAM,iBAAsC,IAAI,SAAa,WAAW,QAAQ,EAAE,eAAe,GAAG,IAAI;AACxG,QAAM,QAAmB,IAAI,SAAa,WAAW,QAAQ,EAAE,KAAK,GAAG,IAAI;AAE3E,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,UAAuB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACvE,QAAM,MAAgB,IAAI,SAAgB,QAAQ,IAAI,GAAG,IAAI;AAC7D,QAAM,MAAgB,IAAI,SAAgB,QAAQ,IAAI,GAAG,IAAI;AAC7D,QAAM,MAAgB,IAAI,SAAgB,QAAQ,IAAI,GAAG,IAAI;AAC7D,QAAM,SAAsB,IAAI,SAAgB,QAAQ,OAAO,GAAG,IAAI;AACtE,QAAM,cAAgC,IAAI,SAAgB,QAAQ,YAAY,GAAG,IAAI;AAErF,SAAO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/sqlite-core/db.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type { ExtractTablesWithRelations, RelationalSchemaConfig, TablesRelationalConfig } from '~/relations.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { ColumnsSelection, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteAsyncDialect, SQLiteSyncDialect } from '~/sqlite-core/dialect.ts';\nimport {\n\tQueryBuilder,\n\tSQLiteDeleteBase,\n\tSQLiteInsertBuilder,\n\tSQLiteSelectBuilder,\n\tSQLiteUpdateBuilder,\n} from '~/sqlite-core/query-builders/index.ts';\nimport type {\n\tDBResult,\n\tResult,\n\tSQLiteSession,\n\tSQLiteTransaction,\n\tSQLiteTransactionConfig,\n} from '~/sqlite-core/session.ts';\nimport type { SQLiteTable } from '~/sqlite-core/table.ts';\nimport { WithSubquery } from '~/subquery.ts';\nimport type { DrizzleTypeError } from '~/utils.ts';\nimport { RelationalQueryBuilder } from './query-builders/query.ts';\nimport { SQLiteRaw } from './query-builders/raw.ts';\nimport type { SelectedFields } from './query-builders/select.types.ts';\nimport type { WithSubqueryWithSelection } from './subquery.ts';\n\nexport class BaseSQLiteDatabase<\n\tTResultKind extends 'sync' | 'async',\n\tTRunResult,\n\tTFullSchema extends Record<string, unknown> = Record<string, never>,\n\tTSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,\n> {\n\tstatic readonly [entityKind]: string = 'BaseSQLiteDatabase';\n\n\tdeclare readonly _: {\n\t\treadonly schema: TSchema | undefined;\n\t\treadonly tableNamesMap: Record<string, string>;\n\t};\n\n\tquery: TFullSchema extends Record<string, never>\n\t\t? DrizzleTypeError<'Seems like the schema generic is missing - did you forget to add it to your DB type?'>\n\t\t: {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>;\n\t\t};\n\n\tconstructor(\n\t\tprivate resultKind: TResultKind,\n\t\t/** @internal */\n\t\treadonly dialect: { sync: SQLiteSyncDialect; async: SQLiteAsyncDialect }[TResultKind],\n\t\t/** @internal */\n\t\treadonly session: SQLiteSession<TResultKind, TRunResult, TFullSchema, TSchema>,\n\t\tschema: RelationalSchemaConfig<TSchema> | undefined,\n\t) {\n\t\tthis._ = schema\n\t\t\t? { schema: schema.schema, tableNamesMap: schema.tableNamesMap }\n\t\t\t: { schema: undefined, tableNamesMap: {} };\n\t\tthis.query = {} as typeof this['query'];\n\t\tconst query = this.query as {\n\t\t\t[K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>;\n\t\t};\n\t\tif (this._.schema) {\n\t\t\tfor (const [tableName, columns] of Object.entries(this._.schema)) {\n\t\t\t\tquery[tableName as keyof TSchema] = new RelationalQueryBuilder(\n\t\t\t\t\tresultKind,\n\t\t\t\t\tschema!.fullSchema,\n\t\t\t\t\tthis._.schema,\n\t\t\t\t\tthis._.tableNamesMap,\n\t\t\t\t\tschema!.fullSchema[tableName] as SQLiteTable,\n\t\t\t\t\tcolumns,\n\t\t\t\t\tdialect,\n\t\t\t\t\tsession as SQLiteSession<any, any, any, any> as any,\n\t\t\t\t) as typeof query[keyof TSchema];\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Creates a subquery that defines a temporary named result set as a CTE.\n\t *\n\t * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param alias The alias for the subquery.\n\t *\n\t * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Create a subquery with alias 'sq' and use it in the select query\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t *\n\t * To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:\n\t *\n\t * ```ts\n\t * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query\n\t * const sq = db.$with('sq').as(db.select({\n\t * name: sql<string>`upper(${users.name})`.as('name'),\n\t * })\n\t * .from(users));\n\t *\n\t * const result = await db.with(sq).select({ name: sq.name }).from(sq);\n\t * ```\n\t */\n\t$with<TAlias extends string>(alias: TAlias) {\n\t\treturn {\n\t\t\tas<TSelection extends ColumnsSelection>(\n\t\t\t\tqb: TypedQueryBuilder<TSelection> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection>),\n\t\t\t): WithSubqueryWithSelection<TSelection, TAlias> {\n\t\t\t\tif (typeof qb === 'function') {\n\t\t\t\t\tqb = qb(new QueryBuilder());\n\t\t\t\t}\n\n\t\t\t\treturn new Proxy(\n\t\t\t\t\tnew WithSubquery(qb.getSQL(), qb.getSelectedFields() as SelectedFields, alias, true),\n\t\t\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t\t\t) as WithSubqueryWithSelection<TSelection, TAlias>;\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Incorporates a previously defined CTE (using `$with`) into the main query.\n\t *\n\t * This method allows the main query to reference a temporary named result set.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}\n\t *\n\t * @param queries The CTEs to incorporate into the main query.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Define a subquery 'sq' as a CTE using $with\n\t * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));\n\t *\n\t * // Incorporate the CTE 'sq' into the main query and select from it\n\t * const result = await db.with(sq).select().from(sq);\n\t * ```\n\t */\n\twith(...queries: WithSubquery[]) {\n\t\tconst self = this;\n\n\t\t/**\n\t\t * Creates a select query.\n\t\t *\n\t\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all columns and all rows from the 'cars' table\n\t\t * const allCars: Car[] = await db.select().from(cars);\n\t\t *\n\t\t * // Select specific columns and all rows from the 'cars' table\n\t\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * brand: cars.brand\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t *\n\t\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t\t *\n\t\t * ```ts\n\t\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t\t * id: cars.id,\n\t\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t\t * })\n\t\t * .from(cars);\n\t\t * ```\n\t\t */\n\t\tfunction select(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;\n\t\tfunction select<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;\n\t\tfunction select(\n\t\t\tfields?: SelectedFields,\n\t\t): SQLiteSelectBuilder<SelectedFields | undefined, TResultKind, TRunResult> {\n\t\t\treturn new SQLiteSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Adds `distinct` expression to the select query.\n\t\t *\n\t\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t\t *\n\t\t * Use `.from()` method to specify which table to select from.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t\t *\n\t\t * @param fields The selection object.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Select all unique rows from the 'cars' table\n\t\t * await db.selectDistinct()\n\t\t * .from(cars)\n\t\t * .orderBy(cars.id, cars.brand, cars.color);\n\t\t *\n\t\t * // Select all unique brands from the 'cars' table\n\t\t * await db.selectDistinct({ brand: cars.brand })\n\t\t * .from(cars)\n\t\t * .orderBy(cars.brand);\n\t\t * ```\n\t\t */\n\t\tfunction selectDistinct(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;\n\t\tfunction selectDistinct<TSelection extends SelectedFields>(\n\t\t\tfields: TSelection,\n\t\t): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;\n\t\tfunction selectDistinct(\n\t\t\tfields?: SelectedFields,\n\t\t): SQLiteSelectBuilder<SelectedFields | undefined, TResultKind, TRunResult> {\n\t\t\treturn new SQLiteSelectBuilder({\n\t\t\t\tfields: fields ?? undefined,\n\t\t\t\tsession: self.session,\n\t\t\t\tdialect: self.dialect,\n\t\t\t\twithList: queries,\n\t\t\t\tdistinct: true,\n\t\t\t});\n\t\t}\n\n\t\t/**\n\t\t * Creates an update query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t\t *\n\t\t * Use `.set()` method to specify which values to update.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t\t *\n\t\t * @param table The table to update.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Update all rows in the 'cars' table\n\t\t * await db.update(cars).set({ color: 'red' });\n\t\t *\n\t\t * // Update rows with filters and conditions\n\t\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t\t *\n\t\t * // Update with returning clause\n\t\t * const updatedCar: Car[] = await db.update(cars)\n\t\t * .set({ color: 'red' })\n\t\t * .where(eq(cars.id, 1))\n\t\t * .returning();\n\t\t * ```\n\t\t */\n\t\tfunction update<TTable extends SQLiteTable>(table: TTable): SQLiteUpdateBuilder<TTable, TResultKind, TRunResult> {\n\t\t\treturn new SQLiteUpdateBuilder(table, self.session, self.dialect);\n\t\t}\n\n\t\t/**\n\t\t * Creates an insert query.\n\t\t *\n\t\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t\t *\n\t\t * @param table The table to insert into.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Insert one row\n\t\t * await db.insert(cars).values({ brand: 'BMW' });\n\t\t *\n\t\t * // Insert multiple rows\n\t\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t\t *\n\t\t * // Insert with returning clause\n\t\t * const insertedCar: Car[] = await db.insert(cars)\n\t\t * .values({ brand: 'BMW' })\n\t\t * .returning();\n\t\t * ```\n\t\t */\n\t\tfunction insert<TTable extends SQLiteTable>(into: TTable): SQLiteInsertBuilder<TTable, TResultKind, TRunResult> {\n\t\t\treturn new SQLiteInsertBuilder(into, self.session, self.dialect);\n\t\t}\n\n\t\t/**\n\t\t * Creates a delete query.\n\t\t *\n\t\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t\t *\n\t\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t\t *\n\t\t * @param table The table to delete from.\n\t\t *\n\t\t * @example\n\t\t *\n\t\t * ```ts\n\t\t * // Delete all rows in the 'cars' table\n\t\t * await db.delete(cars);\n\t\t *\n\t\t * // Delete rows with filters and conditions\n\t\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t\t *\n\t\t * // Delete with returning clause\n\t\t * const deletedCar: Car[] = await db.delete(cars)\n\t\t * .where(eq(cars.id, 1))\n\t\t * .returning();\n\t\t * ```\n\t\t */\n\t\tfunction delete_<TTable extends SQLiteTable>(from: TTable): SQLiteDeleteBase<TTable, TResultKind, TRunResult> {\n\t\t\treturn new SQLiteDeleteBase(from, self.session, self.dialect);\n\t\t}\n\n\t\treturn { select, selectDistinct, update, insert, delete: delete_ };\n\t}\n\n\t/**\n\t * Creates a select query.\n\t *\n\t * Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all columns and all rows from the 'cars' table\n\t * const allCars: Car[] = await db.select().from(cars);\n\t *\n\t * // Select specific columns and all rows from the 'cars' table\n\t * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({\n\t * id: cars.id,\n\t * brand: cars.brand\n\t * })\n\t * .from(cars);\n\t * ```\n\t *\n\t * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:\n\t *\n\t * ```ts\n\t * // Select specific columns along with expression and all rows from the 'cars' table\n\t * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({\n\t * id: cars.id,\n\t * lowerBrand: sql<string>`lower(${cars.brand})`,\n\t * })\n\t * .from(cars);\n\t * ```\n\t */\n\tselect(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;\n\tselect<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;\n\tselect(fields?: SelectedFields): SQLiteSelectBuilder<SelectedFields | undefined, TResultKind, TRunResult> {\n\t\treturn new SQLiteSelectBuilder({ fields: fields ?? undefined, session: this.session, dialect: this.dialect });\n\t}\n\n\t/**\n\t * Adds `distinct` expression to the select query.\n\t *\n\t * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.\n\t *\n\t * Use `.from()` method to specify which table to select from.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#distinct}\n\t *\n\t * @param fields The selection object.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all unique rows from the 'cars' table\n\t * await db.selectDistinct()\n\t * .from(cars)\n\t * .orderBy(cars.id, cars.brand, cars.color);\n\t *\n\t * // Select all unique brands from the 'cars' table\n\t * await db.selectDistinct({ brand: cars.brand })\n\t * .from(cars)\n\t * .orderBy(cars.brand);\n\t * ```\n\t */\n\tselectDistinct(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;\n\tselectDistinct<TSelection extends SelectedFields>(\n\t\tfields: TSelection,\n\t): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;\n\tselectDistinct(\n\t\tfields?: SelectedFields,\n\t): SQLiteSelectBuilder<SelectedFields | undefined, TResultKind, TRunResult> {\n\t\treturn new SQLiteSelectBuilder({\n\t\t\tfields: fields ?? undefined,\n\t\t\tsession: this.session,\n\t\t\tdialect: this.dialect,\n\t\t\tdistinct: true,\n\t\t});\n\t}\n\n\t/**\n\t * Creates an update query.\n\t *\n\t * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.\n\t *\n\t * Use `.set()` method to specify which values to update.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/update}\n\t *\n\t * @param table The table to update.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Update all rows in the 'cars' table\n\t * await db.update(cars).set({ color: 'red' });\n\t *\n\t * // Update rows with filters and conditions\n\t * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));\n\t *\n\t * // Update with returning clause\n\t * const updatedCar: Car[] = await db.update(cars)\n\t * .set({ color: 'red' })\n\t * .where(eq(cars.id, 1))\n\t * .returning();\n\t * ```\n\t */\n\tupdate<TTable extends SQLiteTable>(table: TTable): SQLiteUpdateBuilder<TTable, TResultKind, TRunResult> {\n\t\treturn new SQLiteUpdateBuilder(table, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates an insert query.\n\t *\n\t * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/insert}\n\t *\n\t * @param table The table to insert into.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Insert one row\n\t * await db.insert(cars).values({ brand: 'BMW' });\n\t *\n\t * // Insert multiple rows\n\t * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);\n\t *\n\t * // Insert with returning clause\n\t * const insertedCar: Car[] = await db.insert(cars)\n\t * .values({ brand: 'BMW' })\n\t * .returning();\n\t * ```\n\t */\n\tinsert<TTable extends SQLiteTable>(into: TTable): SQLiteInsertBuilder<TTable, TResultKind, TRunResult> {\n\t\treturn new SQLiteInsertBuilder(into, this.session, this.dialect);\n\t}\n\n\t/**\n\t * Creates a delete query.\n\t *\n\t * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param table The table to delete from.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Delete all rows in the 'cars' table\n\t * await db.delete(cars);\n\t *\n\t * // Delete rows with filters and conditions\n\t * await db.delete(cars).where(eq(cars.color, 'green'));\n\t *\n\t * // Delete with returning clause\n\t * const deletedCar: Car[] = await db.delete(cars)\n\t * .where(eq(cars.id, 1))\n\t * .returning();\n\t * ```\n\t */\n\tdelete<TTable extends SQLiteTable>(from: TTable): SQLiteDeleteBase<TTable, TResultKind, TRunResult> {\n\t\treturn new SQLiteDeleteBase(from, this.session, this.dialect);\n\t}\n\n\trun(query: SQLWrapper): DBResult<TResultKind, TRunResult> {\n\t\tconst sql = query.getSQL();\n\t\tif (this.resultKind === 'async') {\n\t\t\treturn new SQLiteRaw(\n\t\t\t\tasync () => this.session.run(sql),\n\t\t\t\t() => sql,\n\t\t\t\t'run',\n\t\t\t\tthis.dialect as SQLiteAsyncDialect,\n\t\t\t\tthis.session.extractRawRunValueFromBatchResult.bind(this.session),\n\t\t\t) as DBResult<TResultKind, TRunResult>;\n\t\t}\n\t\treturn this.session.run(sql) as DBResult<TResultKind, TRunResult>;\n\t}\n\n\tall<T = unknown>(query: SQLWrapper): DBResult<TResultKind, T[]> {\n\t\tconst sql = query.getSQL();\n\t\tif (this.resultKind === 'async') {\n\t\t\treturn new SQLiteRaw(\n\t\t\t\tasync () => this.session.all(sql),\n\t\t\t\t() => sql,\n\t\t\t\t'all',\n\t\t\t\tthis.dialect as SQLiteAsyncDialect,\n\t\t\t\tthis.session.extractRawAllValueFromBatchResult.bind(this.session),\n\t\t\t) as any;\n\t\t}\n\t\treturn this.session.all(sql) as DBResult<TResultKind, T[]>;\n\t}\n\n\tget<T = unknown>(query: SQLWrapper): DBResult<TResultKind, T> {\n\t\tconst sql = query.getSQL();\n\t\tif (this.resultKind === 'async') {\n\t\t\treturn new SQLiteRaw(\n\t\t\t\tasync () => this.session.get(sql),\n\t\t\t\t() => sql,\n\t\t\t\t'get',\n\t\t\t\tthis.dialect as SQLiteAsyncDialect,\n\t\t\t\tthis.session.extractRawGetValueFromBatchResult.bind(this.session),\n\t\t\t) as DBResult<TResultKind, T>;\n\t\t}\n\t\treturn this.session.get(sql) as DBResult<TResultKind, T>;\n\t}\n\n\tvalues<T extends unknown[] = unknown[]>(query: SQLWrapper): DBResult<TResultKind, T[]> {\n\t\tconst sql = query.getSQL();\n\t\tif (this.resultKind === 'async') {\n\t\t\treturn new SQLiteRaw(\n\t\t\t\tasync () => this.session.values(sql),\n\t\t\t\t() => sql,\n\t\t\t\t'values',\n\t\t\t\tthis.dialect as SQLiteAsyncDialect,\n\t\t\t\tthis.session.extractRawValuesValueFromBatchResult.bind(this.session),\n\t\t\t) as any;\n\t\t}\n\t\treturn this.session.values(sql) as DBResult<TResultKind, T[]>;\n\t}\n\n\ttransaction<T>(\n\t\ttransaction: (tx: SQLiteTransaction<TResultKind, TRunResult, TFullSchema, TSchema>) => Result<TResultKind, T>,\n\t\tconfig?: SQLiteTransactionConfig,\n\t): Result<TResultKind, T> {\n\t\treturn this.session.transaction(transaction, config);\n\t}\n}\n\nexport type SQLiteWithReplicas<Q> = Q & { $primary: Q };\n\nexport const withReplicas = <\n\tTResultKind extends 'sync' | 'async',\n\tTRunResult,\n\tTFullSchema extends Record<string, unknown>,\n\tTSchema extends TablesRelationalConfig,\n\tQ extends BaseSQLiteDatabase<\n\t\tTResultKind,\n\t\tTRunResult,\n\t\tTFullSchema,\n\t\tTSchema extends Record<string, unknown> ? ExtractTablesWithRelations<TFullSchema> : TSchema\n\t>,\n>(\n\tprimary: Q,\n\treplicas: [Q, ...Q[]],\n\tgetReplica: (replicas: Q[]) => Q = () => replicas[Math.floor(Math.random() * replicas.length)]!,\n): SQLiteWithReplicas<Q> => {\n\tconst select: Q['select'] = (...args: []) => getReplica(replicas).select(...args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: []) => getReplica(replicas).selectDistinct(...args);\n\tconst $with: Q['with'] = (...args: []) => getReplica(replicas).with(...args);\n\n\tconst update: Q['update'] = (...args: [any]) => primary.update(...args);\n\tconst insert: Q['insert'] = (...args: [any]) => primary.insert(...args);\n\tconst $delete: Q['delete'] = (...args: [any]) => primary.delete(...args);\n\tconst run: Q['run'] = (...args: [any]) => primary.run(...args);\n\tconst all: Q['all'] = (...args: [any]) => primary.all(...args);\n\tconst get: Q['get'] = (...args: [any]) => primary.get(...args);\n\tconst values: Q['values'] = (...args: [any]) => primary.values(...args);\n\tconst transaction: Q['transaction'] = (...args: [any]) => primary.transaction(...args);\n\n\treturn {\n\t\t...primary,\n\t\tupdate,\n\t\tinsert,\n\t\tdelete: $delete,\n\t\trun,\n\t\tall,\n\t\tget,\n\t\tvalues,\n\t\ttransaction,\n\t\t$primary: primary,\n\t\tselect,\n\t\tselectDistinct,\n\t\twith: $with,\n\t\tget query() {\n\t\t\treturn getReplica(replicas).query;\n\t\t},\n\t};\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAG3B,SAAS,6BAA6B;AAGtC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AASP,SAAS,oBAAoB;AAE7B,SAAS,8BAA8B;AACvC,SAAS,iBAAiB;AAInB,MAAM,mBAKX;AAAA,EAcD,YACS,YAEC,SAEA,SACT,QACC;AANO;AAEC;AAEA;AAGT,SAAK,IAAI,SACN,EAAE,QAAQ,OAAO,QAAQ,eAAe,OAAO,cAAc,IAC7D,EAAE,QAAQ,QAAW,eAAe,CAAC,EAAE;AAC1C,SAAK,QAAQ,CAAC;AAC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O,GAAG,IAAI;AACtE,QAAM,cAAgC,IAAI,SAAgB,QAAQ,YAAY,GAAG,IAAI;AAErF,SAAO;AAAA,IACN,GAAG;AAAA,IACH;AAAA,IACA;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN,IAAI,QAAQ;AACX,aAAO,WAAW,QAAQ,EAAE;AAAA,IAC7B;AAAA,EACD;AACD;","names":[]}
|
|
@@ -36,35 +36,35 @@ class SQLiteDeleteBase extends import_query_promise.QueryPromise {
|
|
|
36
36
|
static [import_entity.entityKind] = "SQLiteDelete";
|
|
37
37
|
/** @internal */
|
|
38
38
|
config;
|
|
39
|
-
/**
|
|
39
|
+
/**
|
|
40
40
|
* Adds a `where` clause to the query.
|
|
41
|
-
*
|
|
41
|
+
*
|
|
42
42
|
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
43
|
-
*
|
|
43
|
+
*
|
|
44
44
|
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
45
|
-
*
|
|
45
|
+
*
|
|
46
46
|
* @param where the `where` clause.
|
|
47
|
-
*
|
|
47
|
+
*
|
|
48
48
|
* @example
|
|
49
49
|
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
50
|
-
*
|
|
50
|
+
*
|
|
51
51
|
* ```ts
|
|
52
52
|
* // Delete all cars with green color
|
|
53
53
|
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
54
54
|
* // or
|
|
55
55
|
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
56
56
|
* ```
|
|
57
|
-
*
|
|
57
|
+
*
|
|
58
58
|
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
59
|
-
*
|
|
59
|
+
*
|
|
60
60
|
* ```ts
|
|
61
61
|
* // Delete all BMW cars with a green color
|
|
62
62
|
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
63
|
-
*
|
|
63
|
+
*
|
|
64
64
|
* // Delete all cars with the green or blue color
|
|
65
65
|
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
66
66
|
* ```
|
|
67
|
-
|
|
67
|
+
*/
|
|
68
68
|
where(where) {
|
|
69
69
|
this.config.where = where;
|
|
70
70
|
return this;
|
|
@@ -81,27 +81,31 @@ class SQLiteDeleteBase extends import_query_promise.QueryPromise {
|
|
|
81
81
|
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
82
82
|
return rest;
|
|
83
83
|
}
|
|
84
|
-
|
|
84
|
+
/** @internal */
|
|
85
|
+
_prepare(isOneTimeQuery = true) {
|
|
85
86
|
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
|
86
87
|
this.dialect.sqlToQuery(this.getSQL()),
|
|
87
88
|
this.config.returning,
|
|
88
89
|
this.config.returning ? "all" : "run"
|
|
89
90
|
);
|
|
90
91
|
}
|
|
92
|
+
prepare() {
|
|
93
|
+
return this._prepare(false);
|
|
94
|
+
}
|
|
91
95
|
run = (placeholderValues) => {
|
|
92
|
-
return this.
|
|
96
|
+
return this._prepare().run(placeholderValues);
|
|
93
97
|
};
|
|
94
98
|
all = (placeholderValues) => {
|
|
95
|
-
return this.
|
|
99
|
+
return this._prepare().all(placeholderValues);
|
|
96
100
|
};
|
|
97
101
|
get = (placeholderValues) => {
|
|
98
|
-
return this.
|
|
102
|
+
return this._prepare().get(placeholderValues);
|
|
99
103
|
};
|
|
100
104
|
values = (placeholderValues) => {
|
|
101
|
-
return this.
|
|
105
|
+
return this._prepare().values(placeholderValues);
|
|
102
106
|
};
|
|
103
107
|
async execute(placeholderValues) {
|
|
104
|
-
return this.
|
|
108
|
+
return this._prepare().execute(placeholderValues);
|
|
105
109
|
}
|
|
106
110
|
$dynamic() {
|
|
107
111
|
return this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/sqlite-core/query-builders/delete.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Query, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport { type DrizzleTypeError, orderSelectedFields } from '~/utils.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\nimport type { SQLiteColumn } from '../columns/common.ts';\n\nexport type SQLiteDeleteWithout<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n> = TDynamic extends true ? T\n\t: Omit<\n\t\tSQLiteDeleteBase<\n\t\t\tT['_']['table'],\n\t\t\tT['_']['resultType'],\n\t\t\tT['_']['runResult'],\n\t\t\tT['_']['returning'],\n\t\t\tTDynamic,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>,\n\t\tT['_']['excludedMethods'] | K\n\t>;\n\nexport type SQLiteDelete<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n> = SQLiteDeleteBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteDeleteConfig {\n\twhere?: SQL | undefined;\n\ttable: SQLiteTable;\n\treturning?: SelectedFieldsOrdered;\n}\n\nexport type SQLiteDeleteReturningAll<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteReturning<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteExecute<T extends AnySQLiteDeleteBase> = T['_']['returning'] extends undefined\n\t? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteDeletePrepare<T extends AnySQLiteDeleteBase> = SQLitePreparedQuery<{\n\ttype: T['_']['resultType'];\n\trun: T['_']['runResult'];\n\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t: T['_']['returning'][];\n\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t: T['_']['returning'] | undefined;\n\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t: any[][];\n\texecute: SQLiteDeleteExecute<T>;\n}>;\n\nexport type SQLiteDeleteDynamic<T extends AnySQLiteDeleteBase> = SQLiteDelete<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type AnySQLiteDeleteBase = SQLiteDeleteBase<any, any, any, any, any, any>;\n\nexport interface SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends SQLWrapper {\n\treadonly _: {\n\t\tdialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic readonly [entityKind]: string = 'SQLiteDelete';\n\n\t/** @internal */\n\tconfig: SQLiteDeleteConfig;\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table };\n\t}\n\n\t/** \n\t * Adds a `where` clause to the query.\n\t * \n\t * Calling this method will delete only those rows that fulfill a specified condition.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t * \n\t * @param where the `where` clause.\n\t * \n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be deleted.\n\t * \n\t * ```ts\n\t * // Delete all cars with green color\n\t * db.delete(cars).where(eq(cars.color, 'green'));\n\t * // or\n\t * db.delete(cars).where(sql`${cars.color} = 'green'`)\n\t * ```\n\t * \n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t * \n\t * ```ts\n\t * // Delete all BMW cars with a green color\n\t * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t * \n\t * // Delete all cars with the green or blue color\n\t * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t*/\n\twhere(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'> {\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t * \n\t * Calling this method will return the specified fields of the deleted rows. If no fields are specified, all fields will be returned.\n\t * \n\t * See docs: {@link https://orm.drizzle.team/docs/delete#delete-with-return} \n\t * \n\t * @example\n\t * ```ts\n\t * // Delete all cars with the green color and return all fields\n\t * const deletedCars: Car[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning();\n\t * \n\t * // Delete all cars with the green color and return only their id and brand fields\n\t * const deletedCarsIdsAndBrands: { id: number, brand: string }[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning({ id: cars.id, brand: cars.brand });\n\t * ```\n\t */\n\treturning(): SQLiteDeleteReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteDeleteReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteDeleteReturning<this, TDynamic, any> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildDeleteQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\tprepare(isOneTimeQuery?: boolean): SQLiteDeletePrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t) as SQLiteDeletePrepare<this>;\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this.prepare(true).run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this.prepare(true).all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this.prepare(true).get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this.prepare(true).values(placeholderValues);\n\t};\n\n\toverride async execute(placeholderValues?: Record<string, unknown>): Promise<SQLiteDeleteExecute<this>> {\n\t\treturn this.prepare(true).execute(placeholderValues) as SQLiteDeleteExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteDeleteDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAE3B,2BAA6B;AAK7B,mBAA4B;AAC5B,mBAA2D;AAgHpD,MAAM,yBASH,kCAEV;AAAA,EAMC,YACS,OACA,SACA,SACP;AACD,UAAM;AAJE;AACA;AACA;AAGR,SAAK,SAAS,EAAE,MAAM;AAAA,EACvB;AAAA,EAZA,QAAiB,wBAAU,IAAY;AAAA;AAAA,EAGvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwCA,MAAM,OAAsE;AAC3E,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EA0BA,UACC,SAA6B,KAAK,MAAM,yBAAY,OAAO,OAAO,GACrB;AAC7C,SAAK,OAAO,gBAAY,kCAAkC,MAAM;AAChE,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,SAAc;AACb,WAAO,KAAK,QAAQ,iBAAiB,KAAK,MAAM;AAAA,EACjD;AAAA,EAEA,QAAe;AACd,UAAM,EAAE,SAAS,UAAU,GAAG,KAAK,IAAI,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAC5E,WAAO;AAAA,EACR;AAAA,EAEA,QAAQ,gBAAqD;AAC5D,WAAO,KAAK,QAAQ,iBAAiB,wBAAwB,cAAc;AAAA,MAC1E,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAAA,MACrC,KAAK,OAAO;AAAA,MACZ,KAAK,OAAO,YAAY,QAAQ;AAAA,IACjC;AAAA,EACD;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,QAAQ,IAAI,EAAE,IAAI,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,QAAQ,IAAI,EAAE,IAAI,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,QAAQ,IAAI,EAAE,IAAI,iBAAiB;AAAA,EAChD;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,QAAQ,IAAI,EAAE,OAAO,iBAAiB;AAAA,EACnD;AAAA,EAEA,MAAe,QAAQ,mBAAiF;AACvG,WAAO,KAAK,QAAQ,IAAI,EAAE,QAAQ,iBAAiB;AAAA,EACpD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/sqlite-core/query-builders/delete.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SelectResultFields } from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport type { RunnableQuery } from '~/runnable-query.ts';\nimport type { Query, SQL, SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '~/sqlite-core/dialect.ts';\nimport type { SQLitePreparedQuery, SQLiteSession } from '~/sqlite-core/session.ts';\nimport { SQLiteTable } from '~/sqlite-core/table.ts';\nimport { type DrizzleTypeError, orderSelectedFields } from '~/utils.ts';\nimport type { SQLiteColumn } from '../columns/common.ts';\nimport type { SelectedFieldsFlat, SelectedFieldsOrdered } from './select.types.ts';\n\nexport type SQLiteDeleteWithout<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n> = TDynamic extends true ? T\n\t: Omit<\n\t\tSQLiteDeleteBase<\n\t\t\tT['_']['table'],\n\t\t\tT['_']['resultType'],\n\t\t\tT['_']['runResult'],\n\t\t\tT['_']['returning'],\n\t\t\tTDynamic,\n\t\t\tT['_']['excludedMethods'] | K\n\t\t>,\n\t\tT['_']['excludedMethods'] | K\n\t>;\n\nexport type SQLiteDelete<\n\tTTable extends SQLiteTable = SQLiteTable,\n\tTResultType extends 'sync' | 'async' = 'sync' | 'async',\n\tTRunResult = unknown,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n> = SQLiteDeleteBase<TTable, TResultType, TRunResult, TReturning, true, never>;\n\nexport interface SQLiteDeleteConfig {\n\twhere?: SQL | undefined;\n\ttable: SQLiteTable;\n\treturning?: SelectedFieldsOrdered;\n}\n\nexport type SQLiteDeleteReturningAll<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tT['_']['table']['$inferSelect'],\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteReturning<\n\tT extends AnySQLiteDeleteBase,\n\tTDynamic extends boolean,\n\tTSelectedFields extends SelectedFieldsFlat,\n> = SQLiteDeleteWithout<\n\tSQLiteDeleteBase<\n\t\tT['_']['table'],\n\t\tT['_']['resultType'],\n\t\tT['_']['runResult'],\n\t\tSelectResultFields<TSelectedFields>,\n\t\tT['_']['dynamic'],\n\t\tT['_']['excludedMethods']\n\t>,\n\tTDynamic,\n\t'returning'\n>;\n\nexport type SQLiteDeleteExecute<T extends AnySQLiteDeleteBase> = T['_']['returning'] extends undefined\n\t? T['_']['runResult']\n\t: T['_']['returning'][];\n\nexport type SQLiteDeletePrepare<T extends AnySQLiteDeleteBase> = SQLitePreparedQuery<{\n\ttype: T['_']['resultType'];\n\trun: T['_']['runResult'];\n\tall: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'>\n\t\t: T['_']['returning'][];\n\tget: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'>\n\t\t: T['_']['returning'] | undefined;\n\tvalues: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'>\n\t\t: any[][];\n\texecute: SQLiteDeleteExecute<T>;\n}>;\n\nexport type SQLiteDeleteDynamic<T extends AnySQLiteDeleteBase> = SQLiteDelete<\n\tT['_']['table'],\n\tT['_']['resultType'],\n\tT['_']['runResult'],\n\tT['_']['returning']\n>;\n\nexport type AnySQLiteDeleteBase = SQLiteDeleteBase<any, any, any, any, any, any>;\n\nexport interface SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n> extends\n\tQueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>,\n\tRunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>,\n\tSQLWrapper\n{\n\treadonly _: {\n\t\tdialect: 'sqlite';\n\t\treadonly table: TTable;\n\t\treadonly resultType: TResultType;\n\t\treadonly runResult: TRunResult;\n\t\treadonly returning: TReturning;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TReturning extends undefined ? TRunResult : TReturning[];\n\t};\n}\n\nexport class SQLiteDeleteBase<\n\tTTable extends SQLiteTable,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTResultType extends 'sync' | 'async',\n\tTRunResult,\n\tTReturning extends Record<string, unknown> | undefined = undefined,\n\tTDynamic extends boolean = false,\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars\n\tTExcludedMethods extends string = never,\n> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>\n\timplements RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper\n{\n\tstatic readonly [entityKind]: string = 'SQLiteDelete';\n\n\t/** @internal */\n\tconfig: SQLiteDeleteConfig;\n\n\tconstructor(\n\t\tprivate table: TTable,\n\t\tprivate session: SQLiteSession<any, any, any, any>,\n\t\tprivate dialect: SQLiteDialect,\n\t) {\n\t\tsuper();\n\t\tthis.config = { table };\n\t}\n\n\t/**\n\t * Adds a `where` clause to the query.\n\t *\n\t * Calling this method will delete only those rows that fulfill a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete}\n\t *\n\t * @param where the `where` clause.\n\t *\n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be deleted.\n\t *\n\t * ```ts\n\t * // Delete all cars with green color\n\t * db.delete(cars).where(eq(cars.color, 'green'));\n\t * // or\n\t * db.delete(cars).where(sql`${cars.color} = 'green'`)\n\t * ```\n\t *\n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t *\n\t * ```ts\n\t * // Delete all BMW cars with a green color\n\t * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t *\n\t * // Delete all cars with the green or blue color\n\t * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'> {\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `returning` clause to the query.\n\t *\n\t * Calling this method will return the specified fields of the deleted rows. If no fields are specified, all fields will be returned.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/delete#delete-with-return}\n\t *\n\t * @example\n\t * ```ts\n\t * // Delete all cars with the green color and return all fields\n\t * const deletedCars: Car[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning();\n\t *\n\t * // Delete all cars with the green color and return only their id and brand fields\n\t * const deletedCarsIdsAndBrands: { id: number, brand: string }[] = await db.delete(cars)\n\t * .where(eq(cars.color, 'green'))\n\t * .returning({ id: cars.id, brand: cars.brand });\n\t * ```\n\t */\n\treturning(): SQLiteDeleteReturningAll<this, TDynamic>;\n\treturning<TSelectedFields extends SelectedFieldsFlat>(\n\t\tfields: TSelectedFields,\n\t): SQLiteDeleteReturning<this, TDynamic, TSelectedFields>;\n\treturning(\n\t\tfields: SelectedFieldsFlat = this.table[SQLiteTable.Symbol.Columns],\n\t): SQLiteDeleteReturning<this, TDynamic, any> {\n\t\tthis.config.returning = orderSelectedFields<SQLiteColumn>(fields);\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildDeleteQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\t/** @internal */\n\t_prepare(isOneTimeQuery = true): SQLiteDeletePrepare<this> {\n\t\treturn this.session[isOneTimeQuery ? 'prepareOneTimeQuery' : 'prepareQuery'](\n\t\t\tthis.dialect.sqlToQuery(this.getSQL()),\n\t\t\tthis.config.returning,\n\t\t\tthis.config.returning ? 'all' : 'run',\n\t\t) as SQLiteDeletePrepare<this>;\n\t}\n\n\tprepare(): SQLiteDeletePrepare<this> {\n\t\treturn this._prepare(false);\n\t}\n\n\trun: ReturnType<this['prepare']>['run'] = (placeholderValues) => {\n\t\treturn this._prepare().run(placeholderValues);\n\t};\n\n\tall: ReturnType<this['prepare']>['all'] = (placeholderValues) => {\n\t\treturn this._prepare().all(placeholderValues);\n\t};\n\n\tget: ReturnType<this['prepare']>['get'] = (placeholderValues) => {\n\t\treturn this._prepare().get(placeholderValues);\n\t};\n\n\tvalues: ReturnType<this['prepare']>['values'] = (placeholderValues) => {\n\t\treturn this._prepare().values(placeholderValues);\n\t};\n\n\toverride async execute(placeholderValues?: Record<string, unknown>): Promise<SQLiteDeleteExecute<this>> {\n\t\treturn this._prepare().execute(placeholderValues) as SQLiteDeleteExecute<this>;\n\t}\n\n\t$dynamic(): SQLiteDeleteDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAE3B,2BAA6B;AAK7B,mBAA4B;AAC5B,mBAA2D;AAoHpD,MAAM,yBASH,kCAEV;AAAA,EAMC,YACS,OACA,SACA,SACP;AACD,UAAM;AAJE;AACA;AACA;AAGR,SAAK,SAAS,EAAE,MAAM;AAAA,EACvB;AAAA,EAZA,QAAiB,wBAAU,IAAY;AAAA;AAAA,EAGvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAwCA,MAAM,OAAsE;AAC3E,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EA0BA,UACC,SAA6B,KAAK,MAAM,yBAAY,OAAO,OAAO,GACrB;AAC7C,SAAK,OAAO,gBAAY,kCAAkC,MAAM;AAChE,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,SAAc;AACb,WAAO,KAAK,QAAQ,iBAAiB,KAAK,MAAM;AAAA,EACjD;AAAA,EAEA,QAAe;AACd,UAAM,EAAE,SAAS,UAAU,GAAG,KAAK,IAAI,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAC5E,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,SAAS,iBAAiB,MAAiC;AAC1D,WAAO,KAAK,QAAQ,iBAAiB,wBAAwB,cAAc;AAAA,MAC1E,KAAK,QAAQ,WAAW,KAAK,OAAO,CAAC;AAAA,MACrC,KAAK,OAAO;AAAA,MACZ,KAAK,OAAO,YAAY,QAAQ;AAAA,IACjC;AAAA,EACD;AAAA,EAEA,UAAqC;AACpC,WAAO,KAAK,SAAS,KAAK;AAAA,EAC3B;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,MAA0C,CAAC,sBAAsB;AAChE,WAAO,KAAK,SAAS,EAAE,IAAI,iBAAiB;AAAA,EAC7C;AAAA,EAEA,SAAgD,CAAC,sBAAsB;AACtE,WAAO,KAAK,SAAS,EAAE,OAAO,iBAAiB;AAAA,EAChD;AAAA,EAEA,MAAe,QAAQ,mBAAiF;AACvG,WAAO,KAAK,SAAS,EAAE,QAAQ,iBAAiB;AAAA,EACjD;AAAA,EAEA,WAAsC;AACrC,WAAO;AAAA,EACR;AACD;","names":[]}
|
|
@@ -28,7 +28,7 @@ export type SQLiteDeletePrepare<T extends AnySQLiteDeleteBase> = SQLitePreparedQ
|
|
|
28
28
|
}>;
|
|
29
29
|
export type SQLiteDeleteDynamic<T extends AnySQLiteDeleteBase> = SQLiteDelete<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning']>;
|
|
30
30
|
export type AnySQLiteDeleteBase = SQLiteDeleteBase<any, any, any, any, any, any>;
|
|
31
|
-
export interface SQLiteDeleteBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning extends Record<string, unknown> | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends SQLWrapper {
|
|
31
|
+
export interface SQLiteDeleteBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning extends Record<string, unknown> | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>, RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper {
|
|
32
32
|
readonly _: {
|
|
33
33
|
dialect: 'sqlite';
|
|
34
34
|
readonly table: TTable;
|
|
@@ -74,7 +74,7 @@ export declare class SQLiteDeleteBase<TTable extends SQLiteTable, TResultType ex
|
|
|
74
74
|
* // Delete all cars with the green or blue color
|
|
75
75
|
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
76
76
|
* ```
|
|
77
|
-
|
|
77
|
+
*/
|
|
78
78
|
where(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'>;
|
|
79
79
|
/**
|
|
80
80
|
* Adds a `returning` clause to the query.
|
|
@@ -99,7 +99,7 @@ export declare class SQLiteDeleteBase<TTable extends SQLiteTable, TResultType ex
|
|
|
99
99
|
returning(): SQLiteDeleteReturningAll<this, TDynamic>;
|
|
100
100
|
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): SQLiteDeleteReturning<this, TDynamic, TSelectedFields>;
|
|
101
101
|
toSQL(): Query;
|
|
102
|
-
prepare(
|
|
102
|
+
prepare(): SQLiteDeletePrepare<this>;
|
|
103
103
|
run: ReturnType<this['prepare']>['run'];
|
|
104
104
|
all: ReturnType<this['prepare']>['all'];
|
|
105
105
|
get: ReturnType<this['prepare']>['get'];
|
|
@@ -28,7 +28,7 @@ export type SQLiteDeletePrepare<T extends AnySQLiteDeleteBase> = SQLitePreparedQ
|
|
|
28
28
|
}>;
|
|
29
29
|
export type SQLiteDeleteDynamic<T extends AnySQLiteDeleteBase> = SQLiteDelete<T['_']['table'], T['_']['resultType'], T['_']['runResult'], T['_']['returning']>;
|
|
30
30
|
export type AnySQLiteDeleteBase = SQLiteDeleteBase<any, any, any, any, any, any>;
|
|
31
|
-
export interface SQLiteDeleteBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning extends Record<string, unknown> | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends SQLWrapper {
|
|
31
|
+
export interface SQLiteDeleteBase<TTable extends SQLiteTable, TResultType extends 'sync' | 'async', TRunResult, TReturning extends Record<string, unknown> | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise<TReturning extends undefined ? TRunResult : TReturning[]>, RunnableQuery<TReturning extends undefined ? TRunResult : TReturning[], 'sqlite'>, SQLWrapper {
|
|
32
32
|
readonly _: {
|
|
33
33
|
dialect: 'sqlite';
|
|
34
34
|
readonly table: TTable;
|
|
@@ -74,7 +74,7 @@ export declare class SQLiteDeleteBase<TTable extends SQLiteTable, TResultType ex
|
|
|
74
74
|
* // Delete all cars with the green or blue color
|
|
75
75
|
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
76
76
|
* ```
|
|
77
|
-
|
|
77
|
+
*/
|
|
78
78
|
where(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'>;
|
|
79
79
|
/**
|
|
80
80
|
* Adds a `returning` clause to the query.
|
|
@@ -99,7 +99,7 @@ export declare class SQLiteDeleteBase<TTable extends SQLiteTable, TResultType ex
|
|
|
99
99
|
returning(): SQLiteDeleteReturningAll<this, TDynamic>;
|
|
100
100
|
returning<TSelectedFields extends SelectedFieldsFlat>(fields: TSelectedFields): SQLiteDeleteReturning<this, TDynamic, TSelectedFields>;
|
|
101
101
|
toSQL(): Query;
|
|
102
|
-
prepare(
|
|
102
|
+
prepare(): SQLiteDeletePrepare<this>;
|
|
103
103
|
run: ReturnType<this['prepare']>['run'];
|
|
104
104
|
all: ReturnType<this['prepare']>['all'];
|
|
105
105
|
get: ReturnType<this['prepare']>['get'];
|
|
@@ -13,35 +13,35 @@ class SQLiteDeleteBase extends QueryPromise {
|
|
|
13
13
|
static [entityKind] = "SQLiteDelete";
|
|
14
14
|
/** @internal */
|
|
15
15
|
config;
|
|
16
|
-
/**
|
|
16
|
+
/**
|
|
17
17
|
* Adds a `where` clause to the query.
|
|
18
|
-
*
|
|
18
|
+
*
|
|
19
19
|
* Calling this method will delete only those rows that fulfill a specified condition.
|
|
20
|
-
*
|
|
20
|
+
*
|
|
21
21
|
* See docs: {@link https://orm.drizzle.team/docs/delete}
|
|
22
|
-
*
|
|
22
|
+
*
|
|
23
23
|
* @param where the `where` clause.
|
|
24
|
-
*
|
|
24
|
+
*
|
|
25
25
|
* @example
|
|
26
26
|
* You can use conditional operators and `sql function` to filter the rows to be deleted.
|
|
27
|
-
*
|
|
27
|
+
*
|
|
28
28
|
* ```ts
|
|
29
29
|
* // Delete all cars with green color
|
|
30
30
|
* db.delete(cars).where(eq(cars.color, 'green'));
|
|
31
31
|
* // or
|
|
32
32
|
* db.delete(cars).where(sql`${cars.color} = 'green'`)
|
|
33
33
|
* ```
|
|
34
|
-
*
|
|
34
|
+
*
|
|
35
35
|
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
36
|
-
*
|
|
36
|
+
*
|
|
37
37
|
* ```ts
|
|
38
38
|
* // Delete all BMW cars with a green color
|
|
39
39
|
* db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
40
|
-
*
|
|
40
|
+
*
|
|
41
41
|
* // Delete all cars with the green or blue color
|
|
42
42
|
* db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
43
43
|
* ```
|
|
44
|
-
|
|
44
|
+
*/
|
|
45
45
|
where(where) {
|
|
46
46
|
this.config.where = where;
|
|
47
47
|
return this;
|
|
@@ -58,27 +58,31 @@ class SQLiteDeleteBase extends QueryPromise {
|
|
|
58
58
|
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
|
59
59
|
return rest;
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
/** @internal */
|
|
62
|
+
_prepare(isOneTimeQuery = true) {
|
|
62
63
|
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
|
63
64
|
this.dialect.sqlToQuery(this.getSQL()),
|
|
64
65
|
this.config.returning,
|
|
65
66
|
this.config.returning ? "all" : "run"
|
|
66
67
|
);
|
|
67
68
|
}
|
|
69
|
+
prepare() {
|
|
70
|
+
return this._prepare(false);
|
|
71
|
+
}
|
|
68
72
|
run = (placeholderValues) => {
|
|
69
|
-
return this.
|
|
73
|
+
return this._prepare().run(placeholderValues);
|
|
70
74
|
};
|
|
71
75
|
all = (placeholderValues) => {
|
|
72
|
-
return this.
|
|
76
|
+
return this._prepare().all(placeholderValues);
|
|
73
77
|
};
|
|
74
78
|
get = (placeholderValues) => {
|
|
75
|
-
return this.
|
|
79
|
+
return this._prepare().get(placeholderValues);
|
|
76
80
|
};
|
|
77
81
|
values = (placeholderValues) => {
|
|
78
|
-
return this.
|
|
82
|
+
return this._prepare().values(placeholderValues);
|
|
79
83
|
};
|
|
80
84
|
async execute(placeholderValues) {
|
|
81
|
-
return this.
|
|
85
|
+
return this._prepare().execute(placeholderValues);
|
|
82
86
|
}
|
|
83
87
|
$dynamic() {
|
|
84
88
|
return this;
|