drizzle-kit 0.28.0-cc4f208 → 0.28.1-166fb8d
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 +1028 -710
- package/api.mjs +1028 -710
- package/bin.cjs +637 -42
- package/package.json +1 -1
package/api.mjs
CHANGED
@@ -21126,7 +21126,7 @@ var version;
|
|
21126
21126
|
var init_version = __esm({
|
21127
21127
|
"../drizzle-orm/dist/version.js"() {
|
21128
21128
|
"use strict";
|
21129
|
-
version = "0.36.
|
21129
|
+
version = "0.36.4";
|
21130
21130
|
}
|
21131
21131
|
});
|
21132
21132
|
|
@@ -22149,7 +22149,7 @@ function haveSameKeys(left, right) {
|
|
22149
22149
|
}
|
22150
22150
|
function mapUpdateSet(table4, values) {
|
22151
22151
|
const entries = Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => {
|
22152
|
-
if (is(value, SQL)) {
|
22152
|
+
if (is(value, SQL) || is(value, Column2)) {
|
22153
22153
|
return [key, value];
|
22154
22154
|
} else {
|
22155
22155
|
return [key, new Param(value, table4[Table2.Symbol.Columns][key])];
|
@@ -24588,9 +24588,10 @@ var init_delete = __esm({
|
|
24588
24588
|
constructor(table4, session, dialect4, withList) {
|
24589
24589
|
super();
|
24590
24590
|
__publicField(this, "config");
|
24591
|
+
__publicField(this, "authToken");
|
24591
24592
|
__publicField(this, "execute", (placeholderValues) => {
|
24592
24593
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
24593
|
-
return this._prepare().execute(placeholderValues);
|
24594
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
24594
24595
|
});
|
24595
24596
|
});
|
24596
24597
|
this.session = session;
|
@@ -24651,167 +24652,16 @@ var init_delete = __esm({
|
|
24651
24652
|
prepare(name2) {
|
24652
24653
|
return this._prepare(name2);
|
24653
24654
|
}
|
24654
|
-
$dynamic() {
|
24655
|
-
return this;
|
24656
|
-
}
|
24657
|
-
};
|
24658
|
-
__publicField(PgDeleteBase, _a124, "PgDelete");
|
24659
|
-
}
|
24660
|
-
});
|
24661
|
-
|
24662
|
-
// ../drizzle-orm/dist/pg-core/query-builders/insert.js
|
24663
|
-
var _a125, PgInsertBuilder, _a126, _b98, PgInsertBase;
|
24664
|
-
var init_insert = __esm({
|
24665
|
-
"../drizzle-orm/dist/pg-core/query-builders/insert.js"() {
|
24666
|
-
"use strict";
|
24667
|
-
init_entity();
|
24668
|
-
init_query_promise();
|
24669
|
-
init_sql();
|
24670
|
-
init_table();
|
24671
|
-
init_tracing();
|
24672
|
-
init_utils2();
|
24673
|
-
_a125 = entityKind;
|
24674
|
-
PgInsertBuilder = class {
|
24675
|
-
constructor(table4, session, dialect4, withList) {
|
24676
|
-
this.table = table4;
|
24677
|
-
this.session = session;
|
24678
|
-
this.dialect = dialect4;
|
24679
|
-
this.withList = withList;
|
24680
|
-
}
|
24681
|
-
values(values) {
|
24682
|
-
values = Array.isArray(values) ? values : [values];
|
24683
|
-
if (values.length === 0) {
|
24684
|
-
throw new Error("values() must be called with at least one value");
|
24685
|
-
}
|
24686
|
-
const mappedValues = values.map((entry) => {
|
24687
|
-
const result = {};
|
24688
|
-
const cols = this.table[Table2.Symbol.Columns];
|
24689
|
-
for (const colKey of Object.keys(entry)) {
|
24690
|
-
const colValue = entry[colKey];
|
24691
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
24692
|
-
}
|
24693
|
-
return result;
|
24694
|
-
});
|
24695
|
-
return new PgInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
24696
|
-
}
|
24697
|
-
};
|
24698
|
-
__publicField(PgInsertBuilder, _a125, "PgInsertBuilder");
|
24699
|
-
PgInsertBase = class extends (_b98 = QueryPromise, _a126 = entityKind, _b98) {
|
24700
|
-
constructor(table4, values, session, dialect4, withList) {
|
24701
|
-
super();
|
24702
|
-
__publicField(this, "config");
|
24703
|
-
__publicField(this, "execute", (placeholderValues) => {
|
24704
|
-
return tracer.startActiveSpan("drizzle.operation", () => {
|
24705
|
-
return this._prepare().execute(placeholderValues);
|
24706
|
-
});
|
24707
|
-
});
|
24708
|
-
this.session = session;
|
24709
|
-
this.dialect = dialect4;
|
24710
|
-
this.config = { table: table4, values, withList };
|
24711
|
-
}
|
24712
|
-
returning(fields = this.config.table[Table2.Symbol.Columns]) {
|
24713
|
-
this.config.returning = orderSelectedFields(fields);
|
24714
|
-
return this;
|
24715
|
-
}
|
24716
|
-
/**
|
24717
|
-
* Adds an `on conflict do nothing` clause to the query.
|
24718
|
-
*
|
24719
|
-
* Calling this method simply avoids inserting a row as its alternative action.
|
24720
|
-
*
|
24721
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
24722
|
-
*
|
24723
|
-
* @param config The `target` and `where` clauses.
|
24724
|
-
*
|
24725
|
-
* @example
|
24726
|
-
* ```ts
|
24727
|
-
* // Insert one row and cancel the insert if there's a conflict
|
24728
|
-
* await db.insert(cars)
|
24729
|
-
* .values({ id: 1, brand: 'BMW' })
|
24730
|
-
* .onConflictDoNothing();
|
24731
|
-
*
|
24732
|
-
* // Explicitly specify conflict target
|
24733
|
-
* await db.insert(cars)
|
24734
|
-
* .values({ id: 1, brand: 'BMW' })
|
24735
|
-
* .onConflictDoNothing({ target: cars.id });
|
24736
|
-
* ```
|
24737
|
-
*/
|
24738
|
-
onConflictDoNothing(config = {}) {
|
24739
|
-
if (config.target === void 0) {
|
24740
|
-
this.config.onConflict = sql`do nothing`;
|
24741
|
-
} else {
|
24742
|
-
let targetColumn = "";
|
24743
|
-
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));
|
24744
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
24745
|
-
this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
|
24746
|
-
}
|
24747
|
-
return this;
|
24748
|
-
}
|
24749
|
-
/**
|
24750
|
-
* Adds an `on conflict do update` clause to the query.
|
24751
|
-
*
|
24752
|
-
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
24753
|
-
*
|
24754
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
24755
|
-
*
|
24756
|
-
* @param config The `target`, `set` and `where` clauses.
|
24757
|
-
*
|
24758
|
-
* @example
|
24759
|
-
* ```ts
|
24760
|
-
* // Update the row if there's a conflict
|
24761
|
-
* await db.insert(cars)
|
24762
|
-
* .values({ id: 1, brand: 'BMW' })
|
24763
|
-
* .onConflictDoUpdate({
|
24764
|
-
* target: cars.id,
|
24765
|
-
* set: { brand: 'Porsche' }
|
24766
|
-
* });
|
24767
|
-
*
|
24768
|
-
* // Upsert with 'where' clause
|
24769
|
-
* await db.insert(cars)
|
24770
|
-
* .values({ id: 1, brand: 'BMW' })
|
24771
|
-
* .onConflictDoUpdate({
|
24772
|
-
* target: cars.id,
|
24773
|
-
* set: { brand: 'newBMW' },
|
24774
|
-
* targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
|
24775
|
-
* });
|
24776
|
-
* ```
|
24777
|
-
*/
|
24778
|
-
onConflictDoUpdate(config) {
|
24779
|
-
if (config.where && (config.targetWhere || config.setWhere)) {
|
24780
|
-
throw new Error(
|
24781
|
-
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
24782
|
-
);
|
24783
|
-
}
|
24784
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
24785
|
-
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
24786
|
-
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
24787
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
24788
|
-
let targetColumn = "";
|
24789
|
-
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));
|
24790
|
-
this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
24791
|
-
return this;
|
24792
|
-
}
|
24793
|
-
/** @internal */
|
24794
|
-
getSQL() {
|
24795
|
-
return this.dialect.buildInsertQuery(this.config);
|
24796
|
-
}
|
24797
|
-
toSQL() {
|
24798
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
24799
|
-
return rest;
|
24800
|
-
}
|
24801
24655
|
/** @internal */
|
24802
|
-
|
24803
|
-
|
24804
|
-
|
24805
|
-
});
|
24806
|
-
}
|
24807
|
-
prepare(name2) {
|
24808
|
-
return this._prepare(name2);
|
24656
|
+
setToken(token) {
|
24657
|
+
this.authToken = token;
|
24658
|
+
return this;
|
24809
24659
|
}
|
24810
24660
|
$dynamic() {
|
24811
24661
|
return this;
|
24812
24662
|
}
|
24813
24663
|
};
|
24814
|
-
__publicField(
|
24664
|
+
__publicField(PgDeleteBase, _a124, "PgDelete");
|
24815
24665
|
}
|
24816
24666
|
});
|
24817
24667
|
|
@@ -24830,13 +24680,13 @@ function toCamelCase(input) {
|
|
24830
24680
|
function noopCase(input) {
|
24831
24681
|
return input;
|
24832
24682
|
}
|
24833
|
-
var
|
24683
|
+
var _a125, CasingCache;
|
24834
24684
|
var init_casing = __esm({
|
24835
24685
|
"../drizzle-orm/dist/casing.js"() {
|
24836
24686
|
"use strict";
|
24837
24687
|
init_entity();
|
24838
24688
|
init_table();
|
24839
|
-
|
24689
|
+
_a125 = entityKind;
|
24840
24690
|
CasingCache = class {
|
24841
24691
|
constructor(casing2) {
|
24842
24692
|
/** @internal */
|
@@ -24873,25 +24723,25 @@ var init_casing = __esm({
|
|
24873
24723
|
this.cachedTables = {};
|
24874
24724
|
}
|
24875
24725
|
};
|
24876
|
-
__publicField(CasingCache,
|
24726
|
+
__publicField(CasingCache, _a125, "CasingCache");
|
24877
24727
|
}
|
24878
24728
|
});
|
24879
24729
|
|
24880
24730
|
// ../drizzle-orm/dist/pg-core/view-base.js
|
24881
|
-
var
|
24731
|
+
var _a126, _b98, PgViewBase;
|
24882
24732
|
var init_view_base = __esm({
|
24883
24733
|
"../drizzle-orm/dist/pg-core/view-base.js"() {
|
24884
24734
|
"use strict";
|
24885
24735
|
init_entity();
|
24886
24736
|
init_sql();
|
24887
|
-
PgViewBase = class extends (
|
24737
|
+
PgViewBase = class extends (_b98 = View3, _a126 = entityKind, _b98) {
|
24888
24738
|
};
|
24889
|
-
__publicField(PgViewBase,
|
24739
|
+
__publicField(PgViewBase, _a126, "PgViewBase");
|
24890
24740
|
}
|
24891
24741
|
});
|
24892
24742
|
|
24893
24743
|
// ../drizzle-orm/dist/pg-core/dialect.js
|
24894
|
-
var
|
24744
|
+
var _a127, PgDialect;
|
24895
24745
|
var init_dialect = __esm({
|
24896
24746
|
"../drizzle-orm/dist/pg-core/dialect.js"() {
|
24897
24747
|
"use strict";
|
@@ -24910,7 +24760,7 @@ var init_dialect = __esm({
|
|
24910
24760
|
init_utils2();
|
24911
24761
|
init_view_common();
|
24912
24762
|
init_view_base();
|
24913
|
-
|
24763
|
+
_a127 = entityKind;
|
24914
24764
|
PgDialect = class {
|
24915
24765
|
constructor(config) {
|
24916
24766
|
/** @internal */
|
@@ -24990,12 +24840,19 @@ var init_dialect = __esm({
|
|
24990
24840
|
return [res];
|
24991
24841
|
}));
|
24992
24842
|
}
|
24993
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList }) {
|
24843
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, from, joins }) {
|
24994
24844
|
const withSql = this.buildWithCTE(withList);
|
24845
|
+
const tableName = table4[PgTable.Symbol.Name];
|
24846
|
+
const tableSchema = table4[PgTable.Symbol.Schema];
|
24847
|
+
const origTableName = table4[PgTable.Symbol.OriginalName];
|
24848
|
+
const alias = tableName === origTableName ? void 0 : tableName;
|
24849
|
+
const tableSql = sql`${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}`;
|
24995
24850
|
const setSql = this.buildUpdateSet(table4, set);
|
24996
|
-
const
|
24851
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
24852
|
+
const joinsSql = this.buildJoins(joins);
|
24853
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: !from })}` : void 0;
|
24997
24854
|
const whereSql = where ? sql` where ${where}` : void 0;
|
24998
|
-
return sql`${withSql}update ${
|
24855
|
+
return sql`${withSql}update ${tableSql} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}`;
|
24999
24856
|
}
|
25000
24857
|
/**
|
25001
24858
|
* Builds selection SQL with provided fields/expressions
|
@@ -25047,6 +24904,54 @@ var init_dialect = __esm({
|
|
25047
24904
|
});
|
25048
24905
|
return sql.join(chunks);
|
25049
24906
|
}
|
24907
|
+
buildJoins(joins) {
|
24908
|
+
if (!joins || joins.length === 0) {
|
24909
|
+
return void 0;
|
24910
|
+
}
|
24911
|
+
const joinsArray = [];
|
24912
|
+
for (const [index4, joinMeta] of joins.entries()) {
|
24913
|
+
if (index4 === 0) {
|
24914
|
+
joinsArray.push(sql` `);
|
24915
|
+
}
|
24916
|
+
const table4 = joinMeta.table;
|
24917
|
+
const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
|
24918
|
+
if (is(table4, PgTable)) {
|
24919
|
+
const tableName = table4[PgTable.Symbol.Name];
|
24920
|
+
const tableSchema = table4[PgTable.Symbol.Schema];
|
24921
|
+
const origTableName = table4[PgTable.Symbol.OriginalName];
|
24922
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
24923
|
+
joinsArray.push(
|
24924
|
+
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
24925
|
+
);
|
24926
|
+
} else if (is(table4, View3)) {
|
24927
|
+
const viewName = table4[ViewBaseConfig].name;
|
24928
|
+
const viewSchema = table4[ViewBaseConfig].schema;
|
24929
|
+
const origViewName = table4[ViewBaseConfig].originalName;
|
24930
|
+
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
24931
|
+
joinsArray.push(
|
24932
|
+
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${viewSchema ? sql`${sql.identifier(viewSchema)}.` : void 0}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
24933
|
+
);
|
24934
|
+
} else {
|
24935
|
+
joinsArray.push(
|
24936
|
+
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table4} on ${joinMeta.on}`
|
24937
|
+
);
|
24938
|
+
}
|
24939
|
+
if (index4 < joins.length - 1) {
|
24940
|
+
joinsArray.push(sql` `);
|
24941
|
+
}
|
24942
|
+
}
|
24943
|
+
return sql.join(joinsArray);
|
24944
|
+
}
|
24945
|
+
buildFromTable(table4) {
|
24946
|
+
if (is(table4, Table2) && table4[Table2.Symbol.OriginalName] !== table4[Table2.Symbol.Name]) {
|
24947
|
+
let fullName = sql`${sql.identifier(table4[Table2.Symbol.OriginalName])}`;
|
24948
|
+
if (table4[Table2.Symbol.Schema]) {
|
24949
|
+
fullName = sql`${sql.identifier(table4[Table2.Symbol.Schema])}.${fullName}`;
|
24950
|
+
}
|
24951
|
+
return sql`${fullName} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
24952
|
+
}
|
24953
|
+
return table4;
|
24954
|
+
}
|
25050
24955
|
buildSelectQuery({
|
25051
24956
|
withList,
|
25052
24957
|
fields,
|
@@ -25081,51 +24986,8 @@ var init_dialect = __esm({
|
|
25081
24986
|
distinctSql = distinct === true ? sql` distinct` : sql` distinct on (${sql.join(distinct.on, sql`, `)})`;
|
25082
24987
|
}
|
25083
24988
|
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
25084
|
-
const tableSql = (
|
25085
|
-
|
25086
|
-
let fullName = sql`${sql.identifier(table4[Table2.Symbol.OriginalName])}`;
|
25087
|
-
if (table4[Table2.Symbol.Schema]) {
|
25088
|
-
fullName = sql`${sql.identifier(table4[Table2.Symbol.Schema])}.${fullName}`;
|
25089
|
-
}
|
25090
|
-
return sql`${fullName} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
25091
|
-
}
|
25092
|
-
return table4;
|
25093
|
-
})();
|
25094
|
-
const joinsArray = [];
|
25095
|
-
if (joins) {
|
25096
|
-
for (const [index4, joinMeta] of joins.entries()) {
|
25097
|
-
if (index4 === 0) {
|
25098
|
-
joinsArray.push(sql` `);
|
25099
|
-
}
|
25100
|
-
const table22 = joinMeta.table;
|
25101
|
-
const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
|
25102
|
-
if (is(table22, PgTable)) {
|
25103
|
-
const tableName = table22[PgTable.Symbol.Name];
|
25104
|
-
const tableSchema = table22[PgTable.Symbol.Schema];
|
25105
|
-
const origTableName = table22[PgTable.Symbol.OriginalName];
|
25106
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
25107
|
-
joinsArray.push(
|
25108
|
-
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
25109
|
-
);
|
25110
|
-
} else if (is(table22, View3)) {
|
25111
|
-
const viewName = table22[ViewBaseConfig].name;
|
25112
|
-
const viewSchema = table22[ViewBaseConfig].schema;
|
25113
|
-
const origViewName = table22[ViewBaseConfig].originalName;
|
25114
|
-
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
25115
|
-
joinsArray.push(
|
25116
|
-
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${viewSchema ? sql`${sql.identifier(viewSchema)}.` : void 0}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
25117
|
-
);
|
25118
|
-
} else {
|
25119
|
-
joinsArray.push(
|
25120
|
-
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table22} on ${joinMeta.on}`
|
25121
|
-
);
|
25122
|
-
}
|
25123
|
-
if (index4 < joins.length - 1) {
|
25124
|
-
joinsArray.push(sql` `);
|
25125
|
-
}
|
25126
|
-
}
|
25127
|
-
}
|
25128
|
-
const joinsSql = sql.join(joinsArray);
|
24989
|
+
const tableSql = this.buildFromTable(table4);
|
24990
|
+
const joinsSql = this.buildJoins(joins);
|
25129
24991
|
const whereSql = where ? sql` where ${where}` : void 0;
|
25130
24992
|
const havingSql = having ? sql` having ${having}` : void 0;
|
25131
24993
|
let orderBySql;
|
@@ -25206,43 +25068,55 @@ var init_dialect = __esm({
|
|
25206
25068
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
25207
25069
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
25208
25070
|
}
|
25209
|
-
buildInsertQuery({ table: table4, values, onConflict, returning, withList }) {
|
25071
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, onConflict, returning, withList, select, overridingSystemValue_ }) {
|
25210
25072
|
const valuesSqlList = [];
|
25211
25073
|
const columns = table4[Table2.Symbol.Columns];
|
25212
25074
|
const colEntries = Object.entries(columns).filter(([_2, col]) => !col.shouldDisableInsert());
|
25213
25075
|
const insertOrder = colEntries.map(
|
25214
25076
|
([, column4]) => sql.identifier(this.casing.getColumnCasing(column4))
|
25215
25077
|
);
|
25216
|
-
|
25217
|
-
const
|
25218
|
-
|
25219
|
-
|
25220
|
-
|
25221
|
-
|
25222
|
-
|
25223
|
-
|
25224
|
-
|
25225
|
-
|
25226
|
-
|
25227
|
-
|
25228
|
-
|
25078
|
+
if (select) {
|
25079
|
+
const select2 = valuesOrSelect;
|
25080
|
+
if (is(select2, SQL)) {
|
25081
|
+
valuesSqlList.push(select2);
|
25082
|
+
} else {
|
25083
|
+
valuesSqlList.push(select2.getSQL());
|
25084
|
+
}
|
25085
|
+
} else {
|
25086
|
+
const values = valuesOrSelect;
|
25087
|
+
valuesSqlList.push(sql.raw("values "));
|
25088
|
+
for (const [valueIndex, value] of values.entries()) {
|
25089
|
+
const valueList = [];
|
25090
|
+
for (const [fieldName, col] of colEntries) {
|
25091
|
+
const colValue = value[fieldName];
|
25092
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
25093
|
+
if (col.defaultFn !== void 0) {
|
25094
|
+
const defaultFnResult = col.defaultFn();
|
25095
|
+
const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
25096
|
+
valueList.push(defaultValue);
|
25097
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
25098
|
+
const onUpdateFnResult = col.onUpdateFn();
|
25099
|
+
const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
25100
|
+
valueList.push(newValue);
|
25101
|
+
} else {
|
25102
|
+
valueList.push(sql`default`);
|
25103
|
+
}
|
25229
25104
|
} else {
|
25230
|
-
valueList.push(
|
25105
|
+
valueList.push(colValue);
|
25231
25106
|
}
|
25232
|
-
} else {
|
25233
|
-
valueList.push(colValue);
|
25234
25107
|
}
|
25235
|
-
|
25236
|
-
|
25237
|
-
|
25238
|
-
|
25108
|
+
valuesSqlList.push(valueList);
|
25109
|
+
if (valueIndex < values.length - 1) {
|
25110
|
+
valuesSqlList.push(sql`, `);
|
25111
|
+
}
|
25239
25112
|
}
|
25240
25113
|
}
|
25241
25114
|
const withSql = this.buildWithCTE(withList);
|
25242
25115
|
const valuesSql = sql.join(valuesSqlList);
|
25243
25116
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
25244
25117
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
25245
|
-
|
25118
|
+
const overridingSql = overridingSystemValue_ === true ? sql`overriding system value ` : void 0;
|
25119
|
+
return sql`${withSql}insert into ${table4} ${insertOrder} ${overridingSql}${valuesSql}${onConflictSql}${returningSql}`;
|
25246
25120
|
}
|
25247
25121
|
buildRefreshMaterializedViewQuery({ view: view4, concurrently, withNoData }) {
|
25248
25122
|
const concurrentlySql = concurrently ? sql` concurrently` : void 0;
|
@@ -25978,12 +25852,12 @@ var init_dialect = __esm({
|
|
25978
25852
|
};
|
25979
25853
|
}
|
25980
25854
|
};
|
25981
|
-
__publicField(PgDialect,
|
25855
|
+
__publicField(PgDialect, _a127, "PgDialect");
|
25982
25856
|
}
|
25983
25857
|
});
|
25984
25858
|
|
25985
25859
|
// ../drizzle-orm/dist/selection-proxy.js
|
25986
|
-
var
|
25860
|
+
var _a128, _SelectionProxyHandler, SelectionProxyHandler;
|
25987
25861
|
var init_selection_proxy = __esm({
|
25988
25862
|
"../drizzle-orm/dist/selection-proxy.js"() {
|
25989
25863
|
"use strict";
|
@@ -25993,7 +25867,7 @@ var init_selection_proxy = __esm({
|
|
25993
25867
|
init_sql();
|
25994
25868
|
init_subquery();
|
25995
25869
|
init_view_common();
|
25996
|
-
|
25870
|
+
_a128 = entityKind;
|
25997
25871
|
_SelectionProxyHandler = class _SelectionProxyHandler {
|
25998
25872
|
constructor(config) {
|
25999
25873
|
__publicField(this, "config");
|
@@ -26059,25 +25933,25 @@ var init_selection_proxy = __esm({
|
|
26059
25933
|
return new Proxy(value, new _SelectionProxyHandler(this.config));
|
26060
25934
|
}
|
26061
25935
|
};
|
26062
|
-
__publicField(_SelectionProxyHandler,
|
25936
|
+
__publicField(_SelectionProxyHandler, _a128, "SelectionProxyHandler");
|
26063
25937
|
SelectionProxyHandler = _SelectionProxyHandler;
|
26064
25938
|
}
|
26065
25939
|
});
|
26066
25940
|
|
26067
25941
|
// ../drizzle-orm/dist/query-builders/query-builder.js
|
26068
|
-
var
|
25942
|
+
var _a129, TypedQueryBuilder;
|
26069
25943
|
var init_query_builder = __esm({
|
26070
25944
|
"../drizzle-orm/dist/query-builders/query-builder.js"() {
|
26071
25945
|
"use strict";
|
26072
25946
|
init_entity();
|
26073
|
-
|
25947
|
+
_a129 = entityKind;
|
26074
25948
|
TypedQueryBuilder = class {
|
26075
25949
|
/** @internal */
|
26076
25950
|
getSelectedFields() {
|
26077
25951
|
return this._.selectedFields;
|
26078
25952
|
}
|
26079
25953
|
};
|
26080
|
-
__publicField(TypedQueryBuilder,
|
25954
|
+
__publicField(TypedQueryBuilder, _a129, "TypedQueryBuilder");
|
26081
25955
|
}
|
26082
25956
|
});
|
26083
25957
|
|
@@ -26099,7 +25973,7 @@ function createSetOperator(type, isAll) {
|
|
26099
25973
|
return leftSelect.addSetOperators(setOperators);
|
26100
25974
|
};
|
26101
25975
|
}
|
26102
|
-
var
|
25976
|
+
var _a130, PgSelectBuilder, _a131, _b99, PgSelectQueryBuilderBase, _a132, _b100, PgSelectBase, getPgSetOperators, union, unionAll, intersect, intersectAll, except, exceptAll;
|
26103
25977
|
var init_select2 = __esm({
|
26104
25978
|
"../drizzle-orm/dist/pg-core/query-builders/select.js"() {
|
26105
25979
|
"use strict";
|
@@ -26115,7 +25989,7 @@ var init_select2 = __esm({
|
|
26115
25989
|
init_utils2();
|
26116
25990
|
init_utils2();
|
26117
25991
|
init_view_common();
|
26118
|
-
|
25992
|
+
_a130 = entityKind;
|
26119
25993
|
PgSelectBuilder = class {
|
26120
25994
|
constructor(config) {
|
26121
25995
|
__publicField(this, "fields");
|
@@ -26123,6 +25997,7 @@ var init_select2 = __esm({
|
|
26123
25997
|
__publicField(this, "dialect");
|
26124
25998
|
__publicField(this, "withList", []);
|
26125
25999
|
__publicField(this, "distinct");
|
26000
|
+
__publicField(this, "authToken");
|
26126
26001
|
this.fields = config.fields;
|
26127
26002
|
this.session = config.session;
|
26128
26003
|
this.dialect = config.dialect;
|
@@ -26131,6 +26006,11 @@ var init_select2 = __esm({
|
|
26131
26006
|
}
|
26132
26007
|
this.distinct = config.distinct;
|
26133
26008
|
}
|
26009
|
+
/** @internal */
|
26010
|
+
setToken(token) {
|
26011
|
+
this.authToken = token;
|
26012
|
+
return this;
|
26013
|
+
}
|
26134
26014
|
/**
|
26135
26015
|
* Specify the table, subquery, or other target that you're
|
26136
26016
|
* building a select query against.
|
@@ -26153,7 +26033,7 @@ var init_select2 = __esm({
|
|
26153
26033
|
} else {
|
26154
26034
|
fields = getTableColumns(source);
|
26155
26035
|
}
|
26156
|
-
return new PgSelectBase({
|
26036
|
+
return this.authToken === void 0 ? new PgSelectBase({
|
26157
26037
|
table: source,
|
26158
26038
|
fields,
|
26159
26039
|
isPartialSelect,
|
@@ -26161,11 +26041,19 @@ var init_select2 = __esm({
|
|
26161
26041
|
dialect: this.dialect,
|
26162
26042
|
withList: this.withList,
|
26163
26043
|
distinct: this.distinct
|
26164
|
-
})
|
26044
|
+
}) : new PgSelectBase({
|
26045
|
+
table: source,
|
26046
|
+
fields,
|
26047
|
+
isPartialSelect,
|
26048
|
+
session: this.session,
|
26049
|
+
dialect: this.dialect,
|
26050
|
+
withList: this.withList,
|
26051
|
+
distinct: this.distinct
|
26052
|
+
}).setToken(this.authToken);
|
26165
26053
|
}
|
26166
26054
|
};
|
26167
|
-
__publicField(PgSelectBuilder,
|
26168
|
-
PgSelectQueryBuilderBase = class extends (
|
26055
|
+
__publicField(PgSelectBuilder, _a130, "PgSelectBuilder");
|
26056
|
+
PgSelectQueryBuilderBase = class extends (_b99 = TypedQueryBuilder, _a131 = entityKind, _b99) {
|
26169
26057
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
26170
26058
|
super();
|
26171
26059
|
__publicField(this, "_");
|
@@ -26765,19 +26653,20 @@ var init_select2 = __esm({
|
|
26765
26653
|
return this;
|
26766
26654
|
}
|
26767
26655
|
};
|
26768
|
-
__publicField(PgSelectQueryBuilderBase,
|
26769
|
-
PgSelectBase = class extends (
|
26656
|
+
__publicField(PgSelectQueryBuilderBase, _a131, "PgSelectQueryBuilder");
|
26657
|
+
PgSelectBase = class extends (_b100 = PgSelectQueryBuilderBase, _a132 = entityKind, _b100) {
|
26770
26658
|
constructor() {
|
26771
26659
|
super(...arguments);
|
26660
|
+
__publicField(this, "authToken");
|
26772
26661
|
__publicField(this, "execute", (placeholderValues) => {
|
26773
26662
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
26774
|
-
return this._prepare().execute(placeholderValues);
|
26663
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
26775
26664
|
});
|
26776
26665
|
});
|
26777
26666
|
}
|
26778
26667
|
/** @internal */
|
26779
26668
|
_prepare(name2) {
|
26780
|
-
const { session, config, dialect: dialect4, joinsNotNullableMap } = this;
|
26669
|
+
const { session, config, dialect: dialect4, joinsNotNullableMap, authToken } = this;
|
26781
26670
|
if (!session) {
|
26782
26671
|
throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
26783
26672
|
}
|
@@ -26785,7 +26674,7 @@ var init_select2 = __esm({
|
|
26785
26674
|
const fieldsList = orderSelectedFields(config.fields);
|
26786
26675
|
const query = session.prepareQuery(dialect4.sqlToQuery(this.getSQL()), fieldsList, name2, true);
|
26787
26676
|
query.joinsNotNullableMap = joinsNotNullableMap;
|
26788
|
-
return query;
|
26677
|
+
return authToken === void 0 ? query : query.setToken(authToken);
|
26789
26678
|
});
|
26790
26679
|
}
|
26791
26680
|
/**
|
@@ -26798,8 +26687,13 @@ var init_select2 = __esm({
|
|
26798
26687
|
prepare(name2) {
|
26799
26688
|
return this._prepare(name2);
|
26800
26689
|
}
|
26690
|
+
/** @internal */
|
26691
|
+
setToken(token) {
|
26692
|
+
this.authToken = token;
|
26693
|
+
return this;
|
26694
|
+
}
|
26801
26695
|
};
|
26802
|
-
__publicField(PgSelectBase,
|
26696
|
+
__publicField(PgSelectBase, _a132, "PgSelect");
|
26803
26697
|
applyMixins(PgSelectBase, [QueryPromise]);
|
26804
26698
|
getPgSetOperators = () => ({
|
26805
26699
|
union,
|
@@ -26819,7 +26713,7 @@ var init_select2 = __esm({
|
|
26819
26713
|
});
|
26820
26714
|
|
26821
26715
|
// ../drizzle-orm/dist/pg-core/query-builders/query-builder.js
|
26822
|
-
var
|
26716
|
+
var _a133, QueryBuilder;
|
26823
26717
|
var init_query_builder2 = __esm({
|
26824
26718
|
"../drizzle-orm/dist/pg-core/query-builders/query-builder.js"() {
|
26825
26719
|
"use strict";
|
@@ -26828,7 +26722,7 @@ var init_query_builder2 = __esm({
|
|
26828
26722
|
init_selection_proxy();
|
26829
26723
|
init_subquery();
|
26830
26724
|
init_select2();
|
26831
|
-
|
26725
|
+
_a133 = entityKind;
|
26832
26726
|
QueryBuilder = class {
|
26833
26727
|
constructor(dialect4) {
|
26834
26728
|
__publicField(this, "dialect");
|
@@ -26909,32 +26803,232 @@ var init_query_builder2 = __esm({
|
|
26909
26803
|
return this.dialect;
|
26910
26804
|
}
|
26911
26805
|
};
|
26912
|
-
__publicField(QueryBuilder,
|
26806
|
+
__publicField(QueryBuilder, _a133, "PgQueryBuilder");
|
26913
26807
|
}
|
26914
26808
|
});
|
26915
26809
|
|
26916
|
-
// ../drizzle-orm/dist/pg-core/query-builders/
|
26917
|
-
var
|
26918
|
-
var
|
26919
|
-
"../drizzle-orm/dist/pg-core/query-builders/
|
26810
|
+
// ../drizzle-orm/dist/pg-core/query-builders/insert.js
|
26811
|
+
var _a134, PgInsertBuilder, _a135, _b101, PgInsertBase;
|
26812
|
+
var init_insert = __esm({
|
26813
|
+
"../drizzle-orm/dist/pg-core/query-builders/insert.js"() {
|
26920
26814
|
"use strict";
|
26921
26815
|
init_entity();
|
26922
26816
|
init_query_promise();
|
26817
|
+
init_sql();
|
26818
|
+
init_table();
|
26923
26819
|
init_tracing();
|
26924
|
-
|
26925
|
-
|
26926
|
-
|
26927
|
-
|
26928
|
-
|
26929
|
-
|
26930
|
-
|
26931
|
-
});
|
26932
|
-
});
|
26820
|
+
init_utils2();
|
26821
|
+
init_query_builder2();
|
26822
|
+
_a134 = entityKind;
|
26823
|
+
PgInsertBuilder = class {
|
26824
|
+
constructor(table4, session, dialect4, withList, overridingSystemValue_) {
|
26825
|
+
__publicField(this, "authToken");
|
26826
|
+
this.table = table4;
|
26933
26827
|
this.session = session;
|
26934
26828
|
this.dialect = dialect4;
|
26935
|
-
this.
|
26829
|
+
this.withList = withList;
|
26830
|
+
this.overridingSystemValue_ = overridingSystemValue_;
|
26936
26831
|
}
|
26937
|
-
|
26832
|
+
/** @internal */
|
26833
|
+
setToken(token) {
|
26834
|
+
this.authToken = token;
|
26835
|
+
return this;
|
26836
|
+
}
|
26837
|
+
overridingSystemValue() {
|
26838
|
+
this.overridingSystemValue_ = true;
|
26839
|
+
return this;
|
26840
|
+
}
|
26841
|
+
values(values) {
|
26842
|
+
values = Array.isArray(values) ? values : [values];
|
26843
|
+
if (values.length === 0) {
|
26844
|
+
throw new Error("values() must be called with at least one value");
|
26845
|
+
}
|
26846
|
+
const mappedValues = values.map((entry) => {
|
26847
|
+
const result = {};
|
26848
|
+
const cols = this.table[Table2.Symbol.Columns];
|
26849
|
+
for (const colKey of Object.keys(entry)) {
|
26850
|
+
const colValue = entry[colKey];
|
26851
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
26852
|
+
}
|
26853
|
+
return result;
|
26854
|
+
});
|
26855
|
+
return this.authToken === void 0 ? new PgInsertBase(
|
26856
|
+
this.table,
|
26857
|
+
mappedValues,
|
26858
|
+
this.session,
|
26859
|
+
this.dialect,
|
26860
|
+
this.withList,
|
26861
|
+
false,
|
26862
|
+
this.overridingSystemValue_
|
26863
|
+
) : new PgInsertBase(
|
26864
|
+
this.table,
|
26865
|
+
mappedValues,
|
26866
|
+
this.session,
|
26867
|
+
this.dialect,
|
26868
|
+
this.withList,
|
26869
|
+
false,
|
26870
|
+
this.overridingSystemValue_
|
26871
|
+
).setToken(this.authToken);
|
26872
|
+
}
|
26873
|
+
select(selectQuery) {
|
26874
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
|
26875
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
26876
|
+
throw new Error(
|
26877
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
26878
|
+
);
|
26879
|
+
}
|
26880
|
+
return new PgInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
26881
|
+
}
|
26882
|
+
};
|
26883
|
+
__publicField(PgInsertBuilder, _a134, "PgInsertBuilder");
|
26884
|
+
PgInsertBase = class extends (_b101 = QueryPromise, _a135 = entityKind, _b101) {
|
26885
|
+
constructor(table4, values, session, dialect4, withList, select, overridingSystemValue_) {
|
26886
|
+
super();
|
26887
|
+
__publicField(this, "config");
|
26888
|
+
__publicField(this, "authToken");
|
26889
|
+
__publicField(this, "execute", (placeholderValues) => {
|
26890
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
26891
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
26892
|
+
});
|
26893
|
+
});
|
26894
|
+
this.session = session;
|
26895
|
+
this.dialect = dialect4;
|
26896
|
+
this.config = { table: table4, values, withList, select, overridingSystemValue_ };
|
26897
|
+
}
|
26898
|
+
returning(fields = this.config.table[Table2.Symbol.Columns]) {
|
26899
|
+
this.config.returning = orderSelectedFields(fields);
|
26900
|
+
return this;
|
26901
|
+
}
|
26902
|
+
/**
|
26903
|
+
* Adds an `on conflict do nothing` clause to the query.
|
26904
|
+
*
|
26905
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
26906
|
+
*
|
26907
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
26908
|
+
*
|
26909
|
+
* @param config The `target` and `where` clauses.
|
26910
|
+
*
|
26911
|
+
* @example
|
26912
|
+
* ```ts
|
26913
|
+
* // Insert one row and cancel the insert if there's a conflict
|
26914
|
+
* await db.insert(cars)
|
26915
|
+
* .values({ id: 1, brand: 'BMW' })
|
26916
|
+
* .onConflictDoNothing();
|
26917
|
+
*
|
26918
|
+
* // Explicitly specify conflict target
|
26919
|
+
* await db.insert(cars)
|
26920
|
+
* .values({ id: 1, brand: 'BMW' })
|
26921
|
+
* .onConflictDoNothing({ target: cars.id });
|
26922
|
+
* ```
|
26923
|
+
*/
|
26924
|
+
onConflictDoNothing(config = {}) {
|
26925
|
+
if (config.target === void 0) {
|
26926
|
+
this.config.onConflict = sql`do nothing`;
|
26927
|
+
} else {
|
26928
|
+
let targetColumn = "";
|
26929
|
+
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));
|
26930
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
26931
|
+
this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
|
26932
|
+
}
|
26933
|
+
return this;
|
26934
|
+
}
|
26935
|
+
/**
|
26936
|
+
* Adds an `on conflict do update` clause to the query.
|
26937
|
+
*
|
26938
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
26939
|
+
*
|
26940
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
26941
|
+
*
|
26942
|
+
* @param config The `target`, `set` and `where` clauses.
|
26943
|
+
*
|
26944
|
+
* @example
|
26945
|
+
* ```ts
|
26946
|
+
* // Update the row if there's a conflict
|
26947
|
+
* await db.insert(cars)
|
26948
|
+
* .values({ id: 1, brand: 'BMW' })
|
26949
|
+
* .onConflictDoUpdate({
|
26950
|
+
* target: cars.id,
|
26951
|
+
* set: { brand: 'Porsche' }
|
26952
|
+
* });
|
26953
|
+
*
|
26954
|
+
* // Upsert with 'where' clause
|
26955
|
+
* await db.insert(cars)
|
26956
|
+
* .values({ id: 1, brand: 'BMW' })
|
26957
|
+
* .onConflictDoUpdate({
|
26958
|
+
* target: cars.id,
|
26959
|
+
* set: { brand: 'newBMW' },
|
26960
|
+
* targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
|
26961
|
+
* });
|
26962
|
+
* ```
|
26963
|
+
*/
|
26964
|
+
onConflictDoUpdate(config) {
|
26965
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
26966
|
+
throw new Error(
|
26967
|
+
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
26968
|
+
);
|
26969
|
+
}
|
26970
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
26971
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
26972
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
26973
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
26974
|
+
let targetColumn = "";
|
26975
|
+
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));
|
26976
|
+
this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
26977
|
+
return this;
|
26978
|
+
}
|
26979
|
+
/** @internal */
|
26980
|
+
getSQL() {
|
26981
|
+
return this.dialect.buildInsertQuery(this.config);
|
26982
|
+
}
|
26983
|
+
toSQL() {
|
26984
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
26985
|
+
return rest;
|
26986
|
+
}
|
26987
|
+
/** @internal */
|
26988
|
+
_prepare(name2) {
|
26989
|
+
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
26990
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
|
26991
|
+
});
|
26992
|
+
}
|
26993
|
+
prepare(name2) {
|
26994
|
+
return this._prepare(name2);
|
26995
|
+
}
|
26996
|
+
/** @internal */
|
26997
|
+
setToken(token) {
|
26998
|
+
this.authToken = token;
|
26999
|
+
return this;
|
27000
|
+
}
|
27001
|
+
$dynamic() {
|
27002
|
+
return this;
|
27003
|
+
}
|
27004
|
+
};
|
27005
|
+
__publicField(PgInsertBase, _a135, "PgInsert");
|
27006
|
+
}
|
27007
|
+
});
|
27008
|
+
|
27009
|
+
// ../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js
|
27010
|
+
var _a136, _b102, PgRefreshMaterializedView;
|
27011
|
+
var init_refresh_materialized_view = __esm({
|
27012
|
+
"../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js"() {
|
27013
|
+
"use strict";
|
27014
|
+
init_entity();
|
27015
|
+
init_query_promise();
|
27016
|
+
init_tracing();
|
27017
|
+
PgRefreshMaterializedView = class extends (_b102 = QueryPromise, _a136 = entityKind, _b102) {
|
27018
|
+
constructor(view4, session, dialect4) {
|
27019
|
+
super();
|
27020
|
+
__publicField(this, "config");
|
27021
|
+
__publicField(this, "authToken");
|
27022
|
+
__publicField(this, "execute", (placeholderValues) => {
|
27023
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
27024
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
27025
|
+
});
|
27026
|
+
});
|
27027
|
+
this.session = session;
|
27028
|
+
this.dialect = dialect4;
|
27029
|
+
this.config = { view: view4 };
|
27030
|
+
}
|
27031
|
+
concurrently() {
|
26938
27032
|
if (this.config.withNoData !== void 0) {
|
26939
27033
|
throw new Error("Cannot use concurrently and withNoData together");
|
26940
27034
|
}
|
@@ -26965,6 +27059,11 @@ var init_refresh_materialized_view = __esm({
|
|
26965
27059
|
prepare(name2) {
|
26966
27060
|
return this._prepare(name2);
|
26967
27061
|
}
|
27062
|
+
/** @internal */
|
27063
|
+
setToken(token) {
|
27064
|
+
this.authToken = token;
|
27065
|
+
return this;
|
27066
|
+
}
|
26968
27067
|
};
|
26969
27068
|
__publicField(PgRefreshMaterializedView, _a136, "PgRefreshMaterializedView");
|
26970
27069
|
}
|
@@ -26983,25 +27082,41 @@ var init_update = __esm({
|
|
26983
27082
|
"../drizzle-orm/dist/pg-core/query-builders/update.js"() {
|
26984
27083
|
"use strict";
|
26985
27084
|
init_entity();
|
27085
|
+
init_table2();
|
26986
27086
|
init_query_promise();
|
27087
|
+
init_selection_proxy();
|
27088
|
+
init_sql();
|
27089
|
+
init_subquery();
|
26987
27090
|
init_table();
|
26988
27091
|
init_utils2();
|
27092
|
+
init_view_common();
|
26989
27093
|
_a137 = entityKind;
|
26990
27094
|
PgUpdateBuilder = class {
|
26991
27095
|
constructor(table4, session, dialect4, withList) {
|
27096
|
+
__publicField(this, "authToken");
|
26992
27097
|
this.table = table4;
|
26993
27098
|
this.session = session;
|
26994
27099
|
this.dialect = dialect4;
|
26995
27100
|
this.withList = withList;
|
26996
27101
|
}
|
27102
|
+
setToken(token) {
|
27103
|
+
this.authToken = token;
|
27104
|
+
return this;
|
27105
|
+
}
|
26997
27106
|
set(values) {
|
26998
|
-
return new PgUpdateBase(
|
27107
|
+
return this.authToken === void 0 ? new PgUpdateBase(
|
26999
27108
|
this.table,
|
27000
27109
|
mapUpdateSet(this.table, values),
|
27001
27110
|
this.session,
|
27002
27111
|
this.dialect,
|
27003
27112
|
this.withList
|
27004
|
-
)
|
27113
|
+
) : new PgUpdateBase(
|
27114
|
+
this.table,
|
27115
|
+
mapUpdateSet(this.table, values),
|
27116
|
+
this.session,
|
27117
|
+
this.dialect,
|
27118
|
+
this.withList
|
27119
|
+
).setToken(this.authToken);
|
27005
27120
|
}
|
27006
27121
|
};
|
27007
27122
|
__publicField(PgUpdateBuilder, _a137, "PgUpdateBuilder");
|
@@ -27009,12 +27124,86 @@ var init_update = __esm({
|
|
27009
27124
|
constructor(table4, set, session, dialect4, withList) {
|
27010
27125
|
super();
|
27011
27126
|
__publicField(this, "config");
|
27127
|
+
__publicField(this, "tableName");
|
27128
|
+
__publicField(this, "joinsNotNullableMap");
|
27129
|
+
__publicField(this, "leftJoin", this.createJoin("left"));
|
27130
|
+
__publicField(this, "rightJoin", this.createJoin("right"));
|
27131
|
+
__publicField(this, "innerJoin", this.createJoin("inner"));
|
27132
|
+
__publicField(this, "fullJoin", this.createJoin("full"));
|
27133
|
+
__publicField(this, "authToken");
|
27012
27134
|
__publicField(this, "execute", (placeholderValues) => {
|
27013
|
-
return this._prepare().execute(placeholderValues);
|
27135
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
27014
27136
|
});
|
27015
27137
|
this.session = session;
|
27016
27138
|
this.dialect = dialect4;
|
27017
|
-
this.config = { set, table: table4, withList };
|
27139
|
+
this.config = { set, table: table4, withList, joins: [] };
|
27140
|
+
this.tableName = getTableLikeName(table4);
|
27141
|
+
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
27142
|
+
}
|
27143
|
+
from(source) {
|
27144
|
+
const tableName = getTableLikeName(source);
|
27145
|
+
if (typeof tableName === "string") {
|
27146
|
+
this.joinsNotNullableMap[tableName] = true;
|
27147
|
+
}
|
27148
|
+
this.config.from = source;
|
27149
|
+
return this;
|
27150
|
+
}
|
27151
|
+
getTableLikeFields(table4) {
|
27152
|
+
if (is(table4, PgTable)) {
|
27153
|
+
return table4[Table2.Symbol.Columns];
|
27154
|
+
} else if (is(table4, Subquery)) {
|
27155
|
+
return table4._.selectedFields;
|
27156
|
+
}
|
27157
|
+
return table4[ViewBaseConfig].selectedFields;
|
27158
|
+
}
|
27159
|
+
createJoin(joinType) {
|
27160
|
+
return (table4, on) => {
|
27161
|
+
const tableName = getTableLikeName(table4);
|
27162
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
27163
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
27164
|
+
}
|
27165
|
+
if (typeof on === "function") {
|
27166
|
+
const from = this.config.from && !is(this.config.from, SQL) ? this.getTableLikeFields(this.config.from) : void 0;
|
27167
|
+
on = on(
|
27168
|
+
new Proxy(
|
27169
|
+
this.config.table[Table2.Symbol.Columns],
|
27170
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
27171
|
+
),
|
27172
|
+
from && new Proxy(
|
27173
|
+
from,
|
27174
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
27175
|
+
)
|
27176
|
+
);
|
27177
|
+
}
|
27178
|
+
this.config.joins.push({ on, table: table4, joinType, alias: tableName });
|
27179
|
+
if (typeof tableName === "string") {
|
27180
|
+
switch (joinType) {
|
27181
|
+
case "left": {
|
27182
|
+
this.joinsNotNullableMap[tableName] = false;
|
27183
|
+
break;
|
27184
|
+
}
|
27185
|
+
case "right": {
|
27186
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
27187
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
27188
|
+
);
|
27189
|
+
this.joinsNotNullableMap[tableName] = true;
|
27190
|
+
break;
|
27191
|
+
}
|
27192
|
+
case "inner": {
|
27193
|
+
this.joinsNotNullableMap[tableName] = true;
|
27194
|
+
break;
|
27195
|
+
}
|
27196
|
+
case "full": {
|
27197
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
27198
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
27199
|
+
);
|
27200
|
+
this.joinsNotNullableMap[tableName] = false;
|
27201
|
+
break;
|
27202
|
+
}
|
27203
|
+
}
|
27204
|
+
}
|
27205
|
+
return this;
|
27206
|
+
};
|
27018
27207
|
}
|
27019
27208
|
/**
|
27020
27209
|
* Adds a 'where' clause to the query.
|
@@ -27053,7 +27242,24 @@ var init_update = __esm({
|
|
27053
27242
|
this.config.where = where;
|
27054
27243
|
return this;
|
27055
27244
|
}
|
27056
|
-
returning(fields
|
27245
|
+
returning(fields) {
|
27246
|
+
if (!fields) {
|
27247
|
+
fields = Object.assign({}, this.config.table[Table2.Symbol.Columns]);
|
27248
|
+
if (this.config.from) {
|
27249
|
+
const tableName = getTableLikeName(this.config.from);
|
27250
|
+
if (typeof tableName === "string" && this.config.from && !is(this.config.from, SQL)) {
|
27251
|
+
const fromFields = this.getTableLikeFields(this.config.from);
|
27252
|
+
fields[tableName] = fromFields;
|
27253
|
+
}
|
27254
|
+
for (const join of this.config.joins) {
|
27255
|
+
const tableName2 = getTableLikeName(join.table);
|
27256
|
+
if (typeof tableName2 === "string" && !is(join.table, SQL)) {
|
27257
|
+
const fromFields = this.getTableLikeFields(join.table);
|
27258
|
+
fields[tableName2] = fromFields;
|
27259
|
+
}
|
27260
|
+
}
|
27261
|
+
}
|
27262
|
+
}
|
27057
27263
|
this.config.returning = orderSelectedFields(fields);
|
27058
27264
|
return this;
|
27059
27265
|
}
|
@@ -27067,11 +27273,18 @@ var init_update = __esm({
|
|
27067
27273
|
}
|
27068
27274
|
/** @internal */
|
27069
27275
|
_prepare(name2) {
|
27070
|
-
|
27276
|
+
const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
|
27277
|
+
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
27278
|
+
return query;
|
27071
27279
|
}
|
27072
27280
|
prepare(name2) {
|
27073
27281
|
return this._prepare(name2);
|
27074
27282
|
}
|
27283
|
+
/** @internal */
|
27284
|
+
setToken(token) {
|
27285
|
+
this.authToken = token;
|
27286
|
+
return this;
|
27287
|
+
}
|
27075
27288
|
$dynamic() {
|
27076
27289
|
return this;
|
27077
27290
|
}
|
@@ -27105,6 +27318,7 @@ var init_count = __esm({
|
|
27105
27318
|
constructor(params) {
|
27106
27319
|
super(_PgCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
|
27107
27320
|
__publicField(this, "sql");
|
27321
|
+
__publicField(this, "token");
|
27108
27322
|
__publicField(this, _a139, "PgCountBuilder");
|
27109
27323
|
__publicField(this, "session");
|
27110
27324
|
this.params = params;
|
@@ -27121,8 +27335,12 @@ var init_count = __esm({
|
|
27121
27335
|
static buildCount(source, filters) {
|
27122
27336
|
return sql`select count(*) as count from ${source}${sql.raw(" where ").if(filters)}${filters};`;
|
27123
27337
|
}
|
27338
|
+
/** @intrnal */
|
27339
|
+
setToken(token) {
|
27340
|
+
this.token = token;
|
27341
|
+
}
|
27124
27342
|
then(onfulfilled, onrejected) {
|
27125
|
-
return Promise.resolve(this.session.count(this.sql)).then(
|
27343
|
+
return Promise.resolve(this.session.count(this.sql, this.token)).then(
|
27126
27344
|
onfulfilled,
|
27127
27345
|
onrejected
|
27128
27346
|
);
|
@@ -27199,6 +27417,7 @@ var init_query = __esm({
|
|
27199
27417
|
PgRelationalQuery = class extends (_b105 = QueryPromise, _a141 = entityKind, _b105) {
|
27200
27418
|
constructor(fullSchema, schema4, tableNamesMap, table4, tableConfig, dialect4, session, config, mode) {
|
27201
27419
|
super();
|
27420
|
+
__publicField(this, "authToken");
|
27202
27421
|
this.fullSchema = fullSchema;
|
27203
27422
|
this.schema = schema4;
|
27204
27423
|
this.tableNamesMap = tableNamesMap;
|
@@ -27256,9 +27475,14 @@ var init_query = __esm({
|
|
27256
27475
|
toSQL() {
|
27257
27476
|
return this._toSQL().builtQuery;
|
27258
27477
|
}
|
27478
|
+
/** @internal */
|
27479
|
+
setToken(token) {
|
27480
|
+
this.authToken = token;
|
27481
|
+
return this;
|
27482
|
+
}
|
27259
27483
|
execute() {
|
27260
27484
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
27261
|
-
return this._prepare().execute();
|
27485
|
+
return this._prepare().execute(void 0, this.authToken);
|
27262
27486
|
});
|
27263
27487
|
}
|
27264
27488
|
};
|
@@ -27321,6 +27545,7 @@ var init_db = __esm({
|
|
27321
27545
|
PgDatabase = class {
|
27322
27546
|
constructor(dialect4, session, schema4) {
|
27323
27547
|
__publicField(this, "query");
|
27548
|
+
__publicField(this, "authToken");
|
27324
27549
|
this.dialect = dialect4;
|
27325
27550
|
this.session = session;
|
27326
27551
|
this._ = schema4 ? {
|
@@ -27576,7 +27801,7 @@ var init_db = __esm({
|
|
27576
27801
|
false
|
27577
27802
|
);
|
27578
27803
|
return new PgRaw(
|
27579
|
-
() => prepared.execute(),
|
27804
|
+
() => prepared.execute(void 0, this.authToken),
|
27580
27805
|
sequel,
|
27581
27806
|
builtQuery,
|
27582
27807
|
(result) => prepared.mapResult(result, true)
|
@@ -28121,6 +28346,7 @@ var init_session = __esm({
|
|
28121
28346
|
_a159 = entityKind;
|
28122
28347
|
PgPreparedQuery = class {
|
28123
28348
|
constructor(query) {
|
28349
|
+
__publicField(this, "authToken");
|
28124
28350
|
/** @internal */
|
28125
28351
|
__publicField(this, "joinsNotNullableMap");
|
28126
28352
|
this.query = query;
|
@@ -28131,6 +28357,11 @@ var init_session = __esm({
|
|
28131
28357
|
mapResult(response, _isFromBatch) {
|
28132
28358
|
return response;
|
28133
28359
|
}
|
28360
|
+
/** @internal */
|
28361
|
+
setToken(token) {
|
28362
|
+
this.authToken = token;
|
28363
|
+
return this;
|
28364
|
+
}
|
28134
28365
|
};
|
28135
28366
|
__publicField(PgPreparedQuery, _a159, "PgPreparedQuery");
|
28136
28367
|
_a160 = entityKind;
|
@@ -28138,7 +28369,8 @@ var init_session = __esm({
|
|
28138
28369
|
constructor(dialect4) {
|
28139
28370
|
this.dialect = dialect4;
|
28140
28371
|
}
|
28141
|
-
|
28372
|
+
/** @internal */
|
28373
|
+
execute(query, token) {
|
28142
28374
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
28143
28375
|
const prepared = tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
28144
28376
|
return this.prepareQuery(
|
@@ -28148,7 +28380,7 @@ var init_session = __esm({
|
|
28148
28380
|
false
|
28149
28381
|
);
|
28150
28382
|
});
|
28151
|
-
return prepared.execute();
|
28383
|
+
return prepared.setToken(token).execute(void 0, token);
|
28152
28384
|
});
|
28153
28385
|
}
|
28154
28386
|
all(query) {
|
@@ -28159,8 +28391,9 @@ var init_session = __esm({
|
|
28159
28391
|
false
|
28160
28392
|
).all();
|
28161
28393
|
}
|
28162
|
-
|
28163
|
-
|
28394
|
+
/** @internal */
|
28395
|
+
async count(sql2, token) {
|
28396
|
+
const res = await this.execute(sql2, token);
|
28164
28397
|
return Number(
|
28165
28398
|
res[0]["count"]
|
28166
28399
|
);
|
@@ -30817,200 +31050,32 @@ var init_delete2 = __esm({
|
|
30817
31050
|
prepare() {
|
30818
31051
|
return this._prepare(false);
|
30819
31052
|
}
|
30820
|
-
async execute(placeholderValues) {
|
30821
|
-
return this._prepare().execute(placeholderValues);
|
30822
|
-
}
|
30823
|
-
$dynamic() {
|
30824
|
-
return this;
|
30825
|
-
}
|
30826
|
-
};
|
30827
|
-
__publicField(SQLiteDeleteBase, _a196, "SQLiteDelete");
|
30828
|
-
}
|
30829
|
-
});
|
30830
|
-
|
30831
|
-
// ../drizzle-orm/dist/sqlite-core/query-builders/insert.js
|
30832
|
-
var _a197, SQLiteInsertBuilder, _a198, _b142, SQLiteInsertBase;
|
30833
|
-
var init_insert2 = __esm({
|
30834
|
-
"../drizzle-orm/dist/sqlite-core/query-builders/insert.js"() {
|
30835
|
-
"use strict";
|
30836
|
-
init_entity();
|
30837
|
-
init_query_promise();
|
30838
|
-
init_sql();
|
30839
|
-
init_table3();
|
30840
|
-
init_table();
|
30841
|
-
init_utils2();
|
30842
|
-
_a197 = entityKind;
|
30843
|
-
SQLiteInsertBuilder = class {
|
30844
|
-
constructor(table4, session, dialect4, withList) {
|
30845
|
-
this.table = table4;
|
30846
|
-
this.session = session;
|
30847
|
-
this.dialect = dialect4;
|
30848
|
-
this.withList = withList;
|
30849
|
-
}
|
30850
|
-
values(values) {
|
30851
|
-
values = Array.isArray(values) ? values : [values];
|
30852
|
-
if (values.length === 0) {
|
30853
|
-
throw new Error("values() must be called with at least one value");
|
30854
|
-
}
|
30855
|
-
const mappedValues = values.map((entry) => {
|
30856
|
-
const result = {};
|
30857
|
-
const cols = this.table[Table2.Symbol.Columns];
|
30858
|
-
for (const colKey of Object.keys(entry)) {
|
30859
|
-
const colValue = entry[colKey];
|
30860
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
30861
|
-
}
|
30862
|
-
return result;
|
30863
|
-
});
|
30864
|
-
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
30865
|
-
}
|
30866
|
-
};
|
30867
|
-
__publicField(SQLiteInsertBuilder, _a197, "SQLiteInsertBuilder");
|
30868
|
-
SQLiteInsertBase = class extends (_b142 = QueryPromise, _a198 = entityKind, _b142) {
|
30869
|
-
constructor(table4, values, session, dialect4, withList) {
|
30870
|
-
super();
|
30871
|
-
/** @internal */
|
30872
|
-
__publicField(this, "config");
|
30873
|
-
__publicField(this, "run", (placeholderValues) => {
|
30874
|
-
return this._prepare().run(placeholderValues);
|
30875
|
-
});
|
30876
|
-
__publicField(this, "all", (placeholderValues) => {
|
30877
|
-
return this._prepare().all(placeholderValues);
|
30878
|
-
});
|
30879
|
-
__publicField(this, "get", (placeholderValues) => {
|
30880
|
-
return this._prepare().get(placeholderValues);
|
30881
|
-
});
|
30882
|
-
__publicField(this, "values", (placeholderValues) => {
|
30883
|
-
return this._prepare().values(placeholderValues);
|
30884
|
-
});
|
30885
|
-
this.session = session;
|
30886
|
-
this.dialect = dialect4;
|
30887
|
-
this.config = { table: table4, values, withList };
|
30888
|
-
}
|
30889
|
-
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
30890
|
-
this.config.returning = orderSelectedFields(fields);
|
30891
|
-
return this;
|
30892
|
-
}
|
30893
|
-
/**
|
30894
|
-
* Adds an `on conflict do nothing` clause to the query.
|
30895
|
-
*
|
30896
|
-
* Calling this method simply avoids inserting a row as its alternative action.
|
30897
|
-
*
|
30898
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
30899
|
-
*
|
30900
|
-
* @param config The `target` and `where` clauses.
|
30901
|
-
*
|
30902
|
-
* @example
|
30903
|
-
* ```ts
|
30904
|
-
* // Insert one row and cancel the insert if there's a conflict
|
30905
|
-
* await db.insert(cars)
|
30906
|
-
* .values({ id: 1, brand: 'BMW' })
|
30907
|
-
* .onConflictDoNothing();
|
30908
|
-
*
|
30909
|
-
* // Explicitly specify conflict target
|
30910
|
-
* await db.insert(cars)
|
30911
|
-
* .values({ id: 1, brand: 'BMW' })
|
30912
|
-
* .onConflictDoNothing({ target: cars.id });
|
30913
|
-
* ```
|
30914
|
-
*/
|
30915
|
-
onConflictDoNothing(config = {}) {
|
30916
|
-
if (config.target === void 0) {
|
30917
|
-
this.config.onConflict = sql`do nothing`;
|
30918
|
-
} else {
|
30919
|
-
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
30920
|
-
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
30921
|
-
this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
|
30922
|
-
}
|
30923
|
-
return this;
|
30924
|
-
}
|
30925
|
-
/**
|
30926
|
-
* Adds an `on conflict do update` clause to the query.
|
30927
|
-
*
|
30928
|
-
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
30929
|
-
*
|
30930
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
30931
|
-
*
|
30932
|
-
* @param config The `target`, `set` and `where` clauses.
|
30933
|
-
*
|
30934
|
-
* @example
|
30935
|
-
* ```ts
|
30936
|
-
* // Update the row if there's a conflict
|
30937
|
-
* await db.insert(cars)
|
30938
|
-
* .values({ id: 1, brand: 'BMW' })
|
30939
|
-
* .onConflictDoUpdate({
|
30940
|
-
* target: cars.id,
|
30941
|
-
* set: { brand: 'Porsche' }
|
30942
|
-
* });
|
30943
|
-
*
|
30944
|
-
* // Upsert with 'where' clause
|
30945
|
-
* await db.insert(cars)
|
30946
|
-
* .values({ id: 1, brand: 'BMW' })
|
30947
|
-
* .onConflictDoUpdate({
|
30948
|
-
* target: cars.id,
|
30949
|
-
* set: { brand: 'newBMW' },
|
30950
|
-
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
30951
|
-
* });
|
30952
|
-
* ```
|
30953
|
-
*/
|
30954
|
-
onConflictDoUpdate(config) {
|
30955
|
-
if (config.where && (config.targetWhere || config.setWhere)) {
|
30956
|
-
throw new Error(
|
30957
|
-
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
30958
|
-
);
|
30959
|
-
}
|
30960
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
30961
|
-
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
30962
|
-
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
30963
|
-
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
30964
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
30965
|
-
this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
30966
|
-
return this;
|
30967
|
-
}
|
30968
|
-
/** @internal */
|
30969
|
-
getSQL() {
|
30970
|
-
return this.dialect.buildInsertQuery(this.config);
|
30971
|
-
}
|
30972
|
-
toSQL() {
|
30973
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
30974
|
-
return rest;
|
30975
|
-
}
|
30976
|
-
/** @internal */
|
30977
|
-
_prepare(isOneTimeQuery = true) {
|
30978
|
-
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
30979
|
-
this.dialect.sqlToQuery(this.getSQL()),
|
30980
|
-
this.config.returning,
|
30981
|
-
this.config.returning ? "all" : "run",
|
30982
|
-
true
|
30983
|
-
);
|
30984
|
-
}
|
30985
|
-
prepare() {
|
30986
|
-
return this._prepare(false);
|
30987
|
-
}
|
30988
|
-
async execute() {
|
30989
|
-
return this.config.returning ? this.all() : this.run();
|
30990
|
-
}
|
31053
|
+
async execute(placeholderValues) {
|
31054
|
+
return this._prepare().execute(placeholderValues);
|
31055
|
+
}
|
30991
31056
|
$dynamic() {
|
30992
31057
|
return this;
|
30993
31058
|
}
|
30994
31059
|
};
|
30995
|
-
__publicField(
|
31060
|
+
__publicField(SQLiteDeleteBase, _a196, "SQLiteDelete");
|
30996
31061
|
}
|
30997
31062
|
});
|
30998
31063
|
|
30999
31064
|
// ../drizzle-orm/dist/sqlite-core/view-base.js
|
31000
|
-
var
|
31065
|
+
var _a197, _b142, SQLiteViewBase;
|
31001
31066
|
var init_view_base2 = __esm({
|
31002
31067
|
"../drizzle-orm/dist/sqlite-core/view-base.js"() {
|
31003
31068
|
"use strict";
|
31004
31069
|
init_entity();
|
31005
31070
|
init_sql();
|
31006
|
-
SQLiteViewBase = class extends (
|
31071
|
+
SQLiteViewBase = class extends (_b142 = View3, _a197 = entityKind, _b142) {
|
31007
31072
|
};
|
31008
|
-
__publicField(SQLiteViewBase,
|
31073
|
+
__publicField(SQLiteViewBase, _a197, "SQLiteViewBase");
|
31009
31074
|
}
|
31010
31075
|
});
|
31011
31076
|
|
31012
31077
|
// ../drizzle-orm/dist/sqlite-core/dialect.js
|
31013
|
-
var
|
31078
|
+
var _a198, SQLiteDialect, _a199, _b143, SQLiteSyncDialect, _a200, _b144, SQLiteAsyncDialect;
|
31014
31079
|
var init_dialect2 = __esm({
|
31015
31080
|
"../drizzle-orm/dist/sqlite-core/dialect.js"() {
|
31016
31081
|
"use strict";
|
@@ -31029,7 +31094,7 @@ var init_dialect2 = __esm({
|
|
31029
31094
|
init_utils2();
|
31030
31095
|
init_view_common();
|
31031
31096
|
init_view_base2();
|
31032
|
-
|
31097
|
+
_a198 = entityKind;
|
31033
31098
|
SQLiteDialect = class {
|
31034
31099
|
constructor(config) {
|
31035
31100
|
/** @internal */
|
@@ -31082,14 +31147,16 @@ var init_dialect2 = __esm({
|
|
31082
31147
|
return [res];
|
31083
31148
|
}));
|
31084
31149
|
}
|
31085
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList, limit, orderBy }) {
|
31150
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, joins, from, limit, orderBy }) {
|
31086
31151
|
const withSql = this.buildWithCTE(withList);
|
31087
31152
|
const setSql = this.buildUpdateSet(table4, set);
|
31153
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
31154
|
+
const joinsSql = this.buildJoins(joins);
|
31088
31155
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
31089
31156
|
const whereSql = where ? sql` where ${where}` : void 0;
|
31090
31157
|
const orderBySql = this.buildOrderBy(orderBy);
|
31091
31158
|
const limitSql = this.buildLimit(limit);
|
31092
|
-
return sql`${withSql}update ${table4} set ${setSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
31159
|
+
return sql`${withSql}update ${table4} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
31093
31160
|
}
|
31094
31161
|
/**
|
31095
31162
|
* Builds selection SQL with provided fields/expressions
|
@@ -31142,6 +31209,37 @@ var init_dialect2 = __esm({
|
|
31142
31209
|
});
|
31143
31210
|
return sql.join(chunks);
|
31144
31211
|
}
|
31212
|
+
buildJoins(joins) {
|
31213
|
+
if (!joins || joins.length === 0) {
|
31214
|
+
return void 0;
|
31215
|
+
}
|
31216
|
+
const joinsArray = [];
|
31217
|
+
if (joins) {
|
31218
|
+
for (const [index4, joinMeta] of joins.entries()) {
|
31219
|
+
if (index4 === 0) {
|
31220
|
+
joinsArray.push(sql` `);
|
31221
|
+
}
|
31222
|
+
const table4 = joinMeta.table;
|
31223
|
+
if (is(table4, SQLiteTable)) {
|
31224
|
+
const tableName = table4[SQLiteTable.Symbol.Name];
|
31225
|
+
const tableSchema = table4[SQLiteTable.Symbol.Schema];
|
31226
|
+
const origTableName = table4[SQLiteTable.Symbol.OriginalName];
|
31227
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
31228
|
+
joinsArray.push(
|
31229
|
+
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
31230
|
+
);
|
31231
|
+
} else {
|
31232
|
+
joinsArray.push(
|
31233
|
+
sql`${sql.raw(joinMeta.joinType)} join ${table4} on ${joinMeta.on}`
|
31234
|
+
);
|
31235
|
+
}
|
31236
|
+
if (index4 < joins.length - 1) {
|
31237
|
+
joinsArray.push(sql` `);
|
31238
|
+
}
|
31239
|
+
}
|
31240
|
+
}
|
31241
|
+
return sql.join(joinsArray);
|
31242
|
+
}
|
31145
31243
|
buildLimit(limit) {
|
31146
31244
|
return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
31147
31245
|
}
|
@@ -31157,6 +31255,12 @@ var init_dialect2 = __esm({
|
|
31157
31255
|
}
|
31158
31256
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
31159
31257
|
}
|
31258
|
+
buildFromTable(table4) {
|
31259
|
+
if (is(table4, Table2) && table4[Table2.Symbol.OriginalName] !== table4[Table2.Symbol.Name]) {
|
31260
|
+
return sql`${sql.identifier(table4[Table2.Symbol.OriginalName])} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
31261
|
+
}
|
31262
|
+
return table4;
|
31263
|
+
}
|
31160
31264
|
buildSelectQuery({
|
31161
31265
|
withList,
|
31162
31266
|
fields,
|
@@ -31187,38 +31291,8 @@ var init_dialect2 = __esm({
|
|
31187
31291
|
const withSql = this.buildWithCTE(withList);
|
31188
31292
|
const distinctSql = distinct ? sql` distinct` : void 0;
|
31189
31293
|
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
31190
|
-
const tableSql = (
|
31191
|
-
|
31192
|
-
return sql`${sql.identifier(table4[Table2.Symbol.OriginalName])} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
31193
|
-
}
|
31194
|
-
return table4;
|
31195
|
-
})();
|
31196
|
-
const joinsArray = [];
|
31197
|
-
if (joins) {
|
31198
|
-
for (const [index4, joinMeta] of joins.entries()) {
|
31199
|
-
if (index4 === 0) {
|
31200
|
-
joinsArray.push(sql` `);
|
31201
|
-
}
|
31202
|
-
const table22 = joinMeta.table;
|
31203
|
-
if (is(table22, SQLiteTable)) {
|
31204
|
-
const tableName = table22[SQLiteTable.Symbol.Name];
|
31205
|
-
const tableSchema = table22[SQLiteTable.Symbol.Schema];
|
31206
|
-
const origTableName = table22[SQLiteTable.Symbol.OriginalName];
|
31207
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
31208
|
-
joinsArray.push(
|
31209
|
-
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
31210
|
-
);
|
31211
|
-
} else {
|
31212
|
-
joinsArray.push(
|
31213
|
-
sql`${sql.raw(joinMeta.joinType)} join ${table22} on ${joinMeta.on}`
|
31214
|
-
);
|
31215
|
-
}
|
31216
|
-
if (index4 < joins.length - 1) {
|
31217
|
-
joinsArray.push(sql` `);
|
31218
|
-
}
|
31219
|
-
}
|
31220
|
-
}
|
31221
|
-
const joinsSql = sql.join(joinsArray);
|
31294
|
+
const tableSql = this.buildFromTable(table4);
|
31295
|
+
const joinsSql = this.buildJoins(joins);
|
31222
31296
|
const whereSql = where ? sql` where ${where}` : void 0;
|
31223
31297
|
const havingSql = having ? sql` having ${having}` : void 0;
|
31224
31298
|
const groupByList = [];
|
@@ -31284,45 +31358,56 @@ var init_dialect2 = __esm({
|
|
31284
31358
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
31285
31359
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
31286
31360
|
}
|
31287
|
-
buildInsertQuery({ table: table4, values, onConflict, returning, withList }) {
|
31361
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, onConflict, returning, withList, select }) {
|
31288
31362
|
const valuesSqlList = [];
|
31289
31363
|
const columns = table4[Table2.Symbol.Columns];
|
31290
31364
|
const colEntries = Object.entries(columns).filter(
|
31291
31365
|
([_2, col]) => !col.shouldDisableInsert()
|
31292
31366
|
);
|
31293
31367
|
const insertOrder = colEntries.map(([, column4]) => sql.identifier(this.casing.getColumnCasing(column4)));
|
31294
|
-
|
31295
|
-
const
|
31296
|
-
|
31297
|
-
|
31298
|
-
|
31299
|
-
|
31300
|
-
|
31301
|
-
|
31302
|
-
|
31303
|
-
|
31304
|
-
|
31305
|
-
|
31306
|
-
|
31307
|
-
|
31368
|
+
if (select) {
|
31369
|
+
const select2 = valuesOrSelect;
|
31370
|
+
if (is(select2, SQL)) {
|
31371
|
+
valuesSqlList.push(select2);
|
31372
|
+
} else {
|
31373
|
+
valuesSqlList.push(select2.getSQL());
|
31374
|
+
}
|
31375
|
+
} else {
|
31376
|
+
const values = valuesOrSelect;
|
31377
|
+
valuesSqlList.push(sql.raw("values "));
|
31378
|
+
for (const [valueIndex, value] of values.entries()) {
|
31379
|
+
const valueList = [];
|
31380
|
+
for (const [fieldName, col] of colEntries) {
|
31381
|
+
const colValue = value[fieldName];
|
31382
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
31383
|
+
let defaultValue;
|
31384
|
+
if (col.default !== null && col.default !== void 0) {
|
31385
|
+
defaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);
|
31386
|
+
} else if (col.defaultFn !== void 0) {
|
31387
|
+
const defaultFnResult = col.defaultFn();
|
31388
|
+
defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
31389
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
31390
|
+
const onUpdateFnResult = col.onUpdateFn();
|
31391
|
+
defaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
31392
|
+
} else {
|
31393
|
+
defaultValue = sql`null`;
|
31394
|
+
}
|
31395
|
+
valueList.push(defaultValue);
|
31308
31396
|
} else {
|
31309
|
-
|
31397
|
+
valueList.push(colValue);
|
31310
31398
|
}
|
31311
|
-
valueList.push(defaultValue);
|
31312
|
-
} else {
|
31313
|
-
valueList.push(colValue);
|
31314
31399
|
}
|
31315
|
-
|
31316
|
-
|
31317
|
-
|
31318
|
-
|
31400
|
+
valuesSqlList.push(valueList);
|
31401
|
+
if (valueIndex < values.length - 1) {
|
31402
|
+
valuesSqlList.push(sql`, `);
|
31403
|
+
}
|
31319
31404
|
}
|
31320
31405
|
}
|
31321
31406
|
const withSql = this.buildWithCTE(withList);
|
31322
31407
|
const valuesSql = sql.join(valuesSqlList);
|
31323
31408
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
31324
31409
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
31325
|
-
return sql`${withSql}insert into ${table4} ${insertOrder}
|
31410
|
+
return sql`${withSql}insert into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;
|
31326
31411
|
}
|
31327
31412
|
sqlToQuery(sql2, invokeSource) {
|
31328
31413
|
return sql2.toQuery({
|
@@ -31551,8 +31636,8 @@ var init_dialect2 = __esm({
|
|
31551
31636
|
};
|
31552
31637
|
}
|
31553
31638
|
};
|
31554
|
-
__publicField(SQLiteDialect,
|
31555
|
-
SQLiteSyncDialect = class extends (
|
31639
|
+
__publicField(SQLiteDialect, _a198, "SQLiteDialect");
|
31640
|
+
SQLiteSyncDialect = class extends (_b143 = SQLiteDialect, _a199 = entityKind, _b143) {
|
31556
31641
|
migrate(migrations, session, config) {
|
31557
31642
|
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
31558
31643
|
const migrationTableCreate = sql`
|
@@ -31586,8 +31671,8 @@ var init_dialect2 = __esm({
|
|
31586
31671
|
}
|
31587
31672
|
}
|
31588
31673
|
};
|
31589
|
-
__publicField(SQLiteSyncDialect,
|
31590
|
-
SQLiteAsyncDialect = class extends (
|
31674
|
+
__publicField(SQLiteSyncDialect, _a199, "SQLiteSyncDialect");
|
31675
|
+
SQLiteAsyncDialect = class extends (_b144 = SQLiteDialect, _a200 = entityKind, _b144) {
|
31591
31676
|
async migrate(migrations, session, config) {
|
31592
31677
|
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
31593
31678
|
const migrationTableCreate = sql`
|
@@ -31616,7 +31701,7 @@ var init_dialect2 = __esm({
|
|
31616
31701
|
});
|
31617
31702
|
}
|
31618
31703
|
};
|
31619
|
-
__publicField(SQLiteAsyncDialect,
|
31704
|
+
__publicField(SQLiteAsyncDialect, _a200, "SQLiteAsyncDialect");
|
31620
31705
|
}
|
31621
31706
|
});
|
31622
31707
|
|
@@ -31638,7 +31723,7 @@ function createSetOperator2(type, isAll) {
|
|
31638
31723
|
return leftSelect.addSetOperators(setOperators);
|
31639
31724
|
};
|
31640
31725
|
}
|
31641
|
-
var
|
31726
|
+
var _a201, SQLiteSelectBuilder, _a202, _b145, SQLiteSelectQueryBuilderBase, _a203, _b146, SQLiteSelectBase, getSQLiteSetOperators, union2, unionAll2, intersect2, except2;
|
31642
31727
|
var init_select3 = __esm({
|
31643
31728
|
"../drizzle-orm/dist/sqlite-core/query-builders/select.js"() {
|
31644
31729
|
"use strict";
|
@@ -31652,7 +31737,7 @@ var init_select3 = __esm({
|
|
31652
31737
|
init_utils2();
|
31653
31738
|
init_view_common();
|
31654
31739
|
init_view_base2();
|
31655
|
-
|
31740
|
+
_a201 = entityKind;
|
31656
31741
|
SQLiteSelectBuilder = class {
|
31657
31742
|
constructor(config) {
|
31658
31743
|
__publicField(this, "fields");
|
@@ -31693,8 +31778,8 @@ var init_select3 = __esm({
|
|
31693
31778
|
});
|
31694
31779
|
}
|
31695
31780
|
};
|
31696
|
-
__publicField(SQLiteSelectBuilder,
|
31697
|
-
SQLiteSelectQueryBuilderBase = class extends (
|
31781
|
+
__publicField(SQLiteSelectBuilder, _a201, "SQLiteSelectBuilder");
|
31782
|
+
SQLiteSelectQueryBuilderBase = class extends (_b145 = TypedQueryBuilder, _a202 = entityKind, _b145) {
|
31698
31783
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
31699
31784
|
super();
|
31700
31785
|
__publicField(this, "_");
|
@@ -32199,8 +32284,8 @@ var init_select3 = __esm({
|
|
32199
32284
|
return this;
|
32200
32285
|
}
|
32201
32286
|
};
|
32202
|
-
__publicField(SQLiteSelectQueryBuilderBase,
|
32203
|
-
SQLiteSelectBase = class extends (
|
32287
|
+
__publicField(SQLiteSelectQueryBuilderBase, _a202, "SQLiteSelectQueryBuilder");
|
32288
|
+
SQLiteSelectBase = class extends (_b146 = SQLiteSelectQueryBuilderBase, _a203 = entityKind, _b146) {
|
32204
32289
|
constructor() {
|
32205
32290
|
super(...arguments);
|
32206
32291
|
__publicField(this, "run", (placeholderValues) => {
|
@@ -32238,7 +32323,7 @@ var init_select3 = __esm({
|
|
32238
32323
|
return this.all();
|
32239
32324
|
}
|
32240
32325
|
};
|
32241
|
-
__publicField(SQLiteSelectBase,
|
32326
|
+
__publicField(SQLiteSelectBase, _a203, "SQLiteSelect");
|
32242
32327
|
applyMixins(SQLiteSelectBase, [QueryPromise]);
|
32243
32328
|
getSQLiteSetOperators = () => ({
|
32244
32329
|
union: union2,
|
@@ -32254,7 +32339,7 @@ var init_select3 = __esm({
|
|
32254
32339
|
});
|
32255
32340
|
|
32256
32341
|
// ../drizzle-orm/dist/sqlite-core/query-builders/query-builder.js
|
32257
|
-
var
|
32342
|
+
var _a204, QueryBuilder2;
|
32258
32343
|
var init_query_builder3 = __esm({
|
32259
32344
|
"../drizzle-orm/dist/sqlite-core/query-builders/query-builder.js"() {
|
32260
32345
|
"use strict";
|
@@ -32263,7 +32348,7 @@ var init_query_builder3 = __esm({
|
|
32263
32348
|
init_dialect2();
|
32264
32349
|
init_subquery();
|
32265
32350
|
init_select3();
|
32266
|
-
|
32351
|
+
_a204 = entityKind;
|
32267
32352
|
QueryBuilder2 = class {
|
32268
32353
|
constructor(dialect4) {
|
32269
32354
|
__publicField(this, "dialect");
|
@@ -32325,7 +32410,185 @@ var init_query_builder3 = __esm({
|
|
32325
32410
|
return this.dialect;
|
32326
32411
|
}
|
32327
32412
|
};
|
32328
|
-
__publicField(QueryBuilder2,
|
32413
|
+
__publicField(QueryBuilder2, _a204, "SQLiteQueryBuilder");
|
32414
|
+
}
|
32415
|
+
});
|
32416
|
+
|
32417
|
+
// ../drizzle-orm/dist/sqlite-core/query-builders/insert.js
|
32418
|
+
var _a205, SQLiteInsertBuilder, _a206, _b147, SQLiteInsertBase;
|
32419
|
+
var init_insert2 = __esm({
|
32420
|
+
"../drizzle-orm/dist/sqlite-core/query-builders/insert.js"() {
|
32421
|
+
"use strict";
|
32422
|
+
init_entity();
|
32423
|
+
init_query_promise();
|
32424
|
+
init_sql();
|
32425
|
+
init_table3();
|
32426
|
+
init_table();
|
32427
|
+
init_utils2();
|
32428
|
+
init_query_builder3();
|
32429
|
+
_a205 = entityKind;
|
32430
|
+
SQLiteInsertBuilder = class {
|
32431
|
+
constructor(table4, session, dialect4, withList) {
|
32432
|
+
this.table = table4;
|
32433
|
+
this.session = session;
|
32434
|
+
this.dialect = dialect4;
|
32435
|
+
this.withList = withList;
|
32436
|
+
}
|
32437
|
+
values(values) {
|
32438
|
+
values = Array.isArray(values) ? values : [values];
|
32439
|
+
if (values.length === 0) {
|
32440
|
+
throw new Error("values() must be called with at least one value");
|
32441
|
+
}
|
32442
|
+
const mappedValues = values.map((entry) => {
|
32443
|
+
const result = {};
|
32444
|
+
const cols = this.table[Table2.Symbol.Columns];
|
32445
|
+
for (const colKey of Object.keys(entry)) {
|
32446
|
+
const colValue = entry[colKey];
|
32447
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
32448
|
+
}
|
32449
|
+
return result;
|
32450
|
+
});
|
32451
|
+
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
32452
|
+
}
|
32453
|
+
select(selectQuery) {
|
32454
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder2()) : selectQuery;
|
32455
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
32456
|
+
throw new Error(
|
32457
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
32458
|
+
);
|
32459
|
+
}
|
32460
|
+
return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
32461
|
+
}
|
32462
|
+
};
|
32463
|
+
__publicField(SQLiteInsertBuilder, _a205, "SQLiteInsertBuilder");
|
32464
|
+
SQLiteInsertBase = class extends (_b147 = QueryPromise, _a206 = entityKind, _b147) {
|
32465
|
+
constructor(table4, values, session, dialect4, withList, select) {
|
32466
|
+
super();
|
32467
|
+
/** @internal */
|
32468
|
+
__publicField(this, "config");
|
32469
|
+
__publicField(this, "run", (placeholderValues) => {
|
32470
|
+
return this._prepare().run(placeholderValues);
|
32471
|
+
});
|
32472
|
+
__publicField(this, "all", (placeholderValues) => {
|
32473
|
+
return this._prepare().all(placeholderValues);
|
32474
|
+
});
|
32475
|
+
__publicField(this, "get", (placeholderValues) => {
|
32476
|
+
return this._prepare().get(placeholderValues);
|
32477
|
+
});
|
32478
|
+
__publicField(this, "values", (placeholderValues) => {
|
32479
|
+
return this._prepare().values(placeholderValues);
|
32480
|
+
});
|
32481
|
+
this.session = session;
|
32482
|
+
this.dialect = dialect4;
|
32483
|
+
this.config = { table: table4, values, withList, select };
|
32484
|
+
}
|
32485
|
+
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
32486
|
+
this.config.returning = orderSelectedFields(fields);
|
32487
|
+
return this;
|
32488
|
+
}
|
32489
|
+
/**
|
32490
|
+
* Adds an `on conflict do nothing` clause to the query.
|
32491
|
+
*
|
32492
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
32493
|
+
*
|
32494
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
32495
|
+
*
|
32496
|
+
* @param config The `target` and `where` clauses.
|
32497
|
+
*
|
32498
|
+
* @example
|
32499
|
+
* ```ts
|
32500
|
+
* // Insert one row and cancel the insert if there's a conflict
|
32501
|
+
* await db.insert(cars)
|
32502
|
+
* .values({ id: 1, brand: 'BMW' })
|
32503
|
+
* .onConflictDoNothing();
|
32504
|
+
*
|
32505
|
+
* // Explicitly specify conflict target
|
32506
|
+
* await db.insert(cars)
|
32507
|
+
* .values({ id: 1, brand: 'BMW' })
|
32508
|
+
* .onConflictDoNothing({ target: cars.id });
|
32509
|
+
* ```
|
32510
|
+
*/
|
32511
|
+
onConflictDoNothing(config = {}) {
|
32512
|
+
if (config.target === void 0) {
|
32513
|
+
this.config.onConflict = sql`do nothing`;
|
32514
|
+
} else {
|
32515
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
32516
|
+
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
32517
|
+
this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
|
32518
|
+
}
|
32519
|
+
return this;
|
32520
|
+
}
|
32521
|
+
/**
|
32522
|
+
* Adds an `on conflict do update` clause to the query.
|
32523
|
+
*
|
32524
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
32525
|
+
*
|
32526
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
32527
|
+
*
|
32528
|
+
* @param config The `target`, `set` and `where` clauses.
|
32529
|
+
*
|
32530
|
+
* @example
|
32531
|
+
* ```ts
|
32532
|
+
* // Update the row if there's a conflict
|
32533
|
+
* await db.insert(cars)
|
32534
|
+
* .values({ id: 1, brand: 'BMW' })
|
32535
|
+
* .onConflictDoUpdate({
|
32536
|
+
* target: cars.id,
|
32537
|
+
* set: { brand: 'Porsche' }
|
32538
|
+
* });
|
32539
|
+
*
|
32540
|
+
* // Upsert with 'where' clause
|
32541
|
+
* await db.insert(cars)
|
32542
|
+
* .values({ id: 1, brand: 'BMW' })
|
32543
|
+
* .onConflictDoUpdate({
|
32544
|
+
* target: cars.id,
|
32545
|
+
* set: { brand: 'newBMW' },
|
32546
|
+
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
32547
|
+
* });
|
32548
|
+
* ```
|
32549
|
+
*/
|
32550
|
+
onConflictDoUpdate(config) {
|
32551
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
32552
|
+
throw new Error(
|
32553
|
+
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
32554
|
+
);
|
32555
|
+
}
|
32556
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
32557
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
32558
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
32559
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
32560
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
32561
|
+
this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
32562
|
+
return this;
|
32563
|
+
}
|
32564
|
+
/** @internal */
|
32565
|
+
getSQL() {
|
32566
|
+
return this.dialect.buildInsertQuery(this.config);
|
32567
|
+
}
|
32568
|
+
toSQL() {
|
32569
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
32570
|
+
return rest;
|
32571
|
+
}
|
32572
|
+
/** @internal */
|
32573
|
+
_prepare(isOneTimeQuery = true) {
|
32574
|
+
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
32575
|
+
this.dialect.sqlToQuery(this.getSQL()),
|
32576
|
+
this.config.returning,
|
32577
|
+
this.config.returning ? "all" : "run",
|
32578
|
+
true
|
32579
|
+
);
|
32580
|
+
}
|
32581
|
+
prepare() {
|
32582
|
+
return this._prepare(false);
|
32583
|
+
}
|
32584
|
+
async execute() {
|
32585
|
+
return this.config.returning ? this.all() : this.run();
|
32586
|
+
}
|
32587
|
+
$dynamic() {
|
32588
|
+
return this;
|
32589
|
+
}
|
32590
|
+
};
|
32591
|
+
__publicField(SQLiteInsertBase, _a206, "SQLiteInsert");
|
32329
32592
|
}
|
32330
32593
|
});
|
32331
32594
|
|
@@ -32345,8 +32608,11 @@ var init_update2 = __esm({
|
|
32345
32608
|
init_query_promise();
|
32346
32609
|
init_selection_proxy();
|
32347
32610
|
init_table3();
|
32611
|
+
init_subquery();
|
32348
32612
|
init_table();
|
32349
32613
|
init_utils2();
|
32614
|
+
init_view_common();
|
32615
|
+
init_view_base2();
|
32350
32616
|
_a207 = entityKind;
|
32351
32617
|
SQLiteUpdateBuilder = class {
|
32352
32618
|
constructor(table4, session, dialect4, withList) {
|
@@ -32371,6 +32637,10 @@ var init_update2 = __esm({
|
|
32371
32637
|
super();
|
32372
32638
|
/** @internal */
|
32373
32639
|
__publicField(this, "config");
|
32640
|
+
__publicField(this, "leftJoin", this.createJoin("left"));
|
32641
|
+
__publicField(this, "rightJoin", this.createJoin("right"));
|
32642
|
+
__publicField(this, "innerJoin", this.createJoin("inner"));
|
32643
|
+
__publicField(this, "fullJoin", this.createJoin("full"));
|
32374
32644
|
__publicField(this, "run", (placeholderValues) => {
|
32375
32645
|
return this._prepare().run(placeholderValues);
|
32376
32646
|
});
|
@@ -32385,7 +32655,34 @@ var init_update2 = __esm({
|
|
32385
32655
|
});
|
32386
32656
|
this.session = session;
|
32387
32657
|
this.dialect = dialect4;
|
32388
|
-
this.config = { set, table: table4, withList };
|
32658
|
+
this.config = { set, table: table4, withList, joins: [] };
|
32659
|
+
}
|
32660
|
+
from(source) {
|
32661
|
+
this.config.from = source;
|
32662
|
+
return this;
|
32663
|
+
}
|
32664
|
+
createJoin(joinType) {
|
32665
|
+
return (table4, on) => {
|
32666
|
+
const tableName = getTableLikeName(table4);
|
32667
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
32668
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
32669
|
+
}
|
32670
|
+
if (typeof on === "function") {
|
32671
|
+
const from = this.config.from ? is(table4, SQLiteTable) ? table4[Table2.Symbol.Columns] : is(table4, Subquery) ? table4._.selectedFields : is(table4, SQLiteViewBase) ? table4[ViewBaseConfig].selectedFields : void 0 : void 0;
|
32672
|
+
on = on(
|
32673
|
+
new Proxy(
|
32674
|
+
this.config.table[Table2.Symbol.Columns],
|
32675
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
32676
|
+
),
|
32677
|
+
from && new Proxy(
|
32678
|
+
from,
|
32679
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
32680
|
+
)
|
32681
|
+
);
|
32682
|
+
}
|
32683
|
+
this.config.joins.push({ on, table: table4, joinType, alias: tableName });
|
32684
|
+
return this;
|
32685
|
+
};
|
32389
32686
|
}
|
32390
32687
|
/**
|
32391
32688
|
* Adds a 'where' clause to the query.
|
@@ -35683,131 +35980,6 @@ var init_delete3 = __esm({
|
|
35683
35980
|
}
|
35684
35981
|
});
|
35685
35982
|
|
35686
|
-
// ../drizzle-orm/dist/mysql-core/query-builders/insert.js
|
35687
|
-
var _a299, MySqlInsertBuilder, _a300, _b222, MySqlInsertBase;
|
35688
|
-
var init_insert3 = __esm({
|
35689
|
-
"../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
|
35690
|
-
"use strict";
|
35691
|
-
init_entity();
|
35692
|
-
init_query_promise();
|
35693
|
-
init_sql();
|
35694
|
-
init_table();
|
35695
|
-
init_utils2();
|
35696
|
-
_a299 = entityKind;
|
35697
|
-
MySqlInsertBuilder = class {
|
35698
|
-
constructor(table4, session, dialect4) {
|
35699
|
-
__publicField(this, "shouldIgnore", false);
|
35700
|
-
this.table = table4;
|
35701
|
-
this.session = session;
|
35702
|
-
this.dialect = dialect4;
|
35703
|
-
}
|
35704
|
-
ignore() {
|
35705
|
-
this.shouldIgnore = true;
|
35706
|
-
return this;
|
35707
|
-
}
|
35708
|
-
values(values) {
|
35709
|
-
values = Array.isArray(values) ? values : [values];
|
35710
|
-
if (values.length === 0) {
|
35711
|
-
throw new Error("values() must be called with at least one value");
|
35712
|
-
}
|
35713
|
-
const mappedValues = values.map((entry) => {
|
35714
|
-
const result = {};
|
35715
|
-
const cols = this.table[Table2.Symbol.Columns];
|
35716
|
-
for (const colKey of Object.keys(entry)) {
|
35717
|
-
const colValue = entry[colKey];
|
35718
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
35719
|
-
}
|
35720
|
-
return result;
|
35721
|
-
});
|
35722
|
-
return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
|
35723
|
-
}
|
35724
|
-
};
|
35725
|
-
__publicField(MySqlInsertBuilder, _a299, "MySqlInsertBuilder");
|
35726
|
-
MySqlInsertBase = class extends (_b222 = QueryPromise, _a300 = entityKind, _b222) {
|
35727
|
-
constructor(table4, values, ignore, session, dialect4) {
|
35728
|
-
super();
|
35729
|
-
__publicField(this, "config");
|
35730
|
-
__publicField(this, "execute", (placeholderValues) => {
|
35731
|
-
return this.prepare().execute(placeholderValues);
|
35732
|
-
});
|
35733
|
-
__publicField(this, "createIterator", () => {
|
35734
|
-
const self2 = this;
|
35735
|
-
return async function* (placeholderValues) {
|
35736
|
-
yield* self2.prepare().iterator(placeholderValues);
|
35737
|
-
};
|
35738
|
-
});
|
35739
|
-
__publicField(this, "iterator", this.createIterator());
|
35740
|
-
this.session = session;
|
35741
|
-
this.dialect = dialect4;
|
35742
|
-
this.config = { table: table4, values, ignore };
|
35743
|
-
}
|
35744
|
-
/**
|
35745
|
-
* Adds an `on duplicate key update` clause to the query.
|
35746
|
-
*
|
35747
|
-
* 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.
|
35748
|
-
*
|
35749
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
|
35750
|
-
*
|
35751
|
-
* @param config The `set` clause
|
35752
|
-
*
|
35753
|
-
* @example
|
35754
|
-
* ```ts
|
35755
|
-
* await db.insert(cars)
|
35756
|
-
* .values({ id: 1, brand: 'BMW'})
|
35757
|
-
* .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
|
35758
|
-
* ```
|
35759
|
-
*
|
35760
|
-
* 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:
|
35761
|
-
*
|
35762
|
-
* ```ts
|
35763
|
-
* import { sql } from 'drizzle-orm';
|
35764
|
-
*
|
35765
|
-
* await db.insert(cars)
|
35766
|
-
* .values({ id: 1, brand: 'BMW' })
|
35767
|
-
* .onDuplicateKeyUpdate({ set: { id: sql`id` } });
|
35768
|
-
* ```
|
35769
|
-
*/
|
35770
|
-
onDuplicateKeyUpdate(config) {
|
35771
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
35772
|
-
this.config.onConflict = sql`update ${setSql}`;
|
35773
|
-
return this;
|
35774
|
-
}
|
35775
|
-
$returningId() {
|
35776
|
-
const returning = [];
|
35777
|
-
for (const [key, value] of Object.entries(this.config.table[Table2.Symbol.Columns])) {
|
35778
|
-
if (value.primary) {
|
35779
|
-
returning.push({ field: value, path: [key] });
|
35780
|
-
}
|
35781
|
-
}
|
35782
|
-
this.config.returning = returning;
|
35783
|
-
return this;
|
35784
|
-
}
|
35785
|
-
/** @internal */
|
35786
|
-
getSQL() {
|
35787
|
-
return this.dialect.buildInsertQuery(this.config).sql;
|
35788
|
-
}
|
35789
|
-
toSQL() {
|
35790
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
35791
|
-
return rest;
|
35792
|
-
}
|
35793
|
-
prepare() {
|
35794
|
-
const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
|
35795
|
-
return this.session.prepareQuery(
|
35796
|
-
this.dialect.sqlToQuery(sql2),
|
35797
|
-
void 0,
|
35798
|
-
void 0,
|
35799
|
-
generatedIds,
|
35800
|
-
this.config.returning
|
35801
|
-
);
|
35802
|
-
}
|
35803
|
-
$dynamic() {
|
35804
|
-
return this;
|
35805
|
-
}
|
35806
|
-
};
|
35807
|
-
__publicField(MySqlInsertBase, _a300, "MySqlInsert");
|
35808
|
-
}
|
35809
|
-
});
|
35810
|
-
|
35811
35983
|
// ../drizzle-orm/dist/mysql-core/columns/all.js
|
35812
35984
|
function getMySqlColumnBuilders() {
|
35813
35985
|
return {
|
@@ -35888,7 +36060,7 @@ function mysqlTableWithSchema(name2, columns, extraConfig, schema4, baseName = n
|
|
35888
36060
|
}
|
35889
36061
|
return table4;
|
35890
36062
|
}
|
35891
|
-
var InlineForeignKeys3,
|
36063
|
+
var InlineForeignKeys3, _a299, _b222, _c9, _d4, _e4, MySqlTable, mysqlTable;
|
35892
36064
|
var init_table4 = __esm({
|
35893
36065
|
"../drizzle-orm/dist/mysql-core/table.js"() {
|
35894
36066
|
"use strict";
|
@@ -35896,15 +36068,15 @@ var init_table4 = __esm({
|
|
35896
36068
|
init_table();
|
35897
36069
|
init_all3();
|
35898
36070
|
InlineForeignKeys3 = Symbol.for("drizzle:MySqlInlineForeignKeys");
|
35899
|
-
MySqlTable = class extends (_e4 = Table2, _d4 = entityKind, _c9 = Table2.Symbol.Columns,
|
36071
|
+
MySqlTable = class extends (_e4 = Table2, _d4 = entityKind, _c9 = Table2.Symbol.Columns, _b222 = InlineForeignKeys3, _a299 = Table2.Symbol.ExtraConfigBuilder, _e4) {
|
35900
36072
|
constructor() {
|
35901
36073
|
super(...arguments);
|
35902
36074
|
/** @internal */
|
35903
36075
|
__publicField(this, _c9);
|
35904
36076
|
/** @internal */
|
35905
|
-
__publicField(this,
|
36077
|
+
__publicField(this, _b222, []);
|
35906
36078
|
/** @internal */
|
35907
|
-
__publicField(this,
|
36079
|
+
__publicField(this, _a299);
|
35908
36080
|
}
|
35909
36081
|
};
|
35910
36082
|
__publicField(MySqlTable, _d4, "MySqlTable");
|
@@ -35919,20 +36091,20 @@ var init_table4 = __esm({
|
|
35919
36091
|
});
|
35920
36092
|
|
35921
36093
|
// ../drizzle-orm/dist/mysql-core/view-base.js
|
35922
|
-
var
|
36094
|
+
var _a300, _b223, MySqlViewBase;
|
35923
36095
|
var init_view_base3 = __esm({
|
35924
36096
|
"../drizzle-orm/dist/mysql-core/view-base.js"() {
|
35925
36097
|
"use strict";
|
35926
36098
|
init_entity();
|
35927
36099
|
init_sql();
|
35928
|
-
MySqlViewBase = class extends (
|
36100
|
+
MySqlViewBase = class extends (_b223 = View3, _a300 = entityKind, _b223) {
|
35929
36101
|
};
|
35930
|
-
__publicField(MySqlViewBase,
|
36102
|
+
__publicField(MySqlViewBase, _a300, "MySqlViewBase");
|
35931
36103
|
}
|
35932
36104
|
});
|
35933
36105
|
|
35934
36106
|
// ../drizzle-orm/dist/mysql-core/dialect.js
|
35935
|
-
var
|
36107
|
+
var _a301, MySqlDialect;
|
35936
36108
|
var init_dialect3 = __esm({
|
35937
36109
|
"../drizzle-orm/dist/mysql-core/dialect.js"() {
|
35938
36110
|
"use strict";
|
@@ -35951,7 +36123,7 @@ var init_dialect3 = __esm({
|
|
35951
36123
|
init_common4();
|
35952
36124
|
init_table4();
|
35953
36125
|
init_view_base3();
|
35954
|
-
|
36126
|
+
_a301 = entityKind;
|
35955
36127
|
MySqlDialect = class {
|
35956
36128
|
constructor(config) {
|
35957
36129
|
/** @internal */
|
@@ -36234,7 +36406,7 @@ var init_dialect3 = __esm({
|
|
36234
36406
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
36235
36407
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
36236
36408
|
}
|
36237
|
-
buildInsertQuery({ table: table4, values, ignore, onConflict }) {
|
36409
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, ignore, onConflict, select }) {
|
36238
36410
|
const valuesSqlList = [];
|
36239
36411
|
const columns = table4[Table2.Symbol.Columns];
|
36240
36412
|
const colEntries = Object.entries(columns).filter(
|
@@ -36242,42 +36414,53 @@ var init_dialect3 = __esm({
|
|
36242
36414
|
);
|
36243
36415
|
const insertOrder = colEntries.map(([, column4]) => sql.identifier(this.casing.getColumnCasing(column4)));
|
36244
36416
|
const generatedIdsResponse = [];
|
36245
|
-
|
36246
|
-
const
|
36247
|
-
|
36248
|
-
|
36249
|
-
|
36250
|
-
|
36251
|
-
|
36252
|
-
|
36253
|
-
|
36254
|
-
|
36255
|
-
|
36256
|
-
|
36257
|
-
|
36258
|
-
|
36259
|
-
|
36417
|
+
if (select) {
|
36418
|
+
const select2 = valuesOrSelect;
|
36419
|
+
if (is(select2, SQL)) {
|
36420
|
+
valuesSqlList.push(select2);
|
36421
|
+
} else {
|
36422
|
+
valuesSqlList.push(select2.getSQL());
|
36423
|
+
}
|
36424
|
+
} else {
|
36425
|
+
const values = valuesOrSelect;
|
36426
|
+
valuesSqlList.push(sql.raw("values "));
|
36427
|
+
for (const [valueIndex, value] of values.entries()) {
|
36428
|
+
const generatedIds = {};
|
36429
|
+
const valueList = [];
|
36430
|
+
for (const [fieldName, col] of colEntries) {
|
36431
|
+
const colValue = value[fieldName];
|
36432
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
36433
|
+
if (col.defaultFn !== void 0) {
|
36434
|
+
const defaultFnResult = col.defaultFn();
|
36435
|
+
generatedIds[fieldName] = defaultFnResult;
|
36436
|
+
const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
36437
|
+
valueList.push(defaultValue);
|
36438
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
36439
|
+
const onUpdateFnResult = col.onUpdateFn();
|
36440
|
+
const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
36441
|
+
valueList.push(newValue);
|
36442
|
+
} else {
|
36443
|
+
valueList.push(sql`default`);
|
36444
|
+
}
|
36260
36445
|
} else {
|
36261
|
-
|
36262
|
-
|
36263
|
-
|
36264
|
-
|
36265
|
-
generatedIds[fieldName] = colValue.value;
|
36446
|
+
if (col.defaultFn && is(colValue, Param)) {
|
36447
|
+
generatedIds[fieldName] = colValue.value;
|
36448
|
+
}
|
36449
|
+
valueList.push(colValue);
|
36266
36450
|
}
|
36267
|
-
valueList.push(colValue);
|
36268
36451
|
}
|
36269
|
-
|
36270
|
-
|
36271
|
-
|
36272
|
-
|
36273
|
-
|
36452
|
+
generatedIdsResponse.push(generatedIds);
|
36453
|
+
valuesSqlList.push(valueList);
|
36454
|
+
if (valueIndex < values.length - 1) {
|
36455
|
+
valuesSqlList.push(sql`, `);
|
36456
|
+
}
|
36274
36457
|
}
|
36275
36458
|
}
|
36276
36459
|
const valuesSql = sql.join(valuesSqlList);
|
36277
36460
|
const ignoreSql = ignore ? sql` ignore` : void 0;
|
36278
36461
|
const onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : void 0;
|
36279
36462
|
return {
|
36280
|
-
sql: sql`insert${ignoreSql} into ${table4} ${insertOrder}
|
36463
|
+
sql: sql`insert${ignoreSql} into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}`,
|
36281
36464
|
generatedIds: generatedIdsResponse
|
36282
36465
|
};
|
36283
36466
|
}
|
@@ -36737,7 +36920,7 @@ var init_dialect3 = __esm({
|
|
36737
36920
|
};
|
36738
36921
|
}
|
36739
36922
|
};
|
36740
|
-
__publicField(MySqlDialect,
|
36923
|
+
__publicField(MySqlDialect, _a301, "MySqlDialect");
|
36741
36924
|
}
|
36742
36925
|
});
|
36743
36926
|
|
@@ -36759,7 +36942,7 @@ function createSetOperator3(type, isAll) {
|
|
36759
36942
|
return leftSelect.addSetOperators(setOperators);
|
36760
36943
|
};
|
36761
36944
|
}
|
36762
|
-
var
|
36945
|
+
var _a302, MySqlSelectBuilder, _a303, _b224, MySqlSelectQueryBuilderBase, _a304, _b225, MySqlSelectBase, getMySqlSetOperators, union3, unionAll3, intersect3, intersectAll2, except3, exceptAll2;
|
36763
36946
|
var init_select4 = __esm({
|
36764
36947
|
"../drizzle-orm/dist/mysql-core/query-builders/select.js"() {
|
36765
36948
|
"use strict";
|
@@ -36774,7 +36957,7 @@ var init_select4 = __esm({
|
|
36774
36957
|
init_utils2();
|
36775
36958
|
init_view_common();
|
36776
36959
|
init_view_base3();
|
36777
|
-
|
36960
|
+
_a302 = entityKind;
|
36778
36961
|
MySqlSelectBuilder = class {
|
36779
36962
|
constructor(config) {
|
36780
36963
|
__publicField(this, "fields");
|
@@ -36819,8 +37002,8 @@ var init_select4 = __esm({
|
|
36819
37002
|
);
|
36820
37003
|
}
|
36821
37004
|
};
|
36822
|
-
__publicField(MySqlSelectBuilder,
|
36823
|
-
MySqlSelectQueryBuilderBase = class extends (
|
37005
|
+
__publicField(MySqlSelectBuilder, _a302, "MySqlSelectBuilder");
|
37006
|
+
MySqlSelectQueryBuilderBase = class extends (_b224 = TypedQueryBuilder, _a303 = entityKind, _b224) {
|
36824
37007
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
36825
37008
|
super();
|
36826
37009
|
__publicField(this, "_");
|
@@ -37421,8 +37604,8 @@ var init_select4 = __esm({
|
|
37421
37604
|
return this;
|
37422
37605
|
}
|
37423
37606
|
};
|
37424
|
-
__publicField(MySqlSelectQueryBuilderBase,
|
37425
|
-
MySqlSelectBase = class extends (
|
37607
|
+
__publicField(MySqlSelectQueryBuilderBase, _a303, "MySqlSelectQueryBuilder");
|
37608
|
+
MySqlSelectBase = class extends (_b225 = MySqlSelectQueryBuilderBase, _a304 = entityKind, _b225) {
|
37426
37609
|
constructor() {
|
37427
37610
|
super(...arguments);
|
37428
37611
|
__publicField(this, "execute", (placeholderValues) => {
|
@@ -37446,7 +37629,7 @@ var init_select4 = __esm({
|
|
37446
37629
|
return query;
|
37447
37630
|
}
|
37448
37631
|
};
|
37449
|
-
__publicField(MySqlSelectBase,
|
37632
|
+
__publicField(MySqlSelectBase, _a304, "MySqlSelect");
|
37450
37633
|
applyMixins(MySqlSelectBase, [QueryPromise]);
|
37451
37634
|
getMySqlSetOperators = () => ({
|
37452
37635
|
union: union3,
|
@@ -37466,7 +37649,7 @@ var init_select4 = __esm({
|
|
37466
37649
|
});
|
37467
37650
|
|
37468
37651
|
// ../drizzle-orm/dist/mysql-core/query-builders/query-builder.js
|
37469
|
-
var
|
37652
|
+
var _a305, QueryBuilder3;
|
37470
37653
|
var init_query_builder4 = __esm({
|
37471
37654
|
"../drizzle-orm/dist/mysql-core/query-builders/query-builder.js"() {
|
37472
37655
|
"use strict";
|
@@ -37475,7 +37658,7 @@ var init_query_builder4 = __esm({
|
|
37475
37658
|
init_selection_proxy();
|
37476
37659
|
init_subquery();
|
37477
37660
|
init_select4();
|
37478
|
-
|
37661
|
+
_a305 = entityKind;
|
37479
37662
|
QueryBuilder3 = class {
|
37480
37663
|
constructor(dialect4) {
|
37481
37664
|
__publicField(this, "dialect");
|
@@ -37537,7 +37720,142 @@ var init_query_builder4 = __esm({
|
|
37537
37720
|
return this.dialect;
|
37538
37721
|
}
|
37539
37722
|
};
|
37540
|
-
__publicField(QueryBuilder3,
|
37723
|
+
__publicField(QueryBuilder3, _a305, "MySqlQueryBuilder");
|
37724
|
+
}
|
37725
|
+
});
|
37726
|
+
|
37727
|
+
// ../drizzle-orm/dist/mysql-core/query-builders/insert.js
|
37728
|
+
var _a306, MySqlInsertBuilder, _a307, _b226, MySqlInsertBase;
|
37729
|
+
var init_insert3 = __esm({
|
37730
|
+
"../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
|
37731
|
+
"use strict";
|
37732
|
+
init_entity();
|
37733
|
+
init_query_promise();
|
37734
|
+
init_sql();
|
37735
|
+
init_table();
|
37736
|
+
init_utils2();
|
37737
|
+
init_query_builder4();
|
37738
|
+
_a306 = entityKind;
|
37739
|
+
MySqlInsertBuilder = class {
|
37740
|
+
constructor(table4, session, dialect4) {
|
37741
|
+
__publicField(this, "shouldIgnore", false);
|
37742
|
+
this.table = table4;
|
37743
|
+
this.session = session;
|
37744
|
+
this.dialect = dialect4;
|
37745
|
+
}
|
37746
|
+
ignore() {
|
37747
|
+
this.shouldIgnore = true;
|
37748
|
+
return this;
|
37749
|
+
}
|
37750
|
+
values(values) {
|
37751
|
+
values = Array.isArray(values) ? values : [values];
|
37752
|
+
if (values.length === 0) {
|
37753
|
+
throw new Error("values() must be called with at least one value");
|
37754
|
+
}
|
37755
|
+
const mappedValues = values.map((entry) => {
|
37756
|
+
const result = {};
|
37757
|
+
const cols = this.table[Table2.Symbol.Columns];
|
37758
|
+
for (const colKey of Object.keys(entry)) {
|
37759
|
+
const colValue = entry[colKey];
|
37760
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
37761
|
+
}
|
37762
|
+
return result;
|
37763
|
+
});
|
37764
|
+
return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
|
37765
|
+
}
|
37766
|
+
select(selectQuery) {
|
37767
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder3()) : selectQuery;
|
37768
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
37769
|
+
throw new Error(
|
37770
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
37771
|
+
);
|
37772
|
+
}
|
37773
|
+
return new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);
|
37774
|
+
}
|
37775
|
+
};
|
37776
|
+
__publicField(MySqlInsertBuilder, _a306, "MySqlInsertBuilder");
|
37777
|
+
MySqlInsertBase = class extends (_b226 = QueryPromise, _a307 = entityKind, _b226) {
|
37778
|
+
constructor(table4, values, ignore, session, dialect4, select) {
|
37779
|
+
super();
|
37780
|
+
__publicField(this, "config");
|
37781
|
+
__publicField(this, "execute", (placeholderValues) => {
|
37782
|
+
return this.prepare().execute(placeholderValues);
|
37783
|
+
});
|
37784
|
+
__publicField(this, "createIterator", () => {
|
37785
|
+
const self2 = this;
|
37786
|
+
return async function* (placeholderValues) {
|
37787
|
+
yield* self2.prepare().iterator(placeholderValues);
|
37788
|
+
};
|
37789
|
+
});
|
37790
|
+
__publicField(this, "iterator", this.createIterator());
|
37791
|
+
this.session = session;
|
37792
|
+
this.dialect = dialect4;
|
37793
|
+
this.config = { table: table4, values, select, ignore };
|
37794
|
+
}
|
37795
|
+
/**
|
37796
|
+
* Adds an `on duplicate key update` clause to the query.
|
37797
|
+
*
|
37798
|
+
* 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.
|
37799
|
+
*
|
37800
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
|
37801
|
+
*
|
37802
|
+
* @param config The `set` clause
|
37803
|
+
*
|
37804
|
+
* @example
|
37805
|
+
* ```ts
|
37806
|
+
* await db.insert(cars)
|
37807
|
+
* .values({ id: 1, brand: 'BMW'})
|
37808
|
+
* .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
|
37809
|
+
* ```
|
37810
|
+
*
|
37811
|
+
* 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:
|
37812
|
+
*
|
37813
|
+
* ```ts
|
37814
|
+
* import { sql } from 'drizzle-orm';
|
37815
|
+
*
|
37816
|
+
* await db.insert(cars)
|
37817
|
+
* .values({ id: 1, brand: 'BMW' })
|
37818
|
+
* .onDuplicateKeyUpdate({ set: { id: sql`id` } });
|
37819
|
+
* ```
|
37820
|
+
*/
|
37821
|
+
onDuplicateKeyUpdate(config) {
|
37822
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
37823
|
+
this.config.onConflict = sql`update ${setSql}`;
|
37824
|
+
return this;
|
37825
|
+
}
|
37826
|
+
$returningId() {
|
37827
|
+
const returning = [];
|
37828
|
+
for (const [key, value] of Object.entries(this.config.table[Table2.Symbol.Columns])) {
|
37829
|
+
if (value.primary) {
|
37830
|
+
returning.push({ field: value, path: [key] });
|
37831
|
+
}
|
37832
|
+
}
|
37833
|
+
this.config.returning = returning;
|
37834
|
+
return this;
|
37835
|
+
}
|
37836
|
+
/** @internal */
|
37837
|
+
getSQL() {
|
37838
|
+
return this.dialect.buildInsertQuery(this.config).sql;
|
37839
|
+
}
|
37840
|
+
toSQL() {
|
37841
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
37842
|
+
return rest;
|
37843
|
+
}
|
37844
|
+
prepare() {
|
37845
|
+
const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
|
37846
|
+
return this.session.prepareQuery(
|
37847
|
+
this.dialect.sqlToQuery(sql2),
|
37848
|
+
void 0,
|
37849
|
+
void 0,
|
37850
|
+
generatedIds,
|
37851
|
+
this.config.returning
|
37852
|
+
);
|
37853
|
+
}
|
37854
|
+
$dynamic() {
|
37855
|
+
return this;
|
37856
|
+
}
|
37857
|
+
};
|
37858
|
+
__publicField(MySqlInsertBase, _a307, "MySqlInsert");
|
37541
37859
|
}
|
37542
37860
|
});
|
37543
37861
|
|