drizzle-orm 0.29.0 → 0.29.1-d55aea4

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.
Files changed (146) hide show
  1. package/mysql-core/db.cjs +134 -31
  2. package/mysql-core/db.cjs.map +1 -1
  3. package/mysql-core/db.d.cts +171 -1
  4. package/mysql-core/db.d.ts +171 -1
  5. package/mysql-core/db.js +134 -31
  6. package/mysql-core/db.js.map +1 -1
  7. package/mysql-core/query-builders/delete.cjs +29 -0
  8. package/mysql-core/query-builders/delete.cjs.map +1 -1
  9. package/mysql-core/query-builders/delete.d.cts +29 -0
  10. package/mysql-core/query-builders/delete.d.ts +29 -0
  11. package/mysql-core/query-builders/delete.js +29 -0
  12. package/mysql-core/query-builders/delete.js.map +1 -1
  13. package/mysql-core/query-builders/insert.cjs +26 -0
  14. package/mysql-core/query-builders/insert.cjs.map +1 -1
  15. package/mysql-core/query-builders/insert.d.cts +26 -0
  16. package/mysql-core/query-builders/insert.d.ts +26 -0
  17. package/mysql-core/query-builders/insert.js +26 -0
  18. package/mysql-core/query-builders/insert.js.map +1 -1
  19. package/mysql-core/query-builders/query.cjs +9 -1
  20. package/mysql-core/query-builders/query.cjs.map +1 -1
  21. package/mysql-core/query-builders/query.d.cts +1 -0
  22. package/mysql-core/query-builders/query.d.ts +1 -0
  23. package/mysql-core/query-builders/query.js +9 -1
  24. package/mysql-core/query-builders/query.js.map +1 -1
  25. package/mysql-core/query-builders/select.cjs +381 -0
  26. package/mysql-core/query-builders/select.cjs.map +1 -1
  27. package/mysql-core/query-builders/select.d.cts +604 -0
  28. package/mysql-core/query-builders/select.d.ts +604 -0
  29. package/mysql-core/query-builders/select.js +381 -0
  30. package/mysql-core/query-builders/select.js.map +1 -1
  31. package/mysql-core/query-builders/update.cjs +33 -0
  32. package/mysql-core/query-builders/update.cjs.map +1 -1
  33. package/mysql-core/query-builders/update.d.cts +33 -0
  34. package/mysql-core/query-builders/update.d.ts +33 -0
  35. package/mysql-core/query-builders/update.js +33 -0
  36. package/mysql-core/query-builders/update.js.map +1 -1
  37. package/mysql-core/view.cjs +2 -2
  38. package/mysql-core/view.cjs.map +1 -1
  39. package/mysql-core/view.d.cts +1 -1
  40. package/mysql-core/view.d.ts +1 -1
  41. package/mysql-core/view.js +2 -2
  42. package/mysql-core/view.js.map +1 -1
  43. package/mysql-proxy/migrator.cjs +2 -2
  44. package/mysql-proxy/migrator.cjs.map +1 -1
  45. package/mysql-proxy/migrator.js +2 -2
  46. package/mysql-proxy/migrator.js.map +1 -1
  47. package/package.json +25 -1
  48. package/pg-core/db.cjs +153 -34
  49. package/pg-core/db.cjs.map +1 -1
  50. package/pg-core/db.d.cts +211 -0
  51. package/pg-core/db.d.ts +211 -0
  52. package/pg-core/db.js +153 -34
  53. package/pg-core/db.js.map +1 -1
  54. package/pg-core/dialect.cjs +1 -1
  55. package/pg-core/dialect.cjs.map +1 -1
  56. package/pg-core/dialect.js +1 -1
  57. package/pg-core/dialect.js.map +1 -1
  58. package/pg-core/query-builders/delete.cjs +29 -0
  59. package/pg-core/query-builders/delete.cjs.map +1 -1
  60. package/pg-core/query-builders/delete.d.cts +49 -0
  61. package/pg-core/query-builders/delete.d.ts +49 -0
  62. package/pg-core/query-builders/delete.js +29 -0
  63. package/pg-core/query-builders/delete.js.map +1 -1
  64. package/pg-core/query-builders/insert.cjs +51 -0
  65. package/pg-core/query-builders/insert.cjs.map +1 -1
  66. package/pg-core/query-builders/insert.d.cts +71 -0
  67. package/pg-core/query-builders/insert.d.ts +71 -0
  68. package/pg-core/query-builders/insert.js +51 -0
  69. package/pg-core/query-builders/insert.js.map +1 -1
  70. package/pg-core/query-builders/query.cjs +9 -2
  71. package/pg-core/query-builders/query.cjs.map +1 -1
  72. package/pg-core/query-builders/query.d.cts +1 -0
  73. package/pg-core/query-builders/query.d.ts +1 -0
  74. package/pg-core/query-builders/query.js +9 -2
  75. package/pg-core/query-builders/query.js.map +1 -1
  76. package/pg-core/query-builders/select.cjs +354 -48
  77. package/pg-core/query-builders/select.cjs.map +1 -1
  78. package/pg-core/query-builders/select.d.cts +555 -59
  79. package/pg-core/query-builders/select.d.ts +555 -59
  80. package/pg-core/query-builders/select.js +354 -48
  81. package/pg-core/query-builders/select.js.map +1 -1
  82. package/pg-core/query-builders/update.cjs +33 -0
  83. package/pg-core/query-builders/update.cjs.map +1 -1
  84. package/pg-core/query-builders/update.d.cts +55 -0
  85. package/pg-core/query-builders/update.d.ts +55 -0
  86. package/pg-core/query-builders/update.js +33 -0
  87. package/pg-core/query-builders/update.js.map +1 -1
  88. package/pg-proxy/migrator.cjs +1 -1
  89. package/pg-proxy/migrator.cjs.map +1 -1
  90. package/pg-proxy/migrator.js +1 -1
  91. package/pg-proxy/migrator.js.map +1 -1
  92. package/sql/functions/aggregate.cjs +69 -0
  93. package/sql/functions/aggregate.cjs.map +1 -0
  94. package/sql/functions/aggregate.d.cts +104 -0
  95. package/sql/functions/aggregate.d.ts +104 -0
  96. package/sql/functions/aggregate.js +38 -0
  97. package/sql/functions/aggregate.js.map +1 -0
  98. package/sql/functions/index.cjs +23 -0
  99. package/sql/functions/index.cjs.map +1 -0
  100. package/sql/functions/index.d.cts +1 -0
  101. package/sql/functions/index.d.ts +1 -0
  102. package/sql/functions/index.js +2 -0
  103. package/sql/functions/index.js.map +1 -0
  104. package/sql/index.cjs +3 -1
  105. package/sql/index.cjs.map +1 -1
  106. package/sql/index.d.cts +1 -0
  107. package/sql/index.d.ts +1 -0
  108. package/sql/index.js +1 -0
  109. package/sql/index.js.map +1 -1
  110. package/sql/sql.cjs.map +1 -1
  111. package/sql/sql.js.map +1 -1
  112. package/sqlite-core/db.cjs +155 -36
  113. package/sqlite-core/db.cjs.map +1 -1
  114. package/sqlite-core/db.d.cts +187 -0
  115. package/sqlite-core/db.d.ts +187 -0
  116. package/sqlite-core/db.js +155 -36
  117. package/sqlite-core/db.js.map +1 -1
  118. package/sqlite-core/query-builders/delete.cjs +29 -0
  119. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  120. package/sqlite-core/query-builders/delete.d.cts +49 -0
  121. package/sqlite-core/query-builders/delete.d.ts +49 -0
  122. package/sqlite-core/query-builders/delete.js +29 -0
  123. package/sqlite-core/query-builders/delete.js.map +1 -1
  124. package/sqlite-core/query-builders/insert.cjs +51 -0
  125. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  126. package/sqlite-core/query-builders/insert.d.cts +71 -0
  127. package/sqlite-core/query-builders/insert.d.ts +71 -0
  128. package/sqlite-core/query-builders/insert.js +51 -0
  129. package/sqlite-core/query-builders/insert.js.map +1 -1
  130. package/sqlite-core/query-builders/select.cjs +291 -0
  131. package/sqlite-core/query-builders/select.cjs.map +1 -1
  132. package/sqlite-core/query-builders/select.d.cts +434 -0
  133. package/sqlite-core/query-builders/select.d.ts +434 -0
  134. package/sqlite-core/query-builders/select.js +291 -0
  135. package/sqlite-core/query-builders/select.js.map +1 -1
  136. package/sqlite-core/query-builders/select.types.cjs.map +1 -1
  137. package/sqlite-core/query-builders/update.cjs +33 -0
  138. package/sqlite-core/query-builders/update.cjs.map +1 -1
  139. package/sqlite-core/query-builders/update.d.cts +55 -0
  140. package/sqlite-core/query-builders/update.d.ts +55 -0
  141. package/sqlite-core/query-builders/update.js +33 -0
  142. package/sqlite-core/query-builders/update.js.map +1 -1
  143. package/version.cjs +1 -1
  144. package/version.d.cts +1 -1
  145. package/version.d.ts +1 -1
  146. package/version.js +1 -1
@@ -29,9 +29,60 @@ export declare class BaseSQLiteDatabase<TResultKind extends 'sync' | 'async', TR
29
29
  }[TResultKind],
30
30
  /** @internal */
31
31
  session: SQLiteSession<TResultKind, TRunResult, TFullSchema, TSchema>, schema: RelationalSchemaConfig<TSchema> | undefined);
32
+ /**
33
+ * Creates a subquery that defines a temporary named result set as a CTE.
34
+ *
35
+ * It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.
36
+ *
37
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
38
+ *
39
+ * @param alias The alias for the subquery.
40
+ *
41
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
42
+ *
43
+ * @example
44
+ *
45
+ * ```ts
46
+ * // Create a subquery with alias 'sq' and use it in the select query
47
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
48
+ *
49
+ * const result = await db.with(sq).select().from(sq);
50
+ * ```
51
+ *
52
+ * 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:
53
+ *
54
+ * ```ts
55
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
56
+ * const sq = db.$with('sq').as(db.select({
57
+ * name: sql<string>`upper(${users.name})`.as('name'),
58
+ * })
59
+ * .from(users));
60
+ *
61
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
62
+ * ```
63
+ */
32
64
  $with<TAlias extends string>(alias: TAlias): {
33
65
  as<TSelection extends ColumnsSelection>(qb: TypedQueryBuilder<TSelection, unknown> | ((qb: QueryBuilder) => TypedQueryBuilder<TSelection, unknown>)): WithSubqueryWithSelection<TSelection, TAlias>;
34
66
  };
67
+ /**
68
+ * Incorporates a previously defined CTE (using `$with`) into the main query.
69
+ *
70
+ * This method allows the main query to reference a temporary named result set.
71
+ *
72
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
73
+ *
74
+ * @param queries The CTEs to incorporate into the main query.
75
+ *
76
+ * @example
77
+ *
78
+ * ```ts
79
+ * // Define a subquery 'sq' as a CTE using $with
80
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
81
+ *
82
+ * // Incorporate the CTE 'sq' into the main query and select from it
83
+ * const result = await db.with(sq).select().from(sq);
84
+ * ```
85
+ */
35
86
  with(...queries: WithSubquery[]): {
36
87
  select: {
37
88
  (): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;
@@ -42,12 +93,148 @@ export declare class BaseSQLiteDatabase<TResultKind extends 'sync' | 'async', TR
42
93
  <TSelection_1 extends SelectedFields>(fields: TSelection_1): SQLiteSelectBuilder<TSelection_1, TResultKind, TRunResult, "db">;
43
94
  };
44
95
  };
96
+ /**
97
+ * Creates a select query.
98
+ *
99
+ * 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.
100
+ *
101
+ * Use `.from()` method to specify which table to select from.
102
+ *
103
+ * See docs: {@link https://orm.drizzle.team/docs/select}
104
+ *
105
+ * @param fields The selection object.
106
+ *
107
+ * @example
108
+ *
109
+ * ```ts
110
+ * // Select all columns and all rows from the 'cars' table
111
+ * const allCars: Car[] = await db.select().from(cars);
112
+ *
113
+ * // Select specific columns and all rows from the 'cars' table
114
+ * const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({
115
+ * id: cars.id,
116
+ * brand: cars.brand
117
+ * })
118
+ * .from(cars);
119
+ * ```
120
+ *
121
+ * Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:
122
+ *
123
+ * ```ts
124
+ * // Select specific columns along with expression and all rows from the 'cars' table
125
+ * const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({
126
+ * id: cars.id,
127
+ * lowerBrand: sql<string>`lower(${cars.brand})`,
128
+ * })
129
+ * .from(cars);
130
+ * ```
131
+ */
45
132
  select(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;
46
133
  select<TSelection extends SelectedFields>(fields: TSelection): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;
134
+ /**
135
+ * Adds `distinct` expression to the select query.
136
+ *
137
+ * Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.
138
+ *
139
+ * Use `.from()` method to specify which table to select from.
140
+ *
141
+ * See docs: {@link https://orm.drizzle.team/docs/select#distinct}
142
+ *
143
+ * @param fields The selection object.
144
+ *
145
+ * @example
146
+ *
147
+ * ```ts
148
+ * // Select all unique rows from the 'cars' table
149
+ * await db.selectDistinct()
150
+ * .from(cars)
151
+ * .orderBy(cars.id, cars.brand, cars.color);
152
+ *
153
+ * // Select all unique brands from the 'cars' table
154
+ * await db.selectDistinct({ brand: cars.brand })
155
+ * .from(cars)
156
+ * .orderBy(cars.brand);
157
+ * ```
158
+ */
47
159
  selectDistinct(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;
48
160
  selectDistinct<TSelection extends SelectedFields>(fields: TSelection): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;
161
+ /**
162
+ * Creates an update query.
163
+ *
164
+ * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
165
+ *
166
+ * Use `.set()` method to specify which values to update.
167
+ *
168
+ * See docs: {@link https://orm.drizzle.team/docs/update}
169
+ *
170
+ * @param table The table to update.
171
+ *
172
+ * @example
173
+ *
174
+ * ```ts
175
+ * // Update all rows in the 'cars' table
176
+ * await db.update(cars).set({ color: 'red' });
177
+ *
178
+ * // Update rows with filters and conditions
179
+ * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
180
+ *
181
+ * // Update with returning clause
182
+ * const updatedCar: Car[] = await db.update(cars)
183
+ * .set({ color: 'red' })
184
+ * .where(eq(cars.id, 1))
185
+ * .returning();
186
+ * ```
187
+ */
49
188
  update<TTable extends SQLiteTable>(table: TTable): SQLiteUpdateBuilder<TTable, TResultKind, TRunResult>;
189
+ /**
190
+ * Creates an insert query.
191
+ *
192
+ * Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.
193
+ *
194
+ * See docs: {@link https://orm.drizzle.team/docs/insert}
195
+ *
196
+ * @param table The table to insert into.
197
+ *
198
+ * @example
199
+ *
200
+ * ```ts
201
+ * // Insert one row
202
+ * await db.insert(cars).values({ brand: 'BMW' });
203
+ *
204
+ * // Insert multiple rows
205
+ * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
206
+ *
207
+ * // Insert with returning clause
208
+ * const insertedCar: Car[] = await db.insert(cars)
209
+ * .values({ brand: 'BMW' })
210
+ * .returning();
211
+ * ```
212
+ */
50
213
  insert<TTable extends SQLiteTable>(into: TTable): SQLiteInsertBuilder<TTable, TResultKind, TRunResult>;
214
+ /**
215
+ * Creates a delete query.
216
+ *
217
+ * Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.
218
+ *
219
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
220
+ *
221
+ * @param table The table to delete from.
222
+ *
223
+ * @example
224
+ *
225
+ * ```ts
226
+ * // Delete all rows in the 'cars' table
227
+ * await db.delete(cars);
228
+ *
229
+ * // Delete rows with filters and conditions
230
+ * await db.delete(cars).where(eq(cars.color, 'green'));
231
+ *
232
+ * // Delete with returning clause
233
+ * const deletedCar: Car[] = await db.delete(cars)
234
+ * .where(eq(cars.id, 1))
235
+ * .returning();
236
+ * ```
237
+ */
51
238
  delete<TTable extends SQLiteTable>(from: TTable): SQLiteDeleteBase<TTable, TResultKind, TRunResult>;
52
239
  run(query: SQLWrapper): DBResult<TResultKind, TRunResult>;
53
240
  all<T = unknown>(query: SQLWrapper): DBResult<TResultKind, T[]>;
package/sqlite-core/db.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { entityKind } from "../entity.js";
2
+ import { SelectionProxyHandler } from "../selection-proxy.js";
2
3
  import {
3
4
  QueryBuilder,
4
5
  SQLiteDeleteBase,
@@ -9,7 +10,6 @@ import {
9
10
  import { WithSubquery } from "../subquery.js";
10
11
  import { RelationalQueryBuilder } from "./query-builders/query.js";
11
12
  import { SQLiteRaw } from "./query-builders/raw.js";
12
- import { SelectionProxyHandler } from "../selection-proxy.js";
13
13
  class BaseSQLiteDatabase {
14
14
  constructor(resultKind, dialect, session, schema) {
15
15
  this.resultKind = resultKind;
@@ -34,6 +34,38 @@ class BaseSQLiteDatabase {
34
34
  }
35
35
  static [entityKind] = "BaseSQLiteDatabase";
36
36
  query;
37
+ /**
38
+ * Creates a subquery that defines a temporary named result set as a CTE.
39
+ *
40
+ * 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
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
43
+ *
44
+ * @param alias The alias for the subquery.
45
+ *
46
+ * Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.
47
+ *
48
+ * @example
49
+ *
50
+ * ```ts
51
+ * // Create a subquery with alias 'sq' and use it in the select query
52
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
53
+ *
54
+ * const result = await db.with(sq).select().from(sq);
55
+ * ```
56
+ *
57
+ * 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
+ * ```ts
60
+ * // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
61
+ * const sq = db.$with('sq').as(db.select({
62
+ * name: sql<string>`upper(${users.name})`.as('name'),
63
+ * })
64
+ * .from(users));
65
+ *
66
+ * const result = await db.with(sq).select({ name: sq.name }).from(sq);
67
+ * ```
68
+ */
37
69
  $with(alias) {
38
70
  return {
39
71
  as(qb) {
@@ -47,6 +79,25 @@ class BaseSQLiteDatabase {
47
79
  }
48
80
  };
49
81
  }
82
+ /**
83
+ * Incorporates a previously defined CTE (using `$with`) into the main query.
84
+ *
85
+ * This method allows the main query to reference a temporary named result set.
86
+ *
87
+ * See docs: {@link https://orm.drizzle.team/docs/select#with-clause}
88
+ *
89
+ * @param queries The CTEs to incorporate into the main query.
90
+ *
91
+ * @example
92
+ *
93
+ * ```ts
94
+ * // Define a subquery 'sq' as a CTE using $with
95
+ * const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
96
+ *
97
+ * // Incorporate the CTE 'sq' into the main query and select from it
98
+ * const result = await db.with(sq).select().from(sq);
99
+ * ```
100
+ */
50
101
  with(...queries) {
51
102
  const self = this;
52
103
  function select(fields) {
@@ -79,12 +130,87 @@ class BaseSQLiteDatabase {
79
130
  distinct: true
80
131
  });
81
132
  }
133
+ /**
134
+ * Creates an update query.
135
+ *
136
+ * Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.
137
+ *
138
+ * Use `.set()` method to specify which values to update.
139
+ *
140
+ * See docs: {@link https://orm.drizzle.team/docs/update}
141
+ *
142
+ * @param table The table to update.
143
+ *
144
+ * @example
145
+ *
146
+ * ```ts
147
+ * // Update all rows in the 'cars' table
148
+ * await db.update(cars).set({ color: 'red' });
149
+ *
150
+ * // Update rows with filters and conditions
151
+ * await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
152
+ *
153
+ * // Update with returning clause
154
+ * const updatedCar: Car[] = await db.update(cars)
155
+ * .set({ color: 'red' })
156
+ * .where(eq(cars.id, 1))
157
+ * .returning();
158
+ * ```
159
+ */
82
160
  update(table) {
83
161
  return new SQLiteUpdateBuilder(table, this.session, this.dialect);
84
162
  }
163
+ /**
164
+ * Creates an insert query.
165
+ *
166
+ * 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
+ *
170
+ * @param table The table to insert into.
171
+ *
172
+ * @example
173
+ *
174
+ * ```ts
175
+ * // Insert one row
176
+ * await db.insert(cars).values({ brand: 'BMW' });
177
+ *
178
+ * // Insert multiple rows
179
+ * await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
180
+ *
181
+ * // Insert with returning clause
182
+ * const insertedCar: Car[] = await db.insert(cars)
183
+ * .values({ brand: 'BMW' })
184
+ * .returning();
185
+ * ```
186
+ */
85
187
  insert(into) {
86
188
  return new SQLiteInsertBuilder(into, this.session, this.dialect);
87
189
  }
190
+ /**
191
+ * 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
+ *
195
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
196
+ *
197
+ * @param table The table to delete from.
198
+ *
199
+ * @example
200
+ *
201
+ * ```ts
202
+ * // Delete all rows in the 'cars' table
203
+ * await db.delete(cars);
204
+ *
205
+ * // Delete rows with filters and conditions
206
+ * await db.delete(cars).where(eq(cars.color, 'green'));
207
+ *
208
+ * // Delete with returning clause
209
+ * const deletedCar: Car[] = await db.delete(cars)
210
+ * .where(eq(cars.id, 1))
211
+ * .returning();
212
+ * ```
213
+ */
88
214
  delete(from) {
89
215
  return new SQLiteDeleteBase(from, this.session, this.dialect);
90
216
  }
@@ -145,42 +271,35 @@ class BaseSQLiteDatabase {
145
271
  }
146
272
  }
147
273
  const withReplicas = (primary, replicas, getReplica = () => replicas[Math.floor(Math.random() * replicas.length)]) => {
148
- const select = (...args) => getReplica(replicas).select(args);
149
- const selectDistinct = (...args) => getReplica(replicas).selectDistinct(args);
150
- const $with = (...args) => getReplica(replicas).with(args);
151
- const update = (...args) => primary.update(args);
152
- const insert = (...args) => primary.insert(args);
153
- const $delete = (...args) => primary.delete(args);
154
- const run = (...args) => primary.run(args);
155
- const all = (...args) => primary.all(args);
156
- const get = (...args) => primary.get(args);
157
- const values = (...args) => primary.values(args);
158
- const transaction = (...args) => primary.transaction(args);
159
- return new Proxy(
160
- {
161
- ...primary,
162
- update,
163
- insert,
164
- delete: $delete,
165
- run,
166
- all,
167
- get,
168
- values,
169
- transaction,
170
- $primary: primary,
171
- select,
172
- selectDistinct,
173
- with: $with
174
- },
175
- {
176
- get(target, prop, _receiver) {
177
- if (prop === "query") {
178
- return getReplica(replicas).query;
179
- }
180
- return target[prop];
181
- }
274
+ const select = (...args) => getReplica(replicas).select(...args);
275
+ const selectDistinct = (...args) => getReplica(replicas).selectDistinct(...args);
276
+ const $with = (...args) => getReplica(replicas).with(...args);
277
+ const update = (...args) => primary.update(...args);
278
+ const insert = (...args) => primary.insert(...args);
279
+ const $delete = (...args) => primary.delete(...args);
280
+ const run = (...args) => primary.run(...args);
281
+ const all = (...args) => primary.all(...args);
282
+ const get = (...args) => primary.get(...args);
283
+ const values = (...args) => primary.values(...args);
284
+ const transaction = (...args) => primary.transaction(...args);
285
+ return {
286
+ ...primary,
287
+ update,
288
+ insert,
289
+ delete: $delete,
290
+ run,
291
+ all,
292
+ get,
293
+ values,
294
+ transaction,
295
+ $primary: primary,
296
+ select,
297
+ selectDistinct,
298
+ with: $with,
299
+ get query() {
300
+ return getReplica(replicas).query;
182
301
  }
183
- );
302
+ };
184
303
  };
185
304
  export {
186
305
  BaseSQLiteDatabase,
@@ -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 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';\nimport { SelectionProxyHandler } from '~/selection-proxy.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$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\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\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\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\tupdate<TTable extends SQLiteTable>(table: TTable): SQLiteUpdateBuilder<TTable, TResultKind, TRunResult> {\n\t\treturn new SQLiteUpdateBuilder(table, this.session, this.dialect);\n\t}\n\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\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: any) => getReplica(replicas).select(args);\n\tconst selectDistinct: Q['selectDistinct'] = (...args: any) => getReplica(replicas).selectDistinct(args);\n\tconst $with: Q['with'] = (...args: any) => 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 new Proxy<Q & { $primary: Q }>(\n\t\t{\n\t\t\t...primary,\n\t\t\tupdate,\n\t\t\tinsert,\n\t\t\tdelete: $delete,\n\t\t\trun,\n\t\t\tall,\n\t\t\tget,\n\t\t\tvalues,\n\t\t\ttransaction,\n\t\t\t$primary: primary,\n\t\t\tselect,\n\t\t\tselectDistinct,\n\t\t\twith: $with,\n\t\t},\n\t\t{\n\t\t\tget(target, prop, _receiver) {\n\t\t\t\tif (prop === 'query') {\n\t\t\t\t\treturn getReplica(replicas).query;\n\t\t\t\t}\n\t\t\t\treturn target[prop as keyof typeof target];\n\t\t\t},\n\t\t},\n\t);\n};\n"],"mappings":"AAAA,SAAS,kBAAkB;AAK3B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AASP,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AI;AAEzE,QAAM,SAAsB,IAAI,SAAc,QAAQ,OAAO,IAAI;AACjE,QAAM,SAAsB,IAAI,SAAc,QAAQ,OAAO,IAAI;AACjE,QAAM,UAAuB,IAAI,SAAc,QAAQ,OAAO,IAAI;AAClE,QAAM,MAAgB,IAAI,SAAc,QAAQ,IAAI,IAAI;AACxD,QAAM,MAAgB,IAAI,SAAc,QAAQ,IAAI,IAAI;AACxD,QAAM,MAAgB,IAAI,SAAc,QAAQ,IAAI,IAAI;AACxD,QAAM,SAAsB,IAAI,SAAc,QAAQ,OAAO,IAAI;AACjE,QAAM,cAAgC,IAAI,SAAc,QAAQ,YAAY,IAAI;AAEhF,SAAO,IAAI;AAAA,IACV;AAAA,MACC,GAAG;AAAA,MACH;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,MAAM;AAAA,IACP;AAAA,IACA;AAAA,MACC,IAAI,QAAQ,MAAM,WAAW;AAC5B,YAAI,SAAS,SAAS;AACrB,iBAAO,WAAW,QAAQ,EAAE;AAAA,QAC7B;AACA,eAAO,OAAO,IAA2B;AAAA,MAC1C;AAAA,IACD;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\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,6BAA6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,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":[]}
@@ -36,6 +36,35 @@ class SQLiteDeleteBase extends import_query_promise.QueryPromise {
36
36
  static [import_entity.entityKind] = "SQLiteDelete";
37
37
  /** @internal */
38
38
  config;
39
+ /**
40
+ * Adds a `where` clause to the query.
41
+ *
42
+ * Calling this method will delete only those rows that fulfill a specified condition.
43
+ *
44
+ * See docs: {@link https://orm.drizzle.team/docs/delete}
45
+ *
46
+ * @param where the `where` clause.
47
+ *
48
+ * @example
49
+ * You can use conditional operators and `sql function` to filter the rows to be deleted.
50
+ *
51
+ * ```ts
52
+ * // Delete all cars with green color
53
+ * db.delete(cars).where(eq(cars.color, 'green'));
54
+ * // or
55
+ * db.delete(cars).where(sql`${cars.color} = 'green'`)
56
+ * ```
57
+ *
58
+ * You can logically combine conditional operators with `and()` and `or()` operators:
59
+ *
60
+ * ```ts
61
+ * // Delete all BMW cars with a green color
62
+ * db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
63
+ *
64
+ * // Delete all cars with the green or blue color
65
+ * db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
66
+ * ```
67
+ */
39
68
  where(where) {
40
69
  this.config.where = where;
41
70
  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';\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\twhere(where: SQL | undefined): SQLiteDeleteWithout<this, TDynamic, 'where'> {\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\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(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;AA+GpD,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,EAWA,MAAM,OAAsE;AAC3E,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EAMA,UACC,SAA6B,KAAK,MAAM,yBAAY,OAAO,OAAO,GACrB;AAC7C,SAAK,OAAO,gBAAY,kCAAoB,MAAM;AAClD,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 { 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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