drizzle-kit 0.28.1-d7e3535 → 0.28.1-ddb97ec
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/api.js +836 -691
- package/api.mjs +836 -691
- package/bin.cjs +673 -78
- package/package.json +1 -1
package/api.js
CHANGED
@@ -21121,7 +21121,7 @@ var version;
|
|
21121
21121
|
var init_version = __esm({
|
21122
21122
|
"../drizzle-orm/dist/version.js"() {
|
21123
21123
|
"use strict";
|
21124
|
-
version = "0.36.
|
21124
|
+
version = "0.36.4";
|
21125
21125
|
}
|
21126
21126
|
});
|
21127
21127
|
|
@@ -24583,9 +24583,10 @@ var init_delete = __esm({
|
|
24583
24583
|
constructor(table4, session, dialect4, withList) {
|
24584
24584
|
super();
|
24585
24585
|
__publicField(this, "config");
|
24586
|
+
__publicField(this, "authToken");
|
24586
24587
|
__publicField(this, "execute", (placeholderValues) => {
|
24587
24588
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
24588
|
-
return this._prepare().execute(placeholderValues);
|
24589
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
24589
24590
|
});
|
24590
24591
|
});
|
24591
24592
|
this.session = session;
|
@@ -24646,167 +24647,16 @@ var init_delete = __esm({
|
|
24646
24647
|
prepare(name2) {
|
24647
24648
|
return this._prepare(name2);
|
24648
24649
|
}
|
24649
|
-
$dynamic() {
|
24650
|
-
return this;
|
24651
|
-
}
|
24652
|
-
};
|
24653
|
-
__publicField(PgDeleteBase, _a124, "PgDelete");
|
24654
|
-
}
|
24655
|
-
});
|
24656
|
-
|
24657
|
-
// ../drizzle-orm/dist/pg-core/query-builders/insert.js
|
24658
|
-
var _a125, PgInsertBuilder, _a126, _b98, PgInsertBase;
|
24659
|
-
var init_insert = __esm({
|
24660
|
-
"../drizzle-orm/dist/pg-core/query-builders/insert.js"() {
|
24661
|
-
"use strict";
|
24662
|
-
init_entity();
|
24663
|
-
init_query_promise();
|
24664
|
-
init_sql();
|
24665
|
-
init_table();
|
24666
|
-
init_tracing();
|
24667
|
-
init_utils2();
|
24668
|
-
_a125 = entityKind;
|
24669
|
-
PgInsertBuilder = class {
|
24670
|
-
constructor(table4, session, dialect4, withList) {
|
24671
|
-
this.table = table4;
|
24672
|
-
this.session = session;
|
24673
|
-
this.dialect = dialect4;
|
24674
|
-
this.withList = withList;
|
24675
|
-
}
|
24676
|
-
values(values) {
|
24677
|
-
values = Array.isArray(values) ? values : [values];
|
24678
|
-
if (values.length === 0) {
|
24679
|
-
throw new Error("values() must be called with at least one value");
|
24680
|
-
}
|
24681
|
-
const mappedValues = values.map((entry) => {
|
24682
|
-
const result = {};
|
24683
|
-
const cols = this.table[Table2.Symbol.Columns];
|
24684
|
-
for (const colKey of Object.keys(entry)) {
|
24685
|
-
const colValue = entry[colKey];
|
24686
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
24687
|
-
}
|
24688
|
-
return result;
|
24689
|
-
});
|
24690
|
-
return new PgInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
24691
|
-
}
|
24692
|
-
};
|
24693
|
-
__publicField(PgInsertBuilder, _a125, "PgInsertBuilder");
|
24694
|
-
PgInsertBase = class extends (_b98 = QueryPromise, _a126 = entityKind, _b98) {
|
24695
|
-
constructor(table4, values, session, dialect4, withList) {
|
24696
|
-
super();
|
24697
|
-
__publicField(this, "config");
|
24698
|
-
__publicField(this, "execute", (placeholderValues) => {
|
24699
|
-
return tracer.startActiveSpan("drizzle.operation", () => {
|
24700
|
-
return this._prepare().execute(placeholderValues);
|
24701
|
-
});
|
24702
|
-
});
|
24703
|
-
this.session = session;
|
24704
|
-
this.dialect = dialect4;
|
24705
|
-
this.config = { table: table4, values, withList };
|
24706
|
-
}
|
24707
|
-
returning(fields = this.config.table[Table2.Symbol.Columns]) {
|
24708
|
-
this.config.returning = orderSelectedFields(fields);
|
24709
|
-
return this;
|
24710
|
-
}
|
24711
|
-
/**
|
24712
|
-
* Adds an `on conflict do nothing` clause to the query.
|
24713
|
-
*
|
24714
|
-
* Calling this method simply avoids inserting a row as its alternative action.
|
24715
|
-
*
|
24716
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
24717
|
-
*
|
24718
|
-
* @param config The `target` and `where` clauses.
|
24719
|
-
*
|
24720
|
-
* @example
|
24721
|
-
* ```ts
|
24722
|
-
* // Insert one row and cancel the insert if there's a conflict
|
24723
|
-
* await db.insert(cars)
|
24724
|
-
* .values({ id: 1, brand: 'BMW' })
|
24725
|
-
* .onConflictDoNothing();
|
24726
|
-
*
|
24727
|
-
* // Explicitly specify conflict target
|
24728
|
-
* await db.insert(cars)
|
24729
|
-
* .values({ id: 1, brand: 'BMW' })
|
24730
|
-
* .onConflictDoNothing({ target: cars.id });
|
24731
|
-
* ```
|
24732
|
-
*/
|
24733
|
-
onConflictDoNothing(config = {}) {
|
24734
|
-
if (config.target === void 0) {
|
24735
|
-
this.config.onConflict = sql`do nothing`;
|
24736
|
-
} else {
|
24737
|
-
let targetColumn = "";
|
24738
|
-
targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
|
24739
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
24740
|
-
this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
|
24741
|
-
}
|
24742
|
-
return this;
|
24743
|
-
}
|
24744
|
-
/**
|
24745
|
-
* Adds an `on conflict do update` clause to the query.
|
24746
|
-
*
|
24747
|
-
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
24748
|
-
*
|
24749
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
24750
|
-
*
|
24751
|
-
* @param config The `target`, `set` and `where` clauses.
|
24752
|
-
*
|
24753
|
-
* @example
|
24754
|
-
* ```ts
|
24755
|
-
* // Update the row if there's a conflict
|
24756
|
-
* await db.insert(cars)
|
24757
|
-
* .values({ id: 1, brand: 'BMW' })
|
24758
|
-
* .onConflictDoUpdate({
|
24759
|
-
* target: cars.id,
|
24760
|
-
* set: { brand: 'Porsche' }
|
24761
|
-
* });
|
24762
|
-
*
|
24763
|
-
* // Upsert with 'where' clause
|
24764
|
-
* await db.insert(cars)
|
24765
|
-
* .values({ id: 1, brand: 'BMW' })
|
24766
|
-
* .onConflictDoUpdate({
|
24767
|
-
* target: cars.id,
|
24768
|
-
* set: { brand: 'newBMW' },
|
24769
|
-
* targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
|
24770
|
-
* });
|
24771
|
-
* ```
|
24772
|
-
*/
|
24773
|
-
onConflictDoUpdate(config) {
|
24774
|
-
if (config.where && (config.targetWhere || config.setWhere)) {
|
24775
|
-
throw new Error(
|
24776
|
-
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
24777
|
-
);
|
24778
|
-
}
|
24779
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
24780
|
-
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
24781
|
-
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
24782
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
24783
|
-
let targetColumn = "";
|
24784
|
-
targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
|
24785
|
-
this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
24786
|
-
return this;
|
24787
|
-
}
|
24788
|
-
/** @internal */
|
24789
|
-
getSQL() {
|
24790
|
-
return this.dialect.buildInsertQuery(this.config);
|
24791
|
-
}
|
24792
|
-
toSQL() {
|
24793
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
24794
|
-
return rest;
|
24795
|
-
}
|
24796
24650
|
/** @internal */
|
24797
|
-
|
24798
|
-
|
24799
|
-
|
24800
|
-
});
|
24801
|
-
}
|
24802
|
-
prepare(name2) {
|
24803
|
-
return this._prepare(name2);
|
24651
|
+
setToken(token) {
|
24652
|
+
this.authToken = token;
|
24653
|
+
return this;
|
24804
24654
|
}
|
24805
24655
|
$dynamic() {
|
24806
24656
|
return this;
|
24807
24657
|
}
|
24808
24658
|
};
|
24809
|
-
__publicField(
|
24659
|
+
__publicField(PgDeleteBase, _a124, "PgDelete");
|
24810
24660
|
}
|
24811
24661
|
});
|
24812
24662
|
|
@@ -24825,13 +24675,13 @@ function toCamelCase(input) {
|
|
24825
24675
|
function noopCase(input) {
|
24826
24676
|
return input;
|
24827
24677
|
}
|
24828
|
-
var
|
24678
|
+
var _a125, CasingCache;
|
24829
24679
|
var init_casing = __esm({
|
24830
24680
|
"../drizzle-orm/dist/casing.js"() {
|
24831
24681
|
"use strict";
|
24832
24682
|
init_entity();
|
24833
24683
|
init_table();
|
24834
|
-
|
24684
|
+
_a125 = entityKind;
|
24835
24685
|
CasingCache = class {
|
24836
24686
|
constructor(casing2) {
|
24837
24687
|
/** @internal */
|
@@ -24868,25 +24718,25 @@ var init_casing = __esm({
|
|
24868
24718
|
this.cachedTables = {};
|
24869
24719
|
}
|
24870
24720
|
};
|
24871
|
-
__publicField(CasingCache,
|
24721
|
+
__publicField(CasingCache, _a125, "CasingCache");
|
24872
24722
|
}
|
24873
24723
|
});
|
24874
24724
|
|
24875
24725
|
// ../drizzle-orm/dist/pg-core/view-base.js
|
24876
|
-
var
|
24726
|
+
var _a126, _b98, PgViewBase;
|
24877
24727
|
var init_view_base = __esm({
|
24878
24728
|
"../drizzle-orm/dist/pg-core/view-base.js"() {
|
24879
24729
|
"use strict";
|
24880
24730
|
init_entity();
|
24881
24731
|
init_sql();
|
24882
|
-
PgViewBase = class extends (
|
24732
|
+
PgViewBase = class extends (_b98 = View3, _a126 = entityKind, _b98) {
|
24883
24733
|
};
|
24884
|
-
__publicField(PgViewBase,
|
24734
|
+
__publicField(PgViewBase, _a126, "PgViewBase");
|
24885
24735
|
}
|
24886
24736
|
});
|
24887
24737
|
|
24888
24738
|
// ../drizzle-orm/dist/pg-core/dialect.js
|
24889
|
-
var
|
24739
|
+
var _a127, PgDialect;
|
24890
24740
|
var init_dialect = __esm({
|
24891
24741
|
"../drizzle-orm/dist/pg-core/dialect.js"() {
|
24892
24742
|
"use strict";
|
@@ -24905,7 +24755,7 @@ var init_dialect = __esm({
|
|
24905
24755
|
init_utils2();
|
24906
24756
|
init_view_common();
|
24907
24757
|
init_view_base();
|
24908
|
-
|
24758
|
+
_a127 = entityKind;
|
24909
24759
|
PgDialect = class {
|
24910
24760
|
constructor(config) {
|
24911
24761
|
/** @internal */
|
@@ -25213,43 +25063,55 @@ var init_dialect = __esm({
|
|
25213
25063
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
25214
25064
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
25215
25065
|
}
|
25216
|
-
buildInsertQuery({ table: table4, values, onConflict, returning, withList }) {
|
25066
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, onConflict, returning, withList, select, overridingSystemValue_ }) {
|
25217
25067
|
const valuesSqlList = [];
|
25218
25068
|
const columns = table4[Table2.Symbol.Columns];
|
25219
25069
|
const colEntries = Object.entries(columns).filter(([_2, col]) => !col.shouldDisableInsert());
|
25220
25070
|
const insertOrder = colEntries.map(
|
25221
25071
|
([, column4]) => sql.identifier(this.casing.getColumnCasing(column4))
|
25222
25072
|
);
|
25223
|
-
|
25224
|
-
const
|
25225
|
-
|
25226
|
-
|
25227
|
-
|
25228
|
-
|
25229
|
-
|
25230
|
-
|
25231
|
-
|
25232
|
-
|
25233
|
-
|
25234
|
-
|
25235
|
-
|
25073
|
+
if (select) {
|
25074
|
+
const select2 = valuesOrSelect;
|
25075
|
+
if (is(select2, SQL)) {
|
25076
|
+
valuesSqlList.push(select2);
|
25077
|
+
} else {
|
25078
|
+
valuesSqlList.push(select2.getSQL());
|
25079
|
+
}
|
25080
|
+
} else {
|
25081
|
+
const values = valuesOrSelect;
|
25082
|
+
valuesSqlList.push(sql.raw("values "));
|
25083
|
+
for (const [valueIndex, value] of values.entries()) {
|
25084
|
+
const valueList = [];
|
25085
|
+
for (const [fieldName, col] of colEntries) {
|
25086
|
+
const colValue = value[fieldName];
|
25087
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
25088
|
+
if (col.defaultFn !== void 0) {
|
25089
|
+
const defaultFnResult = col.defaultFn();
|
25090
|
+
const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
25091
|
+
valueList.push(defaultValue);
|
25092
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
25093
|
+
const onUpdateFnResult = col.onUpdateFn();
|
25094
|
+
const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
25095
|
+
valueList.push(newValue);
|
25096
|
+
} else {
|
25097
|
+
valueList.push(sql`default`);
|
25098
|
+
}
|
25236
25099
|
} else {
|
25237
|
-
valueList.push(
|
25100
|
+
valueList.push(colValue);
|
25238
25101
|
}
|
25239
|
-
} else {
|
25240
|
-
valueList.push(colValue);
|
25241
25102
|
}
|
25242
|
-
|
25243
|
-
|
25244
|
-
|
25245
|
-
|
25103
|
+
valuesSqlList.push(valueList);
|
25104
|
+
if (valueIndex < values.length - 1) {
|
25105
|
+
valuesSqlList.push(sql`, `);
|
25106
|
+
}
|
25246
25107
|
}
|
25247
25108
|
}
|
25248
25109
|
const withSql = this.buildWithCTE(withList);
|
25249
25110
|
const valuesSql = sql.join(valuesSqlList);
|
25250
25111
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
25251
25112
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
25252
|
-
|
25113
|
+
const overridingSql = overridingSystemValue_ === true ? sql`overriding system value ` : void 0;
|
25114
|
+
return sql`${withSql}insert into ${table4} ${insertOrder} ${overridingSql}${valuesSql}${onConflictSql}${returningSql}`;
|
25253
25115
|
}
|
25254
25116
|
buildRefreshMaterializedViewQuery({ view: view4, concurrently, withNoData }) {
|
25255
25117
|
const concurrentlySql = concurrently ? sql` concurrently` : void 0;
|
@@ -25985,12 +25847,12 @@ var init_dialect = __esm({
|
|
25985
25847
|
};
|
25986
25848
|
}
|
25987
25849
|
};
|
25988
|
-
__publicField(PgDialect,
|
25850
|
+
__publicField(PgDialect, _a127, "PgDialect");
|
25989
25851
|
}
|
25990
25852
|
});
|
25991
25853
|
|
25992
25854
|
// ../drizzle-orm/dist/selection-proxy.js
|
25993
|
-
var
|
25855
|
+
var _a128, _SelectionProxyHandler, SelectionProxyHandler;
|
25994
25856
|
var init_selection_proxy = __esm({
|
25995
25857
|
"../drizzle-orm/dist/selection-proxy.js"() {
|
25996
25858
|
"use strict";
|
@@ -26000,7 +25862,7 @@ var init_selection_proxy = __esm({
|
|
26000
25862
|
init_sql();
|
26001
25863
|
init_subquery();
|
26002
25864
|
init_view_common();
|
26003
|
-
|
25865
|
+
_a128 = entityKind;
|
26004
25866
|
_SelectionProxyHandler = class _SelectionProxyHandler {
|
26005
25867
|
constructor(config) {
|
26006
25868
|
__publicField(this, "config");
|
@@ -26066,25 +25928,25 @@ var init_selection_proxy = __esm({
|
|
26066
25928
|
return new Proxy(value, new _SelectionProxyHandler(this.config));
|
26067
25929
|
}
|
26068
25930
|
};
|
26069
|
-
__publicField(_SelectionProxyHandler,
|
25931
|
+
__publicField(_SelectionProxyHandler, _a128, "SelectionProxyHandler");
|
26070
25932
|
SelectionProxyHandler = _SelectionProxyHandler;
|
26071
25933
|
}
|
26072
25934
|
});
|
26073
25935
|
|
26074
25936
|
// ../drizzle-orm/dist/query-builders/query-builder.js
|
26075
|
-
var
|
25937
|
+
var _a129, TypedQueryBuilder;
|
26076
25938
|
var init_query_builder = __esm({
|
26077
25939
|
"../drizzle-orm/dist/query-builders/query-builder.js"() {
|
26078
25940
|
"use strict";
|
26079
25941
|
init_entity();
|
26080
|
-
|
25942
|
+
_a129 = entityKind;
|
26081
25943
|
TypedQueryBuilder = class {
|
26082
25944
|
/** @internal */
|
26083
25945
|
getSelectedFields() {
|
26084
25946
|
return this._.selectedFields;
|
26085
25947
|
}
|
26086
25948
|
};
|
26087
|
-
__publicField(TypedQueryBuilder,
|
25949
|
+
__publicField(TypedQueryBuilder, _a129, "TypedQueryBuilder");
|
26088
25950
|
}
|
26089
25951
|
});
|
26090
25952
|
|
@@ -26106,7 +25968,7 @@ function createSetOperator(type, isAll) {
|
|
26106
25968
|
return leftSelect.addSetOperators(setOperators);
|
26107
25969
|
};
|
26108
25970
|
}
|
26109
|
-
var
|
25971
|
+
var _a130, PgSelectBuilder, _a131, _b99, PgSelectQueryBuilderBase, _a132, _b100, PgSelectBase, getPgSetOperators, union, unionAll, intersect, intersectAll, except, exceptAll;
|
26110
25972
|
var init_select2 = __esm({
|
26111
25973
|
"../drizzle-orm/dist/pg-core/query-builders/select.js"() {
|
26112
25974
|
"use strict";
|
@@ -26122,7 +25984,7 @@ var init_select2 = __esm({
|
|
26122
25984
|
init_utils2();
|
26123
25985
|
init_utils2();
|
26124
25986
|
init_view_common();
|
26125
|
-
|
25987
|
+
_a130 = entityKind;
|
26126
25988
|
PgSelectBuilder = class {
|
26127
25989
|
constructor(config) {
|
26128
25990
|
__publicField(this, "fields");
|
@@ -26130,6 +25992,7 @@ var init_select2 = __esm({
|
|
26130
25992
|
__publicField(this, "dialect");
|
26131
25993
|
__publicField(this, "withList", []);
|
26132
25994
|
__publicField(this, "distinct");
|
25995
|
+
__publicField(this, "authToken");
|
26133
25996
|
this.fields = config.fields;
|
26134
25997
|
this.session = config.session;
|
26135
25998
|
this.dialect = config.dialect;
|
@@ -26138,6 +26001,11 @@ var init_select2 = __esm({
|
|
26138
26001
|
}
|
26139
26002
|
this.distinct = config.distinct;
|
26140
26003
|
}
|
26004
|
+
/** @internal */
|
26005
|
+
setToken(token) {
|
26006
|
+
this.authToken = token;
|
26007
|
+
return this;
|
26008
|
+
}
|
26141
26009
|
/**
|
26142
26010
|
* Specify the table, subquery, or other target that you're
|
26143
26011
|
* building a select query against.
|
@@ -26168,11 +26036,11 @@ var init_select2 = __esm({
|
|
26168
26036
|
dialect: this.dialect,
|
26169
26037
|
withList: this.withList,
|
26170
26038
|
distinct: this.distinct
|
26171
|
-
});
|
26039
|
+
}).setToken(this.authToken);
|
26172
26040
|
}
|
26173
26041
|
};
|
26174
|
-
__publicField(PgSelectBuilder,
|
26175
|
-
PgSelectQueryBuilderBase = class extends (
|
26042
|
+
__publicField(PgSelectBuilder, _a130, "PgSelectBuilder");
|
26043
|
+
PgSelectQueryBuilderBase = class extends (_b99 = TypedQueryBuilder, _a131 = entityKind, _b99) {
|
26176
26044
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
26177
26045
|
super();
|
26178
26046
|
__publicField(this, "_");
|
@@ -26772,19 +26640,20 @@ var init_select2 = __esm({
|
|
26772
26640
|
return this;
|
26773
26641
|
}
|
26774
26642
|
};
|
26775
|
-
__publicField(PgSelectQueryBuilderBase,
|
26776
|
-
PgSelectBase = class extends (
|
26643
|
+
__publicField(PgSelectQueryBuilderBase, _a131, "PgSelectQueryBuilder");
|
26644
|
+
PgSelectBase = class extends (_b100 = PgSelectQueryBuilderBase, _a132 = entityKind, _b100) {
|
26777
26645
|
constructor() {
|
26778
26646
|
super(...arguments);
|
26647
|
+
__publicField(this, "authToken");
|
26779
26648
|
__publicField(this, "execute", (placeholderValues) => {
|
26780
26649
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
26781
|
-
return this._prepare().execute(placeholderValues);
|
26650
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
26782
26651
|
});
|
26783
26652
|
});
|
26784
26653
|
}
|
26785
26654
|
/** @internal */
|
26786
26655
|
_prepare(name2) {
|
26787
|
-
const { session, config, dialect: dialect4, joinsNotNullableMap } = this;
|
26656
|
+
const { session, config, dialect: dialect4, joinsNotNullableMap, authToken } = this;
|
26788
26657
|
if (!session) {
|
26789
26658
|
throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
26790
26659
|
}
|
@@ -26792,7 +26661,7 @@ var init_select2 = __esm({
|
|
26792
26661
|
const fieldsList = orderSelectedFields(config.fields);
|
26793
26662
|
const query = session.prepareQuery(dialect4.sqlToQuery(this.getSQL()), fieldsList, name2, true);
|
26794
26663
|
query.joinsNotNullableMap = joinsNotNullableMap;
|
26795
|
-
return query;
|
26664
|
+
return query.setToken(authToken);
|
26796
26665
|
});
|
26797
26666
|
}
|
26798
26667
|
/**
|
@@ -26805,8 +26674,13 @@ var init_select2 = __esm({
|
|
26805
26674
|
prepare(name2) {
|
26806
26675
|
return this._prepare(name2);
|
26807
26676
|
}
|
26677
|
+
/** @internal */
|
26678
|
+
setToken(token) {
|
26679
|
+
this.authToken = token;
|
26680
|
+
return this;
|
26681
|
+
}
|
26808
26682
|
};
|
26809
|
-
__publicField(PgSelectBase,
|
26683
|
+
__publicField(PgSelectBase, _a132, "PgSelect");
|
26810
26684
|
applyMixins(PgSelectBase, [QueryPromise]);
|
26811
26685
|
getPgSetOperators = () => ({
|
26812
26686
|
union,
|
@@ -26826,7 +26700,7 @@ var init_select2 = __esm({
|
|
26826
26700
|
});
|
26827
26701
|
|
26828
26702
|
// ../drizzle-orm/dist/pg-core/query-builders/query-builder.js
|
26829
|
-
var
|
26703
|
+
var _a133, QueryBuilder;
|
26830
26704
|
var init_query_builder2 = __esm({
|
26831
26705
|
"../drizzle-orm/dist/pg-core/query-builders/query-builder.js"() {
|
26832
26706
|
"use strict";
|
@@ -26835,7 +26709,7 @@ var init_query_builder2 = __esm({
|
|
26835
26709
|
init_selection_proxy();
|
26836
26710
|
init_subquery();
|
26837
26711
|
init_select2();
|
26838
|
-
|
26712
|
+
_a133 = entityKind;
|
26839
26713
|
QueryBuilder = class {
|
26840
26714
|
constructor(dialect4) {
|
26841
26715
|
__publicField(this, "dialect");
|
@@ -26916,67 +26790,264 @@ var init_query_builder2 = __esm({
|
|
26916
26790
|
return this.dialect;
|
26917
26791
|
}
|
26918
26792
|
};
|
26919
|
-
__publicField(QueryBuilder,
|
26793
|
+
__publicField(QueryBuilder, _a133, "PgQueryBuilder");
|
26920
26794
|
}
|
26921
26795
|
});
|
26922
26796
|
|
26923
|
-
// ../drizzle-orm/dist/pg-core/query-builders/
|
26924
|
-
var
|
26925
|
-
var
|
26926
|
-
"../drizzle-orm/dist/pg-core/query-builders/
|
26797
|
+
// ../drizzle-orm/dist/pg-core/query-builders/insert.js
|
26798
|
+
var _a134, PgInsertBuilder, _a135, _b101, PgInsertBase;
|
26799
|
+
var init_insert = __esm({
|
26800
|
+
"../drizzle-orm/dist/pg-core/query-builders/insert.js"() {
|
26927
26801
|
"use strict";
|
26928
26802
|
init_entity();
|
26929
26803
|
init_query_promise();
|
26804
|
+
init_sql();
|
26805
|
+
init_table();
|
26930
26806
|
init_tracing();
|
26931
|
-
|
26932
|
-
|
26933
|
-
|
26934
|
-
|
26935
|
-
|
26936
|
-
|
26937
|
-
|
26938
|
-
});
|
26939
|
-
});
|
26807
|
+
init_utils2();
|
26808
|
+
init_query_builder2();
|
26809
|
+
_a134 = entityKind;
|
26810
|
+
PgInsertBuilder = class {
|
26811
|
+
constructor(table4, session, dialect4, withList, overridingSystemValue_) {
|
26812
|
+
__publicField(this, "authToken");
|
26813
|
+
this.table = table4;
|
26940
26814
|
this.session = session;
|
26941
26815
|
this.dialect = dialect4;
|
26942
|
-
this.
|
26816
|
+
this.withList = withList;
|
26817
|
+
this.overridingSystemValue_ = overridingSystemValue_;
|
26943
26818
|
}
|
26944
|
-
|
26945
|
-
|
26946
|
-
|
26947
|
-
}
|
26948
|
-
this.config.concurrently = true;
|
26819
|
+
/** @internal */
|
26820
|
+
setToken(token) {
|
26821
|
+
this.authToken = token;
|
26949
26822
|
return this;
|
26950
26823
|
}
|
26951
|
-
|
26952
|
-
|
26953
|
-
throw new Error("Cannot use concurrently and withNoData together");
|
26954
|
-
}
|
26955
|
-
this.config.withNoData = true;
|
26824
|
+
overridingSystemValue() {
|
26825
|
+
this.overridingSystemValue_ = true;
|
26956
26826
|
return this;
|
26957
26827
|
}
|
26958
|
-
|
26959
|
-
|
26960
|
-
|
26828
|
+
values(values) {
|
26829
|
+
values = Array.isArray(values) ? values : [values];
|
26830
|
+
if (values.length === 0) {
|
26831
|
+
throw new Error("values() must be called with at least one value");
|
26832
|
+
}
|
26833
|
+
const mappedValues = values.map((entry) => {
|
26834
|
+
const result = {};
|
26835
|
+
const cols = this.table[Table2.Symbol.Columns];
|
26836
|
+
for (const colKey of Object.keys(entry)) {
|
26837
|
+
const colValue = entry[colKey];
|
26838
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
26839
|
+
}
|
26840
|
+
return result;
|
26841
|
+
});
|
26842
|
+
return new PgInsertBase(
|
26843
|
+
this.table,
|
26844
|
+
mappedValues,
|
26845
|
+
this.session,
|
26846
|
+
this.dialect,
|
26847
|
+
this.withList,
|
26848
|
+
false,
|
26849
|
+
this.overridingSystemValue_
|
26850
|
+
).setToken(this.authToken);
|
26961
26851
|
}
|
26962
|
-
|
26963
|
-
const
|
26964
|
-
|
26852
|
+
select(selectQuery) {
|
26853
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
|
26854
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
26855
|
+
throw new Error(
|
26856
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
26857
|
+
);
|
26858
|
+
}
|
26859
|
+
return new PgInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
26965
26860
|
}
|
26966
|
-
|
26967
|
-
|
26968
|
-
|
26969
|
-
|
26861
|
+
};
|
26862
|
+
__publicField(PgInsertBuilder, _a134, "PgInsertBuilder");
|
26863
|
+
PgInsertBase = class extends (_b101 = QueryPromise, _a135 = entityKind, _b101) {
|
26864
|
+
constructor(table4, values, session, dialect4, withList, select, overridingSystemValue_) {
|
26865
|
+
super();
|
26866
|
+
__publicField(this, "config");
|
26867
|
+
__publicField(this, "authToken");
|
26868
|
+
__publicField(this, "execute", (placeholderValues) => {
|
26869
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
26870
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
26871
|
+
});
|
26970
26872
|
});
|
26873
|
+
this.session = session;
|
26874
|
+
this.dialect = dialect4;
|
26875
|
+
this.config = { table: table4, values, withList, select, overridingSystemValue_ };
|
26971
26876
|
}
|
26972
|
-
|
26973
|
-
|
26877
|
+
returning(fields = this.config.table[Table2.Symbol.Columns]) {
|
26878
|
+
this.config.returning = orderSelectedFields(fields);
|
26879
|
+
return this;
|
26974
26880
|
}
|
26975
|
-
|
26976
|
-
|
26977
|
-
|
26978
|
-
|
26979
|
-
|
26881
|
+
/**
|
26882
|
+
* Adds an `on conflict do nothing` clause to the query.
|
26883
|
+
*
|
26884
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
26885
|
+
*
|
26886
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
26887
|
+
*
|
26888
|
+
* @param config The `target` and `where` clauses.
|
26889
|
+
*
|
26890
|
+
* @example
|
26891
|
+
* ```ts
|
26892
|
+
* // Insert one row and cancel the insert if there's a conflict
|
26893
|
+
* await db.insert(cars)
|
26894
|
+
* .values({ id: 1, brand: 'BMW' })
|
26895
|
+
* .onConflictDoNothing();
|
26896
|
+
*
|
26897
|
+
* // Explicitly specify conflict target
|
26898
|
+
* await db.insert(cars)
|
26899
|
+
* .values({ id: 1, brand: 'BMW' })
|
26900
|
+
* .onConflictDoNothing({ target: cars.id });
|
26901
|
+
* ```
|
26902
|
+
*/
|
26903
|
+
onConflictDoNothing(config = {}) {
|
26904
|
+
if (config.target === void 0) {
|
26905
|
+
this.config.onConflict = sql`do nothing`;
|
26906
|
+
} else {
|
26907
|
+
let targetColumn = "";
|
26908
|
+
targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
|
26909
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
26910
|
+
this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
|
26911
|
+
}
|
26912
|
+
return this;
|
26913
|
+
}
|
26914
|
+
/**
|
26915
|
+
* Adds an `on conflict do update` clause to the query.
|
26916
|
+
*
|
26917
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
26918
|
+
*
|
26919
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
26920
|
+
*
|
26921
|
+
* @param config The `target`, `set` and `where` clauses.
|
26922
|
+
*
|
26923
|
+
* @example
|
26924
|
+
* ```ts
|
26925
|
+
* // Update the row if there's a conflict
|
26926
|
+
* await db.insert(cars)
|
26927
|
+
* .values({ id: 1, brand: 'BMW' })
|
26928
|
+
* .onConflictDoUpdate({
|
26929
|
+
* target: cars.id,
|
26930
|
+
* set: { brand: 'Porsche' }
|
26931
|
+
* });
|
26932
|
+
*
|
26933
|
+
* // Upsert with 'where' clause
|
26934
|
+
* await db.insert(cars)
|
26935
|
+
* .values({ id: 1, brand: 'BMW' })
|
26936
|
+
* .onConflictDoUpdate({
|
26937
|
+
* target: cars.id,
|
26938
|
+
* set: { brand: 'newBMW' },
|
26939
|
+
* targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
|
26940
|
+
* });
|
26941
|
+
* ```
|
26942
|
+
*/
|
26943
|
+
onConflictDoUpdate(config) {
|
26944
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
26945
|
+
throw new Error(
|
26946
|
+
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
26947
|
+
);
|
26948
|
+
}
|
26949
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
26950
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
26951
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
26952
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
26953
|
+
let targetColumn = "";
|
26954
|
+
targetColumn = Array.isArray(config.target) ? config.target.map((it) => this.dialect.escapeName(this.dialect.casing.getColumnCasing(it))).join(",") : this.dialect.escapeName(this.dialect.casing.getColumnCasing(config.target));
|
26955
|
+
this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
26956
|
+
return this;
|
26957
|
+
}
|
26958
|
+
/** @internal */
|
26959
|
+
getSQL() {
|
26960
|
+
return this.dialect.buildInsertQuery(this.config);
|
26961
|
+
}
|
26962
|
+
toSQL() {
|
26963
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
26964
|
+
return rest;
|
26965
|
+
}
|
26966
|
+
/** @internal */
|
26967
|
+
_prepare(name2) {
|
26968
|
+
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
26969
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
|
26970
|
+
});
|
26971
|
+
}
|
26972
|
+
prepare(name2) {
|
26973
|
+
return this._prepare(name2);
|
26974
|
+
}
|
26975
|
+
/** @internal */
|
26976
|
+
setToken(token) {
|
26977
|
+
this.authToken = token;
|
26978
|
+
return this;
|
26979
|
+
}
|
26980
|
+
$dynamic() {
|
26981
|
+
return this;
|
26982
|
+
}
|
26983
|
+
};
|
26984
|
+
__publicField(PgInsertBase, _a135, "PgInsert");
|
26985
|
+
}
|
26986
|
+
});
|
26987
|
+
|
26988
|
+
// ../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js
|
26989
|
+
var _a136, _b102, PgRefreshMaterializedView;
|
26990
|
+
var init_refresh_materialized_view = __esm({
|
26991
|
+
"../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js"() {
|
26992
|
+
"use strict";
|
26993
|
+
init_entity();
|
26994
|
+
init_query_promise();
|
26995
|
+
init_tracing();
|
26996
|
+
PgRefreshMaterializedView = class extends (_b102 = QueryPromise, _a136 = entityKind, _b102) {
|
26997
|
+
constructor(view4, session, dialect4) {
|
26998
|
+
super();
|
26999
|
+
__publicField(this, "config");
|
27000
|
+
__publicField(this, "authToken");
|
27001
|
+
__publicField(this, "execute", (placeholderValues) => {
|
27002
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
27003
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
27004
|
+
});
|
27005
|
+
});
|
27006
|
+
this.session = session;
|
27007
|
+
this.dialect = dialect4;
|
27008
|
+
this.config = { view: view4 };
|
27009
|
+
}
|
27010
|
+
concurrently() {
|
27011
|
+
if (this.config.withNoData !== void 0) {
|
27012
|
+
throw new Error("Cannot use concurrently and withNoData together");
|
27013
|
+
}
|
27014
|
+
this.config.concurrently = true;
|
27015
|
+
return this;
|
27016
|
+
}
|
27017
|
+
withNoData() {
|
27018
|
+
if (this.config.concurrently !== void 0) {
|
27019
|
+
throw new Error("Cannot use concurrently and withNoData together");
|
27020
|
+
}
|
27021
|
+
this.config.withNoData = true;
|
27022
|
+
return this;
|
27023
|
+
}
|
27024
|
+
/** @internal */
|
27025
|
+
getSQL() {
|
27026
|
+
return this.dialect.buildRefreshMaterializedViewQuery(this.config);
|
27027
|
+
}
|
27028
|
+
toSQL() {
|
27029
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
27030
|
+
return rest;
|
27031
|
+
}
|
27032
|
+
/** @internal */
|
27033
|
+
_prepare(name2) {
|
27034
|
+
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
27035
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), void 0, name2, true);
|
27036
|
+
});
|
27037
|
+
}
|
27038
|
+
prepare(name2) {
|
27039
|
+
return this._prepare(name2);
|
27040
|
+
}
|
27041
|
+
/** @internal */
|
27042
|
+
setToken(token) {
|
27043
|
+
this.authToken = token;
|
27044
|
+
return this;
|
27045
|
+
}
|
27046
|
+
};
|
27047
|
+
__publicField(PgRefreshMaterializedView, _a136, "PgRefreshMaterializedView");
|
27048
|
+
}
|
27049
|
+
});
|
27050
|
+
|
26980
27051
|
// ../drizzle-orm/dist/pg-core/query-builders/select.types.js
|
26981
27052
|
var init_select_types = __esm({
|
26982
27053
|
"../drizzle-orm/dist/pg-core/query-builders/select.types.js"() {
|
@@ -27001,11 +27072,16 @@ var init_update = __esm({
|
|
27001
27072
|
_a137 = entityKind;
|
27002
27073
|
PgUpdateBuilder = class {
|
27003
27074
|
constructor(table4, session, dialect4, withList) {
|
27075
|
+
__publicField(this, "authToken");
|
27004
27076
|
this.table = table4;
|
27005
27077
|
this.session = session;
|
27006
27078
|
this.dialect = dialect4;
|
27007
27079
|
this.withList = withList;
|
27008
27080
|
}
|
27081
|
+
setToken(token) {
|
27082
|
+
this.authToken = token;
|
27083
|
+
return this;
|
27084
|
+
}
|
27009
27085
|
set(values) {
|
27010
27086
|
return new PgUpdateBase(
|
27011
27087
|
this.table,
|
@@ -27013,7 +27089,7 @@ var init_update = __esm({
|
|
27013
27089
|
this.session,
|
27014
27090
|
this.dialect,
|
27015
27091
|
this.withList
|
27016
|
-
);
|
27092
|
+
).setToken(this.authToken);
|
27017
27093
|
}
|
27018
27094
|
};
|
27019
27095
|
__publicField(PgUpdateBuilder, _a137, "PgUpdateBuilder");
|
@@ -27027,8 +27103,9 @@ var init_update = __esm({
|
|
27027
27103
|
__publicField(this, "rightJoin", this.createJoin("right"));
|
27028
27104
|
__publicField(this, "innerJoin", this.createJoin("inner"));
|
27029
27105
|
__publicField(this, "fullJoin", this.createJoin("full"));
|
27106
|
+
__publicField(this, "authToken");
|
27030
27107
|
__publicField(this, "execute", (placeholderValues) => {
|
27031
|
-
return this._prepare().execute(placeholderValues);
|
27108
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
27032
27109
|
});
|
27033
27110
|
this.session = session;
|
27034
27111
|
this.dialect = dialect4;
|
@@ -27176,6 +27253,11 @@ var init_update = __esm({
|
|
27176
27253
|
prepare(name2) {
|
27177
27254
|
return this._prepare(name2);
|
27178
27255
|
}
|
27256
|
+
/** @internal */
|
27257
|
+
setToken(token) {
|
27258
|
+
this.authToken = token;
|
27259
|
+
return this;
|
27260
|
+
}
|
27179
27261
|
$dynamic() {
|
27180
27262
|
return this;
|
27181
27263
|
}
|
@@ -27209,6 +27291,7 @@ var init_count = __esm({
|
|
27209
27291
|
constructor(params) {
|
27210
27292
|
super(_PgCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
|
27211
27293
|
__publicField(this, "sql");
|
27294
|
+
__publicField(this, "token");
|
27212
27295
|
__publicField(this, _a139, "PgCountBuilder");
|
27213
27296
|
__publicField(this, "session");
|
27214
27297
|
this.params = params;
|
@@ -27225,8 +27308,13 @@ var init_count = __esm({
|
|
27225
27308
|
static buildCount(source, filters) {
|
27226
27309
|
return sql`select count(*) as count from ${source}${sql.raw(" where ").if(filters)}${filters};`;
|
27227
27310
|
}
|
27311
|
+
/** @intrnal */
|
27312
|
+
setToken(token) {
|
27313
|
+
this.token = token;
|
27314
|
+
return this;
|
27315
|
+
}
|
27228
27316
|
then(onfulfilled, onrejected) {
|
27229
|
-
return Promise.resolve(this.session.count(this.sql)).then(
|
27317
|
+
return Promise.resolve(this.session.count(this.sql, this.token)).then(
|
27230
27318
|
onfulfilled,
|
27231
27319
|
onrejected
|
27232
27320
|
);
|
@@ -27303,6 +27391,7 @@ var init_query = __esm({
|
|
27303
27391
|
PgRelationalQuery = class extends (_b105 = QueryPromise, _a141 = entityKind, _b105) {
|
27304
27392
|
constructor(fullSchema, schema4, tableNamesMap, table4, tableConfig, dialect4, session, config, mode) {
|
27305
27393
|
super();
|
27394
|
+
__publicField(this, "authToken");
|
27306
27395
|
this.fullSchema = fullSchema;
|
27307
27396
|
this.schema = schema4;
|
27308
27397
|
this.tableNamesMap = tableNamesMap;
|
@@ -27360,9 +27449,14 @@ var init_query = __esm({
|
|
27360
27449
|
toSQL() {
|
27361
27450
|
return this._toSQL().builtQuery;
|
27362
27451
|
}
|
27452
|
+
/** @internal */
|
27453
|
+
setToken(token) {
|
27454
|
+
this.authToken = token;
|
27455
|
+
return this;
|
27456
|
+
}
|
27363
27457
|
execute() {
|
27364
27458
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
27365
|
-
return this._prepare().execute();
|
27459
|
+
return this._prepare().execute(void 0, this.authToken);
|
27366
27460
|
});
|
27367
27461
|
}
|
27368
27462
|
};
|
@@ -27425,6 +27519,7 @@ var init_db = __esm({
|
|
27425
27519
|
PgDatabase = class {
|
27426
27520
|
constructor(dialect4, session, schema4) {
|
27427
27521
|
__publicField(this, "query");
|
27522
|
+
__publicField(this, "authToken");
|
27428
27523
|
this.dialect = dialect4;
|
27429
27524
|
this.session = session;
|
27430
27525
|
this._ = schema4 ? {
|
@@ -27680,7 +27775,7 @@ var init_db = __esm({
|
|
27680
27775
|
false
|
27681
27776
|
);
|
27682
27777
|
return new PgRaw(
|
27683
|
-
() => prepared.execute(),
|
27778
|
+
() => prepared.execute(void 0, this.authToken),
|
27684
27779
|
sequel,
|
27685
27780
|
builtQuery,
|
27686
27781
|
(result) => prepared.mapResult(result, true)
|
@@ -28225,6 +28320,7 @@ var init_session = __esm({
|
|
28225
28320
|
_a159 = entityKind;
|
28226
28321
|
PgPreparedQuery = class {
|
28227
28322
|
constructor(query) {
|
28323
|
+
__publicField(this, "authToken");
|
28228
28324
|
/** @internal */
|
28229
28325
|
__publicField(this, "joinsNotNullableMap");
|
28230
28326
|
this.query = query;
|
@@ -28235,6 +28331,11 @@ var init_session = __esm({
|
|
28235
28331
|
mapResult(response, _isFromBatch) {
|
28236
28332
|
return response;
|
28237
28333
|
}
|
28334
|
+
/** @internal */
|
28335
|
+
setToken(token) {
|
28336
|
+
this.authToken = token;
|
28337
|
+
return this;
|
28338
|
+
}
|
28238
28339
|
};
|
28239
28340
|
__publicField(PgPreparedQuery, _a159, "PgPreparedQuery");
|
28240
28341
|
_a160 = entityKind;
|
@@ -28242,7 +28343,8 @@ var init_session = __esm({
|
|
28242
28343
|
constructor(dialect4) {
|
28243
28344
|
this.dialect = dialect4;
|
28244
28345
|
}
|
28245
|
-
|
28346
|
+
/** @internal */
|
28347
|
+
execute(query, token) {
|
28246
28348
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
28247
28349
|
const prepared = tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
28248
28350
|
return this.prepareQuery(
|
@@ -28252,7 +28354,7 @@ var init_session = __esm({
|
|
28252
28354
|
false
|
28253
28355
|
);
|
28254
28356
|
});
|
28255
|
-
return prepared.execute();
|
28357
|
+
return prepared.setToken(token).execute(void 0, token);
|
28256
28358
|
});
|
28257
28359
|
}
|
28258
28360
|
all(query) {
|
@@ -28263,8 +28365,9 @@ var init_session = __esm({
|
|
28263
28365
|
false
|
28264
28366
|
).all();
|
28265
28367
|
}
|
28266
|
-
|
28267
|
-
|
28368
|
+
/** @internal */
|
28369
|
+
async count(sql2, token) {
|
28370
|
+
const res = await this.execute(sql2, token);
|
28268
28371
|
return Number(
|
28269
28372
|
res[0]["count"]
|
28270
28373
|
);
|
@@ -30932,235 +31035,67 @@ var init_delete2 = __esm({
|
|
30932
31035
|
}
|
30933
31036
|
});
|
30934
31037
|
|
30935
|
-
// ../drizzle-orm/dist/sqlite-core/
|
30936
|
-
var _a197,
|
30937
|
-
var
|
30938
|
-
"../drizzle-orm/dist/sqlite-core/
|
31038
|
+
// ../drizzle-orm/dist/sqlite-core/view-base.js
|
31039
|
+
var _a197, _b142, SQLiteViewBase;
|
31040
|
+
var init_view_base2 = __esm({
|
31041
|
+
"../drizzle-orm/dist/sqlite-core/view-base.js"() {
|
30939
31042
|
"use strict";
|
30940
31043
|
init_entity();
|
30941
|
-
init_query_promise();
|
30942
31044
|
init_sql();
|
31045
|
+
SQLiteViewBase = class extends (_b142 = View3, _a197 = entityKind, _b142) {
|
31046
|
+
};
|
31047
|
+
__publicField(SQLiteViewBase, _a197, "SQLiteViewBase");
|
31048
|
+
}
|
31049
|
+
});
|
31050
|
+
|
31051
|
+
// ../drizzle-orm/dist/sqlite-core/dialect.js
|
31052
|
+
var _a198, SQLiteDialect, _a199, _b143, SQLiteSyncDialect, _a200, _b144, SQLiteAsyncDialect;
|
31053
|
+
var init_dialect2 = __esm({
|
31054
|
+
"../drizzle-orm/dist/sqlite-core/dialect.js"() {
|
31055
|
+
"use strict";
|
31056
|
+
init_alias();
|
31057
|
+
init_casing();
|
31058
|
+
init_column();
|
31059
|
+
init_entity();
|
31060
|
+
init_errors();
|
31061
|
+
init_relations();
|
31062
|
+
init_sql2();
|
31063
|
+
init_sql();
|
31064
|
+
init_columns2();
|
30943
31065
|
init_table3();
|
31066
|
+
init_subquery();
|
30944
31067
|
init_table();
|
30945
31068
|
init_utils2();
|
30946
|
-
|
30947
|
-
|
30948
|
-
|
30949
|
-
|
30950
|
-
|
30951
|
-
|
30952
|
-
this
|
31069
|
+
init_view_common();
|
31070
|
+
init_view_base2();
|
31071
|
+
_a198 = entityKind;
|
31072
|
+
SQLiteDialect = class {
|
31073
|
+
constructor(config) {
|
31074
|
+
/** @internal */
|
31075
|
+
__publicField(this, "casing");
|
31076
|
+
this.casing = new CasingCache(config?.casing);
|
30953
31077
|
}
|
30954
|
-
|
30955
|
-
|
30956
|
-
|
30957
|
-
|
30958
|
-
|
30959
|
-
|
30960
|
-
|
30961
|
-
|
30962
|
-
|
30963
|
-
|
30964
|
-
|
31078
|
+
escapeName(name2) {
|
31079
|
+
return `"${name2}"`;
|
31080
|
+
}
|
31081
|
+
escapeParam(_num) {
|
31082
|
+
return "?";
|
31083
|
+
}
|
31084
|
+
escapeString(str) {
|
31085
|
+
return `'${str.replace(/'/g, "''")}'`;
|
31086
|
+
}
|
31087
|
+
buildWithCTE(queries) {
|
31088
|
+
if (!queries?.length)
|
31089
|
+
return void 0;
|
31090
|
+
const withSqlChunks = [sql`with `];
|
31091
|
+
for (const [i, w] of queries.entries()) {
|
31092
|
+
withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
|
31093
|
+
if (i < queries.length - 1) {
|
31094
|
+
withSqlChunks.push(sql`, `);
|
30965
31095
|
}
|
30966
|
-
|
30967
|
-
|
30968
|
-
return
|
30969
|
-
}
|
30970
|
-
};
|
30971
|
-
__publicField(SQLiteInsertBuilder, _a197, "SQLiteInsertBuilder");
|
30972
|
-
SQLiteInsertBase = class extends (_b142 = QueryPromise, _a198 = entityKind, _b142) {
|
30973
|
-
constructor(table4, values, session, dialect4, withList) {
|
30974
|
-
super();
|
30975
|
-
/** @internal */
|
30976
|
-
__publicField(this, "config");
|
30977
|
-
__publicField(this, "run", (placeholderValues) => {
|
30978
|
-
return this._prepare().run(placeholderValues);
|
30979
|
-
});
|
30980
|
-
__publicField(this, "all", (placeholderValues) => {
|
30981
|
-
return this._prepare().all(placeholderValues);
|
30982
|
-
});
|
30983
|
-
__publicField(this, "get", (placeholderValues) => {
|
30984
|
-
return this._prepare().get(placeholderValues);
|
30985
|
-
});
|
30986
|
-
__publicField(this, "values", (placeholderValues) => {
|
30987
|
-
return this._prepare().values(placeholderValues);
|
30988
|
-
});
|
30989
|
-
this.session = session;
|
30990
|
-
this.dialect = dialect4;
|
30991
|
-
this.config = { table: table4, values, withList };
|
30992
|
-
}
|
30993
|
-
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
30994
|
-
this.config.returning = orderSelectedFields(fields);
|
30995
|
-
return this;
|
30996
|
-
}
|
30997
|
-
/**
|
30998
|
-
* Adds an `on conflict do nothing` clause to the query.
|
30999
|
-
*
|
31000
|
-
* Calling this method simply avoids inserting a row as its alternative action.
|
31001
|
-
*
|
31002
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
31003
|
-
*
|
31004
|
-
* @param config The `target` and `where` clauses.
|
31005
|
-
*
|
31006
|
-
* @example
|
31007
|
-
* ```ts
|
31008
|
-
* // Insert one row and cancel the insert if there's a conflict
|
31009
|
-
* await db.insert(cars)
|
31010
|
-
* .values({ id: 1, brand: 'BMW' })
|
31011
|
-
* .onConflictDoNothing();
|
31012
|
-
*
|
31013
|
-
* // Explicitly specify conflict target
|
31014
|
-
* await db.insert(cars)
|
31015
|
-
* .values({ id: 1, brand: 'BMW' })
|
31016
|
-
* .onConflictDoNothing({ target: cars.id });
|
31017
|
-
* ```
|
31018
|
-
*/
|
31019
|
-
onConflictDoNothing(config = {}) {
|
31020
|
-
if (config.target === void 0) {
|
31021
|
-
this.config.onConflict = sql`do nothing`;
|
31022
|
-
} else {
|
31023
|
-
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
31024
|
-
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
31025
|
-
this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
|
31026
|
-
}
|
31027
|
-
return this;
|
31028
|
-
}
|
31029
|
-
/**
|
31030
|
-
* Adds an `on conflict do update` clause to the query.
|
31031
|
-
*
|
31032
|
-
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
31033
|
-
*
|
31034
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
31035
|
-
*
|
31036
|
-
* @param config The `target`, `set` and `where` clauses.
|
31037
|
-
*
|
31038
|
-
* @example
|
31039
|
-
* ```ts
|
31040
|
-
* // Update the row if there's a conflict
|
31041
|
-
* await db.insert(cars)
|
31042
|
-
* .values({ id: 1, brand: 'BMW' })
|
31043
|
-
* .onConflictDoUpdate({
|
31044
|
-
* target: cars.id,
|
31045
|
-
* set: { brand: 'Porsche' }
|
31046
|
-
* });
|
31047
|
-
*
|
31048
|
-
* // Upsert with 'where' clause
|
31049
|
-
* await db.insert(cars)
|
31050
|
-
* .values({ id: 1, brand: 'BMW' })
|
31051
|
-
* .onConflictDoUpdate({
|
31052
|
-
* target: cars.id,
|
31053
|
-
* set: { brand: 'newBMW' },
|
31054
|
-
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
31055
|
-
* });
|
31056
|
-
* ```
|
31057
|
-
*/
|
31058
|
-
onConflictDoUpdate(config) {
|
31059
|
-
if (config.where && (config.targetWhere || config.setWhere)) {
|
31060
|
-
throw new Error(
|
31061
|
-
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
31062
|
-
);
|
31063
|
-
}
|
31064
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
31065
|
-
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
31066
|
-
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
31067
|
-
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
31068
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
31069
|
-
this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
31070
|
-
return this;
|
31071
|
-
}
|
31072
|
-
/** @internal */
|
31073
|
-
getSQL() {
|
31074
|
-
return this.dialect.buildInsertQuery(this.config);
|
31075
|
-
}
|
31076
|
-
toSQL() {
|
31077
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
31078
|
-
return rest;
|
31079
|
-
}
|
31080
|
-
/** @internal */
|
31081
|
-
_prepare(isOneTimeQuery = true) {
|
31082
|
-
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
31083
|
-
this.dialect.sqlToQuery(this.getSQL()),
|
31084
|
-
this.config.returning,
|
31085
|
-
this.config.returning ? "all" : "run",
|
31086
|
-
true
|
31087
|
-
);
|
31088
|
-
}
|
31089
|
-
prepare() {
|
31090
|
-
return this._prepare(false);
|
31091
|
-
}
|
31092
|
-
async execute() {
|
31093
|
-
return this.config.returning ? this.all() : this.run();
|
31094
|
-
}
|
31095
|
-
$dynamic() {
|
31096
|
-
return this;
|
31097
|
-
}
|
31098
|
-
};
|
31099
|
-
__publicField(SQLiteInsertBase, _a198, "SQLiteInsert");
|
31100
|
-
}
|
31101
|
-
});
|
31102
|
-
|
31103
|
-
// ../drizzle-orm/dist/sqlite-core/view-base.js
|
31104
|
-
var _a199, _b143, SQLiteViewBase;
|
31105
|
-
var init_view_base2 = __esm({
|
31106
|
-
"../drizzle-orm/dist/sqlite-core/view-base.js"() {
|
31107
|
-
"use strict";
|
31108
|
-
init_entity();
|
31109
|
-
init_sql();
|
31110
|
-
SQLiteViewBase = class extends (_b143 = View3, _a199 = entityKind, _b143) {
|
31111
|
-
};
|
31112
|
-
__publicField(SQLiteViewBase, _a199, "SQLiteViewBase");
|
31113
|
-
}
|
31114
|
-
});
|
31115
|
-
|
31116
|
-
// ../drizzle-orm/dist/sqlite-core/dialect.js
|
31117
|
-
var _a200, SQLiteDialect, _a201, _b144, SQLiteSyncDialect, _a202, _b145, SQLiteAsyncDialect;
|
31118
|
-
var init_dialect2 = __esm({
|
31119
|
-
"../drizzle-orm/dist/sqlite-core/dialect.js"() {
|
31120
|
-
"use strict";
|
31121
|
-
init_alias();
|
31122
|
-
init_casing();
|
31123
|
-
init_column();
|
31124
|
-
init_entity();
|
31125
|
-
init_errors();
|
31126
|
-
init_relations();
|
31127
|
-
init_sql2();
|
31128
|
-
init_sql();
|
31129
|
-
init_columns2();
|
31130
|
-
init_table3();
|
31131
|
-
init_subquery();
|
31132
|
-
init_table();
|
31133
|
-
init_utils2();
|
31134
|
-
init_view_common();
|
31135
|
-
init_view_base2();
|
31136
|
-
_a200 = entityKind;
|
31137
|
-
SQLiteDialect = class {
|
31138
|
-
constructor(config) {
|
31139
|
-
/** @internal */
|
31140
|
-
__publicField(this, "casing");
|
31141
|
-
this.casing = new CasingCache(config?.casing);
|
31142
|
-
}
|
31143
|
-
escapeName(name2) {
|
31144
|
-
return `"${name2}"`;
|
31145
|
-
}
|
31146
|
-
escapeParam(_num) {
|
31147
|
-
return "?";
|
31148
|
-
}
|
31149
|
-
escapeString(str) {
|
31150
|
-
return `'${str.replace(/'/g, "''")}'`;
|
31151
|
-
}
|
31152
|
-
buildWithCTE(queries) {
|
31153
|
-
if (!queries?.length)
|
31154
|
-
return void 0;
|
31155
|
-
const withSqlChunks = [sql`with `];
|
31156
|
-
for (const [i, w] of queries.entries()) {
|
31157
|
-
withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
|
31158
|
-
if (i < queries.length - 1) {
|
31159
|
-
withSqlChunks.push(sql`, `);
|
31160
|
-
}
|
31161
|
-
}
|
31162
|
-
withSqlChunks.push(sql` `);
|
31163
|
-
return sql.join(withSqlChunks);
|
31096
|
+
}
|
31097
|
+
withSqlChunks.push(sql` `);
|
31098
|
+
return sql.join(withSqlChunks);
|
31164
31099
|
}
|
31165
31100
|
buildDeleteQuery({ table: table4, where, returning, withList, limit, orderBy }) {
|
31166
31101
|
const withSql = this.buildWithCTE(withList);
|
@@ -31397,45 +31332,56 @@ var init_dialect2 = __esm({
|
|
31397
31332
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
31398
31333
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
31399
31334
|
}
|
31400
|
-
buildInsertQuery({ table: table4, values, onConflict, returning, withList }) {
|
31335
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, onConflict, returning, withList, select }) {
|
31401
31336
|
const valuesSqlList = [];
|
31402
31337
|
const columns = table4[Table2.Symbol.Columns];
|
31403
31338
|
const colEntries = Object.entries(columns).filter(
|
31404
31339
|
([_2, col]) => !col.shouldDisableInsert()
|
31405
31340
|
);
|
31406
31341
|
const insertOrder = colEntries.map(([, column4]) => sql.identifier(this.casing.getColumnCasing(column4)));
|
31407
|
-
|
31408
|
-
const
|
31409
|
-
|
31410
|
-
|
31411
|
-
|
31412
|
-
|
31413
|
-
|
31414
|
-
|
31415
|
-
|
31416
|
-
|
31417
|
-
|
31418
|
-
|
31419
|
-
|
31420
|
-
|
31342
|
+
if (select) {
|
31343
|
+
const select2 = valuesOrSelect;
|
31344
|
+
if (is(select2, SQL)) {
|
31345
|
+
valuesSqlList.push(select2);
|
31346
|
+
} else {
|
31347
|
+
valuesSqlList.push(select2.getSQL());
|
31348
|
+
}
|
31349
|
+
} else {
|
31350
|
+
const values = valuesOrSelect;
|
31351
|
+
valuesSqlList.push(sql.raw("values "));
|
31352
|
+
for (const [valueIndex, value] of values.entries()) {
|
31353
|
+
const valueList = [];
|
31354
|
+
for (const [fieldName, col] of colEntries) {
|
31355
|
+
const colValue = value[fieldName];
|
31356
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
31357
|
+
let defaultValue;
|
31358
|
+
if (col.default !== null && col.default !== void 0) {
|
31359
|
+
defaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);
|
31360
|
+
} else if (col.defaultFn !== void 0) {
|
31361
|
+
const defaultFnResult = col.defaultFn();
|
31362
|
+
defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
31363
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
31364
|
+
const onUpdateFnResult = col.onUpdateFn();
|
31365
|
+
defaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
31366
|
+
} else {
|
31367
|
+
defaultValue = sql`null`;
|
31368
|
+
}
|
31369
|
+
valueList.push(defaultValue);
|
31421
31370
|
} else {
|
31422
|
-
|
31371
|
+
valueList.push(colValue);
|
31423
31372
|
}
|
31424
|
-
valueList.push(defaultValue);
|
31425
|
-
} else {
|
31426
|
-
valueList.push(colValue);
|
31427
31373
|
}
|
31428
|
-
|
31429
|
-
|
31430
|
-
|
31431
|
-
|
31374
|
+
valuesSqlList.push(valueList);
|
31375
|
+
if (valueIndex < values.length - 1) {
|
31376
|
+
valuesSqlList.push(sql`, `);
|
31377
|
+
}
|
31432
31378
|
}
|
31433
31379
|
}
|
31434
31380
|
const withSql = this.buildWithCTE(withList);
|
31435
31381
|
const valuesSql = sql.join(valuesSqlList);
|
31436
31382
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
31437
31383
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
31438
|
-
return sql`${withSql}insert into ${table4} ${insertOrder}
|
31384
|
+
return sql`${withSql}insert into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;
|
31439
31385
|
}
|
31440
31386
|
sqlToQuery(sql2, invokeSource) {
|
31441
31387
|
return sql2.toQuery({
|
@@ -31664,8 +31610,8 @@ var init_dialect2 = __esm({
|
|
31664
31610
|
};
|
31665
31611
|
}
|
31666
31612
|
};
|
31667
|
-
__publicField(SQLiteDialect,
|
31668
|
-
SQLiteSyncDialect = class extends (
|
31613
|
+
__publicField(SQLiteDialect, _a198, "SQLiteDialect");
|
31614
|
+
SQLiteSyncDialect = class extends (_b143 = SQLiteDialect, _a199 = entityKind, _b143) {
|
31669
31615
|
migrate(migrations, session, config) {
|
31670
31616
|
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
31671
31617
|
const migrationTableCreate = sql`
|
@@ -31699,8 +31645,8 @@ var init_dialect2 = __esm({
|
|
31699
31645
|
}
|
31700
31646
|
}
|
31701
31647
|
};
|
31702
|
-
__publicField(SQLiteSyncDialect,
|
31703
|
-
SQLiteAsyncDialect = class extends (
|
31648
|
+
__publicField(SQLiteSyncDialect, _a199, "SQLiteSyncDialect");
|
31649
|
+
SQLiteAsyncDialect = class extends (_b144 = SQLiteDialect, _a200 = entityKind, _b144) {
|
31704
31650
|
async migrate(migrations, session, config) {
|
31705
31651
|
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
31706
31652
|
const migrationTableCreate = sql`
|
@@ -31729,7 +31675,7 @@ var init_dialect2 = __esm({
|
|
31729
31675
|
});
|
31730
31676
|
}
|
31731
31677
|
};
|
31732
|
-
__publicField(SQLiteAsyncDialect,
|
31678
|
+
__publicField(SQLiteAsyncDialect, _a200, "SQLiteAsyncDialect");
|
31733
31679
|
}
|
31734
31680
|
});
|
31735
31681
|
|
@@ -31751,7 +31697,7 @@ function createSetOperator2(type, isAll) {
|
|
31751
31697
|
return leftSelect.addSetOperators(setOperators);
|
31752
31698
|
};
|
31753
31699
|
}
|
31754
|
-
var
|
31700
|
+
var _a201, SQLiteSelectBuilder, _a202, _b145, SQLiteSelectQueryBuilderBase, _a203, _b146, SQLiteSelectBase, getSQLiteSetOperators, union2, unionAll2, intersect2, except2;
|
31755
31701
|
var init_select3 = __esm({
|
31756
31702
|
"../drizzle-orm/dist/sqlite-core/query-builders/select.js"() {
|
31757
31703
|
"use strict";
|
@@ -31765,7 +31711,7 @@ var init_select3 = __esm({
|
|
31765
31711
|
init_utils2();
|
31766
31712
|
init_view_common();
|
31767
31713
|
init_view_base2();
|
31768
|
-
|
31714
|
+
_a201 = entityKind;
|
31769
31715
|
SQLiteSelectBuilder = class {
|
31770
31716
|
constructor(config) {
|
31771
31717
|
__publicField(this, "fields");
|
@@ -31806,8 +31752,8 @@ var init_select3 = __esm({
|
|
31806
31752
|
});
|
31807
31753
|
}
|
31808
31754
|
};
|
31809
|
-
__publicField(SQLiteSelectBuilder,
|
31810
|
-
SQLiteSelectQueryBuilderBase = class extends (
|
31755
|
+
__publicField(SQLiteSelectBuilder, _a201, "SQLiteSelectBuilder");
|
31756
|
+
SQLiteSelectQueryBuilderBase = class extends (_b145 = TypedQueryBuilder, _a202 = entityKind, _b145) {
|
31811
31757
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
31812
31758
|
super();
|
31813
31759
|
__publicField(this, "_");
|
@@ -32312,8 +32258,8 @@ var init_select3 = __esm({
|
|
32312
32258
|
return this;
|
32313
32259
|
}
|
32314
32260
|
};
|
32315
|
-
__publicField(SQLiteSelectQueryBuilderBase,
|
32316
|
-
SQLiteSelectBase = class extends (
|
32261
|
+
__publicField(SQLiteSelectQueryBuilderBase, _a202, "SQLiteSelectQueryBuilder");
|
32262
|
+
SQLiteSelectBase = class extends (_b146 = SQLiteSelectQueryBuilderBase, _a203 = entityKind, _b146) {
|
32317
32263
|
constructor() {
|
32318
32264
|
super(...arguments);
|
32319
32265
|
__publicField(this, "run", (placeholderValues) => {
|
@@ -32351,7 +32297,7 @@ var init_select3 = __esm({
|
|
32351
32297
|
return this.all();
|
32352
32298
|
}
|
32353
32299
|
};
|
32354
|
-
__publicField(SQLiteSelectBase,
|
32300
|
+
__publicField(SQLiteSelectBase, _a203, "SQLiteSelect");
|
32355
32301
|
applyMixins(SQLiteSelectBase, [QueryPromise]);
|
32356
32302
|
getSQLiteSetOperators = () => ({
|
32357
32303
|
union: union2,
|
@@ -32367,7 +32313,7 @@ var init_select3 = __esm({
|
|
32367
32313
|
});
|
32368
32314
|
|
32369
32315
|
// ../drizzle-orm/dist/sqlite-core/query-builders/query-builder.js
|
32370
|
-
var
|
32316
|
+
var _a204, QueryBuilder2;
|
32371
32317
|
var init_query_builder3 = __esm({
|
32372
32318
|
"../drizzle-orm/dist/sqlite-core/query-builders/query-builder.js"() {
|
32373
32319
|
"use strict";
|
@@ -32376,7 +32322,7 @@ var init_query_builder3 = __esm({
|
|
32376
32322
|
init_dialect2();
|
32377
32323
|
init_subquery();
|
32378
32324
|
init_select3();
|
32379
|
-
|
32325
|
+
_a204 = entityKind;
|
32380
32326
|
QueryBuilder2 = class {
|
32381
32327
|
constructor(dialect4) {
|
32382
32328
|
__publicField(this, "dialect");
|
@@ -32438,7 +32384,185 @@ var init_query_builder3 = __esm({
|
|
32438
32384
|
return this.dialect;
|
32439
32385
|
}
|
32440
32386
|
};
|
32441
|
-
__publicField(QueryBuilder2,
|
32387
|
+
__publicField(QueryBuilder2, _a204, "SQLiteQueryBuilder");
|
32388
|
+
}
|
32389
|
+
});
|
32390
|
+
|
32391
|
+
// ../drizzle-orm/dist/sqlite-core/query-builders/insert.js
|
32392
|
+
var _a205, SQLiteInsertBuilder, _a206, _b147, SQLiteInsertBase;
|
32393
|
+
var init_insert2 = __esm({
|
32394
|
+
"../drizzle-orm/dist/sqlite-core/query-builders/insert.js"() {
|
32395
|
+
"use strict";
|
32396
|
+
init_entity();
|
32397
|
+
init_query_promise();
|
32398
|
+
init_sql();
|
32399
|
+
init_table3();
|
32400
|
+
init_table();
|
32401
|
+
init_utils2();
|
32402
|
+
init_query_builder3();
|
32403
|
+
_a205 = entityKind;
|
32404
|
+
SQLiteInsertBuilder = class {
|
32405
|
+
constructor(table4, session, dialect4, withList) {
|
32406
|
+
this.table = table4;
|
32407
|
+
this.session = session;
|
32408
|
+
this.dialect = dialect4;
|
32409
|
+
this.withList = withList;
|
32410
|
+
}
|
32411
|
+
values(values) {
|
32412
|
+
values = Array.isArray(values) ? values : [values];
|
32413
|
+
if (values.length === 0) {
|
32414
|
+
throw new Error("values() must be called with at least one value");
|
32415
|
+
}
|
32416
|
+
const mappedValues = values.map((entry) => {
|
32417
|
+
const result = {};
|
32418
|
+
const cols = this.table[Table2.Symbol.Columns];
|
32419
|
+
for (const colKey of Object.keys(entry)) {
|
32420
|
+
const colValue = entry[colKey];
|
32421
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
32422
|
+
}
|
32423
|
+
return result;
|
32424
|
+
});
|
32425
|
+
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
32426
|
+
}
|
32427
|
+
select(selectQuery) {
|
32428
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder2()) : selectQuery;
|
32429
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
32430
|
+
throw new Error(
|
32431
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
32432
|
+
);
|
32433
|
+
}
|
32434
|
+
return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
32435
|
+
}
|
32436
|
+
};
|
32437
|
+
__publicField(SQLiteInsertBuilder, _a205, "SQLiteInsertBuilder");
|
32438
|
+
SQLiteInsertBase = class extends (_b147 = QueryPromise, _a206 = entityKind, _b147) {
|
32439
|
+
constructor(table4, values, session, dialect4, withList, select) {
|
32440
|
+
super();
|
32441
|
+
/** @internal */
|
32442
|
+
__publicField(this, "config");
|
32443
|
+
__publicField(this, "run", (placeholderValues) => {
|
32444
|
+
return this._prepare().run(placeholderValues);
|
32445
|
+
});
|
32446
|
+
__publicField(this, "all", (placeholderValues) => {
|
32447
|
+
return this._prepare().all(placeholderValues);
|
32448
|
+
});
|
32449
|
+
__publicField(this, "get", (placeholderValues) => {
|
32450
|
+
return this._prepare().get(placeholderValues);
|
32451
|
+
});
|
32452
|
+
__publicField(this, "values", (placeholderValues) => {
|
32453
|
+
return this._prepare().values(placeholderValues);
|
32454
|
+
});
|
32455
|
+
this.session = session;
|
32456
|
+
this.dialect = dialect4;
|
32457
|
+
this.config = { table: table4, values, withList, select };
|
32458
|
+
}
|
32459
|
+
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
32460
|
+
this.config.returning = orderSelectedFields(fields);
|
32461
|
+
return this;
|
32462
|
+
}
|
32463
|
+
/**
|
32464
|
+
* Adds an `on conflict do nothing` clause to the query.
|
32465
|
+
*
|
32466
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
32467
|
+
*
|
32468
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
32469
|
+
*
|
32470
|
+
* @param config The `target` and `where` clauses.
|
32471
|
+
*
|
32472
|
+
* @example
|
32473
|
+
* ```ts
|
32474
|
+
* // Insert one row and cancel the insert if there's a conflict
|
32475
|
+
* await db.insert(cars)
|
32476
|
+
* .values({ id: 1, brand: 'BMW' })
|
32477
|
+
* .onConflictDoNothing();
|
32478
|
+
*
|
32479
|
+
* // Explicitly specify conflict target
|
32480
|
+
* await db.insert(cars)
|
32481
|
+
* .values({ id: 1, brand: 'BMW' })
|
32482
|
+
* .onConflictDoNothing({ target: cars.id });
|
32483
|
+
* ```
|
32484
|
+
*/
|
32485
|
+
onConflictDoNothing(config = {}) {
|
32486
|
+
if (config.target === void 0) {
|
32487
|
+
this.config.onConflict = sql`do nothing`;
|
32488
|
+
} else {
|
32489
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
32490
|
+
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
32491
|
+
this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
|
32492
|
+
}
|
32493
|
+
return this;
|
32494
|
+
}
|
32495
|
+
/**
|
32496
|
+
* Adds an `on conflict do update` clause to the query.
|
32497
|
+
*
|
32498
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
32499
|
+
*
|
32500
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
32501
|
+
*
|
32502
|
+
* @param config The `target`, `set` and `where` clauses.
|
32503
|
+
*
|
32504
|
+
* @example
|
32505
|
+
* ```ts
|
32506
|
+
* // Update the row if there's a conflict
|
32507
|
+
* await db.insert(cars)
|
32508
|
+
* .values({ id: 1, brand: 'BMW' })
|
32509
|
+
* .onConflictDoUpdate({
|
32510
|
+
* target: cars.id,
|
32511
|
+
* set: { brand: 'Porsche' }
|
32512
|
+
* });
|
32513
|
+
*
|
32514
|
+
* // Upsert with 'where' clause
|
32515
|
+
* await db.insert(cars)
|
32516
|
+
* .values({ id: 1, brand: 'BMW' })
|
32517
|
+
* .onConflictDoUpdate({
|
32518
|
+
* target: cars.id,
|
32519
|
+
* set: { brand: 'newBMW' },
|
32520
|
+
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
32521
|
+
* });
|
32522
|
+
* ```
|
32523
|
+
*/
|
32524
|
+
onConflictDoUpdate(config) {
|
32525
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
32526
|
+
throw new Error(
|
32527
|
+
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
32528
|
+
);
|
32529
|
+
}
|
32530
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
32531
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
32532
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
32533
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
32534
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
32535
|
+
this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
32536
|
+
return this;
|
32537
|
+
}
|
32538
|
+
/** @internal */
|
32539
|
+
getSQL() {
|
32540
|
+
return this.dialect.buildInsertQuery(this.config);
|
32541
|
+
}
|
32542
|
+
toSQL() {
|
32543
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
32544
|
+
return rest;
|
32545
|
+
}
|
32546
|
+
/** @internal */
|
32547
|
+
_prepare(isOneTimeQuery = true) {
|
32548
|
+
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
32549
|
+
this.dialect.sqlToQuery(this.getSQL()),
|
32550
|
+
this.config.returning,
|
32551
|
+
this.config.returning ? "all" : "run",
|
32552
|
+
true
|
32553
|
+
);
|
32554
|
+
}
|
32555
|
+
prepare() {
|
32556
|
+
return this._prepare(false);
|
32557
|
+
}
|
32558
|
+
async execute() {
|
32559
|
+
return this.config.returning ? this.all() : this.run();
|
32560
|
+
}
|
32561
|
+
$dynamic() {
|
32562
|
+
return this;
|
32563
|
+
}
|
32564
|
+
};
|
32565
|
+
__publicField(SQLiteInsertBase, _a206, "SQLiteInsert");
|
32442
32566
|
}
|
32443
32567
|
});
|
32444
32568
|
|
@@ -35830,131 +35954,6 @@ var init_delete3 = __esm({
|
|
35830
35954
|
}
|
35831
35955
|
});
|
35832
35956
|
|
35833
|
-
// ../drizzle-orm/dist/mysql-core/query-builders/insert.js
|
35834
|
-
var _a299, MySqlInsertBuilder, _a300, _b222, MySqlInsertBase;
|
35835
|
-
var init_insert3 = __esm({
|
35836
|
-
"../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
|
35837
|
-
"use strict";
|
35838
|
-
init_entity();
|
35839
|
-
init_query_promise();
|
35840
|
-
init_sql();
|
35841
|
-
init_table();
|
35842
|
-
init_utils2();
|
35843
|
-
_a299 = entityKind;
|
35844
|
-
MySqlInsertBuilder = class {
|
35845
|
-
constructor(table4, session, dialect4) {
|
35846
|
-
__publicField(this, "shouldIgnore", false);
|
35847
|
-
this.table = table4;
|
35848
|
-
this.session = session;
|
35849
|
-
this.dialect = dialect4;
|
35850
|
-
}
|
35851
|
-
ignore() {
|
35852
|
-
this.shouldIgnore = true;
|
35853
|
-
return this;
|
35854
|
-
}
|
35855
|
-
values(values) {
|
35856
|
-
values = Array.isArray(values) ? values : [values];
|
35857
|
-
if (values.length === 0) {
|
35858
|
-
throw new Error("values() must be called with at least one value");
|
35859
|
-
}
|
35860
|
-
const mappedValues = values.map((entry) => {
|
35861
|
-
const result = {};
|
35862
|
-
const cols = this.table[Table2.Symbol.Columns];
|
35863
|
-
for (const colKey of Object.keys(entry)) {
|
35864
|
-
const colValue = entry[colKey];
|
35865
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
35866
|
-
}
|
35867
|
-
return result;
|
35868
|
-
});
|
35869
|
-
return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
|
35870
|
-
}
|
35871
|
-
};
|
35872
|
-
__publicField(MySqlInsertBuilder, _a299, "MySqlInsertBuilder");
|
35873
|
-
MySqlInsertBase = class extends (_b222 = QueryPromise, _a300 = entityKind, _b222) {
|
35874
|
-
constructor(table4, values, ignore, session, dialect4) {
|
35875
|
-
super();
|
35876
|
-
__publicField(this, "config");
|
35877
|
-
__publicField(this, "execute", (placeholderValues) => {
|
35878
|
-
return this.prepare().execute(placeholderValues);
|
35879
|
-
});
|
35880
|
-
__publicField(this, "createIterator", () => {
|
35881
|
-
const self2 = this;
|
35882
|
-
return async function* (placeholderValues) {
|
35883
|
-
yield* self2.prepare().iterator(placeholderValues);
|
35884
|
-
};
|
35885
|
-
});
|
35886
|
-
__publicField(this, "iterator", this.createIterator());
|
35887
|
-
this.session = session;
|
35888
|
-
this.dialect = dialect4;
|
35889
|
-
this.config = { table: table4, values, ignore };
|
35890
|
-
}
|
35891
|
-
/**
|
35892
|
-
* Adds an `on duplicate key update` clause to the query.
|
35893
|
-
*
|
35894
|
-
* Calling this method will update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.
|
35895
|
-
*
|
35896
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
|
35897
|
-
*
|
35898
|
-
* @param config The `set` clause
|
35899
|
-
*
|
35900
|
-
* @example
|
35901
|
-
* ```ts
|
35902
|
-
* await db.insert(cars)
|
35903
|
-
* .values({ id: 1, brand: 'BMW'})
|
35904
|
-
* .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
|
35905
|
-
* ```
|
35906
|
-
*
|
35907
|
-
* While MySQL does not directly support doing nothing on conflict, you can perform a no-op by setting any column's value to itself and achieve the same effect:
|
35908
|
-
*
|
35909
|
-
* ```ts
|
35910
|
-
* import { sql } from 'drizzle-orm';
|
35911
|
-
*
|
35912
|
-
* await db.insert(cars)
|
35913
|
-
* .values({ id: 1, brand: 'BMW' })
|
35914
|
-
* .onDuplicateKeyUpdate({ set: { id: sql`id` } });
|
35915
|
-
* ```
|
35916
|
-
*/
|
35917
|
-
onDuplicateKeyUpdate(config) {
|
35918
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
35919
|
-
this.config.onConflict = sql`update ${setSql}`;
|
35920
|
-
return this;
|
35921
|
-
}
|
35922
|
-
$returningId() {
|
35923
|
-
const returning = [];
|
35924
|
-
for (const [key, value] of Object.entries(this.config.table[Table2.Symbol.Columns])) {
|
35925
|
-
if (value.primary) {
|
35926
|
-
returning.push({ field: value, path: [key] });
|
35927
|
-
}
|
35928
|
-
}
|
35929
|
-
this.config.returning = returning;
|
35930
|
-
return this;
|
35931
|
-
}
|
35932
|
-
/** @internal */
|
35933
|
-
getSQL() {
|
35934
|
-
return this.dialect.buildInsertQuery(this.config).sql;
|
35935
|
-
}
|
35936
|
-
toSQL() {
|
35937
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
35938
|
-
return rest;
|
35939
|
-
}
|
35940
|
-
prepare() {
|
35941
|
-
const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
|
35942
|
-
return this.session.prepareQuery(
|
35943
|
-
this.dialect.sqlToQuery(sql2),
|
35944
|
-
void 0,
|
35945
|
-
void 0,
|
35946
|
-
generatedIds,
|
35947
|
-
this.config.returning
|
35948
|
-
);
|
35949
|
-
}
|
35950
|
-
$dynamic() {
|
35951
|
-
return this;
|
35952
|
-
}
|
35953
|
-
};
|
35954
|
-
__publicField(MySqlInsertBase, _a300, "MySqlInsert");
|
35955
|
-
}
|
35956
|
-
});
|
35957
|
-
|
35958
35957
|
// ../drizzle-orm/dist/mysql-core/columns/all.js
|
35959
35958
|
function getMySqlColumnBuilders() {
|
35960
35959
|
return {
|
@@ -36035,7 +36034,7 @@ function mysqlTableWithSchema(name2, columns, extraConfig, schema4, baseName = n
|
|
36035
36034
|
}
|
36036
36035
|
return table4;
|
36037
36036
|
}
|
36038
|
-
var InlineForeignKeys3,
|
36037
|
+
var InlineForeignKeys3, _a299, _b222, _c9, _d4, _e4, MySqlTable, mysqlTable;
|
36039
36038
|
var init_table4 = __esm({
|
36040
36039
|
"../drizzle-orm/dist/mysql-core/table.js"() {
|
36041
36040
|
"use strict";
|
@@ -36043,15 +36042,15 @@ var init_table4 = __esm({
|
|
36043
36042
|
init_table();
|
36044
36043
|
init_all3();
|
36045
36044
|
InlineForeignKeys3 = Symbol.for("drizzle:MySqlInlineForeignKeys");
|
36046
|
-
MySqlTable = class extends (_e4 = Table2, _d4 = entityKind, _c9 = Table2.Symbol.Columns,
|
36045
|
+
MySqlTable = class extends (_e4 = Table2, _d4 = entityKind, _c9 = Table2.Symbol.Columns, _b222 = InlineForeignKeys3, _a299 = Table2.Symbol.ExtraConfigBuilder, _e4) {
|
36047
36046
|
constructor() {
|
36048
36047
|
super(...arguments);
|
36049
36048
|
/** @internal */
|
36050
36049
|
__publicField(this, _c9);
|
36051
36050
|
/** @internal */
|
36052
|
-
__publicField(this,
|
36051
|
+
__publicField(this, _b222, []);
|
36053
36052
|
/** @internal */
|
36054
|
-
__publicField(this,
|
36053
|
+
__publicField(this, _a299);
|
36055
36054
|
}
|
36056
36055
|
};
|
36057
36056
|
__publicField(MySqlTable, _d4, "MySqlTable");
|
@@ -36066,20 +36065,20 @@ var init_table4 = __esm({
|
|
36066
36065
|
});
|
36067
36066
|
|
36068
36067
|
// ../drizzle-orm/dist/mysql-core/view-base.js
|
36069
|
-
var
|
36068
|
+
var _a300, _b223, MySqlViewBase;
|
36070
36069
|
var init_view_base3 = __esm({
|
36071
36070
|
"../drizzle-orm/dist/mysql-core/view-base.js"() {
|
36072
36071
|
"use strict";
|
36073
36072
|
init_entity();
|
36074
36073
|
init_sql();
|
36075
|
-
MySqlViewBase = class extends (
|
36074
|
+
MySqlViewBase = class extends (_b223 = View3, _a300 = entityKind, _b223) {
|
36076
36075
|
};
|
36077
|
-
__publicField(MySqlViewBase,
|
36076
|
+
__publicField(MySqlViewBase, _a300, "MySqlViewBase");
|
36078
36077
|
}
|
36079
36078
|
});
|
36080
36079
|
|
36081
36080
|
// ../drizzle-orm/dist/mysql-core/dialect.js
|
36082
|
-
var
|
36081
|
+
var _a301, MySqlDialect;
|
36083
36082
|
var init_dialect3 = __esm({
|
36084
36083
|
"../drizzle-orm/dist/mysql-core/dialect.js"() {
|
36085
36084
|
"use strict";
|
@@ -36098,7 +36097,7 @@ var init_dialect3 = __esm({
|
|
36098
36097
|
init_common4();
|
36099
36098
|
init_table4();
|
36100
36099
|
init_view_base3();
|
36101
|
-
|
36100
|
+
_a301 = entityKind;
|
36102
36101
|
MySqlDialect = class {
|
36103
36102
|
constructor(config) {
|
36104
36103
|
/** @internal */
|
@@ -36381,7 +36380,7 @@ var init_dialect3 = __esm({
|
|
36381
36380
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
36382
36381
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
36383
36382
|
}
|
36384
|
-
buildInsertQuery({ table: table4, values, ignore, onConflict }) {
|
36383
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, ignore, onConflict, select }) {
|
36385
36384
|
const valuesSqlList = [];
|
36386
36385
|
const columns = table4[Table2.Symbol.Columns];
|
36387
36386
|
const colEntries = Object.entries(columns).filter(
|
@@ -36389,42 +36388,53 @@ var init_dialect3 = __esm({
|
|
36389
36388
|
);
|
36390
36389
|
const insertOrder = colEntries.map(([, column4]) => sql.identifier(this.casing.getColumnCasing(column4)));
|
36391
36390
|
const generatedIdsResponse = [];
|
36392
|
-
|
36393
|
-
const
|
36394
|
-
|
36395
|
-
|
36396
|
-
|
36397
|
-
|
36398
|
-
|
36399
|
-
|
36400
|
-
|
36401
|
-
|
36402
|
-
|
36403
|
-
|
36404
|
-
|
36405
|
-
|
36406
|
-
|
36391
|
+
if (select) {
|
36392
|
+
const select2 = valuesOrSelect;
|
36393
|
+
if (is(select2, SQL)) {
|
36394
|
+
valuesSqlList.push(select2);
|
36395
|
+
} else {
|
36396
|
+
valuesSqlList.push(select2.getSQL());
|
36397
|
+
}
|
36398
|
+
} else {
|
36399
|
+
const values = valuesOrSelect;
|
36400
|
+
valuesSqlList.push(sql.raw("values "));
|
36401
|
+
for (const [valueIndex, value] of values.entries()) {
|
36402
|
+
const generatedIds = {};
|
36403
|
+
const valueList = [];
|
36404
|
+
for (const [fieldName, col] of colEntries) {
|
36405
|
+
const colValue = value[fieldName];
|
36406
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
36407
|
+
if (col.defaultFn !== void 0) {
|
36408
|
+
const defaultFnResult = col.defaultFn();
|
36409
|
+
generatedIds[fieldName] = defaultFnResult;
|
36410
|
+
const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
36411
|
+
valueList.push(defaultValue);
|
36412
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
36413
|
+
const onUpdateFnResult = col.onUpdateFn();
|
36414
|
+
const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
36415
|
+
valueList.push(newValue);
|
36416
|
+
} else {
|
36417
|
+
valueList.push(sql`default`);
|
36418
|
+
}
|
36407
36419
|
} else {
|
36408
|
-
|
36409
|
-
|
36410
|
-
|
36411
|
-
|
36412
|
-
generatedIds[fieldName] = colValue.value;
|
36420
|
+
if (col.defaultFn && is(colValue, Param)) {
|
36421
|
+
generatedIds[fieldName] = colValue.value;
|
36422
|
+
}
|
36423
|
+
valueList.push(colValue);
|
36413
36424
|
}
|
36414
|
-
valueList.push(colValue);
|
36415
36425
|
}
|
36416
|
-
|
36417
|
-
|
36418
|
-
|
36419
|
-
|
36420
|
-
|
36426
|
+
generatedIdsResponse.push(generatedIds);
|
36427
|
+
valuesSqlList.push(valueList);
|
36428
|
+
if (valueIndex < values.length - 1) {
|
36429
|
+
valuesSqlList.push(sql`, `);
|
36430
|
+
}
|
36421
36431
|
}
|
36422
36432
|
}
|
36423
36433
|
const valuesSql = sql.join(valuesSqlList);
|
36424
36434
|
const ignoreSql = ignore ? sql` ignore` : void 0;
|
36425
36435
|
const onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : void 0;
|
36426
36436
|
return {
|
36427
|
-
sql: sql`insert${ignoreSql} into ${table4} ${insertOrder}
|
36437
|
+
sql: sql`insert${ignoreSql} into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}`,
|
36428
36438
|
generatedIds: generatedIdsResponse
|
36429
36439
|
};
|
36430
36440
|
}
|
@@ -36884,7 +36894,7 @@ var init_dialect3 = __esm({
|
|
36884
36894
|
};
|
36885
36895
|
}
|
36886
36896
|
};
|
36887
|
-
__publicField(MySqlDialect,
|
36897
|
+
__publicField(MySqlDialect, _a301, "MySqlDialect");
|
36888
36898
|
}
|
36889
36899
|
});
|
36890
36900
|
|
@@ -36906,7 +36916,7 @@ function createSetOperator3(type, isAll) {
|
|
36906
36916
|
return leftSelect.addSetOperators(setOperators);
|
36907
36917
|
};
|
36908
36918
|
}
|
36909
|
-
var
|
36919
|
+
var _a302, MySqlSelectBuilder, _a303, _b224, MySqlSelectQueryBuilderBase, _a304, _b225, MySqlSelectBase, getMySqlSetOperators, union3, unionAll3, intersect3, intersectAll2, except3, exceptAll2;
|
36910
36920
|
var init_select4 = __esm({
|
36911
36921
|
"../drizzle-orm/dist/mysql-core/query-builders/select.js"() {
|
36912
36922
|
"use strict";
|
@@ -36921,7 +36931,7 @@ var init_select4 = __esm({
|
|
36921
36931
|
init_utils2();
|
36922
36932
|
init_view_common();
|
36923
36933
|
init_view_base3();
|
36924
|
-
|
36934
|
+
_a302 = entityKind;
|
36925
36935
|
MySqlSelectBuilder = class {
|
36926
36936
|
constructor(config) {
|
36927
36937
|
__publicField(this, "fields");
|
@@ -36966,8 +36976,8 @@ var init_select4 = __esm({
|
|
36966
36976
|
);
|
36967
36977
|
}
|
36968
36978
|
};
|
36969
|
-
__publicField(MySqlSelectBuilder,
|
36970
|
-
MySqlSelectQueryBuilderBase = class extends (
|
36979
|
+
__publicField(MySqlSelectBuilder, _a302, "MySqlSelectBuilder");
|
36980
|
+
MySqlSelectQueryBuilderBase = class extends (_b224 = TypedQueryBuilder, _a303 = entityKind, _b224) {
|
36971
36981
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
36972
36982
|
super();
|
36973
36983
|
__publicField(this, "_");
|
@@ -37568,8 +37578,8 @@ var init_select4 = __esm({
|
|
37568
37578
|
return this;
|
37569
37579
|
}
|
37570
37580
|
};
|
37571
|
-
__publicField(MySqlSelectQueryBuilderBase,
|
37572
|
-
MySqlSelectBase = class extends (
|
37581
|
+
__publicField(MySqlSelectQueryBuilderBase, _a303, "MySqlSelectQueryBuilder");
|
37582
|
+
MySqlSelectBase = class extends (_b225 = MySqlSelectQueryBuilderBase, _a304 = entityKind, _b225) {
|
37573
37583
|
constructor() {
|
37574
37584
|
super(...arguments);
|
37575
37585
|
__publicField(this, "execute", (placeholderValues) => {
|
@@ -37593,7 +37603,7 @@ var init_select4 = __esm({
|
|
37593
37603
|
return query;
|
37594
37604
|
}
|
37595
37605
|
};
|
37596
|
-
__publicField(MySqlSelectBase,
|
37606
|
+
__publicField(MySqlSelectBase, _a304, "MySqlSelect");
|
37597
37607
|
applyMixins(MySqlSelectBase, [QueryPromise]);
|
37598
37608
|
getMySqlSetOperators = () => ({
|
37599
37609
|
union: union3,
|
@@ -37613,7 +37623,7 @@ var init_select4 = __esm({
|
|
37613
37623
|
});
|
37614
37624
|
|
37615
37625
|
// ../drizzle-orm/dist/mysql-core/query-builders/query-builder.js
|
37616
|
-
var
|
37626
|
+
var _a305, QueryBuilder3;
|
37617
37627
|
var init_query_builder4 = __esm({
|
37618
37628
|
"../drizzle-orm/dist/mysql-core/query-builders/query-builder.js"() {
|
37619
37629
|
"use strict";
|
@@ -37622,7 +37632,7 @@ var init_query_builder4 = __esm({
|
|
37622
37632
|
init_selection_proxy();
|
37623
37633
|
init_subquery();
|
37624
37634
|
init_select4();
|
37625
|
-
|
37635
|
+
_a305 = entityKind;
|
37626
37636
|
QueryBuilder3 = class {
|
37627
37637
|
constructor(dialect4) {
|
37628
37638
|
__publicField(this, "dialect");
|
@@ -37684,7 +37694,142 @@ var init_query_builder4 = __esm({
|
|
37684
37694
|
return this.dialect;
|
37685
37695
|
}
|
37686
37696
|
};
|
37687
|
-
__publicField(QueryBuilder3,
|
37697
|
+
__publicField(QueryBuilder3, _a305, "MySqlQueryBuilder");
|
37698
|
+
}
|
37699
|
+
});
|
37700
|
+
|
37701
|
+
// ../drizzle-orm/dist/mysql-core/query-builders/insert.js
|
37702
|
+
var _a306, MySqlInsertBuilder, _a307, _b226, MySqlInsertBase;
|
37703
|
+
var init_insert3 = __esm({
|
37704
|
+
"../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
|
37705
|
+
"use strict";
|
37706
|
+
init_entity();
|
37707
|
+
init_query_promise();
|
37708
|
+
init_sql();
|
37709
|
+
init_table();
|
37710
|
+
init_utils2();
|
37711
|
+
init_query_builder4();
|
37712
|
+
_a306 = entityKind;
|
37713
|
+
MySqlInsertBuilder = class {
|
37714
|
+
constructor(table4, session, dialect4) {
|
37715
|
+
__publicField(this, "shouldIgnore", false);
|
37716
|
+
this.table = table4;
|
37717
|
+
this.session = session;
|
37718
|
+
this.dialect = dialect4;
|
37719
|
+
}
|
37720
|
+
ignore() {
|
37721
|
+
this.shouldIgnore = true;
|
37722
|
+
return this;
|
37723
|
+
}
|
37724
|
+
values(values) {
|
37725
|
+
values = Array.isArray(values) ? values : [values];
|
37726
|
+
if (values.length === 0) {
|
37727
|
+
throw new Error("values() must be called with at least one value");
|
37728
|
+
}
|
37729
|
+
const mappedValues = values.map((entry) => {
|
37730
|
+
const result = {};
|
37731
|
+
const cols = this.table[Table2.Symbol.Columns];
|
37732
|
+
for (const colKey of Object.keys(entry)) {
|
37733
|
+
const colValue = entry[colKey];
|
37734
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
37735
|
+
}
|
37736
|
+
return result;
|
37737
|
+
});
|
37738
|
+
return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
|
37739
|
+
}
|
37740
|
+
select(selectQuery) {
|
37741
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder3()) : selectQuery;
|
37742
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
37743
|
+
throw new Error(
|
37744
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
37745
|
+
);
|
37746
|
+
}
|
37747
|
+
return new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);
|
37748
|
+
}
|
37749
|
+
};
|
37750
|
+
__publicField(MySqlInsertBuilder, _a306, "MySqlInsertBuilder");
|
37751
|
+
MySqlInsertBase = class extends (_b226 = QueryPromise, _a307 = entityKind, _b226) {
|
37752
|
+
constructor(table4, values, ignore, session, dialect4, select) {
|
37753
|
+
super();
|
37754
|
+
__publicField(this, "config");
|
37755
|
+
__publicField(this, "execute", (placeholderValues) => {
|
37756
|
+
return this.prepare().execute(placeholderValues);
|
37757
|
+
});
|
37758
|
+
__publicField(this, "createIterator", () => {
|
37759
|
+
const self2 = this;
|
37760
|
+
return async function* (placeholderValues) {
|
37761
|
+
yield* self2.prepare().iterator(placeholderValues);
|
37762
|
+
};
|
37763
|
+
});
|
37764
|
+
__publicField(this, "iterator", this.createIterator());
|
37765
|
+
this.session = session;
|
37766
|
+
this.dialect = dialect4;
|
37767
|
+
this.config = { table: table4, values, select, ignore };
|
37768
|
+
}
|
37769
|
+
/**
|
37770
|
+
* Adds an `on duplicate key update` clause to the query.
|
37771
|
+
*
|
37772
|
+
* Calling this method will update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.
|
37773
|
+
*
|
37774
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
|
37775
|
+
*
|
37776
|
+
* @param config The `set` clause
|
37777
|
+
*
|
37778
|
+
* @example
|
37779
|
+
* ```ts
|
37780
|
+
* await db.insert(cars)
|
37781
|
+
* .values({ id: 1, brand: 'BMW'})
|
37782
|
+
* .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
|
37783
|
+
* ```
|
37784
|
+
*
|
37785
|
+
* While MySQL does not directly support doing nothing on conflict, you can perform a no-op by setting any column's value to itself and achieve the same effect:
|
37786
|
+
*
|
37787
|
+
* ```ts
|
37788
|
+
* import { sql } from 'drizzle-orm';
|
37789
|
+
*
|
37790
|
+
* await db.insert(cars)
|
37791
|
+
* .values({ id: 1, brand: 'BMW' })
|
37792
|
+
* .onDuplicateKeyUpdate({ set: { id: sql`id` } });
|
37793
|
+
* ```
|
37794
|
+
*/
|
37795
|
+
onDuplicateKeyUpdate(config) {
|
37796
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
37797
|
+
this.config.onConflict = sql`update ${setSql}`;
|
37798
|
+
return this;
|
37799
|
+
}
|
37800
|
+
$returningId() {
|
37801
|
+
const returning = [];
|
37802
|
+
for (const [key, value] of Object.entries(this.config.table[Table2.Symbol.Columns])) {
|
37803
|
+
if (value.primary) {
|
37804
|
+
returning.push({ field: value, path: [key] });
|
37805
|
+
}
|
37806
|
+
}
|
37807
|
+
this.config.returning = returning;
|
37808
|
+
return this;
|
37809
|
+
}
|
37810
|
+
/** @internal */
|
37811
|
+
getSQL() {
|
37812
|
+
return this.dialect.buildInsertQuery(this.config).sql;
|
37813
|
+
}
|
37814
|
+
toSQL() {
|
37815
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
37816
|
+
return rest;
|
37817
|
+
}
|
37818
|
+
prepare() {
|
37819
|
+
const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
|
37820
|
+
return this.session.prepareQuery(
|
37821
|
+
this.dialect.sqlToQuery(sql2),
|
37822
|
+
void 0,
|
37823
|
+
void 0,
|
37824
|
+
generatedIds,
|
37825
|
+
this.config.returning
|
37826
|
+
);
|
37827
|
+
}
|
37828
|
+
$dynamic() {
|
37829
|
+
return this;
|
37830
|
+
}
|
37831
|
+
};
|
37832
|
+
__publicField(MySqlInsertBase, _a307, "MySqlInsert");
|
37688
37833
|
}
|
37689
37834
|
});
|
37690
37835
|
|