drizzle-kit 0.28.0 → 0.28.1-44b6c8a
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +7 -7
- package/api.js +937 -718
- package/api.mjs +937 -718
- package/bin.cjs +8 -8
- package/package.json +1 -1
package/api.js
CHANGED
@@ -21121,7 +21121,7 @@ var version;
|
|
21121
21121
|
var init_version = __esm({
|
21122
21122
|
"../drizzle-orm/dist/version.js"() {
|
21123
21123
|
"use strict";
|
21124
|
-
version = "0.36.
|
21124
|
+
version = "0.36.2";
|
21125
21125
|
}
|
21126
21126
|
});
|
21127
21127
|
|
@@ -21407,7 +21407,11 @@ var init_sql = __esm({
|
|
21407
21407
|
if (_config.invokeSource === "indexes") {
|
21408
21408
|
return { sql: escapeName(columnName), params: [] };
|
21409
21409
|
}
|
21410
|
-
|
21410
|
+
const schemaName = chunk.table[Table2.Symbol.Schema];
|
21411
|
+
return {
|
21412
|
+
sql: chunk.table[IsAlias] || schemaName === void 0 ? escapeName(chunk.table[Table2.Symbol.Name]) + "." + escapeName(columnName) : escapeName(schemaName) + "." + escapeName(chunk.table[Table2.Symbol.Name]) + "." + escapeName(columnName),
|
21413
|
+
params: []
|
21414
|
+
};
|
21411
21415
|
}
|
21412
21416
|
if (is(chunk, View3)) {
|
21413
21417
|
const schemaName = chunk[ViewBaseConfig].schema;
|
@@ -22140,7 +22144,7 @@ function haveSameKeys(left, right) {
|
|
22140
22144
|
}
|
22141
22145
|
function mapUpdateSet(table4, values) {
|
22142
22146
|
const entries = Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => {
|
22143
|
-
if (is(value, SQL)) {
|
22147
|
+
if (is(value, SQL) || is(value, Column2)) {
|
22144
22148
|
return [key, value];
|
22145
22149
|
} else {
|
22146
22150
|
return [key, new Param(value, table4[Table2.Symbol.Columns][key])];
|
@@ -24650,162 +24654,6 @@ var init_delete = __esm({
|
|
24650
24654
|
}
|
24651
24655
|
});
|
24652
24656
|
|
24653
|
-
// ../drizzle-orm/dist/pg-core/query-builders/insert.js
|
24654
|
-
var _a125, PgInsertBuilder, _a126, _b98, PgInsertBase;
|
24655
|
-
var init_insert = __esm({
|
24656
|
-
"../drizzle-orm/dist/pg-core/query-builders/insert.js"() {
|
24657
|
-
"use strict";
|
24658
|
-
init_entity();
|
24659
|
-
init_query_promise();
|
24660
|
-
init_sql();
|
24661
|
-
init_table();
|
24662
|
-
init_tracing();
|
24663
|
-
init_utils2();
|
24664
|
-
_a125 = entityKind;
|
24665
|
-
PgInsertBuilder = class {
|
24666
|
-
constructor(table4, session, dialect4, withList) {
|
24667
|
-
this.table = table4;
|
24668
|
-
this.session = session;
|
24669
|
-
this.dialect = dialect4;
|
24670
|
-
this.withList = withList;
|
24671
|
-
}
|
24672
|
-
values(values) {
|
24673
|
-
values = Array.isArray(values) ? values : [values];
|
24674
|
-
if (values.length === 0) {
|
24675
|
-
throw new Error("values() must be called with at least one value");
|
24676
|
-
}
|
24677
|
-
const mappedValues = values.map((entry) => {
|
24678
|
-
const result = {};
|
24679
|
-
const cols = this.table[Table2.Symbol.Columns];
|
24680
|
-
for (const colKey of Object.keys(entry)) {
|
24681
|
-
const colValue = entry[colKey];
|
24682
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
24683
|
-
}
|
24684
|
-
return result;
|
24685
|
-
});
|
24686
|
-
return new PgInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
24687
|
-
}
|
24688
|
-
};
|
24689
|
-
__publicField(PgInsertBuilder, _a125, "PgInsertBuilder");
|
24690
|
-
PgInsertBase = class extends (_b98 = QueryPromise, _a126 = entityKind, _b98) {
|
24691
|
-
constructor(table4, values, session, dialect4, withList) {
|
24692
|
-
super();
|
24693
|
-
__publicField(this, "config");
|
24694
|
-
__publicField(this, "execute", (placeholderValues) => {
|
24695
|
-
return tracer.startActiveSpan("drizzle.operation", () => {
|
24696
|
-
return this._prepare().execute(placeholderValues);
|
24697
|
-
});
|
24698
|
-
});
|
24699
|
-
this.session = session;
|
24700
|
-
this.dialect = dialect4;
|
24701
|
-
this.config = { table: table4, values, withList };
|
24702
|
-
}
|
24703
|
-
returning(fields = this.config.table[Table2.Symbol.Columns]) {
|
24704
|
-
this.config.returning = orderSelectedFields(fields);
|
24705
|
-
return this;
|
24706
|
-
}
|
24707
|
-
/**
|
24708
|
-
* Adds an `on conflict do nothing` clause to the query.
|
24709
|
-
*
|
24710
|
-
* Calling this method simply avoids inserting a row as its alternative action.
|
24711
|
-
*
|
24712
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
24713
|
-
*
|
24714
|
-
* @param config The `target` and `where` clauses.
|
24715
|
-
*
|
24716
|
-
* @example
|
24717
|
-
* ```ts
|
24718
|
-
* // Insert one row and cancel the insert if there's a conflict
|
24719
|
-
* await db.insert(cars)
|
24720
|
-
* .values({ id: 1, brand: 'BMW' })
|
24721
|
-
* .onConflictDoNothing();
|
24722
|
-
*
|
24723
|
-
* // Explicitly specify conflict target
|
24724
|
-
* await db.insert(cars)
|
24725
|
-
* .values({ id: 1, brand: 'BMW' })
|
24726
|
-
* .onConflictDoNothing({ target: cars.id });
|
24727
|
-
* ```
|
24728
|
-
*/
|
24729
|
-
onConflictDoNothing(config = {}) {
|
24730
|
-
if (config.target === void 0) {
|
24731
|
-
this.config.onConflict = sql`do nothing`;
|
24732
|
-
} else {
|
24733
|
-
let targetColumn = "";
|
24734
|
-
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));
|
24735
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
24736
|
-
this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
|
24737
|
-
}
|
24738
|
-
return this;
|
24739
|
-
}
|
24740
|
-
/**
|
24741
|
-
* Adds an `on conflict do update` clause to the query.
|
24742
|
-
*
|
24743
|
-
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
24744
|
-
*
|
24745
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
24746
|
-
*
|
24747
|
-
* @param config The `target`, `set` and `where` clauses.
|
24748
|
-
*
|
24749
|
-
* @example
|
24750
|
-
* ```ts
|
24751
|
-
* // Update the row if there's a conflict
|
24752
|
-
* await db.insert(cars)
|
24753
|
-
* .values({ id: 1, brand: 'BMW' })
|
24754
|
-
* .onConflictDoUpdate({
|
24755
|
-
* target: cars.id,
|
24756
|
-
* set: { brand: 'Porsche' }
|
24757
|
-
* });
|
24758
|
-
*
|
24759
|
-
* // Upsert with 'where' clause
|
24760
|
-
* await db.insert(cars)
|
24761
|
-
* .values({ id: 1, brand: 'BMW' })
|
24762
|
-
* .onConflictDoUpdate({
|
24763
|
-
* target: cars.id,
|
24764
|
-
* set: { brand: 'newBMW' },
|
24765
|
-
* targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
|
24766
|
-
* });
|
24767
|
-
* ```
|
24768
|
-
*/
|
24769
|
-
onConflictDoUpdate(config) {
|
24770
|
-
if (config.where && (config.targetWhere || config.setWhere)) {
|
24771
|
-
throw new Error(
|
24772
|
-
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
24773
|
-
);
|
24774
|
-
}
|
24775
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
24776
|
-
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
24777
|
-
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
24778
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
24779
|
-
let targetColumn = "";
|
24780
|
-
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));
|
24781
|
-
this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
24782
|
-
return this;
|
24783
|
-
}
|
24784
|
-
/** @internal */
|
24785
|
-
getSQL() {
|
24786
|
-
return this.dialect.buildInsertQuery(this.config);
|
24787
|
-
}
|
24788
|
-
toSQL() {
|
24789
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
24790
|
-
return rest;
|
24791
|
-
}
|
24792
|
-
/** @internal */
|
24793
|
-
_prepare(name2) {
|
24794
|
-
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
24795
|
-
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
|
24796
|
-
});
|
24797
|
-
}
|
24798
|
-
prepare(name2) {
|
24799
|
-
return this._prepare(name2);
|
24800
|
-
}
|
24801
|
-
$dynamic() {
|
24802
|
-
return this;
|
24803
|
-
}
|
24804
|
-
};
|
24805
|
-
__publicField(PgInsertBase, _a126, "PgInsert");
|
24806
|
-
}
|
24807
|
-
});
|
24808
|
-
|
24809
24657
|
// ../drizzle-orm/dist/casing.js
|
24810
24658
|
function toSnakeCase(input) {
|
24811
24659
|
const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? [];
|
@@ -24821,13 +24669,13 @@ function toCamelCase(input) {
|
|
24821
24669
|
function noopCase(input) {
|
24822
24670
|
return input;
|
24823
24671
|
}
|
24824
|
-
var
|
24672
|
+
var _a125, CasingCache;
|
24825
24673
|
var init_casing = __esm({
|
24826
24674
|
"../drizzle-orm/dist/casing.js"() {
|
24827
24675
|
"use strict";
|
24828
24676
|
init_entity();
|
24829
24677
|
init_table();
|
24830
|
-
|
24678
|
+
_a125 = entityKind;
|
24831
24679
|
CasingCache = class {
|
24832
24680
|
constructor(casing2) {
|
24833
24681
|
/** @internal */
|
@@ -24864,25 +24712,25 @@ var init_casing = __esm({
|
|
24864
24712
|
this.cachedTables = {};
|
24865
24713
|
}
|
24866
24714
|
};
|
24867
|
-
__publicField(CasingCache,
|
24715
|
+
__publicField(CasingCache, _a125, "CasingCache");
|
24868
24716
|
}
|
24869
24717
|
});
|
24870
24718
|
|
24871
24719
|
// ../drizzle-orm/dist/pg-core/view-base.js
|
24872
|
-
var
|
24720
|
+
var _a126, _b98, PgViewBase;
|
24873
24721
|
var init_view_base = __esm({
|
24874
24722
|
"../drizzle-orm/dist/pg-core/view-base.js"() {
|
24875
24723
|
"use strict";
|
24876
24724
|
init_entity();
|
24877
24725
|
init_sql();
|
24878
|
-
PgViewBase = class extends (
|
24726
|
+
PgViewBase = class extends (_b98 = View3, _a126 = entityKind, _b98) {
|
24879
24727
|
};
|
24880
|
-
__publicField(PgViewBase,
|
24728
|
+
__publicField(PgViewBase, _a126, "PgViewBase");
|
24881
24729
|
}
|
24882
24730
|
});
|
24883
24731
|
|
24884
24732
|
// ../drizzle-orm/dist/pg-core/dialect.js
|
24885
|
-
var
|
24733
|
+
var _a127, PgDialect;
|
24886
24734
|
var init_dialect = __esm({
|
24887
24735
|
"../drizzle-orm/dist/pg-core/dialect.js"() {
|
24888
24736
|
"use strict";
|
@@ -24901,7 +24749,7 @@ var init_dialect = __esm({
|
|
24901
24749
|
init_utils2();
|
24902
24750
|
init_view_common();
|
24903
24751
|
init_view_base();
|
24904
|
-
|
24752
|
+
_a127 = entityKind;
|
24905
24753
|
PgDialect = class {
|
24906
24754
|
constructor(config) {
|
24907
24755
|
/** @internal */
|
@@ -24981,12 +24829,19 @@ var init_dialect = __esm({
|
|
24981
24829
|
return [res];
|
24982
24830
|
}));
|
24983
24831
|
}
|
24984
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList }) {
|
24832
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, from, joins }) {
|
24985
24833
|
const withSql = this.buildWithCTE(withList);
|
24834
|
+
const tableName = table4[PgTable.Symbol.Name];
|
24835
|
+
const tableSchema = table4[PgTable.Symbol.Schema];
|
24836
|
+
const origTableName = table4[PgTable.Symbol.OriginalName];
|
24837
|
+
const alias = tableName === origTableName ? void 0 : tableName;
|
24838
|
+
const tableSql = sql`${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}`;
|
24986
24839
|
const setSql = this.buildUpdateSet(table4, set);
|
24987
|
-
const
|
24840
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
24841
|
+
const joinsSql = this.buildJoins(joins);
|
24842
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: !from })}` : void 0;
|
24988
24843
|
const whereSql = where ? sql` where ${where}` : void 0;
|
24989
|
-
return sql`${withSql}update ${
|
24844
|
+
return sql`${withSql}update ${tableSql} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}`;
|
24990
24845
|
}
|
24991
24846
|
/**
|
24992
24847
|
* Builds selection SQL with provided fields/expressions
|
@@ -25038,6 +24893,54 @@ var init_dialect = __esm({
|
|
25038
24893
|
});
|
25039
24894
|
return sql.join(chunks);
|
25040
24895
|
}
|
24896
|
+
buildJoins(joins) {
|
24897
|
+
if (!joins || joins.length === 0) {
|
24898
|
+
return void 0;
|
24899
|
+
}
|
24900
|
+
const joinsArray = [];
|
24901
|
+
for (const [index4, joinMeta] of joins.entries()) {
|
24902
|
+
if (index4 === 0) {
|
24903
|
+
joinsArray.push(sql` `);
|
24904
|
+
}
|
24905
|
+
const table4 = joinMeta.table;
|
24906
|
+
const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
|
24907
|
+
if (is(table4, PgTable)) {
|
24908
|
+
const tableName = table4[PgTable.Symbol.Name];
|
24909
|
+
const tableSchema = table4[PgTable.Symbol.Schema];
|
24910
|
+
const origTableName = table4[PgTable.Symbol.OriginalName];
|
24911
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
24912
|
+
joinsArray.push(
|
24913
|
+
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}`
|
24914
|
+
);
|
24915
|
+
} else if (is(table4, View3)) {
|
24916
|
+
const viewName = table4[ViewBaseConfig].name;
|
24917
|
+
const viewSchema = table4[ViewBaseConfig].schema;
|
24918
|
+
const origViewName = table4[ViewBaseConfig].originalName;
|
24919
|
+
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
24920
|
+
joinsArray.push(
|
24921
|
+
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}`
|
24922
|
+
);
|
24923
|
+
} else {
|
24924
|
+
joinsArray.push(
|
24925
|
+
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table4} on ${joinMeta.on}`
|
24926
|
+
);
|
24927
|
+
}
|
24928
|
+
if (index4 < joins.length - 1) {
|
24929
|
+
joinsArray.push(sql` `);
|
24930
|
+
}
|
24931
|
+
}
|
24932
|
+
return sql.join(joinsArray);
|
24933
|
+
}
|
24934
|
+
buildFromTable(table4) {
|
24935
|
+
if (is(table4, Table2) && table4[Table2.Symbol.OriginalName] !== table4[Table2.Symbol.Name]) {
|
24936
|
+
let fullName = sql`${sql.identifier(table4[Table2.Symbol.OriginalName])}`;
|
24937
|
+
if (table4[Table2.Symbol.Schema]) {
|
24938
|
+
fullName = sql`${sql.identifier(table4[Table2.Symbol.Schema])}.${fullName}`;
|
24939
|
+
}
|
24940
|
+
return sql`${fullName} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
24941
|
+
}
|
24942
|
+
return table4;
|
24943
|
+
}
|
25041
24944
|
buildSelectQuery({
|
25042
24945
|
withList,
|
25043
24946
|
fields,
|
@@ -25072,51 +24975,8 @@ var init_dialect = __esm({
|
|
25072
24975
|
distinctSql = distinct === true ? sql` distinct` : sql` distinct on (${sql.join(distinct.on, sql`, `)})`;
|
25073
24976
|
}
|
25074
24977
|
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
25075
|
-
const tableSql = (
|
25076
|
-
|
25077
|
-
let fullName = sql`${sql.identifier(table4[Table2.Symbol.OriginalName])}`;
|
25078
|
-
if (table4[Table2.Symbol.Schema]) {
|
25079
|
-
fullName = sql`${sql.identifier(table4[Table2.Symbol.Schema])}.${fullName}`;
|
25080
|
-
}
|
25081
|
-
return sql`${fullName} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
25082
|
-
}
|
25083
|
-
return table4;
|
25084
|
-
})();
|
25085
|
-
const joinsArray = [];
|
25086
|
-
if (joins) {
|
25087
|
-
for (const [index4, joinMeta] of joins.entries()) {
|
25088
|
-
if (index4 === 0) {
|
25089
|
-
joinsArray.push(sql` `);
|
25090
|
-
}
|
25091
|
-
const table22 = joinMeta.table;
|
25092
|
-
const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
|
25093
|
-
if (is(table22, PgTable)) {
|
25094
|
-
const tableName = table22[PgTable.Symbol.Name];
|
25095
|
-
const tableSchema = table22[PgTable.Symbol.Schema];
|
25096
|
-
const origTableName = table22[PgTable.Symbol.OriginalName];
|
25097
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
25098
|
-
joinsArray.push(
|
25099
|
-
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}`
|
25100
|
-
);
|
25101
|
-
} else if (is(table22, View3)) {
|
25102
|
-
const viewName = table22[ViewBaseConfig].name;
|
25103
|
-
const viewSchema = table22[ViewBaseConfig].schema;
|
25104
|
-
const origViewName = table22[ViewBaseConfig].originalName;
|
25105
|
-
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
25106
|
-
joinsArray.push(
|
25107
|
-
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}`
|
25108
|
-
);
|
25109
|
-
} else {
|
25110
|
-
joinsArray.push(
|
25111
|
-
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table22} on ${joinMeta.on}`
|
25112
|
-
);
|
25113
|
-
}
|
25114
|
-
if (index4 < joins.length - 1) {
|
25115
|
-
joinsArray.push(sql` `);
|
25116
|
-
}
|
25117
|
-
}
|
25118
|
-
}
|
25119
|
-
const joinsSql = sql.join(joinsArray);
|
24978
|
+
const tableSql = this.buildFromTable(table4);
|
24979
|
+
const joinsSql = this.buildJoins(joins);
|
25120
24980
|
const whereSql = where ? sql` where ${where}` : void 0;
|
25121
24981
|
const havingSql = having ? sql` having ${having}` : void 0;
|
25122
24982
|
let orderBySql;
|
@@ -25197,43 +25057,54 @@ var init_dialect = __esm({
|
|
25197
25057
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
25198
25058
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
25199
25059
|
}
|
25200
|
-
buildInsertQuery({ table: table4, values, onConflict, returning, withList }) {
|
25060
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, onConflict, returning, withList, select }) {
|
25201
25061
|
const valuesSqlList = [];
|
25202
25062
|
const columns = table4[Table2.Symbol.Columns];
|
25203
25063
|
const colEntries = Object.entries(columns).filter(([_2, col]) => !col.shouldDisableInsert());
|
25204
25064
|
const insertOrder = colEntries.map(
|
25205
25065
|
([, column4]) => sql.identifier(this.casing.getColumnCasing(column4))
|
25206
25066
|
);
|
25207
|
-
|
25208
|
-
const
|
25209
|
-
|
25210
|
-
|
25211
|
-
|
25212
|
-
|
25213
|
-
|
25214
|
-
|
25215
|
-
|
25216
|
-
|
25217
|
-
|
25218
|
-
|
25219
|
-
|
25067
|
+
if (select) {
|
25068
|
+
const select2 = valuesOrSelect;
|
25069
|
+
if (is(select2, SQL)) {
|
25070
|
+
valuesSqlList.push(select2);
|
25071
|
+
} else {
|
25072
|
+
valuesSqlList.push(select2.getSQL());
|
25073
|
+
}
|
25074
|
+
} else {
|
25075
|
+
const values = valuesOrSelect;
|
25076
|
+
valuesSqlList.push(sql.raw("values "));
|
25077
|
+
for (const [valueIndex, value] of values.entries()) {
|
25078
|
+
const valueList = [];
|
25079
|
+
for (const [fieldName, col] of colEntries) {
|
25080
|
+
const colValue = value[fieldName];
|
25081
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
25082
|
+
if (col.defaultFn !== void 0) {
|
25083
|
+
const defaultFnResult = col.defaultFn();
|
25084
|
+
const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
25085
|
+
valueList.push(defaultValue);
|
25086
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
25087
|
+
const onUpdateFnResult = col.onUpdateFn();
|
25088
|
+
const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
25089
|
+
valueList.push(newValue);
|
25090
|
+
} else {
|
25091
|
+
valueList.push(sql`default`);
|
25092
|
+
}
|
25220
25093
|
} else {
|
25221
|
-
valueList.push(
|
25094
|
+
valueList.push(colValue);
|
25222
25095
|
}
|
25223
|
-
} else {
|
25224
|
-
valueList.push(colValue);
|
25225
25096
|
}
|
25226
|
-
|
25227
|
-
|
25228
|
-
|
25229
|
-
|
25097
|
+
valuesSqlList.push(valueList);
|
25098
|
+
if (valueIndex < values.length - 1) {
|
25099
|
+
valuesSqlList.push(sql`, `);
|
25100
|
+
}
|
25230
25101
|
}
|
25231
25102
|
}
|
25232
25103
|
const withSql = this.buildWithCTE(withList);
|
25233
25104
|
const valuesSql = sql.join(valuesSqlList);
|
25234
25105
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
25235
25106
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
25236
|
-
return sql`${withSql}insert into ${table4} ${insertOrder}
|
25107
|
+
return sql`${withSql}insert into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;
|
25237
25108
|
}
|
25238
25109
|
buildRefreshMaterializedViewQuery({ view: view4, concurrently, withNoData }) {
|
25239
25110
|
const concurrentlySql = concurrently ? sql` concurrently` : void 0;
|
@@ -25969,12 +25840,12 @@ var init_dialect = __esm({
|
|
25969
25840
|
};
|
25970
25841
|
}
|
25971
25842
|
};
|
25972
|
-
__publicField(PgDialect,
|
25843
|
+
__publicField(PgDialect, _a127, "PgDialect");
|
25973
25844
|
}
|
25974
25845
|
});
|
25975
25846
|
|
25976
25847
|
// ../drizzle-orm/dist/selection-proxy.js
|
25977
|
-
var
|
25848
|
+
var _a128, _SelectionProxyHandler, SelectionProxyHandler;
|
25978
25849
|
var init_selection_proxy = __esm({
|
25979
25850
|
"../drizzle-orm/dist/selection-proxy.js"() {
|
25980
25851
|
"use strict";
|
@@ -25984,7 +25855,7 @@ var init_selection_proxy = __esm({
|
|
25984
25855
|
init_sql();
|
25985
25856
|
init_subquery();
|
25986
25857
|
init_view_common();
|
25987
|
-
|
25858
|
+
_a128 = entityKind;
|
25988
25859
|
_SelectionProxyHandler = class _SelectionProxyHandler {
|
25989
25860
|
constructor(config) {
|
25990
25861
|
__publicField(this, "config");
|
@@ -26050,25 +25921,25 @@ var init_selection_proxy = __esm({
|
|
26050
25921
|
return new Proxy(value, new _SelectionProxyHandler(this.config));
|
26051
25922
|
}
|
26052
25923
|
};
|
26053
|
-
__publicField(_SelectionProxyHandler,
|
25924
|
+
__publicField(_SelectionProxyHandler, _a128, "SelectionProxyHandler");
|
26054
25925
|
SelectionProxyHandler = _SelectionProxyHandler;
|
26055
25926
|
}
|
26056
25927
|
});
|
26057
25928
|
|
26058
25929
|
// ../drizzle-orm/dist/query-builders/query-builder.js
|
26059
|
-
var
|
25930
|
+
var _a129, TypedQueryBuilder;
|
26060
25931
|
var init_query_builder = __esm({
|
26061
25932
|
"../drizzle-orm/dist/query-builders/query-builder.js"() {
|
26062
25933
|
"use strict";
|
26063
25934
|
init_entity();
|
26064
|
-
|
25935
|
+
_a129 = entityKind;
|
26065
25936
|
TypedQueryBuilder = class {
|
26066
25937
|
/** @internal */
|
26067
25938
|
getSelectedFields() {
|
26068
25939
|
return this._.selectedFields;
|
26069
25940
|
}
|
26070
25941
|
};
|
26071
|
-
__publicField(TypedQueryBuilder,
|
25942
|
+
__publicField(TypedQueryBuilder, _a129, "TypedQueryBuilder");
|
26072
25943
|
}
|
26073
25944
|
});
|
26074
25945
|
|
@@ -26090,7 +25961,7 @@ function createSetOperator(type, isAll) {
|
|
26090
25961
|
return leftSelect.addSetOperators(setOperators);
|
26091
25962
|
};
|
26092
25963
|
}
|
26093
|
-
var
|
25964
|
+
var _a130, PgSelectBuilder, _a131, _b99, PgSelectQueryBuilderBase, _a132, _b100, PgSelectBase, getPgSetOperators, union, unionAll, intersect, intersectAll, except, exceptAll;
|
26094
25965
|
var init_select2 = __esm({
|
26095
25966
|
"../drizzle-orm/dist/pg-core/query-builders/select.js"() {
|
26096
25967
|
"use strict";
|
@@ -26106,7 +25977,7 @@ var init_select2 = __esm({
|
|
26106
25977
|
init_utils2();
|
26107
25978
|
init_utils2();
|
26108
25979
|
init_view_common();
|
26109
|
-
|
25980
|
+
_a130 = entityKind;
|
26110
25981
|
PgSelectBuilder = class {
|
26111
25982
|
constructor(config) {
|
26112
25983
|
__publicField(this, "fields");
|
@@ -26155,8 +26026,8 @@ var init_select2 = __esm({
|
|
26155
26026
|
});
|
26156
26027
|
}
|
26157
26028
|
};
|
26158
|
-
__publicField(PgSelectBuilder,
|
26159
|
-
PgSelectQueryBuilderBase = class extends (
|
26029
|
+
__publicField(PgSelectBuilder, _a130, "PgSelectBuilder");
|
26030
|
+
PgSelectQueryBuilderBase = class extends (_b99 = TypedQueryBuilder, _a131 = entityKind, _b99) {
|
26160
26031
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
26161
26032
|
super();
|
26162
26033
|
__publicField(this, "_");
|
@@ -26756,8 +26627,8 @@ var init_select2 = __esm({
|
|
26756
26627
|
return this;
|
26757
26628
|
}
|
26758
26629
|
};
|
26759
|
-
__publicField(PgSelectQueryBuilderBase,
|
26760
|
-
PgSelectBase = class extends (
|
26630
|
+
__publicField(PgSelectQueryBuilderBase, _a131, "PgSelectQueryBuilder");
|
26631
|
+
PgSelectBase = class extends (_b100 = PgSelectQueryBuilderBase, _a132 = entityKind, _b100) {
|
26761
26632
|
constructor() {
|
26762
26633
|
super(...arguments);
|
26763
26634
|
__publicField(this, "execute", (placeholderValues) => {
|
@@ -26790,7 +26661,7 @@ var init_select2 = __esm({
|
|
26790
26661
|
return this._prepare(name2);
|
26791
26662
|
}
|
26792
26663
|
};
|
26793
|
-
__publicField(PgSelectBase,
|
26664
|
+
__publicField(PgSelectBase, _a132, "PgSelect");
|
26794
26665
|
applyMixins(PgSelectBase, [QueryPromise]);
|
26795
26666
|
getPgSetOperators = () => ({
|
26796
26667
|
union,
|
@@ -26810,7 +26681,7 @@ var init_select2 = __esm({
|
|
26810
26681
|
});
|
26811
26682
|
|
26812
26683
|
// ../drizzle-orm/dist/pg-core/query-builders/query-builder.js
|
26813
|
-
var
|
26684
|
+
var _a133, QueryBuilder;
|
26814
26685
|
var init_query_builder2 = __esm({
|
26815
26686
|
"../drizzle-orm/dist/pg-core/query-builders/query-builder.js"() {
|
26816
26687
|
"use strict";
|
@@ -26819,7 +26690,7 @@ var init_query_builder2 = __esm({
|
|
26819
26690
|
init_selection_proxy();
|
26820
26691
|
init_subquery();
|
26821
26692
|
init_select2();
|
26822
|
-
|
26693
|
+
_a133 = entityKind;
|
26823
26694
|
QueryBuilder = class {
|
26824
26695
|
constructor(dialect4) {
|
26825
26696
|
__publicField(this, "dialect");
|
@@ -26900,38 +26771,204 @@ var init_query_builder2 = __esm({
|
|
26900
26771
|
return this.dialect;
|
26901
26772
|
}
|
26902
26773
|
};
|
26903
|
-
__publicField(QueryBuilder,
|
26774
|
+
__publicField(QueryBuilder, _a133, "PgQueryBuilder");
|
26904
26775
|
}
|
26905
26776
|
});
|
26906
26777
|
|
26907
|
-
// ../drizzle-orm/dist/pg-core/query-builders/
|
26908
|
-
var
|
26909
|
-
var
|
26910
|
-
"../drizzle-orm/dist/pg-core/query-builders/
|
26778
|
+
// ../drizzle-orm/dist/pg-core/query-builders/insert.js
|
26779
|
+
var _a134, PgInsertBuilder, _a135, _b101, PgInsertBase;
|
26780
|
+
var init_insert = __esm({
|
26781
|
+
"../drizzle-orm/dist/pg-core/query-builders/insert.js"() {
|
26911
26782
|
"use strict";
|
26912
26783
|
init_entity();
|
26913
26784
|
init_query_promise();
|
26785
|
+
init_sql();
|
26786
|
+
init_table();
|
26914
26787
|
init_tracing();
|
26915
|
-
|
26916
|
-
|
26917
|
-
|
26918
|
-
|
26919
|
-
|
26920
|
-
|
26921
|
-
return this._prepare().execute(placeholderValues);
|
26922
|
-
});
|
26923
|
-
});
|
26788
|
+
init_utils2();
|
26789
|
+
init_query_builder2();
|
26790
|
+
_a134 = entityKind;
|
26791
|
+
PgInsertBuilder = class {
|
26792
|
+
constructor(table4, session, dialect4, withList) {
|
26793
|
+
this.table = table4;
|
26924
26794
|
this.session = session;
|
26925
26795
|
this.dialect = dialect4;
|
26926
|
-
this.
|
26796
|
+
this.withList = withList;
|
26927
26797
|
}
|
26928
|
-
|
26929
|
-
|
26930
|
-
|
26798
|
+
values(values) {
|
26799
|
+
values = Array.isArray(values) ? values : [values];
|
26800
|
+
if (values.length === 0) {
|
26801
|
+
throw new Error("values() must be called with at least one value");
|
26931
26802
|
}
|
26932
|
-
|
26933
|
-
|
26934
|
-
|
26803
|
+
const mappedValues = values.map((entry) => {
|
26804
|
+
const result = {};
|
26805
|
+
const cols = this.table[Table2.Symbol.Columns];
|
26806
|
+
for (const colKey of Object.keys(entry)) {
|
26807
|
+
const colValue = entry[colKey];
|
26808
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
26809
|
+
}
|
26810
|
+
return result;
|
26811
|
+
});
|
26812
|
+
return new PgInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
26813
|
+
}
|
26814
|
+
select(selectQuery) {
|
26815
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
|
26816
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
26817
|
+
throw new Error(
|
26818
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
26819
|
+
);
|
26820
|
+
}
|
26821
|
+
return new PgInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
26822
|
+
}
|
26823
|
+
};
|
26824
|
+
__publicField(PgInsertBuilder, _a134, "PgInsertBuilder");
|
26825
|
+
PgInsertBase = class extends (_b101 = QueryPromise, _a135 = entityKind, _b101) {
|
26826
|
+
constructor(table4, values, session, dialect4, withList, select) {
|
26827
|
+
super();
|
26828
|
+
__publicField(this, "config");
|
26829
|
+
__publicField(this, "execute", (placeholderValues) => {
|
26830
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
26831
|
+
return this._prepare().execute(placeholderValues);
|
26832
|
+
});
|
26833
|
+
});
|
26834
|
+
this.session = session;
|
26835
|
+
this.dialect = dialect4;
|
26836
|
+
this.config = { table: table4, values, withList, select };
|
26837
|
+
}
|
26838
|
+
returning(fields = this.config.table[Table2.Symbol.Columns]) {
|
26839
|
+
this.config.returning = orderSelectedFields(fields);
|
26840
|
+
return this;
|
26841
|
+
}
|
26842
|
+
/**
|
26843
|
+
* Adds an `on conflict do nothing` clause to the query.
|
26844
|
+
*
|
26845
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
26846
|
+
*
|
26847
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
26848
|
+
*
|
26849
|
+
* @param config The `target` and `where` clauses.
|
26850
|
+
*
|
26851
|
+
* @example
|
26852
|
+
* ```ts
|
26853
|
+
* // Insert one row and cancel the insert if there's a conflict
|
26854
|
+
* await db.insert(cars)
|
26855
|
+
* .values({ id: 1, brand: 'BMW' })
|
26856
|
+
* .onConflictDoNothing();
|
26857
|
+
*
|
26858
|
+
* // Explicitly specify conflict target
|
26859
|
+
* await db.insert(cars)
|
26860
|
+
* .values({ id: 1, brand: 'BMW' })
|
26861
|
+
* .onConflictDoNothing({ target: cars.id });
|
26862
|
+
* ```
|
26863
|
+
*/
|
26864
|
+
onConflictDoNothing(config = {}) {
|
26865
|
+
if (config.target === void 0) {
|
26866
|
+
this.config.onConflict = sql`do nothing`;
|
26867
|
+
} else {
|
26868
|
+
let targetColumn = "";
|
26869
|
+
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));
|
26870
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
26871
|
+
this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
|
26872
|
+
}
|
26873
|
+
return this;
|
26874
|
+
}
|
26875
|
+
/**
|
26876
|
+
* Adds an `on conflict do update` clause to the query.
|
26877
|
+
*
|
26878
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
26879
|
+
*
|
26880
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
26881
|
+
*
|
26882
|
+
* @param config The `target`, `set` and `where` clauses.
|
26883
|
+
*
|
26884
|
+
* @example
|
26885
|
+
* ```ts
|
26886
|
+
* // Update the row if there's a conflict
|
26887
|
+
* await db.insert(cars)
|
26888
|
+
* .values({ id: 1, brand: 'BMW' })
|
26889
|
+
* .onConflictDoUpdate({
|
26890
|
+
* target: cars.id,
|
26891
|
+
* set: { brand: 'Porsche' }
|
26892
|
+
* });
|
26893
|
+
*
|
26894
|
+
* // Upsert with 'where' clause
|
26895
|
+
* await db.insert(cars)
|
26896
|
+
* .values({ id: 1, brand: 'BMW' })
|
26897
|
+
* .onConflictDoUpdate({
|
26898
|
+
* target: cars.id,
|
26899
|
+
* set: { brand: 'newBMW' },
|
26900
|
+
* targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
|
26901
|
+
* });
|
26902
|
+
* ```
|
26903
|
+
*/
|
26904
|
+
onConflictDoUpdate(config) {
|
26905
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
26906
|
+
throw new Error(
|
26907
|
+
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
26908
|
+
);
|
26909
|
+
}
|
26910
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
26911
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
26912
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
26913
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
26914
|
+
let targetColumn = "";
|
26915
|
+
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));
|
26916
|
+
this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
26917
|
+
return this;
|
26918
|
+
}
|
26919
|
+
/** @internal */
|
26920
|
+
getSQL() {
|
26921
|
+
return this.dialect.buildInsertQuery(this.config);
|
26922
|
+
}
|
26923
|
+
toSQL() {
|
26924
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
26925
|
+
return rest;
|
26926
|
+
}
|
26927
|
+
/** @internal */
|
26928
|
+
_prepare(name2) {
|
26929
|
+
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
26930
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
|
26931
|
+
});
|
26932
|
+
}
|
26933
|
+
prepare(name2) {
|
26934
|
+
return this._prepare(name2);
|
26935
|
+
}
|
26936
|
+
$dynamic() {
|
26937
|
+
return this;
|
26938
|
+
}
|
26939
|
+
};
|
26940
|
+
__publicField(PgInsertBase, _a135, "PgInsert");
|
26941
|
+
}
|
26942
|
+
});
|
26943
|
+
|
26944
|
+
// ../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js
|
26945
|
+
var _a136, _b102, PgRefreshMaterializedView;
|
26946
|
+
var init_refresh_materialized_view = __esm({
|
26947
|
+
"../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js"() {
|
26948
|
+
"use strict";
|
26949
|
+
init_entity();
|
26950
|
+
init_query_promise();
|
26951
|
+
init_tracing();
|
26952
|
+
PgRefreshMaterializedView = class extends (_b102 = QueryPromise, _a136 = entityKind, _b102) {
|
26953
|
+
constructor(view4, session, dialect4) {
|
26954
|
+
super();
|
26955
|
+
__publicField(this, "config");
|
26956
|
+
__publicField(this, "execute", (placeholderValues) => {
|
26957
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
26958
|
+
return this._prepare().execute(placeholderValues);
|
26959
|
+
});
|
26960
|
+
});
|
26961
|
+
this.session = session;
|
26962
|
+
this.dialect = dialect4;
|
26963
|
+
this.config = { view: view4 };
|
26964
|
+
}
|
26965
|
+
concurrently() {
|
26966
|
+
if (this.config.withNoData !== void 0) {
|
26967
|
+
throw new Error("Cannot use concurrently and withNoData together");
|
26968
|
+
}
|
26969
|
+
this.config.concurrently = true;
|
26970
|
+
return this;
|
26971
|
+
}
|
26935
26972
|
withNoData() {
|
26936
26973
|
if (this.config.concurrently !== void 0) {
|
26937
26974
|
throw new Error("Cannot use concurrently and withNoData together");
|
@@ -26974,9 +27011,14 @@ var init_update = __esm({
|
|
26974
27011
|
"../drizzle-orm/dist/pg-core/query-builders/update.js"() {
|
26975
27012
|
"use strict";
|
26976
27013
|
init_entity();
|
27014
|
+
init_table2();
|
26977
27015
|
init_query_promise();
|
27016
|
+
init_selection_proxy();
|
27017
|
+
init_sql();
|
27018
|
+
init_subquery();
|
26978
27019
|
init_table();
|
26979
27020
|
init_utils2();
|
27021
|
+
init_view_common();
|
26980
27022
|
_a137 = entityKind;
|
26981
27023
|
PgUpdateBuilder = class {
|
26982
27024
|
constructor(table4, session, dialect4, withList) {
|
@@ -27000,12 +27042,85 @@ var init_update = __esm({
|
|
27000
27042
|
constructor(table4, set, session, dialect4, withList) {
|
27001
27043
|
super();
|
27002
27044
|
__publicField(this, "config");
|
27045
|
+
__publicField(this, "tableName");
|
27046
|
+
__publicField(this, "joinsNotNullableMap");
|
27047
|
+
__publicField(this, "leftJoin", this.createJoin("left"));
|
27048
|
+
__publicField(this, "rightJoin", this.createJoin("right"));
|
27049
|
+
__publicField(this, "innerJoin", this.createJoin("inner"));
|
27050
|
+
__publicField(this, "fullJoin", this.createJoin("full"));
|
27003
27051
|
__publicField(this, "execute", (placeholderValues) => {
|
27004
27052
|
return this._prepare().execute(placeholderValues);
|
27005
27053
|
});
|
27006
27054
|
this.session = session;
|
27007
27055
|
this.dialect = dialect4;
|
27008
|
-
this.config = { set, table: table4, withList };
|
27056
|
+
this.config = { set, table: table4, withList, joins: [] };
|
27057
|
+
this.tableName = getTableLikeName(table4);
|
27058
|
+
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
27059
|
+
}
|
27060
|
+
from(source) {
|
27061
|
+
const tableName = getTableLikeName(source);
|
27062
|
+
if (typeof tableName === "string") {
|
27063
|
+
this.joinsNotNullableMap[tableName] = true;
|
27064
|
+
}
|
27065
|
+
this.config.from = source;
|
27066
|
+
return this;
|
27067
|
+
}
|
27068
|
+
getTableLikeFields(table4) {
|
27069
|
+
if (is(table4, PgTable)) {
|
27070
|
+
return table4[Table2.Symbol.Columns];
|
27071
|
+
} else if (is(table4, Subquery)) {
|
27072
|
+
return table4._.selectedFields;
|
27073
|
+
}
|
27074
|
+
return table4[ViewBaseConfig].selectedFields;
|
27075
|
+
}
|
27076
|
+
createJoin(joinType) {
|
27077
|
+
return (table4, on) => {
|
27078
|
+
const tableName = getTableLikeName(table4);
|
27079
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
27080
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
27081
|
+
}
|
27082
|
+
if (typeof on === "function") {
|
27083
|
+
const from = this.config.from && !is(this.config.from, SQL) ? this.getTableLikeFields(this.config.from) : void 0;
|
27084
|
+
on = on(
|
27085
|
+
new Proxy(
|
27086
|
+
this.config.table[Table2.Symbol.Columns],
|
27087
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
27088
|
+
),
|
27089
|
+
from && new Proxy(
|
27090
|
+
from,
|
27091
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
27092
|
+
)
|
27093
|
+
);
|
27094
|
+
}
|
27095
|
+
this.config.joins.push({ on, table: table4, joinType, alias: tableName });
|
27096
|
+
if (typeof tableName === "string") {
|
27097
|
+
switch (joinType) {
|
27098
|
+
case "left": {
|
27099
|
+
this.joinsNotNullableMap[tableName] = false;
|
27100
|
+
break;
|
27101
|
+
}
|
27102
|
+
case "right": {
|
27103
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
27104
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
27105
|
+
);
|
27106
|
+
this.joinsNotNullableMap[tableName] = true;
|
27107
|
+
break;
|
27108
|
+
}
|
27109
|
+
case "inner": {
|
27110
|
+
this.joinsNotNullableMap[tableName] = true;
|
27111
|
+
break;
|
27112
|
+
}
|
27113
|
+
case "full": {
|
27114
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
27115
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
27116
|
+
);
|
27117
|
+
this.joinsNotNullableMap[tableName] = false;
|
27118
|
+
break;
|
27119
|
+
}
|
27120
|
+
}
|
27121
|
+
}
|
27122
|
+
return this;
|
27123
|
+
};
|
27009
27124
|
}
|
27010
27125
|
/**
|
27011
27126
|
* Adds a 'where' clause to the query.
|
@@ -27044,7 +27159,24 @@ var init_update = __esm({
|
|
27044
27159
|
this.config.where = where;
|
27045
27160
|
return this;
|
27046
27161
|
}
|
27047
|
-
returning(fields
|
27162
|
+
returning(fields) {
|
27163
|
+
if (!fields) {
|
27164
|
+
fields = Object.assign({}, this.config.table[Table2.Symbol.Columns]);
|
27165
|
+
if (this.config.from) {
|
27166
|
+
const tableName = getTableLikeName(this.config.from);
|
27167
|
+
if (typeof tableName === "string" && this.config.from && !is(this.config.from, SQL)) {
|
27168
|
+
const fromFields = this.getTableLikeFields(this.config.from);
|
27169
|
+
fields[tableName] = fromFields;
|
27170
|
+
}
|
27171
|
+
for (const join of this.config.joins) {
|
27172
|
+
const tableName2 = getTableLikeName(join.table);
|
27173
|
+
if (typeof tableName2 === "string" && !is(join.table, SQL)) {
|
27174
|
+
const fromFields = this.getTableLikeFields(join.table);
|
27175
|
+
fields[tableName2] = fromFields;
|
27176
|
+
}
|
27177
|
+
}
|
27178
|
+
}
|
27179
|
+
}
|
27048
27180
|
this.config.returning = orderSelectedFields(fields);
|
27049
27181
|
return this;
|
27050
27182
|
}
|
@@ -27058,7 +27190,9 @@ var init_update = __esm({
|
|
27058
27190
|
}
|
27059
27191
|
/** @internal */
|
27060
27192
|
_prepare(name2) {
|
27061
|
-
|
27193
|
+
const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
|
27194
|
+
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
27195
|
+
return query;
|
27062
27196
|
}
|
27063
27197
|
prepare(name2) {
|
27064
27198
|
return this._prepare(name2);
|
@@ -30819,208 +30953,40 @@ var init_delete2 = __esm({
|
|
30819
30953
|
}
|
30820
30954
|
});
|
30821
30955
|
|
30822
|
-
// ../drizzle-orm/dist/sqlite-core/
|
30823
|
-
var _a197,
|
30824
|
-
var
|
30825
|
-
"../drizzle-orm/dist/sqlite-core/
|
30956
|
+
// ../drizzle-orm/dist/sqlite-core/view-base.js
|
30957
|
+
var _a197, _b142, SQLiteViewBase;
|
30958
|
+
var init_view_base2 = __esm({
|
30959
|
+
"../drizzle-orm/dist/sqlite-core/view-base.js"() {
|
30826
30960
|
"use strict";
|
30827
30961
|
init_entity();
|
30828
|
-
init_query_promise();
|
30829
30962
|
init_sql();
|
30963
|
+
SQLiteViewBase = class extends (_b142 = View3, _a197 = entityKind, _b142) {
|
30964
|
+
};
|
30965
|
+
__publicField(SQLiteViewBase, _a197, "SQLiteViewBase");
|
30966
|
+
}
|
30967
|
+
});
|
30968
|
+
|
30969
|
+
// ../drizzle-orm/dist/sqlite-core/dialect.js
|
30970
|
+
var _a198, SQLiteDialect, _a199, _b143, SQLiteSyncDialect, _a200, _b144, SQLiteAsyncDialect;
|
30971
|
+
var init_dialect2 = __esm({
|
30972
|
+
"../drizzle-orm/dist/sqlite-core/dialect.js"() {
|
30973
|
+
"use strict";
|
30974
|
+
init_alias();
|
30975
|
+
init_casing();
|
30976
|
+
init_column();
|
30977
|
+
init_entity();
|
30978
|
+
init_errors();
|
30979
|
+
init_relations();
|
30980
|
+
init_sql2();
|
30981
|
+
init_sql();
|
30982
|
+
init_columns2();
|
30830
30983
|
init_table3();
|
30831
|
-
|
30832
|
-
init_utils2();
|
30833
|
-
_a197 = entityKind;
|
30834
|
-
SQLiteInsertBuilder = class {
|
30835
|
-
constructor(table4, session, dialect4, withList) {
|
30836
|
-
this.table = table4;
|
30837
|
-
this.session = session;
|
30838
|
-
this.dialect = dialect4;
|
30839
|
-
this.withList = withList;
|
30840
|
-
}
|
30841
|
-
values(values) {
|
30842
|
-
values = Array.isArray(values) ? values : [values];
|
30843
|
-
if (values.length === 0) {
|
30844
|
-
throw new Error("values() must be called with at least one value");
|
30845
|
-
}
|
30846
|
-
const mappedValues = values.map((entry) => {
|
30847
|
-
const result = {};
|
30848
|
-
const cols = this.table[Table2.Symbol.Columns];
|
30849
|
-
for (const colKey of Object.keys(entry)) {
|
30850
|
-
const colValue = entry[colKey];
|
30851
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
30852
|
-
}
|
30853
|
-
return result;
|
30854
|
-
});
|
30855
|
-
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
30856
|
-
}
|
30857
|
-
};
|
30858
|
-
__publicField(SQLiteInsertBuilder, _a197, "SQLiteInsertBuilder");
|
30859
|
-
SQLiteInsertBase = class extends (_b142 = QueryPromise, _a198 = entityKind, _b142) {
|
30860
|
-
constructor(table4, values, session, dialect4, withList) {
|
30861
|
-
super();
|
30862
|
-
/** @internal */
|
30863
|
-
__publicField(this, "config");
|
30864
|
-
__publicField(this, "run", (placeholderValues) => {
|
30865
|
-
return this._prepare().run(placeholderValues);
|
30866
|
-
});
|
30867
|
-
__publicField(this, "all", (placeholderValues) => {
|
30868
|
-
return this._prepare().all(placeholderValues);
|
30869
|
-
});
|
30870
|
-
__publicField(this, "get", (placeholderValues) => {
|
30871
|
-
return this._prepare().get(placeholderValues);
|
30872
|
-
});
|
30873
|
-
__publicField(this, "values", (placeholderValues) => {
|
30874
|
-
return this._prepare().values(placeholderValues);
|
30875
|
-
});
|
30876
|
-
this.session = session;
|
30877
|
-
this.dialect = dialect4;
|
30878
|
-
this.config = { table: table4, values, withList };
|
30879
|
-
}
|
30880
|
-
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
30881
|
-
this.config.returning = orderSelectedFields(fields);
|
30882
|
-
return this;
|
30883
|
-
}
|
30884
|
-
/**
|
30885
|
-
* Adds an `on conflict do nothing` clause to the query.
|
30886
|
-
*
|
30887
|
-
* Calling this method simply avoids inserting a row as its alternative action.
|
30888
|
-
*
|
30889
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
30890
|
-
*
|
30891
|
-
* @param config The `target` and `where` clauses.
|
30892
|
-
*
|
30893
|
-
* @example
|
30894
|
-
* ```ts
|
30895
|
-
* // Insert one row and cancel the insert if there's a conflict
|
30896
|
-
* await db.insert(cars)
|
30897
|
-
* .values({ id: 1, brand: 'BMW' })
|
30898
|
-
* .onConflictDoNothing();
|
30899
|
-
*
|
30900
|
-
* // Explicitly specify conflict target
|
30901
|
-
* await db.insert(cars)
|
30902
|
-
* .values({ id: 1, brand: 'BMW' })
|
30903
|
-
* .onConflictDoNothing({ target: cars.id });
|
30904
|
-
* ```
|
30905
|
-
*/
|
30906
|
-
onConflictDoNothing(config = {}) {
|
30907
|
-
if (config.target === void 0) {
|
30908
|
-
this.config.onConflict = sql`do nothing`;
|
30909
|
-
} else {
|
30910
|
-
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
30911
|
-
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
30912
|
-
this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
|
30913
|
-
}
|
30914
|
-
return this;
|
30915
|
-
}
|
30916
|
-
/**
|
30917
|
-
* Adds an `on conflict do update` clause to the query.
|
30918
|
-
*
|
30919
|
-
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
30920
|
-
*
|
30921
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
30922
|
-
*
|
30923
|
-
* @param config The `target`, `set` and `where` clauses.
|
30924
|
-
*
|
30925
|
-
* @example
|
30926
|
-
* ```ts
|
30927
|
-
* // Update the row if there's a conflict
|
30928
|
-
* await db.insert(cars)
|
30929
|
-
* .values({ id: 1, brand: 'BMW' })
|
30930
|
-
* .onConflictDoUpdate({
|
30931
|
-
* target: cars.id,
|
30932
|
-
* set: { brand: 'Porsche' }
|
30933
|
-
* });
|
30934
|
-
*
|
30935
|
-
* // Upsert with 'where' clause
|
30936
|
-
* await db.insert(cars)
|
30937
|
-
* .values({ id: 1, brand: 'BMW' })
|
30938
|
-
* .onConflictDoUpdate({
|
30939
|
-
* target: cars.id,
|
30940
|
-
* set: { brand: 'newBMW' },
|
30941
|
-
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
30942
|
-
* });
|
30943
|
-
* ```
|
30944
|
-
*/
|
30945
|
-
onConflictDoUpdate(config) {
|
30946
|
-
if (config.where && (config.targetWhere || config.setWhere)) {
|
30947
|
-
throw new Error(
|
30948
|
-
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
30949
|
-
);
|
30950
|
-
}
|
30951
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
30952
|
-
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
30953
|
-
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
30954
|
-
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
30955
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
30956
|
-
this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
30957
|
-
return this;
|
30958
|
-
}
|
30959
|
-
/** @internal */
|
30960
|
-
getSQL() {
|
30961
|
-
return this.dialect.buildInsertQuery(this.config);
|
30962
|
-
}
|
30963
|
-
toSQL() {
|
30964
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
30965
|
-
return rest;
|
30966
|
-
}
|
30967
|
-
/** @internal */
|
30968
|
-
_prepare(isOneTimeQuery = true) {
|
30969
|
-
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
30970
|
-
this.dialect.sqlToQuery(this.getSQL()),
|
30971
|
-
this.config.returning,
|
30972
|
-
this.config.returning ? "all" : "run",
|
30973
|
-
true
|
30974
|
-
);
|
30975
|
-
}
|
30976
|
-
prepare() {
|
30977
|
-
return this._prepare(false);
|
30978
|
-
}
|
30979
|
-
async execute() {
|
30980
|
-
return this.config.returning ? this.all() : this.run();
|
30981
|
-
}
|
30982
|
-
$dynamic() {
|
30983
|
-
return this;
|
30984
|
-
}
|
30985
|
-
};
|
30986
|
-
__publicField(SQLiteInsertBase, _a198, "SQLiteInsert");
|
30987
|
-
}
|
30988
|
-
});
|
30989
|
-
|
30990
|
-
// ../drizzle-orm/dist/sqlite-core/view-base.js
|
30991
|
-
var _a199, _b143, SQLiteViewBase;
|
30992
|
-
var init_view_base2 = __esm({
|
30993
|
-
"../drizzle-orm/dist/sqlite-core/view-base.js"() {
|
30994
|
-
"use strict";
|
30995
|
-
init_entity();
|
30996
|
-
init_sql();
|
30997
|
-
SQLiteViewBase = class extends (_b143 = View3, _a199 = entityKind, _b143) {
|
30998
|
-
};
|
30999
|
-
__publicField(SQLiteViewBase, _a199, "SQLiteViewBase");
|
31000
|
-
}
|
31001
|
-
});
|
31002
|
-
|
31003
|
-
// ../drizzle-orm/dist/sqlite-core/dialect.js
|
31004
|
-
var _a200, SQLiteDialect, _a201, _b144, SQLiteSyncDialect, _a202, _b145, SQLiteAsyncDialect;
|
31005
|
-
var init_dialect2 = __esm({
|
31006
|
-
"../drizzle-orm/dist/sqlite-core/dialect.js"() {
|
31007
|
-
"use strict";
|
31008
|
-
init_alias();
|
31009
|
-
init_casing();
|
31010
|
-
init_column();
|
31011
|
-
init_entity();
|
31012
|
-
init_errors();
|
31013
|
-
init_relations();
|
31014
|
-
init_sql2();
|
31015
|
-
init_sql();
|
31016
|
-
init_columns2();
|
31017
|
-
init_table3();
|
31018
|
-
init_subquery();
|
30984
|
+
init_subquery();
|
31019
30985
|
init_table();
|
31020
30986
|
init_utils2();
|
31021
30987
|
init_view_common();
|
31022
30988
|
init_view_base2();
|
31023
|
-
|
30989
|
+
_a198 = entityKind;
|
31024
30990
|
SQLiteDialect = class {
|
31025
30991
|
constructor(config) {
|
31026
30992
|
/** @internal */
|
@@ -31073,14 +31039,16 @@ var init_dialect2 = __esm({
|
|
31073
31039
|
return [res];
|
31074
31040
|
}));
|
31075
31041
|
}
|
31076
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList, limit, orderBy }) {
|
31042
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, joins, from, limit, orderBy }) {
|
31077
31043
|
const withSql = this.buildWithCTE(withList);
|
31078
31044
|
const setSql = this.buildUpdateSet(table4, set);
|
31045
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
31046
|
+
const joinsSql = this.buildJoins(joins);
|
31079
31047
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
31080
31048
|
const whereSql = where ? sql` where ${where}` : void 0;
|
31081
31049
|
const orderBySql = this.buildOrderBy(orderBy);
|
31082
31050
|
const limitSql = this.buildLimit(limit);
|
31083
|
-
return sql`${withSql}update ${table4} set ${setSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
31051
|
+
return sql`${withSql}update ${table4} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
31084
31052
|
}
|
31085
31053
|
/**
|
31086
31054
|
* Builds selection SQL with provided fields/expressions
|
@@ -31133,6 +31101,37 @@ var init_dialect2 = __esm({
|
|
31133
31101
|
});
|
31134
31102
|
return sql.join(chunks);
|
31135
31103
|
}
|
31104
|
+
buildJoins(joins) {
|
31105
|
+
if (!joins || joins.length === 0) {
|
31106
|
+
return void 0;
|
31107
|
+
}
|
31108
|
+
const joinsArray = [];
|
31109
|
+
if (joins) {
|
31110
|
+
for (const [index4, joinMeta] of joins.entries()) {
|
31111
|
+
if (index4 === 0) {
|
31112
|
+
joinsArray.push(sql` `);
|
31113
|
+
}
|
31114
|
+
const table4 = joinMeta.table;
|
31115
|
+
if (is(table4, SQLiteTable)) {
|
31116
|
+
const tableName = table4[SQLiteTable.Symbol.Name];
|
31117
|
+
const tableSchema = table4[SQLiteTable.Symbol.Schema];
|
31118
|
+
const origTableName = table4[SQLiteTable.Symbol.OriginalName];
|
31119
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
31120
|
+
joinsArray.push(
|
31121
|
+
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
31122
|
+
);
|
31123
|
+
} else {
|
31124
|
+
joinsArray.push(
|
31125
|
+
sql`${sql.raw(joinMeta.joinType)} join ${table4} on ${joinMeta.on}`
|
31126
|
+
);
|
31127
|
+
}
|
31128
|
+
if (index4 < joins.length - 1) {
|
31129
|
+
joinsArray.push(sql` `);
|
31130
|
+
}
|
31131
|
+
}
|
31132
|
+
}
|
31133
|
+
return sql.join(joinsArray);
|
31134
|
+
}
|
31136
31135
|
buildLimit(limit) {
|
31137
31136
|
return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
31138
31137
|
}
|
@@ -31148,6 +31147,12 @@ var init_dialect2 = __esm({
|
|
31148
31147
|
}
|
31149
31148
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
31150
31149
|
}
|
31150
|
+
buildFromTable(table4) {
|
31151
|
+
if (is(table4, Table2) && table4[Table2.Symbol.OriginalName] !== table4[Table2.Symbol.Name]) {
|
31152
|
+
return sql`${sql.identifier(table4[Table2.Symbol.OriginalName])} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
31153
|
+
}
|
31154
|
+
return table4;
|
31155
|
+
}
|
31151
31156
|
buildSelectQuery({
|
31152
31157
|
withList,
|
31153
31158
|
fields,
|
@@ -31178,38 +31183,8 @@ var init_dialect2 = __esm({
|
|
31178
31183
|
const withSql = this.buildWithCTE(withList);
|
31179
31184
|
const distinctSql = distinct ? sql` distinct` : void 0;
|
31180
31185
|
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
31181
|
-
const tableSql = (
|
31182
|
-
|
31183
|
-
return sql`${sql.identifier(table4[Table2.Symbol.OriginalName])} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
31184
|
-
}
|
31185
|
-
return table4;
|
31186
|
-
})();
|
31187
|
-
const joinsArray = [];
|
31188
|
-
if (joins) {
|
31189
|
-
for (const [index4, joinMeta] of joins.entries()) {
|
31190
|
-
if (index4 === 0) {
|
31191
|
-
joinsArray.push(sql` `);
|
31192
|
-
}
|
31193
|
-
const table22 = joinMeta.table;
|
31194
|
-
if (is(table22, SQLiteTable)) {
|
31195
|
-
const tableName = table22[SQLiteTable.Symbol.Name];
|
31196
|
-
const tableSchema = table22[SQLiteTable.Symbol.Schema];
|
31197
|
-
const origTableName = table22[SQLiteTable.Symbol.OriginalName];
|
31198
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
31199
|
-
joinsArray.push(
|
31200
|
-
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
31201
|
-
);
|
31202
|
-
} else {
|
31203
|
-
joinsArray.push(
|
31204
|
-
sql`${sql.raw(joinMeta.joinType)} join ${table22} on ${joinMeta.on}`
|
31205
|
-
);
|
31206
|
-
}
|
31207
|
-
if (index4 < joins.length - 1) {
|
31208
|
-
joinsArray.push(sql` `);
|
31209
|
-
}
|
31210
|
-
}
|
31211
|
-
}
|
31212
|
-
const joinsSql = sql.join(joinsArray);
|
31186
|
+
const tableSql = this.buildFromTable(table4);
|
31187
|
+
const joinsSql = this.buildJoins(joins);
|
31213
31188
|
const whereSql = where ? sql` where ${where}` : void 0;
|
31214
31189
|
const havingSql = having ? sql` having ${having}` : void 0;
|
31215
31190
|
const groupByList = [];
|
@@ -31275,45 +31250,56 @@ var init_dialect2 = __esm({
|
|
31275
31250
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
31276
31251
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
31277
31252
|
}
|
31278
|
-
buildInsertQuery({ table: table4, values, onConflict, returning, withList }) {
|
31253
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, onConflict, returning, withList, select }) {
|
31279
31254
|
const valuesSqlList = [];
|
31280
31255
|
const columns = table4[Table2.Symbol.Columns];
|
31281
31256
|
const colEntries = Object.entries(columns).filter(
|
31282
31257
|
([_2, col]) => !col.shouldDisableInsert()
|
31283
31258
|
);
|
31284
31259
|
const insertOrder = colEntries.map(([, column4]) => sql.identifier(this.casing.getColumnCasing(column4)));
|
31285
|
-
|
31286
|
-
const
|
31287
|
-
|
31288
|
-
|
31289
|
-
|
31290
|
-
|
31291
|
-
|
31292
|
-
|
31293
|
-
|
31294
|
-
|
31295
|
-
|
31296
|
-
|
31297
|
-
|
31298
|
-
|
31260
|
+
if (select) {
|
31261
|
+
const select2 = valuesOrSelect;
|
31262
|
+
if (is(select2, SQL)) {
|
31263
|
+
valuesSqlList.push(select2);
|
31264
|
+
} else {
|
31265
|
+
valuesSqlList.push(select2.getSQL());
|
31266
|
+
}
|
31267
|
+
} else {
|
31268
|
+
const values = valuesOrSelect;
|
31269
|
+
valuesSqlList.push(sql.raw("values "));
|
31270
|
+
for (const [valueIndex, value] of values.entries()) {
|
31271
|
+
const valueList = [];
|
31272
|
+
for (const [fieldName, col] of colEntries) {
|
31273
|
+
const colValue = value[fieldName];
|
31274
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
31275
|
+
let defaultValue;
|
31276
|
+
if (col.default !== null && col.default !== void 0) {
|
31277
|
+
defaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);
|
31278
|
+
} else if (col.defaultFn !== void 0) {
|
31279
|
+
const defaultFnResult = col.defaultFn();
|
31280
|
+
defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
31281
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
31282
|
+
const onUpdateFnResult = col.onUpdateFn();
|
31283
|
+
defaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
31284
|
+
} else {
|
31285
|
+
defaultValue = sql`null`;
|
31286
|
+
}
|
31287
|
+
valueList.push(defaultValue);
|
31299
31288
|
} else {
|
31300
|
-
|
31289
|
+
valueList.push(colValue);
|
31301
31290
|
}
|
31302
|
-
valueList.push(defaultValue);
|
31303
|
-
} else {
|
31304
|
-
valueList.push(colValue);
|
31305
31291
|
}
|
31306
|
-
|
31307
|
-
|
31308
|
-
|
31309
|
-
|
31292
|
+
valuesSqlList.push(valueList);
|
31293
|
+
if (valueIndex < values.length - 1) {
|
31294
|
+
valuesSqlList.push(sql`, `);
|
31295
|
+
}
|
31310
31296
|
}
|
31311
31297
|
}
|
31312
31298
|
const withSql = this.buildWithCTE(withList);
|
31313
31299
|
const valuesSql = sql.join(valuesSqlList);
|
31314
31300
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
31315
31301
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
31316
|
-
return sql`${withSql}insert into ${table4} ${insertOrder}
|
31302
|
+
return sql`${withSql}insert into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;
|
31317
31303
|
}
|
31318
31304
|
sqlToQuery(sql2, invokeSource) {
|
31319
31305
|
return sql2.toQuery({
|
@@ -31542,8 +31528,8 @@ var init_dialect2 = __esm({
|
|
31542
31528
|
};
|
31543
31529
|
}
|
31544
31530
|
};
|
31545
|
-
__publicField(SQLiteDialect,
|
31546
|
-
SQLiteSyncDialect = class extends (
|
31531
|
+
__publicField(SQLiteDialect, _a198, "SQLiteDialect");
|
31532
|
+
SQLiteSyncDialect = class extends (_b143 = SQLiteDialect, _a199 = entityKind, _b143) {
|
31547
31533
|
migrate(migrations, session, config) {
|
31548
31534
|
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
31549
31535
|
const migrationTableCreate = sql`
|
@@ -31577,8 +31563,8 @@ var init_dialect2 = __esm({
|
|
31577
31563
|
}
|
31578
31564
|
}
|
31579
31565
|
};
|
31580
|
-
__publicField(SQLiteSyncDialect,
|
31581
|
-
SQLiteAsyncDialect = class extends (
|
31566
|
+
__publicField(SQLiteSyncDialect, _a199, "SQLiteSyncDialect");
|
31567
|
+
SQLiteAsyncDialect = class extends (_b144 = SQLiteDialect, _a200 = entityKind, _b144) {
|
31582
31568
|
async migrate(migrations, session, config) {
|
31583
31569
|
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
31584
31570
|
const migrationTableCreate = sql`
|
@@ -31607,7 +31593,7 @@ var init_dialect2 = __esm({
|
|
31607
31593
|
});
|
31608
31594
|
}
|
31609
31595
|
};
|
31610
|
-
__publicField(SQLiteAsyncDialect,
|
31596
|
+
__publicField(SQLiteAsyncDialect, _a200, "SQLiteAsyncDialect");
|
31611
31597
|
}
|
31612
31598
|
});
|
31613
31599
|
|
@@ -31629,7 +31615,7 @@ function createSetOperator2(type, isAll) {
|
|
31629
31615
|
return leftSelect.addSetOperators(setOperators);
|
31630
31616
|
};
|
31631
31617
|
}
|
31632
|
-
var
|
31618
|
+
var _a201, SQLiteSelectBuilder, _a202, _b145, SQLiteSelectQueryBuilderBase, _a203, _b146, SQLiteSelectBase, getSQLiteSetOperators, union2, unionAll2, intersect2, except2;
|
31633
31619
|
var init_select3 = __esm({
|
31634
31620
|
"../drizzle-orm/dist/sqlite-core/query-builders/select.js"() {
|
31635
31621
|
"use strict";
|
@@ -31643,7 +31629,7 @@ var init_select3 = __esm({
|
|
31643
31629
|
init_utils2();
|
31644
31630
|
init_view_common();
|
31645
31631
|
init_view_base2();
|
31646
|
-
|
31632
|
+
_a201 = entityKind;
|
31647
31633
|
SQLiteSelectBuilder = class {
|
31648
31634
|
constructor(config) {
|
31649
31635
|
__publicField(this, "fields");
|
@@ -31684,8 +31670,8 @@ var init_select3 = __esm({
|
|
31684
31670
|
});
|
31685
31671
|
}
|
31686
31672
|
};
|
31687
|
-
__publicField(SQLiteSelectBuilder,
|
31688
|
-
SQLiteSelectQueryBuilderBase = class extends (
|
31673
|
+
__publicField(SQLiteSelectBuilder, _a201, "SQLiteSelectBuilder");
|
31674
|
+
SQLiteSelectQueryBuilderBase = class extends (_b145 = TypedQueryBuilder, _a202 = entityKind, _b145) {
|
31689
31675
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
31690
31676
|
super();
|
31691
31677
|
__publicField(this, "_");
|
@@ -32190,8 +32176,8 @@ var init_select3 = __esm({
|
|
32190
32176
|
return this;
|
32191
32177
|
}
|
32192
32178
|
};
|
32193
|
-
__publicField(SQLiteSelectQueryBuilderBase,
|
32194
|
-
SQLiteSelectBase = class extends (
|
32179
|
+
__publicField(SQLiteSelectQueryBuilderBase, _a202, "SQLiteSelectQueryBuilder");
|
32180
|
+
SQLiteSelectBase = class extends (_b146 = SQLiteSelectQueryBuilderBase, _a203 = entityKind, _b146) {
|
32195
32181
|
constructor() {
|
32196
32182
|
super(...arguments);
|
32197
32183
|
__publicField(this, "run", (placeholderValues) => {
|
@@ -32229,7 +32215,7 @@ var init_select3 = __esm({
|
|
32229
32215
|
return this.all();
|
32230
32216
|
}
|
32231
32217
|
};
|
32232
|
-
__publicField(SQLiteSelectBase,
|
32218
|
+
__publicField(SQLiteSelectBase, _a203, "SQLiteSelect");
|
32233
32219
|
applyMixins(SQLiteSelectBase, [QueryPromise]);
|
32234
32220
|
getSQLiteSetOperators = () => ({
|
32235
32221
|
union: union2,
|
@@ -32245,7 +32231,7 @@ var init_select3 = __esm({
|
|
32245
32231
|
});
|
32246
32232
|
|
32247
32233
|
// ../drizzle-orm/dist/sqlite-core/query-builders/query-builder.js
|
32248
|
-
var
|
32234
|
+
var _a204, QueryBuilder2;
|
32249
32235
|
var init_query_builder3 = __esm({
|
32250
32236
|
"../drizzle-orm/dist/sqlite-core/query-builders/query-builder.js"() {
|
32251
32237
|
"use strict";
|
@@ -32254,7 +32240,7 @@ var init_query_builder3 = __esm({
|
|
32254
32240
|
init_dialect2();
|
32255
32241
|
init_subquery();
|
32256
32242
|
init_select3();
|
32257
|
-
|
32243
|
+
_a204 = entityKind;
|
32258
32244
|
QueryBuilder2 = class {
|
32259
32245
|
constructor(dialect4) {
|
32260
32246
|
__publicField(this, "dialect");
|
@@ -32316,7 +32302,185 @@ var init_query_builder3 = __esm({
|
|
32316
32302
|
return this.dialect;
|
32317
32303
|
}
|
32318
32304
|
};
|
32319
|
-
__publicField(QueryBuilder2,
|
32305
|
+
__publicField(QueryBuilder2, _a204, "SQLiteQueryBuilder");
|
32306
|
+
}
|
32307
|
+
});
|
32308
|
+
|
32309
|
+
// ../drizzle-orm/dist/sqlite-core/query-builders/insert.js
|
32310
|
+
var _a205, SQLiteInsertBuilder, _a206, _b147, SQLiteInsertBase;
|
32311
|
+
var init_insert2 = __esm({
|
32312
|
+
"../drizzle-orm/dist/sqlite-core/query-builders/insert.js"() {
|
32313
|
+
"use strict";
|
32314
|
+
init_entity();
|
32315
|
+
init_query_promise();
|
32316
|
+
init_sql();
|
32317
|
+
init_table3();
|
32318
|
+
init_table();
|
32319
|
+
init_utils2();
|
32320
|
+
init_query_builder3();
|
32321
|
+
_a205 = entityKind;
|
32322
|
+
SQLiteInsertBuilder = class {
|
32323
|
+
constructor(table4, session, dialect4, withList) {
|
32324
|
+
this.table = table4;
|
32325
|
+
this.session = session;
|
32326
|
+
this.dialect = dialect4;
|
32327
|
+
this.withList = withList;
|
32328
|
+
}
|
32329
|
+
values(values) {
|
32330
|
+
values = Array.isArray(values) ? values : [values];
|
32331
|
+
if (values.length === 0) {
|
32332
|
+
throw new Error("values() must be called with at least one value");
|
32333
|
+
}
|
32334
|
+
const mappedValues = values.map((entry) => {
|
32335
|
+
const result = {};
|
32336
|
+
const cols = this.table[Table2.Symbol.Columns];
|
32337
|
+
for (const colKey of Object.keys(entry)) {
|
32338
|
+
const colValue = entry[colKey];
|
32339
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
32340
|
+
}
|
32341
|
+
return result;
|
32342
|
+
});
|
32343
|
+
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
32344
|
+
}
|
32345
|
+
select(selectQuery) {
|
32346
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder2()) : selectQuery;
|
32347
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
32348
|
+
throw new Error(
|
32349
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
32350
|
+
);
|
32351
|
+
}
|
32352
|
+
return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
32353
|
+
}
|
32354
|
+
};
|
32355
|
+
__publicField(SQLiteInsertBuilder, _a205, "SQLiteInsertBuilder");
|
32356
|
+
SQLiteInsertBase = class extends (_b147 = QueryPromise, _a206 = entityKind, _b147) {
|
32357
|
+
constructor(table4, values, session, dialect4, withList, select) {
|
32358
|
+
super();
|
32359
|
+
/** @internal */
|
32360
|
+
__publicField(this, "config");
|
32361
|
+
__publicField(this, "run", (placeholderValues) => {
|
32362
|
+
return this._prepare().run(placeholderValues);
|
32363
|
+
});
|
32364
|
+
__publicField(this, "all", (placeholderValues) => {
|
32365
|
+
return this._prepare().all(placeholderValues);
|
32366
|
+
});
|
32367
|
+
__publicField(this, "get", (placeholderValues) => {
|
32368
|
+
return this._prepare().get(placeholderValues);
|
32369
|
+
});
|
32370
|
+
__publicField(this, "values", (placeholderValues) => {
|
32371
|
+
return this._prepare().values(placeholderValues);
|
32372
|
+
});
|
32373
|
+
this.session = session;
|
32374
|
+
this.dialect = dialect4;
|
32375
|
+
this.config = { table: table4, values, withList, select };
|
32376
|
+
}
|
32377
|
+
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
32378
|
+
this.config.returning = orderSelectedFields(fields);
|
32379
|
+
return this;
|
32380
|
+
}
|
32381
|
+
/**
|
32382
|
+
* Adds an `on conflict do nothing` clause to the query.
|
32383
|
+
*
|
32384
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
32385
|
+
*
|
32386
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
32387
|
+
*
|
32388
|
+
* @param config The `target` and `where` clauses.
|
32389
|
+
*
|
32390
|
+
* @example
|
32391
|
+
* ```ts
|
32392
|
+
* // Insert one row and cancel the insert if there's a conflict
|
32393
|
+
* await db.insert(cars)
|
32394
|
+
* .values({ id: 1, brand: 'BMW' })
|
32395
|
+
* .onConflictDoNothing();
|
32396
|
+
*
|
32397
|
+
* // Explicitly specify conflict target
|
32398
|
+
* await db.insert(cars)
|
32399
|
+
* .values({ id: 1, brand: 'BMW' })
|
32400
|
+
* .onConflictDoNothing({ target: cars.id });
|
32401
|
+
* ```
|
32402
|
+
*/
|
32403
|
+
onConflictDoNothing(config = {}) {
|
32404
|
+
if (config.target === void 0) {
|
32405
|
+
this.config.onConflict = sql`do nothing`;
|
32406
|
+
} else {
|
32407
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
32408
|
+
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
32409
|
+
this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
|
32410
|
+
}
|
32411
|
+
return this;
|
32412
|
+
}
|
32413
|
+
/**
|
32414
|
+
* Adds an `on conflict do update` clause to the query.
|
32415
|
+
*
|
32416
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
32417
|
+
*
|
32418
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
32419
|
+
*
|
32420
|
+
* @param config The `target`, `set` and `where` clauses.
|
32421
|
+
*
|
32422
|
+
* @example
|
32423
|
+
* ```ts
|
32424
|
+
* // Update the row if there's a conflict
|
32425
|
+
* await db.insert(cars)
|
32426
|
+
* .values({ id: 1, brand: 'BMW' })
|
32427
|
+
* .onConflictDoUpdate({
|
32428
|
+
* target: cars.id,
|
32429
|
+
* set: { brand: 'Porsche' }
|
32430
|
+
* });
|
32431
|
+
*
|
32432
|
+
* // Upsert with 'where' clause
|
32433
|
+
* await db.insert(cars)
|
32434
|
+
* .values({ id: 1, brand: 'BMW' })
|
32435
|
+
* .onConflictDoUpdate({
|
32436
|
+
* target: cars.id,
|
32437
|
+
* set: { brand: 'newBMW' },
|
32438
|
+
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
32439
|
+
* });
|
32440
|
+
* ```
|
32441
|
+
*/
|
32442
|
+
onConflictDoUpdate(config) {
|
32443
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
32444
|
+
throw new Error(
|
32445
|
+
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
32446
|
+
);
|
32447
|
+
}
|
32448
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
32449
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
32450
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
32451
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
32452
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
32453
|
+
this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
32454
|
+
return this;
|
32455
|
+
}
|
32456
|
+
/** @internal */
|
32457
|
+
getSQL() {
|
32458
|
+
return this.dialect.buildInsertQuery(this.config);
|
32459
|
+
}
|
32460
|
+
toSQL() {
|
32461
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
32462
|
+
return rest;
|
32463
|
+
}
|
32464
|
+
/** @internal */
|
32465
|
+
_prepare(isOneTimeQuery = true) {
|
32466
|
+
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
32467
|
+
this.dialect.sqlToQuery(this.getSQL()),
|
32468
|
+
this.config.returning,
|
32469
|
+
this.config.returning ? "all" : "run",
|
32470
|
+
true
|
32471
|
+
);
|
32472
|
+
}
|
32473
|
+
prepare() {
|
32474
|
+
return this._prepare(false);
|
32475
|
+
}
|
32476
|
+
async execute() {
|
32477
|
+
return this.config.returning ? this.all() : this.run();
|
32478
|
+
}
|
32479
|
+
$dynamic() {
|
32480
|
+
return this;
|
32481
|
+
}
|
32482
|
+
};
|
32483
|
+
__publicField(SQLiteInsertBase, _a206, "SQLiteInsert");
|
32320
32484
|
}
|
32321
32485
|
});
|
32322
32486
|
|
@@ -32336,8 +32500,11 @@ var init_update2 = __esm({
|
|
32336
32500
|
init_query_promise();
|
32337
32501
|
init_selection_proxy();
|
32338
32502
|
init_table3();
|
32503
|
+
init_subquery();
|
32339
32504
|
init_table();
|
32340
32505
|
init_utils2();
|
32506
|
+
init_view_common();
|
32507
|
+
init_view_base2();
|
32341
32508
|
_a207 = entityKind;
|
32342
32509
|
SQLiteUpdateBuilder = class {
|
32343
32510
|
constructor(table4, session, dialect4, withList) {
|
@@ -32362,6 +32529,10 @@ var init_update2 = __esm({
|
|
32362
32529
|
super();
|
32363
32530
|
/** @internal */
|
32364
32531
|
__publicField(this, "config");
|
32532
|
+
__publicField(this, "leftJoin", this.createJoin("left"));
|
32533
|
+
__publicField(this, "rightJoin", this.createJoin("right"));
|
32534
|
+
__publicField(this, "innerJoin", this.createJoin("inner"));
|
32535
|
+
__publicField(this, "fullJoin", this.createJoin("full"));
|
32365
32536
|
__publicField(this, "run", (placeholderValues) => {
|
32366
32537
|
return this._prepare().run(placeholderValues);
|
32367
32538
|
});
|
@@ -32376,7 +32547,34 @@ var init_update2 = __esm({
|
|
32376
32547
|
});
|
32377
32548
|
this.session = session;
|
32378
32549
|
this.dialect = dialect4;
|
32379
|
-
this.config = { set, table: table4, withList };
|
32550
|
+
this.config = { set, table: table4, withList, joins: [] };
|
32551
|
+
}
|
32552
|
+
from(source) {
|
32553
|
+
this.config.from = source;
|
32554
|
+
return this;
|
32555
|
+
}
|
32556
|
+
createJoin(joinType) {
|
32557
|
+
return (table4, on) => {
|
32558
|
+
const tableName = getTableLikeName(table4);
|
32559
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
32560
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
32561
|
+
}
|
32562
|
+
if (typeof on === "function") {
|
32563
|
+
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;
|
32564
|
+
on = on(
|
32565
|
+
new Proxy(
|
32566
|
+
this.config.table[Table2.Symbol.Columns],
|
32567
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
32568
|
+
),
|
32569
|
+
from && new Proxy(
|
32570
|
+
from,
|
32571
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
32572
|
+
)
|
32573
|
+
);
|
32574
|
+
}
|
32575
|
+
this.config.joins.push({ on, table: table4, joinType, alias: tableName });
|
32576
|
+
return this;
|
32577
|
+
};
|
32380
32578
|
}
|
32381
32579
|
/**
|
32382
32580
|
* Adds a 'where' clause to the query.
|
@@ -35674,131 +35872,6 @@ var init_delete3 = __esm({
|
|
35674
35872
|
}
|
35675
35873
|
});
|
35676
35874
|
|
35677
|
-
// ../drizzle-orm/dist/mysql-core/query-builders/insert.js
|
35678
|
-
var _a299, MySqlInsertBuilder, _a300, _b222, MySqlInsertBase;
|
35679
|
-
var init_insert3 = __esm({
|
35680
|
-
"../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
|
35681
|
-
"use strict";
|
35682
|
-
init_entity();
|
35683
|
-
init_query_promise();
|
35684
|
-
init_sql();
|
35685
|
-
init_table();
|
35686
|
-
init_utils2();
|
35687
|
-
_a299 = entityKind;
|
35688
|
-
MySqlInsertBuilder = class {
|
35689
|
-
constructor(table4, session, dialect4) {
|
35690
|
-
__publicField(this, "shouldIgnore", false);
|
35691
|
-
this.table = table4;
|
35692
|
-
this.session = session;
|
35693
|
-
this.dialect = dialect4;
|
35694
|
-
}
|
35695
|
-
ignore() {
|
35696
|
-
this.shouldIgnore = true;
|
35697
|
-
return this;
|
35698
|
-
}
|
35699
|
-
values(values) {
|
35700
|
-
values = Array.isArray(values) ? values : [values];
|
35701
|
-
if (values.length === 0) {
|
35702
|
-
throw new Error("values() must be called with at least one value");
|
35703
|
-
}
|
35704
|
-
const mappedValues = values.map((entry) => {
|
35705
|
-
const result = {};
|
35706
|
-
const cols = this.table[Table2.Symbol.Columns];
|
35707
|
-
for (const colKey of Object.keys(entry)) {
|
35708
|
-
const colValue = entry[colKey];
|
35709
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
35710
|
-
}
|
35711
|
-
return result;
|
35712
|
-
});
|
35713
|
-
return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
|
35714
|
-
}
|
35715
|
-
};
|
35716
|
-
__publicField(MySqlInsertBuilder, _a299, "MySqlInsertBuilder");
|
35717
|
-
MySqlInsertBase = class extends (_b222 = QueryPromise, _a300 = entityKind, _b222) {
|
35718
|
-
constructor(table4, values, ignore, session, dialect4) {
|
35719
|
-
super();
|
35720
|
-
__publicField(this, "config");
|
35721
|
-
__publicField(this, "execute", (placeholderValues) => {
|
35722
|
-
return this.prepare().execute(placeholderValues);
|
35723
|
-
});
|
35724
|
-
__publicField(this, "createIterator", () => {
|
35725
|
-
const self2 = this;
|
35726
|
-
return async function* (placeholderValues) {
|
35727
|
-
yield* self2.prepare().iterator(placeholderValues);
|
35728
|
-
};
|
35729
|
-
});
|
35730
|
-
__publicField(this, "iterator", this.createIterator());
|
35731
|
-
this.session = session;
|
35732
|
-
this.dialect = dialect4;
|
35733
|
-
this.config = { table: table4, values, ignore };
|
35734
|
-
}
|
35735
|
-
/**
|
35736
|
-
* Adds an `on duplicate key update` clause to the query.
|
35737
|
-
*
|
35738
|
-
* Calling this method will update update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.
|
35739
|
-
*
|
35740
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
|
35741
|
-
*
|
35742
|
-
* @param config The `set` clause
|
35743
|
-
*
|
35744
|
-
* @example
|
35745
|
-
* ```ts
|
35746
|
-
* await db.insert(cars)
|
35747
|
-
* .values({ id: 1, brand: 'BMW'})
|
35748
|
-
* .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
|
35749
|
-
* ```
|
35750
|
-
*
|
35751
|
-
* 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:
|
35752
|
-
*
|
35753
|
-
* ```ts
|
35754
|
-
* import { sql } from 'drizzle-orm';
|
35755
|
-
*
|
35756
|
-
* await db.insert(cars)
|
35757
|
-
* .values({ id: 1, brand: 'BMW' })
|
35758
|
-
* .onDuplicateKeyUpdate({ set: { id: sql`id` } });
|
35759
|
-
* ```
|
35760
|
-
*/
|
35761
|
-
onDuplicateKeyUpdate(config) {
|
35762
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
35763
|
-
this.config.onConflict = sql`update ${setSql}`;
|
35764
|
-
return this;
|
35765
|
-
}
|
35766
|
-
$returningId() {
|
35767
|
-
const returning = [];
|
35768
|
-
for (const [key, value] of Object.entries(this.config.table[Table2.Symbol.Columns])) {
|
35769
|
-
if (value.primary) {
|
35770
|
-
returning.push({ field: value, path: [key] });
|
35771
|
-
}
|
35772
|
-
}
|
35773
|
-
this.config.returning = orderSelectedFields(this.config.table[Table2.Symbol.Columns]);
|
35774
|
-
return this;
|
35775
|
-
}
|
35776
|
-
/** @internal */
|
35777
|
-
getSQL() {
|
35778
|
-
return this.dialect.buildInsertQuery(this.config).sql;
|
35779
|
-
}
|
35780
|
-
toSQL() {
|
35781
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
35782
|
-
return rest;
|
35783
|
-
}
|
35784
|
-
prepare() {
|
35785
|
-
const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
|
35786
|
-
return this.session.prepareQuery(
|
35787
|
-
this.dialect.sqlToQuery(sql2),
|
35788
|
-
void 0,
|
35789
|
-
void 0,
|
35790
|
-
generatedIds,
|
35791
|
-
this.config.returning
|
35792
|
-
);
|
35793
|
-
}
|
35794
|
-
$dynamic() {
|
35795
|
-
return this;
|
35796
|
-
}
|
35797
|
-
};
|
35798
|
-
__publicField(MySqlInsertBase, _a300, "MySqlInsert");
|
35799
|
-
}
|
35800
|
-
});
|
35801
|
-
|
35802
35875
|
// ../drizzle-orm/dist/mysql-core/columns/all.js
|
35803
35876
|
function getMySqlColumnBuilders() {
|
35804
35877
|
return {
|
@@ -35879,7 +35952,7 @@ function mysqlTableWithSchema(name2, columns, extraConfig, schema4, baseName = n
|
|
35879
35952
|
}
|
35880
35953
|
return table4;
|
35881
35954
|
}
|
35882
|
-
var InlineForeignKeys3,
|
35955
|
+
var InlineForeignKeys3, _a299, _b222, _c9, _d4, _e4, MySqlTable, mysqlTable;
|
35883
35956
|
var init_table4 = __esm({
|
35884
35957
|
"../drizzle-orm/dist/mysql-core/table.js"() {
|
35885
35958
|
"use strict";
|
@@ -35887,15 +35960,15 @@ var init_table4 = __esm({
|
|
35887
35960
|
init_table();
|
35888
35961
|
init_all3();
|
35889
35962
|
InlineForeignKeys3 = Symbol.for("drizzle:MySqlInlineForeignKeys");
|
35890
|
-
MySqlTable = class extends (_e4 = Table2, _d4 = entityKind, _c9 = Table2.Symbol.Columns,
|
35963
|
+
MySqlTable = class extends (_e4 = Table2, _d4 = entityKind, _c9 = Table2.Symbol.Columns, _b222 = InlineForeignKeys3, _a299 = Table2.Symbol.ExtraConfigBuilder, _e4) {
|
35891
35964
|
constructor() {
|
35892
35965
|
super(...arguments);
|
35893
35966
|
/** @internal */
|
35894
35967
|
__publicField(this, _c9);
|
35895
35968
|
/** @internal */
|
35896
|
-
__publicField(this,
|
35969
|
+
__publicField(this, _b222, []);
|
35897
35970
|
/** @internal */
|
35898
|
-
__publicField(this,
|
35971
|
+
__publicField(this, _a299);
|
35899
35972
|
}
|
35900
35973
|
};
|
35901
35974
|
__publicField(MySqlTable, _d4, "MySqlTable");
|
@@ -35910,20 +35983,20 @@ var init_table4 = __esm({
|
|
35910
35983
|
});
|
35911
35984
|
|
35912
35985
|
// ../drizzle-orm/dist/mysql-core/view-base.js
|
35913
|
-
var
|
35986
|
+
var _a300, _b223, MySqlViewBase;
|
35914
35987
|
var init_view_base3 = __esm({
|
35915
35988
|
"../drizzle-orm/dist/mysql-core/view-base.js"() {
|
35916
35989
|
"use strict";
|
35917
35990
|
init_entity();
|
35918
35991
|
init_sql();
|
35919
|
-
MySqlViewBase = class extends (
|
35992
|
+
MySqlViewBase = class extends (_b223 = View3, _a300 = entityKind, _b223) {
|
35920
35993
|
};
|
35921
|
-
__publicField(MySqlViewBase,
|
35994
|
+
__publicField(MySqlViewBase, _a300, "MySqlViewBase");
|
35922
35995
|
}
|
35923
35996
|
});
|
35924
35997
|
|
35925
35998
|
// ../drizzle-orm/dist/mysql-core/dialect.js
|
35926
|
-
var
|
35999
|
+
var _a301, MySqlDialect;
|
35927
36000
|
var init_dialect3 = __esm({
|
35928
36001
|
"../drizzle-orm/dist/mysql-core/dialect.js"() {
|
35929
36002
|
"use strict";
|
@@ -35942,7 +36015,7 @@ var init_dialect3 = __esm({
|
|
35942
36015
|
init_common4();
|
35943
36016
|
init_table4();
|
35944
36017
|
init_view_base3();
|
35945
|
-
|
36018
|
+
_a301 = entityKind;
|
35946
36019
|
MySqlDialect = class {
|
35947
36020
|
constructor(config) {
|
35948
36021
|
/** @internal */
|
@@ -36225,7 +36298,7 @@ var init_dialect3 = __esm({
|
|
36225
36298
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
36226
36299
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
36227
36300
|
}
|
36228
|
-
buildInsertQuery({ table: table4, values, ignore, onConflict }) {
|
36301
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, ignore, onConflict, select }) {
|
36229
36302
|
const valuesSqlList = [];
|
36230
36303
|
const columns = table4[Table2.Symbol.Columns];
|
36231
36304
|
const colEntries = Object.entries(columns).filter(
|
@@ -36233,42 +36306,53 @@ var init_dialect3 = __esm({
|
|
36233
36306
|
);
|
36234
36307
|
const insertOrder = colEntries.map(([, column4]) => sql.identifier(this.casing.getColumnCasing(column4)));
|
36235
36308
|
const generatedIdsResponse = [];
|
36236
|
-
|
36237
|
-
const
|
36238
|
-
|
36239
|
-
|
36240
|
-
|
36241
|
-
|
36242
|
-
|
36243
|
-
|
36244
|
-
|
36245
|
-
|
36246
|
-
|
36247
|
-
|
36248
|
-
|
36249
|
-
|
36250
|
-
|
36309
|
+
if (select) {
|
36310
|
+
const select2 = valuesOrSelect;
|
36311
|
+
if (is(select2, SQL)) {
|
36312
|
+
valuesSqlList.push(select2);
|
36313
|
+
} else {
|
36314
|
+
valuesSqlList.push(select2.getSQL());
|
36315
|
+
}
|
36316
|
+
} else {
|
36317
|
+
const values = valuesOrSelect;
|
36318
|
+
valuesSqlList.push(sql.raw("values "));
|
36319
|
+
for (const [valueIndex, value] of values.entries()) {
|
36320
|
+
const generatedIds = {};
|
36321
|
+
const valueList = [];
|
36322
|
+
for (const [fieldName, col] of colEntries) {
|
36323
|
+
const colValue = value[fieldName];
|
36324
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
36325
|
+
if (col.defaultFn !== void 0) {
|
36326
|
+
const defaultFnResult = col.defaultFn();
|
36327
|
+
generatedIds[fieldName] = defaultFnResult;
|
36328
|
+
const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
36329
|
+
valueList.push(defaultValue);
|
36330
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
36331
|
+
const onUpdateFnResult = col.onUpdateFn();
|
36332
|
+
const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
36333
|
+
valueList.push(newValue);
|
36334
|
+
} else {
|
36335
|
+
valueList.push(sql`default`);
|
36336
|
+
}
|
36251
36337
|
} else {
|
36252
|
-
|
36253
|
-
|
36254
|
-
|
36255
|
-
|
36256
|
-
generatedIds[fieldName] = colValue.value;
|
36338
|
+
if (col.defaultFn && is(colValue, Param)) {
|
36339
|
+
generatedIds[fieldName] = colValue.value;
|
36340
|
+
}
|
36341
|
+
valueList.push(colValue);
|
36257
36342
|
}
|
36258
|
-
valueList.push(colValue);
|
36259
36343
|
}
|
36260
|
-
|
36261
|
-
|
36262
|
-
|
36263
|
-
|
36264
|
-
|
36344
|
+
generatedIdsResponse.push(generatedIds);
|
36345
|
+
valuesSqlList.push(valueList);
|
36346
|
+
if (valueIndex < values.length - 1) {
|
36347
|
+
valuesSqlList.push(sql`, `);
|
36348
|
+
}
|
36265
36349
|
}
|
36266
36350
|
}
|
36267
36351
|
const valuesSql = sql.join(valuesSqlList);
|
36268
36352
|
const ignoreSql = ignore ? sql` ignore` : void 0;
|
36269
36353
|
const onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : void 0;
|
36270
36354
|
return {
|
36271
|
-
sql: sql`insert${ignoreSql} into ${table4} ${insertOrder}
|
36355
|
+
sql: sql`insert${ignoreSql} into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}`,
|
36272
36356
|
generatedIds: generatedIdsResponse
|
36273
36357
|
};
|
36274
36358
|
}
|
@@ -36728,7 +36812,7 @@ var init_dialect3 = __esm({
|
|
36728
36812
|
};
|
36729
36813
|
}
|
36730
36814
|
};
|
36731
|
-
__publicField(MySqlDialect,
|
36815
|
+
__publicField(MySqlDialect, _a301, "MySqlDialect");
|
36732
36816
|
}
|
36733
36817
|
});
|
36734
36818
|
|
@@ -36750,7 +36834,7 @@ function createSetOperator3(type, isAll) {
|
|
36750
36834
|
return leftSelect.addSetOperators(setOperators);
|
36751
36835
|
};
|
36752
36836
|
}
|
36753
|
-
var
|
36837
|
+
var _a302, MySqlSelectBuilder, _a303, _b224, MySqlSelectQueryBuilderBase, _a304, _b225, MySqlSelectBase, getMySqlSetOperators, union3, unionAll3, intersect3, intersectAll2, except3, exceptAll2;
|
36754
36838
|
var init_select4 = __esm({
|
36755
36839
|
"../drizzle-orm/dist/mysql-core/query-builders/select.js"() {
|
36756
36840
|
"use strict";
|
@@ -36765,7 +36849,7 @@ var init_select4 = __esm({
|
|
36765
36849
|
init_utils2();
|
36766
36850
|
init_view_common();
|
36767
36851
|
init_view_base3();
|
36768
|
-
|
36852
|
+
_a302 = entityKind;
|
36769
36853
|
MySqlSelectBuilder = class {
|
36770
36854
|
constructor(config) {
|
36771
36855
|
__publicField(this, "fields");
|
@@ -36810,8 +36894,8 @@ var init_select4 = __esm({
|
|
36810
36894
|
);
|
36811
36895
|
}
|
36812
36896
|
};
|
36813
|
-
__publicField(MySqlSelectBuilder,
|
36814
|
-
MySqlSelectQueryBuilderBase = class extends (
|
36897
|
+
__publicField(MySqlSelectBuilder, _a302, "MySqlSelectBuilder");
|
36898
|
+
MySqlSelectQueryBuilderBase = class extends (_b224 = TypedQueryBuilder, _a303 = entityKind, _b224) {
|
36815
36899
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
36816
36900
|
super();
|
36817
36901
|
__publicField(this, "_");
|
@@ -37412,8 +37496,8 @@ var init_select4 = __esm({
|
|
37412
37496
|
return this;
|
37413
37497
|
}
|
37414
37498
|
};
|
37415
|
-
__publicField(MySqlSelectQueryBuilderBase,
|
37416
|
-
MySqlSelectBase = class extends (
|
37499
|
+
__publicField(MySqlSelectQueryBuilderBase, _a303, "MySqlSelectQueryBuilder");
|
37500
|
+
MySqlSelectBase = class extends (_b225 = MySqlSelectQueryBuilderBase, _a304 = entityKind, _b225) {
|
37417
37501
|
constructor() {
|
37418
37502
|
super(...arguments);
|
37419
37503
|
__publicField(this, "execute", (placeholderValues) => {
|
@@ -37437,7 +37521,7 @@ var init_select4 = __esm({
|
|
37437
37521
|
return query;
|
37438
37522
|
}
|
37439
37523
|
};
|
37440
|
-
__publicField(MySqlSelectBase,
|
37524
|
+
__publicField(MySqlSelectBase, _a304, "MySqlSelect");
|
37441
37525
|
applyMixins(MySqlSelectBase, [QueryPromise]);
|
37442
37526
|
getMySqlSetOperators = () => ({
|
37443
37527
|
union: union3,
|
@@ -37457,7 +37541,7 @@ var init_select4 = __esm({
|
|
37457
37541
|
});
|
37458
37542
|
|
37459
37543
|
// ../drizzle-orm/dist/mysql-core/query-builders/query-builder.js
|
37460
|
-
var
|
37544
|
+
var _a305, QueryBuilder3;
|
37461
37545
|
var init_query_builder4 = __esm({
|
37462
37546
|
"../drizzle-orm/dist/mysql-core/query-builders/query-builder.js"() {
|
37463
37547
|
"use strict";
|
@@ -37466,7 +37550,7 @@ var init_query_builder4 = __esm({
|
|
37466
37550
|
init_selection_proxy();
|
37467
37551
|
init_subquery();
|
37468
37552
|
init_select4();
|
37469
|
-
|
37553
|
+
_a305 = entityKind;
|
37470
37554
|
QueryBuilder3 = class {
|
37471
37555
|
constructor(dialect4) {
|
37472
37556
|
__publicField(this, "dialect");
|
@@ -37528,7 +37612,142 @@ var init_query_builder4 = __esm({
|
|
37528
37612
|
return this.dialect;
|
37529
37613
|
}
|
37530
37614
|
};
|
37531
|
-
__publicField(QueryBuilder3,
|
37615
|
+
__publicField(QueryBuilder3, _a305, "MySqlQueryBuilder");
|
37616
|
+
}
|
37617
|
+
});
|
37618
|
+
|
37619
|
+
// ../drizzle-orm/dist/mysql-core/query-builders/insert.js
|
37620
|
+
var _a306, MySqlInsertBuilder, _a307, _b226, MySqlInsertBase;
|
37621
|
+
var init_insert3 = __esm({
|
37622
|
+
"../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
|
37623
|
+
"use strict";
|
37624
|
+
init_entity();
|
37625
|
+
init_query_promise();
|
37626
|
+
init_sql();
|
37627
|
+
init_table();
|
37628
|
+
init_utils2();
|
37629
|
+
init_query_builder4();
|
37630
|
+
_a306 = entityKind;
|
37631
|
+
MySqlInsertBuilder = class {
|
37632
|
+
constructor(table4, session, dialect4) {
|
37633
|
+
__publicField(this, "shouldIgnore", false);
|
37634
|
+
this.table = table4;
|
37635
|
+
this.session = session;
|
37636
|
+
this.dialect = dialect4;
|
37637
|
+
}
|
37638
|
+
ignore() {
|
37639
|
+
this.shouldIgnore = true;
|
37640
|
+
return this;
|
37641
|
+
}
|
37642
|
+
values(values) {
|
37643
|
+
values = Array.isArray(values) ? values : [values];
|
37644
|
+
if (values.length === 0) {
|
37645
|
+
throw new Error("values() must be called with at least one value");
|
37646
|
+
}
|
37647
|
+
const mappedValues = values.map((entry) => {
|
37648
|
+
const result = {};
|
37649
|
+
const cols = this.table[Table2.Symbol.Columns];
|
37650
|
+
for (const colKey of Object.keys(entry)) {
|
37651
|
+
const colValue = entry[colKey];
|
37652
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
37653
|
+
}
|
37654
|
+
return result;
|
37655
|
+
});
|
37656
|
+
return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
|
37657
|
+
}
|
37658
|
+
select(selectQuery) {
|
37659
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder3()) : selectQuery;
|
37660
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
37661
|
+
throw new Error(
|
37662
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
37663
|
+
);
|
37664
|
+
}
|
37665
|
+
return new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);
|
37666
|
+
}
|
37667
|
+
};
|
37668
|
+
__publicField(MySqlInsertBuilder, _a306, "MySqlInsertBuilder");
|
37669
|
+
MySqlInsertBase = class extends (_b226 = QueryPromise, _a307 = entityKind, _b226) {
|
37670
|
+
constructor(table4, values, ignore, session, dialect4, select) {
|
37671
|
+
super();
|
37672
|
+
__publicField(this, "config");
|
37673
|
+
__publicField(this, "execute", (placeholderValues) => {
|
37674
|
+
return this.prepare().execute(placeholderValues);
|
37675
|
+
});
|
37676
|
+
__publicField(this, "createIterator", () => {
|
37677
|
+
const self2 = this;
|
37678
|
+
return async function* (placeholderValues) {
|
37679
|
+
yield* self2.prepare().iterator(placeholderValues);
|
37680
|
+
};
|
37681
|
+
});
|
37682
|
+
__publicField(this, "iterator", this.createIterator());
|
37683
|
+
this.session = session;
|
37684
|
+
this.dialect = dialect4;
|
37685
|
+
this.config = { table: table4, values, select, ignore };
|
37686
|
+
}
|
37687
|
+
/**
|
37688
|
+
* Adds an `on duplicate key update` clause to the query.
|
37689
|
+
*
|
37690
|
+
* 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.
|
37691
|
+
*
|
37692
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
|
37693
|
+
*
|
37694
|
+
* @param config The `set` clause
|
37695
|
+
*
|
37696
|
+
* @example
|
37697
|
+
* ```ts
|
37698
|
+
* await db.insert(cars)
|
37699
|
+
* .values({ id: 1, brand: 'BMW'})
|
37700
|
+
* .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
|
37701
|
+
* ```
|
37702
|
+
*
|
37703
|
+
* 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:
|
37704
|
+
*
|
37705
|
+
* ```ts
|
37706
|
+
* import { sql } from 'drizzle-orm';
|
37707
|
+
*
|
37708
|
+
* await db.insert(cars)
|
37709
|
+
* .values({ id: 1, brand: 'BMW' })
|
37710
|
+
* .onDuplicateKeyUpdate({ set: { id: sql`id` } });
|
37711
|
+
* ```
|
37712
|
+
*/
|
37713
|
+
onDuplicateKeyUpdate(config) {
|
37714
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
37715
|
+
this.config.onConflict = sql`update ${setSql}`;
|
37716
|
+
return this;
|
37717
|
+
}
|
37718
|
+
$returningId() {
|
37719
|
+
const returning = [];
|
37720
|
+
for (const [key, value] of Object.entries(this.config.table[Table2.Symbol.Columns])) {
|
37721
|
+
if (value.primary) {
|
37722
|
+
returning.push({ field: value, path: [key] });
|
37723
|
+
}
|
37724
|
+
}
|
37725
|
+
this.config.returning = returning;
|
37726
|
+
return this;
|
37727
|
+
}
|
37728
|
+
/** @internal */
|
37729
|
+
getSQL() {
|
37730
|
+
return this.dialect.buildInsertQuery(this.config).sql;
|
37731
|
+
}
|
37732
|
+
toSQL() {
|
37733
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
37734
|
+
return rest;
|
37735
|
+
}
|
37736
|
+
prepare() {
|
37737
|
+
const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
|
37738
|
+
return this.session.prepareQuery(
|
37739
|
+
this.dialect.sqlToQuery(sql2),
|
37740
|
+
void 0,
|
37741
|
+
void 0,
|
37742
|
+
generatedIds,
|
37743
|
+
this.config.returning
|
37744
|
+
);
|
37745
|
+
}
|
37746
|
+
$dynamic() {
|
37747
|
+
return this;
|
37748
|
+
}
|
37749
|
+
};
|
37750
|
+
__publicField(MySqlInsertBase, _a307, "MySqlInsert");
|
37532
37751
|
}
|
37533
37752
|
});
|
37534
37753
|
|