drizzle-kit 0.28.0 → 0.28.1-08d2486
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 +1015 -714
- package/api.mjs +1015 -714
- package/bin.cjs +680 -85
- package/package.json +1 -1
package/api.mjs
CHANGED
@@ -21126,7 +21126,7 @@ var version;
|
|
21126
21126
|
var init_version = __esm({
|
21127
21127
|
"../drizzle-orm/dist/version.js"() {
|
21128
21128
|
"use strict";
|
21129
|
-
version = "0.36.
|
21129
|
+
version = "0.36.4";
|
21130
21130
|
}
|
21131
21131
|
});
|
21132
21132
|
|
@@ -21412,7 +21412,11 @@ var init_sql = __esm({
|
|
21412
21412
|
if (_config.invokeSource === "indexes") {
|
21413
21413
|
return { sql: escapeName(columnName), params: [] };
|
21414
21414
|
}
|
21415
|
-
|
21415
|
+
const schemaName = chunk.table[Table2.Symbol.Schema];
|
21416
|
+
return {
|
21417
|
+
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),
|
21418
|
+
params: []
|
21419
|
+
};
|
21416
21420
|
}
|
21417
21421
|
if (is(chunk, View3)) {
|
21418
21422
|
const schemaName = chunk[ViewBaseConfig].schema;
|
@@ -22145,7 +22149,7 @@ function haveSameKeys(left, right) {
|
|
22145
22149
|
}
|
22146
22150
|
function mapUpdateSet(table4, values) {
|
22147
22151
|
const entries = Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => {
|
22148
|
-
if (is(value, SQL)) {
|
22152
|
+
if (is(value, SQL) || is(value, Column2)) {
|
22149
22153
|
return [key, value];
|
22150
22154
|
} else {
|
22151
22155
|
return [key, new Param(value, table4[Table2.Symbol.Columns][key])];
|
@@ -24584,9 +24588,10 @@ var init_delete = __esm({
|
|
24584
24588
|
constructor(table4, session, dialect4, withList) {
|
24585
24589
|
super();
|
24586
24590
|
__publicField(this, "config");
|
24591
|
+
__publicField(this, "authToken");
|
24587
24592
|
__publicField(this, "execute", (placeholderValues) => {
|
24588
24593
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
24589
|
-
return this._prepare().execute(placeholderValues);
|
24594
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
24590
24595
|
});
|
24591
24596
|
});
|
24592
24597
|
this.session = session;
|
@@ -24647,167 +24652,16 @@ var init_delete = __esm({
|
|
24647
24652
|
prepare(name2) {
|
24648
24653
|
return this._prepare(name2);
|
24649
24654
|
}
|
24650
|
-
$dynamic() {
|
24651
|
-
return this;
|
24652
|
-
}
|
24653
|
-
};
|
24654
|
-
__publicField(PgDeleteBase, _a124, "PgDelete");
|
24655
|
-
}
|
24656
|
-
});
|
24657
|
-
|
24658
|
-
// ../drizzle-orm/dist/pg-core/query-builders/insert.js
|
24659
|
-
var _a125, PgInsertBuilder, _a126, _b98, PgInsertBase;
|
24660
|
-
var init_insert = __esm({
|
24661
|
-
"../drizzle-orm/dist/pg-core/query-builders/insert.js"() {
|
24662
|
-
"use strict";
|
24663
|
-
init_entity();
|
24664
|
-
init_query_promise();
|
24665
|
-
init_sql();
|
24666
|
-
init_table();
|
24667
|
-
init_tracing();
|
24668
|
-
init_utils2();
|
24669
|
-
_a125 = entityKind;
|
24670
|
-
PgInsertBuilder = class {
|
24671
|
-
constructor(table4, session, dialect4, withList) {
|
24672
|
-
this.table = table4;
|
24673
|
-
this.session = session;
|
24674
|
-
this.dialect = dialect4;
|
24675
|
-
this.withList = withList;
|
24676
|
-
}
|
24677
|
-
values(values) {
|
24678
|
-
values = Array.isArray(values) ? values : [values];
|
24679
|
-
if (values.length === 0) {
|
24680
|
-
throw new Error("values() must be called with at least one value");
|
24681
|
-
}
|
24682
|
-
const mappedValues = values.map((entry) => {
|
24683
|
-
const result = {};
|
24684
|
-
const cols = this.table[Table2.Symbol.Columns];
|
24685
|
-
for (const colKey of Object.keys(entry)) {
|
24686
|
-
const colValue = entry[colKey];
|
24687
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
24688
|
-
}
|
24689
|
-
return result;
|
24690
|
-
});
|
24691
|
-
return new PgInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
24692
|
-
}
|
24693
|
-
};
|
24694
|
-
__publicField(PgInsertBuilder, _a125, "PgInsertBuilder");
|
24695
|
-
PgInsertBase = class extends (_b98 = QueryPromise, _a126 = entityKind, _b98) {
|
24696
|
-
constructor(table4, values, session, dialect4, withList) {
|
24697
|
-
super();
|
24698
|
-
__publicField(this, "config");
|
24699
|
-
__publicField(this, "execute", (placeholderValues) => {
|
24700
|
-
return tracer.startActiveSpan("drizzle.operation", () => {
|
24701
|
-
return this._prepare().execute(placeholderValues);
|
24702
|
-
});
|
24703
|
-
});
|
24704
|
-
this.session = session;
|
24705
|
-
this.dialect = dialect4;
|
24706
|
-
this.config = { table: table4, values, withList };
|
24707
|
-
}
|
24708
|
-
returning(fields = this.config.table[Table2.Symbol.Columns]) {
|
24709
|
-
this.config.returning = orderSelectedFields(fields);
|
24710
|
-
return this;
|
24711
|
-
}
|
24712
|
-
/**
|
24713
|
-
* Adds an `on conflict do nothing` clause to the query.
|
24714
|
-
*
|
24715
|
-
* Calling this method simply avoids inserting a row as its alternative action.
|
24716
|
-
*
|
24717
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
24718
|
-
*
|
24719
|
-
* @param config The `target` and `where` clauses.
|
24720
|
-
*
|
24721
|
-
* @example
|
24722
|
-
* ```ts
|
24723
|
-
* // Insert one row and cancel the insert if there's a conflict
|
24724
|
-
* await db.insert(cars)
|
24725
|
-
* .values({ id: 1, brand: 'BMW' })
|
24726
|
-
* .onConflictDoNothing();
|
24727
|
-
*
|
24728
|
-
* // Explicitly specify conflict target
|
24729
|
-
* await db.insert(cars)
|
24730
|
-
* .values({ id: 1, brand: 'BMW' })
|
24731
|
-
* .onConflictDoNothing({ target: cars.id });
|
24732
|
-
* ```
|
24733
|
-
*/
|
24734
|
-
onConflictDoNothing(config = {}) {
|
24735
|
-
if (config.target === void 0) {
|
24736
|
-
this.config.onConflict = sql`do nothing`;
|
24737
|
-
} else {
|
24738
|
-
let targetColumn = "";
|
24739
|
-
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));
|
24740
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
24741
|
-
this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
|
24742
|
-
}
|
24743
|
-
return this;
|
24744
|
-
}
|
24745
|
-
/**
|
24746
|
-
* Adds an `on conflict do update` clause to the query.
|
24747
|
-
*
|
24748
|
-
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
24749
|
-
*
|
24750
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
24751
|
-
*
|
24752
|
-
* @param config The `target`, `set` and `where` clauses.
|
24753
|
-
*
|
24754
|
-
* @example
|
24755
|
-
* ```ts
|
24756
|
-
* // Update the row if there's a conflict
|
24757
|
-
* await db.insert(cars)
|
24758
|
-
* .values({ id: 1, brand: 'BMW' })
|
24759
|
-
* .onConflictDoUpdate({
|
24760
|
-
* target: cars.id,
|
24761
|
-
* set: { brand: 'Porsche' }
|
24762
|
-
* });
|
24763
|
-
*
|
24764
|
-
* // Upsert with 'where' clause
|
24765
|
-
* await db.insert(cars)
|
24766
|
-
* .values({ id: 1, brand: 'BMW' })
|
24767
|
-
* .onConflictDoUpdate({
|
24768
|
-
* target: cars.id,
|
24769
|
-
* set: { brand: 'newBMW' },
|
24770
|
-
* targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
|
24771
|
-
* });
|
24772
|
-
* ```
|
24773
|
-
*/
|
24774
|
-
onConflictDoUpdate(config) {
|
24775
|
-
if (config.where && (config.targetWhere || config.setWhere)) {
|
24776
|
-
throw new Error(
|
24777
|
-
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
24778
|
-
);
|
24779
|
-
}
|
24780
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
24781
|
-
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
24782
|
-
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
24783
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
24784
|
-
let targetColumn = "";
|
24785
|
-
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));
|
24786
|
-
this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
24787
|
-
return this;
|
24788
|
-
}
|
24789
|
-
/** @internal */
|
24790
|
-
getSQL() {
|
24791
|
-
return this.dialect.buildInsertQuery(this.config);
|
24792
|
-
}
|
24793
|
-
toSQL() {
|
24794
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
24795
|
-
return rest;
|
24796
|
-
}
|
24797
24655
|
/** @internal */
|
24798
|
-
|
24799
|
-
|
24800
|
-
|
24801
|
-
});
|
24802
|
-
}
|
24803
|
-
prepare(name2) {
|
24804
|
-
return this._prepare(name2);
|
24656
|
+
setToken(token) {
|
24657
|
+
this.authToken = token;
|
24658
|
+
return this;
|
24805
24659
|
}
|
24806
24660
|
$dynamic() {
|
24807
24661
|
return this;
|
24808
24662
|
}
|
24809
24663
|
};
|
24810
|
-
__publicField(
|
24664
|
+
__publicField(PgDeleteBase, _a124, "PgDelete");
|
24811
24665
|
}
|
24812
24666
|
});
|
24813
24667
|
|
@@ -24826,13 +24680,13 @@ function toCamelCase(input) {
|
|
24826
24680
|
function noopCase(input) {
|
24827
24681
|
return input;
|
24828
24682
|
}
|
24829
|
-
var
|
24683
|
+
var _a125, CasingCache;
|
24830
24684
|
var init_casing = __esm({
|
24831
24685
|
"../drizzle-orm/dist/casing.js"() {
|
24832
24686
|
"use strict";
|
24833
24687
|
init_entity();
|
24834
24688
|
init_table();
|
24835
|
-
|
24689
|
+
_a125 = entityKind;
|
24836
24690
|
CasingCache = class {
|
24837
24691
|
constructor(casing2) {
|
24838
24692
|
/** @internal */
|
@@ -24869,25 +24723,25 @@ var init_casing = __esm({
|
|
24869
24723
|
this.cachedTables = {};
|
24870
24724
|
}
|
24871
24725
|
};
|
24872
|
-
__publicField(CasingCache,
|
24726
|
+
__publicField(CasingCache, _a125, "CasingCache");
|
24873
24727
|
}
|
24874
24728
|
});
|
24875
24729
|
|
24876
24730
|
// ../drizzle-orm/dist/pg-core/view-base.js
|
24877
|
-
var
|
24731
|
+
var _a126, _b98, PgViewBase;
|
24878
24732
|
var init_view_base = __esm({
|
24879
24733
|
"../drizzle-orm/dist/pg-core/view-base.js"() {
|
24880
24734
|
"use strict";
|
24881
24735
|
init_entity();
|
24882
24736
|
init_sql();
|
24883
|
-
PgViewBase = class extends (
|
24737
|
+
PgViewBase = class extends (_b98 = View3, _a126 = entityKind, _b98) {
|
24884
24738
|
};
|
24885
|
-
__publicField(PgViewBase,
|
24739
|
+
__publicField(PgViewBase, _a126, "PgViewBase");
|
24886
24740
|
}
|
24887
24741
|
});
|
24888
24742
|
|
24889
24743
|
// ../drizzle-orm/dist/pg-core/dialect.js
|
24890
|
-
var
|
24744
|
+
var _a127, PgDialect;
|
24891
24745
|
var init_dialect = __esm({
|
24892
24746
|
"../drizzle-orm/dist/pg-core/dialect.js"() {
|
24893
24747
|
"use strict";
|
@@ -24906,7 +24760,7 @@ var init_dialect = __esm({
|
|
24906
24760
|
init_utils2();
|
24907
24761
|
init_view_common();
|
24908
24762
|
init_view_base();
|
24909
|
-
|
24763
|
+
_a127 = entityKind;
|
24910
24764
|
PgDialect = class {
|
24911
24765
|
constructor(config) {
|
24912
24766
|
/** @internal */
|
@@ -24986,12 +24840,19 @@ var init_dialect = __esm({
|
|
24986
24840
|
return [res];
|
24987
24841
|
}));
|
24988
24842
|
}
|
24989
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList }) {
|
24843
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, from, joins }) {
|
24990
24844
|
const withSql = this.buildWithCTE(withList);
|
24845
|
+
const tableName = table4[PgTable.Symbol.Name];
|
24846
|
+
const tableSchema = table4[PgTable.Symbol.Schema];
|
24847
|
+
const origTableName = table4[PgTable.Symbol.OriginalName];
|
24848
|
+
const alias = tableName === origTableName ? void 0 : tableName;
|
24849
|
+
const tableSql = sql`${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}`;
|
24991
24850
|
const setSql = this.buildUpdateSet(table4, set);
|
24992
|
-
const
|
24851
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
24852
|
+
const joinsSql = this.buildJoins(joins);
|
24853
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: !from })}` : void 0;
|
24993
24854
|
const whereSql = where ? sql` where ${where}` : void 0;
|
24994
|
-
return sql`${withSql}update ${
|
24855
|
+
return sql`${withSql}update ${tableSql} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}`;
|
24995
24856
|
}
|
24996
24857
|
/**
|
24997
24858
|
* Builds selection SQL with provided fields/expressions
|
@@ -25043,6 +24904,54 @@ var init_dialect = __esm({
|
|
25043
24904
|
});
|
25044
24905
|
return sql.join(chunks);
|
25045
24906
|
}
|
24907
|
+
buildJoins(joins) {
|
24908
|
+
if (!joins || joins.length === 0) {
|
24909
|
+
return void 0;
|
24910
|
+
}
|
24911
|
+
const joinsArray = [];
|
24912
|
+
for (const [index4, joinMeta] of joins.entries()) {
|
24913
|
+
if (index4 === 0) {
|
24914
|
+
joinsArray.push(sql` `);
|
24915
|
+
}
|
24916
|
+
const table4 = joinMeta.table;
|
24917
|
+
const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
|
24918
|
+
if (is(table4, PgTable)) {
|
24919
|
+
const tableName = table4[PgTable.Symbol.Name];
|
24920
|
+
const tableSchema = table4[PgTable.Symbol.Schema];
|
24921
|
+
const origTableName = table4[PgTable.Symbol.OriginalName];
|
24922
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
24923
|
+
joinsArray.push(
|
24924
|
+
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
24925
|
+
);
|
24926
|
+
} else if (is(table4, View3)) {
|
24927
|
+
const viewName = table4[ViewBaseConfig].name;
|
24928
|
+
const viewSchema = table4[ViewBaseConfig].schema;
|
24929
|
+
const origViewName = table4[ViewBaseConfig].originalName;
|
24930
|
+
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
24931
|
+
joinsArray.push(
|
24932
|
+
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${viewSchema ? sql`${sql.identifier(viewSchema)}.` : void 0}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
24933
|
+
);
|
24934
|
+
} else {
|
24935
|
+
joinsArray.push(
|
24936
|
+
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table4} on ${joinMeta.on}`
|
24937
|
+
);
|
24938
|
+
}
|
24939
|
+
if (index4 < joins.length - 1) {
|
24940
|
+
joinsArray.push(sql` `);
|
24941
|
+
}
|
24942
|
+
}
|
24943
|
+
return sql.join(joinsArray);
|
24944
|
+
}
|
24945
|
+
buildFromTable(table4) {
|
24946
|
+
if (is(table4, Table2) && table4[Table2.Symbol.OriginalName] !== table4[Table2.Symbol.Name]) {
|
24947
|
+
let fullName = sql`${sql.identifier(table4[Table2.Symbol.OriginalName])}`;
|
24948
|
+
if (table4[Table2.Symbol.Schema]) {
|
24949
|
+
fullName = sql`${sql.identifier(table4[Table2.Symbol.Schema])}.${fullName}`;
|
24950
|
+
}
|
24951
|
+
return sql`${fullName} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
24952
|
+
}
|
24953
|
+
return table4;
|
24954
|
+
}
|
25046
24955
|
buildSelectQuery({
|
25047
24956
|
withList,
|
25048
24957
|
fields,
|
@@ -25077,51 +24986,8 @@ var init_dialect = __esm({
|
|
25077
24986
|
distinctSql = distinct === true ? sql` distinct` : sql` distinct on (${sql.join(distinct.on, sql`, `)})`;
|
25078
24987
|
}
|
25079
24988
|
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
25080
|
-
const tableSql = (
|
25081
|
-
|
25082
|
-
let fullName = sql`${sql.identifier(table4[Table2.Symbol.OriginalName])}`;
|
25083
|
-
if (table4[Table2.Symbol.Schema]) {
|
25084
|
-
fullName = sql`${sql.identifier(table4[Table2.Symbol.Schema])}.${fullName}`;
|
25085
|
-
}
|
25086
|
-
return sql`${fullName} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
25087
|
-
}
|
25088
|
-
return table4;
|
25089
|
-
})();
|
25090
|
-
const joinsArray = [];
|
25091
|
-
if (joins) {
|
25092
|
-
for (const [index4, joinMeta] of joins.entries()) {
|
25093
|
-
if (index4 === 0) {
|
25094
|
-
joinsArray.push(sql` `);
|
25095
|
-
}
|
25096
|
-
const table22 = joinMeta.table;
|
25097
|
-
const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
|
25098
|
-
if (is(table22, PgTable)) {
|
25099
|
-
const tableName = table22[PgTable.Symbol.Name];
|
25100
|
-
const tableSchema = table22[PgTable.Symbol.Schema];
|
25101
|
-
const origTableName = table22[PgTable.Symbol.OriginalName];
|
25102
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
25103
|
-
joinsArray.push(
|
25104
|
-
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}`
|
25105
|
-
);
|
25106
|
-
} else if (is(table22, View3)) {
|
25107
|
-
const viewName = table22[ViewBaseConfig].name;
|
25108
|
-
const viewSchema = table22[ViewBaseConfig].schema;
|
25109
|
-
const origViewName = table22[ViewBaseConfig].originalName;
|
25110
|
-
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
25111
|
-
joinsArray.push(
|
25112
|
-
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}`
|
25113
|
-
);
|
25114
|
-
} else {
|
25115
|
-
joinsArray.push(
|
25116
|
-
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table22} on ${joinMeta.on}`
|
25117
|
-
);
|
25118
|
-
}
|
25119
|
-
if (index4 < joins.length - 1) {
|
25120
|
-
joinsArray.push(sql` `);
|
25121
|
-
}
|
25122
|
-
}
|
25123
|
-
}
|
25124
|
-
const joinsSql = sql.join(joinsArray);
|
24989
|
+
const tableSql = this.buildFromTable(table4);
|
24990
|
+
const joinsSql = this.buildJoins(joins);
|
25125
24991
|
const whereSql = where ? sql` where ${where}` : void 0;
|
25126
24992
|
const havingSql = having ? sql` having ${having}` : void 0;
|
25127
24993
|
let orderBySql;
|
@@ -25202,43 +25068,55 @@ var init_dialect = __esm({
|
|
25202
25068
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
25203
25069
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
25204
25070
|
}
|
25205
|
-
buildInsertQuery({ table: table4, values, onConflict, returning, withList }) {
|
25071
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, onConflict, returning, withList, select, overridingSystemValue_ }) {
|
25206
25072
|
const valuesSqlList = [];
|
25207
25073
|
const columns = table4[Table2.Symbol.Columns];
|
25208
25074
|
const colEntries = Object.entries(columns).filter(([_2, col]) => !col.shouldDisableInsert());
|
25209
25075
|
const insertOrder = colEntries.map(
|
25210
25076
|
([, column4]) => sql.identifier(this.casing.getColumnCasing(column4))
|
25211
25077
|
);
|
25212
|
-
|
25213
|
-
const
|
25214
|
-
|
25215
|
-
|
25216
|
-
|
25217
|
-
|
25218
|
-
|
25219
|
-
|
25220
|
-
|
25221
|
-
|
25222
|
-
|
25223
|
-
|
25224
|
-
|
25078
|
+
if (select) {
|
25079
|
+
const select2 = valuesOrSelect;
|
25080
|
+
if (is(select2, SQL)) {
|
25081
|
+
valuesSqlList.push(select2);
|
25082
|
+
} else {
|
25083
|
+
valuesSqlList.push(select2.getSQL());
|
25084
|
+
}
|
25085
|
+
} else {
|
25086
|
+
const values = valuesOrSelect;
|
25087
|
+
valuesSqlList.push(sql.raw("values "));
|
25088
|
+
for (const [valueIndex, value] of values.entries()) {
|
25089
|
+
const valueList = [];
|
25090
|
+
for (const [fieldName, col] of colEntries) {
|
25091
|
+
const colValue = value[fieldName];
|
25092
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
25093
|
+
if (col.defaultFn !== void 0) {
|
25094
|
+
const defaultFnResult = col.defaultFn();
|
25095
|
+
const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
25096
|
+
valueList.push(defaultValue);
|
25097
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
25098
|
+
const onUpdateFnResult = col.onUpdateFn();
|
25099
|
+
const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
25100
|
+
valueList.push(newValue);
|
25101
|
+
} else {
|
25102
|
+
valueList.push(sql`default`);
|
25103
|
+
}
|
25225
25104
|
} else {
|
25226
|
-
valueList.push(
|
25105
|
+
valueList.push(colValue);
|
25227
25106
|
}
|
25228
|
-
} else {
|
25229
|
-
valueList.push(colValue);
|
25230
25107
|
}
|
25231
|
-
|
25232
|
-
|
25233
|
-
|
25234
|
-
|
25108
|
+
valuesSqlList.push(valueList);
|
25109
|
+
if (valueIndex < values.length - 1) {
|
25110
|
+
valuesSqlList.push(sql`, `);
|
25111
|
+
}
|
25235
25112
|
}
|
25236
25113
|
}
|
25237
25114
|
const withSql = this.buildWithCTE(withList);
|
25238
25115
|
const valuesSql = sql.join(valuesSqlList);
|
25239
25116
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
25240
25117
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
25241
|
-
|
25118
|
+
const overridingSql = overridingSystemValue_ === true ? sql`overriding system value ` : void 0;
|
25119
|
+
return sql`${withSql}insert into ${table4} ${insertOrder} ${overridingSql}${valuesSql}${onConflictSql}${returningSql}`;
|
25242
25120
|
}
|
25243
25121
|
buildRefreshMaterializedViewQuery({ view: view4, concurrently, withNoData }) {
|
25244
25122
|
const concurrentlySql = concurrently ? sql` concurrently` : void 0;
|
@@ -25974,12 +25852,12 @@ var init_dialect = __esm({
|
|
25974
25852
|
};
|
25975
25853
|
}
|
25976
25854
|
};
|
25977
|
-
__publicField(PgDialect,
|
25855
|
+
__publicField(PgDialect, _a127, "PgDialect");
|
25978
25856
|
}
|
25979
25857
|
});
|
25980
25858
|
|
25981
25859
|
// ../drizzle-orm/dist/selection-proxy.js
|
25982
|
-
var
|
25860
|
+
var _a128, _SelectionProxyHandler, SelectionProxyHandler;
|
25983
25861
|
var init_selection_proxy = __esm({
|
25984
25862
|
"../drizzle-orm/dist/selection-proxy.js"() {
|
25985
25863
|
"use strict";
|
@@ -25989,7 +25867,7 @@ var init_selection_proxy = __esm({
|
|
25989
25867
|
init_sql();
|
25990
25868
|
init_subquery();
|
25991
25869
|
init_view_common();
|
25992
|
-
|
25870
|
+
_a128 = entityKind;
|
25993
25871
|
_SelectionProxyHandler = class _SelectionProxyHandler {
|
25994
25872
|
constructor(config) {
|
25995
25873
|
__publicField(this, "config");
|
@@ -26055,25 +25933,25 @@ var init_selection_proxy = __esm({
|
|
26055
25933
|
return new Proxy(value, new _SelectionProxyHandler(this.config));
|
26056
25934
|
}
|
26057
25935
|
};
|
26058
|
-
__publicField(_SelectionProxyHandler,
|
25936
|
+
__publicField(_SelectionProxyHandler, _a128, "SelectionProxyHandler");
|
26059
25937
|
SelectionProxyHandler = _SelectionProxyHandler;
|
26060
25938
|
}
|
26061
25939
|
});
|
26062
25940
|
|
26063
25941
|
// ../drizzle-orm/dist/query-builders/query-builder.js
|
26064
|
-
var
|
25942
|
+
var _a129, TypedQueryBuilder;
|
26065
25943
|
var init_query_builder = __esm({
|
26066
25944
|
"../drizzle-orm/dist/query-builders/query-builder.js"() {
|
26067
25945
|
"use strict";
|
26068
25946
|
init_entity();
|
26069
|
-
|
25947
|
+
_a129 = entityKind;
|
26070
25948
|
TypedQueryBuilder = class {
|
26071
25949
|
/** @internal */
|
26072
25950
|
getSelectedFields() {
|
26073
25951
|
return this._.selectedFields;
|
26074
25952
|
}
|
26075
25953
|
};
|
26076
|
-
__publicField(TypedQueryBuilder,
|
25954
|
+
__publicField(TypedQueryBuilder, _a129, "TypedQueryBuilder");
|
26077
25955
|
}
|
26078
25956
|
});
|
26079
25957
|
|
@@ -26095,7 +25973,7 @@ function createSetOperator(type, isAll) {
|
|
26095
25973
|
return leftSelect.addSetOperators(setOperators);
|
26096
25974
|
};
|
26097
25975
|
}
|
26098
|
-
var
|
25976
|
+
var _a130, PgSelectBuilder, _a131, _b99, PgSelectQueryBuilderBase, _a132, _b100, PgSelectBase, getPgSetOperators, union, unionAll, intersect, intersectAll, except, exceptAll;
|
26099
25977
|
var init_select2 = __esm({
|
26100
25978
|
"../drizzle-orm/dist/pg-core/query-builders/select.js"() {
|
26101
25979
|
"use strict";
|
@@ -26111,7 +25989,7 @@ var init_select2 = __esm({
|
|
26111
25989
|
init_utils2();
|
26112
25990
|
init_utils2();
|
26113
25991
|
init_view_common();
|
26114
|
-
|
25992
|
+
_a130 = entityKind;
|
26115
25993
|
PgSelectBuilder = class {
|
26116
25994
|
constructor(config) {
|
26117
25995
|
__publicField(this, "fields");
|
@@ -26119,6 +25997,7 @@ var init_select2 = __esm({
|
|
26119
25997
|
__publicField(this, "dialect");
|
26120
25998
|
__publicField(this, "withList", []);
|
26121
25999
|
__publicField(this, "distinct");
|
26000
|
+
__publicField(this, "authToken");
|
26122
26001
|
this.fields = config.fields;
|
26123
26002
|
this.session = config.session;
|
26124
26003
|
this.dialect = config.dialect;
|
@@ -26127,6 +26006,11 @@ var init_select2 = __esm({
|
|
26127
26006
|
}
|
26128
26007
|
this.distinct = config.distinct;
|
26129
26008
|
}
|
26009
|
+
/** @internal */
|
26010
|
+
setToken(token) {
|
26011
|
+
this.authToken = token;
|
26012
|
+
return this;
|
26013
|
+
}
|
26130
26014
|
/**
|
26131
26015
|
* Specify the table, subquery, or other target that you're
|
26132
26016
|
* building a select query against.
|
@@ -26157,11 +26041,11 @@ var init_select2 = __esm({
|
|
26157
26041
|
dialect: this.dialect,
|
26158
26042
|
withList: this.withList,
|
26159
26043
|
distinct: this.distinct
|
26160
|
-
});
|
26044
|
+
}).setToken(this.authToken);
|
26161
26045
|
}
|
26162
26046
|
};
|
26163
|
-
__publicField(PgSelectBuilder,
|
26164
|
-
PgSelectQueryBuilderBase = class extends (
|
26047
|
+
__publicField(PgSelectBuilder, _a130, "PgSelectBuilder");
|
26048
|
+
PgSelectQueryBuilderBase = class extends (_b99 = TypedQueryBuilder, _a131 = entityKind, _b99) {
|
26165
26049
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
26166
26050
|
super();
|
26167
26051
|
__publicField(this, "_");
|
@@ -26761,19 +26645,20 @@ var init_select2 = __esm({
|
|
26761
26645
|
return this;
|
26762
26646
|
}
|
26763
26647
|
};
|
26764
|
-
__publicField(PgSelectQueryBuilderBase,
|
26765
|
-
PgSelectBase = class extends (
|
26648
|
+
__publicField(PgSelectQueryBuilderBase, _a131, "PgSelectQueryBuilder");
|
26649
|
+
PgSelectBase = class extends (_b100 = PgSelectQueryBuilderBase, _a132 = entityKind, _b100) {
|
26766
26650
|
constructor() {
|
26767
26651
|
super(...arguments);
|
26652
|
+
__publicField(this, "authToken");
|
26768
26653
|
__publicField(this, "execute", (placeholderValues) => {
|
26769
26654
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
26770
|
-
return this._prepare().execute(placeholderValues);
|
26655
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
26771
26656
|
});
|
26772
26657
|
});
|
26773
26658
|
}
|
26774
26659
|
/** @internal */
|
26775
26660
|
_prepare(name2) {
|
26776
|
-
const { session, config, dialect: dialect4, joinsNotNullableMap } = this;
|
26661
|
+
const { session, config, dialect: dialect4, joinsNotNullableMap, authToken } = this;
|
26777
26662
|
if (!session) {
|
26778
26663
|
throw new Error("Cannot execute a query on a query builder. Please use a database instance instead.");
|
26779
26664
|
}
|
@@ -26781,7 +26666,7 @@ var init_select2 = __esm({
|
|
26781
26666
|
const fieldsList = orderSelectedFields(config.fields);
|
26782
26667
|
const query = session.prepareQuery(dialect4.sqlToQuery(this.getSQL()), fieldsList, name2, true);
|
26783
26668
|
query.joinsNotNullableMap = joinsNotNullableMap;
|
26784
|
-
return query;
|
26669
|
+
return query.setToken(authToken);
|
26785
26670
|
});
|
26786
26671
|
}
|
26787
26672
|
/**
|
@@ -26794,8 +26679,13 @@ var init_select2 = __esm({
|
|
26794
26679
|
prepare(name2) {
|
26795
26680
|
return this._prepare(name2);
|
26796
26681
|
}
|
26682
|
+
/** @internal */
|
26683
|
+
setToken(token) {
|
26684
|
+
this.authToken = token;
|
26685
|
+
return this;
|
26686
|
+
}
|
26797
26687
|
};
|
26798
|
-
__publicField(PgSelectBase,
|
26688
|
+
__publicField(PgSelectBase, _a132, "PgSelect");
|
26799
26689
|
applyMixins(PgSelectBase, [QueryPromise]);
|
26800
26690
|
getPgSetOperators = () => ({
|
26801
26691
|
union,
|
@@ -26815,7 +26705,7 @@ var init_select2 = __esm({
|
|
26815
26705
|
});
|
26816
26706
|
|
26817
26707
|
// ../drizzle-orm/dist/pg-core/query-builders/query-builder.js
|
26818
|
-
var
|
26708
|
+
var _a133, QueryBuilder;
|
26819
26709
|
var init_query_builder2 = __esm({
|
26820
26710
|
"../drizzle-orm/dist/pg-core/query-builders/query-builder.js"() {
|
26821
26711
|
"use strict";
|
@@ -26824,7 +26714,7 @@ var init_query_builder2 = __esm({
|
|
26824
26714
|
init_selection_proxy();
|
26825
26715
|
init_subquery();
|
26826
26716
|
init_select2();
|
26827
|
-
|
26717
|
+
_a133 = entityKind;
|
26828
26718
|
QueryBuilder = class {
|
26829
26719
|
constructor(dialect4) {
|
26830
26720
|
__publicField(this, "dialect");
|
@@ -26905,36 +26795,228 @@ var init_query_builder2 = __esm({
|
|
26905
26795
|
return this.dialect;
|
26906
26796
|
}
|
26907
26797
|
};
|
26908
|
-
__publicField(QueryBuilder,
|
26798
|
+
__publicField(QueryBuilder, _a133, "PgQueryBuilder");
|
26909
26799
|
}
|
26910
26800
|
});
|
26911
26801
|
|
26912
|
-
// ../drizzle-orm/dist/pg-core/query-builders/
|
26913
|
-
var
|
26914
|
-
var
|
26915
|
-
"../drizzle-orm/dist/pg-core/query-builders/
|
26802
|
+
// ../drizzle-orm/dist/pg-core/query-builders/insert.js
|
26803
|
+
var _a134, PgInsertBuilder, _a135, _b101, PgInsertBase;
|
26804
|
+
var init_insert = __esm({
|
26805
|
+
"../drizzle-orm/dist/pg-core/query-builders/insert.js"() {
|
26916
26806
|
"use strict";
|
26917
26807
|
init_entity();
|
26918
26808
|
init_query_promise();
|
26809
|
+
init_sql();
|
26810
|
+
init_table();
|
26919
26811
|
init_tracing();
|
26920
|
-
|
26921
|
-
|
26922
|
-
|
26923
|
-
|
26924
|
-
|
26925
|
-
|
26926
|
-
|
26927
|
-
});
|
26928
|
-
});
|
26812
|
+
init_utils2();
|
26813
|
+
init_query_builder2();
|
26814
|
+
_a134 = entityKind;
|
26815
|
+
PgInsertBuilder = class {
|
26816
|
+
constructor(table4, session, dialect4, withList, overridingSystemValue_) {
|
26817
|
+
__publicField(this, "authToken");
|
26818
|
+
this.table = table4;
|
26929
26819
|
this.session = session;
|
26930
26820
|
this.dialect = dialect4;
|
26931
|
-
this.
|
26821
|
+
this.withList = withList;
|
26822
|
+
this.overridingSystemValue_ = overridingSystemValue_;
|
26932
26823
|
}
|
26933
|
-
|
26934
|
-
|
26935
|
-
|
26936
|
-
|
26937
|
-
|
26824
|
+
/** @internal */
|
26825
|
+
setToken(token) {
|
26826
|
+
this.authToken = token;
|
26827
|
+
return this;
|
26828
|
+
}
|
26829
|
+
overridingSystemValue() {
|
26830
|
+
this.overridingSystemValue_ = true;
|
26831
|
+
return this;
|
26832
|
+
}
|
26833
|
+
values(values) {
|
26834
|
+
values = Array.isArray(values) ? values : [values];
|
26835
|
+
if (values.length === 0) {
|
26836
|
+
throw new Error("values() must be called with at least one value");
|
26837
|
+
}
|
26838
|
+
const mappedValues = values.map((entry) => {
|
26839
|
+
const result = {};
|
26840
|
+
const cols = this.table[Table2.Symbol.Columns];
|
26841
|
+
for (const colKey of Object.keys(entry)) {
|
26842
|
+
const colValue = entry[colKey];
|
26843
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
26844
|
+
}
|
26845
|
+
return result;
|
26846
|
+
});
|
26847
|
+
return new PgInsertBase(
|
26848
|
+
this.table,
|
26849
|
+
mappedValues,
|
26850
|
+
this.session,
|
26851
|
+
this.dialect,
|
26852
|
+
this.withList,
|
26853
|
+
false,
|
26854
|
+
this.overridingSystemValue_
|
26855
|
+
).setToken(this.authToken);
|
26856
|
+
}
|
26857
|
+
select(selectQuery) {
|
26858
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
|
26859
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
26860
|
+
throw new Error(
|
26861
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
26862
|
+
);
|
26863
|
+
}
|
26864
|
+
return new PgInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
26865
|
+
}
|
26866
|
+
};
|
26867
|
+
__publicField(PgInsertBuilder, _a134, "PgInsertBuilder");
|
26868
|
+
PgInsertBase = class extends (_b101 = QueryPromise, _a135 = entityKind, _b101) {
|
26869
|
+
constructor(table4, values, session, dialect4, withList, select, overridingSystemValue_) {
|
26870
|
+
super();
|
26871
|
+
__publicField(this, "config");
|
26872
|
+
__publicField(this, "authToken");
|
26873
|
+
__publicField(this, "execute", (placeholderValues) => {
|
26874
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
26875
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
26876
|
+
});
|
26877
|
+
});
|
26878
|
+
this.session = session;
|
26879
|
+
this.dialect = dialect4;
|
26880
|
+
this.config = { table: table4, values, withList, select, overridingSystemValue_ };
|
26881
|
+
}
|
26882
|
+
returning(fields = this.config.table[Table2.Symbol.Columns]) {
|
26883
|
+
this.config.returning = orderSelectedFields(fields);
|
26884
|
+
return this;
|
26885
|
+
}
|
26886
|
+
/**
|
26887
|
+
* Adds an `on conflict do nothing` clause to the query.
|
26888
|
+
*
|
26889
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
26890
|
+
*
|
26891
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
26892
|
+
*
|
26893
|
+
* @param config The `target` and `where` clauses.
|
26894
|
+
*
|
26895
|
+
* @example
|
26896
|
+
* ```ts
|
26897
|
+
* // Insert one row and cancel the insert if there's a conflict
|
26898
|
+
* await db.insert(cars)
|
26899
|
+
* .values({ id: 1, brand: 'BMW' })
|
26900
|
+
* .onConflictDoNothing();
|
26901
|
+
*
|
26902
|
+
* // Explicitly specify conflict target
|
26903
|
+
* await db.insert(cars)
|
26904
|
+
* .values({ id: 1, brand: 'BMW' })
|
26905
|
+
* .onConflictDoNothing({ target: cars.id });
|
26906
|
+
* ```
|
26907
|
+
*/
|
26908
|
+
onConflictDoNothing(config = {}) {
|
26909
|
+
if (config.target === void 0) {
|
26910
|
+
this.config.onConflict = sql`do nothing`;
|
26911
|
+
} else {
|
26912
|
+
let targetColumn = "";
|
26913
|
+
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));
|
26914
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
26915
|
+
this.config.onConflict = sql`(${sql.raw(targetColumn)})${whereSql} do nothing`;
|
26916
|
+
}
|
26917
|
+
return this;
|
26918
|
+
}
|
26919
|
+
/**
|
26920
|
+
* Adds an `on conflict do update` clause to the query.
|
26921
|
+
*
|
26922
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
26923
|
+
*
|
26924
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
26925
|
+
*
|
26926
|
+
* @param config The `target`, `set` and `where` clauses.
|
26927
|
+
*
|
26928
|
+
* @example
|
26929
|
+
* ```ts
|
26930
|
+
* // Update the row if there's a conflict
|
26931
|
+
* await db.insert(cars)
|
26932
|
+
* .values({ id: 1, brand: 'BMW' })
|
26933
|
+
* .onConflictDoUpdate({
|
26934
|
+
* target: cars.id,
|
26935
|
+
* set: { brand: 'Porsche' }
|
26936
|
+
* });
|
26937
|
+
*
|
26938
|
+
* // Upsert with 'where' clause
|
26939
|
+
* await db.insert(cars)
|
26940
|
+
* .values({ id: 1, brand: 'BMW' })
|
26941
|
+
* .onConflictDoUpdate({
|
26942
|
+
* target: cars.id,
|
26943
|
+
* set: { brand: 'newBMW' },
|
26944
|
+
* targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
|
26945
|
+
* });
|
26946
|
+
* ```
|
26947
|
+
*/
|
26948
|
+
onConflictDoUpdate(config) {
|
26949
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
26950
|
+
throw new Error(
|
26951
|
+
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
26952
|
+
);
|
26953
|
+
}
|
26954
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
26955
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
26956
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
26957
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
26958
|
+
let targetColumn = "";
|
26959
|
+
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));
|
26960
|
+
this.config.onConflict = sql`(${sql.raw(targetColumn)})${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
26961
|
+
return this;
|
26962
|
+
}
|
26963
|
+
/** @internal */
|
26964
|
+
getSQL() {
|
26965
|
+
return this.dialect.buildInsertQuery(this.config);
|
26966
|
+
}
|
26967
|
+
toSQL() {
|
26968
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
26969
|
+
return rest;
|
26970
|
+
}
|
26971
|
+
/** @internal */
|
26972
|
+
_prepare(name2) {
|
26973
|
+
return tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
26974
|
+
return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
|
26975
|
+
});
|
26976
|
+
}
|
26977
|
+
prepare(name2) {
|
26978
|
+
return this._prepare(name2);
|
26979
|
+
}
|
26980
|
+
/** @internal */
|
26981
|
+
setToken(token) {
|
26982
|
+
this.authToken = token;
|
26983
|
+
return this;
|
26984
|
+
}
|
26985
|
+
$dynamic() {
|
26986
|
+
return this;
|
26987
|
+
}
|
26988
|
+
};
|
26989
|
+
__publicField(PgInsertBase, _a135, "PgInsert");
|
26990
|
+
}
|
26991
|
+
});
|
26992
|
+
|
26993
|
+
// ../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js
|
26994
|
+
var _a136, _b102, PgRefreshMaterializedView;
|
26995
|
+
var init_refresh_materialized_view = __esm({
|
26996
|
+
"../drizzle-orm/dist/pg-core/query-builders/refresh-materialized-view.js"() {
|
26997
|
+
"use strict";
|
26998
|
+
init_entity();
|
26999
|
+
init_query_promise();
|
27000
|
+
init_tracing();
|
27001
|
+
PgRefreshMaterializedView = class extends (_b102 = QueryPromise, _a136 = entityKind, _b102) {
|
27002
|
+
constructor(view4, session, dialect4) {
|
27003
|
+
super();
|
27004
|
+
__publicField(this, "config");
|
27005
|
+
__publicField(this, "authToken");
|
27006
|
+
__publicField(this, "execute", (placeholderValues) => {
|
27007
|
+
return tracer.startActiveSpan("drizzle.operation", () => {
|
27008
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
27009
|
+
});
|
27010
|
+
});
|
27011
|
+
this.session = session;
|
27012
|
+
this.dialect = dialect4;
|
27013
|
+
this.config = { view: view4 };
|
27014
|
+
}
|
27015
|
+
concurrently() {
|
27016
|
+
if (this.config.withNoData !== void 0) {
|
27017
|
+
throw new Error("Cannot use concurrently and withNoData together");
|
27018
|
+
}
|
27019
|
+
this.config.concurrently = true;
|
26938
27020
|
return this;
|
26939
27021
|
}
|
26940
27022
|
withNoData() {
|
@@ -26961,6 +27043,11 @@ var init_refresh_materialized_view = __esm({
|
|
26961
27043
|
prepare(name2) {
|
26962
27044
|
return this._prepare(name2);
|
26963
27045
|
}
|
27046
|
+
/** @internal */
|
27047
|
+
setToken(token) {
|
27048
|
+
this.authToken = token;
|
27049
|
+
return this;
|
27050
|
+
}
|
26964
27051
|
};
|
26965
27052
|
__publicField(PgRefreshMaterializedView, _a136, "PgRefreshMaterializedView");
|
26966
27053
|
}
|
@@ -26979,17 +27066,27 @@ var init_update = __esm({
|
|
26979
27066
|
"../drizzle-orm/dist/pg-core/query-builders/update.js"() {
|
26980
27067
|
"use strict";
|
26981
27068
|
init_entity();
|
27069
|
+
init_table2();
|
26982
27070
|
init_query_promise();
|
27071
|
+
init_selection_proxy();
|
27072
|
+
init_sql();
|
27073
|
+
init_subquery();
|
26983
27074
|
init_table();
|
26984
27075
|
init_utils2();
|
27076
|
+
init_view_common();
|
26985
27077
|
_a137 = entityKind;
|
26986
27078
|
PgUpdateBuilder = class {
|
26987
27079
|
constructor(table4, session, dialect4, withList) {
|
27080
|
+
__publicField(this, "authToken");
|
26988
27081
|
this.table = table4;
|
26989
27082
|
this.session = session;
|
26990
27083
|
this.dialect = dialect4;
|
26991
27084
|
this.withList = withList;
|
26992
27085
|
}
|
27086
|
+
setToken(token) {
|
27087
|
+
this.authToken = token;
|
27088
|
+
return this;
|
27089
|
+
}
|
26993
27090
|
set(values) {
|
26994
27091
|
return new PgUpdateBase(
|
26995
27092
|
this.table,
|
@@ -26997,7 +27094,7 @@ var init_update = __esm({
|
|
26997
27094
|
this.session,
|
26998
27095
|
this.dialect,
|
26999
27096
|
this.withList
|
27000
|
-
);
|
27097
|
+
).setToken(this.authToken);
|
27001
27098
|
}
|
27002
27099
|
};
|
27003
27100
|
__publicField(PgUpdateBuilder, _a137, "PgUpdateBuilder");
|
@@ -27005,12 +27102,86 @@ var init_update = __esm({
|
|
27005
27102
|
constructor(table4, set, session, dialect4, withList) {
|
27006
27103
|
super();
|
27007
27104
|
__publicField(this, "config");
|
27105
|
+
__publicField(this, "tableName");
|
27106
|
+
__publicField(this, "joinsNotNullableMap");
|
27107
|
+
__publicField(this, "leftJoin", this.createJoin("left"));
|
27108
|
+
__publicField(this, "rightJoin", this.createJoin("right"));
|
27109
|
+
__publicField(this, "innerJoin", this.createJoin("inner"));
|
27110
|
+
__publicField(this, "fullJoin", this.createJoin("full"));
|
27111
|
+
__publicField(this, "authToken");
|
27008
27112
|
__publicField(this, "execute", (placeholderValues) => {
|
27009
|
-
return this._prepare().execute(placeholderValues);
|
27113
|
+
return this._prepare().execute(placeholderValues, this.authToken);
|
27010
27114
|
});
|
27011
27115
|
this.session = session;
|
27012
27116
|
this.dialect = dialect4;
|
27013
|
-
this.config = { set, table: table4, withList };
|
27117
|
+
this.config = { set, table: table4, withList, joins: [] };
|
27118
|
+
this.tableName = getTableLikeName(table4);
|
27119
|
+
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
27120
|
+
}
|
27121
|
+
from(source) {
|
27122
|
+
const tableName = getTableLikeName(source);
|
27123
|
+
if (typeof tableName === "string") {
|
27124
|
+
this.joinsNotNullableMap[tableName] = true;
|
27125
|
+
}
|
27126
|
+
this.config.from = source;
|
27127
|
+
return this;
|
27128
|
+
}
|
27129
|
+
getTableLikeFields(table4) {
|
27130
|
+
if (is(table4, PgTable)) {
|
27131
|
+
return table4[Table2.Symbol.Columns];
|
27132
|
+
} else if (is(table4, Subquery)) {
|
27133
|
+
return table4._.selectedFields;
|
27134
|
+
}
|
27135
|
+
return table4[ViewBaseConfig].selectedFields;
|
27136
|
+
}
|
27137
|
+
createJoin(joinType) {
|
27138
|
+
return (table4, on) => {
|
27139
|
+
const tableName = getTableLikeName(table4);
|
27140
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
27141
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
27142
|
+
}
|
27143
|
+
if (typeof on === "function") {
|
27144
|
+
const from = this.config.from && !is(this.config.from, SQL) ? this.getTableLikeFields(this.config.from) : void 0;
|
27145
|
+
on = on(
|
27146
|
+
new Proxy(
|
27147
|
+
this.config.table[Table2.Symbol.Columns],
|
27148
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
27149
|
+
),
|
27150
|
+
from && new Proxy(
|
27151
|
+
from,
|
27152
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
27153
|
+
)
|
27154
|
+
);
|
27155
|
+
}
|
27156
|
+
this.config.joins.push({ on, table: table4, joinType, alias: tableName });
|
27157
|
+
if (typeof tableName === "string") {
|
27158
|
+
switch (joinType) {
|
27159
|
+
case "left": {
|
27160
|
+
this.joinsNotNullableMap[tableName] = false;
|
27161
|
+
break;
|
27162
|
+
}
|
27163
|
+
case "right": {
|
27164
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
27165
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
27166
|
+
);
|
27167
|
+
this.joinsNotNullableMap[tableName] = true;
|
27168
|
+
break;
|
27169
|
+
}
|
27170
|
+
case "inner": {
|
27171
|
+
this.joinsNotNullableMap[tableName] = true;
|
27172
|
+
break;
|
27173
|
+
}
|
27174
|
+
case "full": {
|
27175
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
27176
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
27177
|
+
);
|
27178
|
+
this.joinsNotNullableMap[tableName] = false;
|
27179
|
+
break;
|
27180
|
+
}
|
27181
|
+
}
|
27182
|
+
}
|
27183
|
+
return this;
|
27184
|
+
};
|
27014
27185
|
}
|
27015
27186
|
/**
|
27016
27187
|
* Adds a 'where' clause to the query.
|
@@ -27049,7 +27220,24 @@ var init_update = __esm({
|
|
27049
27220
|
this.config.where = where;
|
27050
27221
|
return this;
|
27051
27222
|
}
|
27052
|
-
returning(fields
|
27223
|
+
returning(fields) {
|
27224
|
+
if (!fields) {
|
27225
|
+
fields = Object.assign({}, this.config.table[Table2.Symbol.Columns]);
|
27226
|
+
if (this.config.from) {
|
27227
|
+
const tableName = getTableLikeName(this.config.from);
|
27228
|
+
if (typeof tableName === "string" && this.config.from && !is(this.config.from, SQL)) {
|
27229
|
+
const fromFields = this.getTableLikeFields(this.config.from);
|
27230
|
+
fields[tableName] = fromFields;
|
27231
|
+
}
|
27232
|
+
for (const join of this.config.joins) {
|
27233
|
+
const tableName2 = getTableLikeName(join.table);
|
27234
|
+
if (typeof tableName2 === "string" && !is(join.table, SQL)) {
|
27235
|
+
const fromFields = this.getTableLikeFields(join.table);
|
27236
|
+
fields[tableName2] = fromFields;
|
27237
|
+
}
|
27238
|
+
}
|
27239
|
+
}
|
27240
|
+
}
|
27053
27241
|
this.config.returning = orderSelectedFields(fields);
|
27054
27242
|
return this;
|
27055
27243
|
}
|
@@ -27063,11 +27251,18 @@ var init_update = __esm({
|
|
27063
27251
|
}
|
27064
27252
|
/** @internal */
|
27065
27253
|
_prepare(name2) {
|
27066
|
-
|
27254
|
+
const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
|
27255
|
+
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
27256
|
+
return query;
|
27067
27257
|
}
|
27068
27258
|
prepare(name2) {
|
27069
27259
|
return this._prepare(name2);
|
27070
27260
|
}
|
27261
|
+
/** @internal */
|
27262
|
+
setToken(token) {
|
27263
|
+
this.authToken = token;
|
27264
|
+
return this;
|
27265
|
+
}
|
27071
27266
|
$dynamic() {
|
27072
27267
|
return this;
|
27073
27268
|
}
|
@@ -27101,6 +27296,7 @@ var init_count = __esm({
|
|
27101
27296
|
constructor(params) {
|
27102
27297
|
super(_PgCountBuilder.buildEmbeddedCount(params.source, params.filters).queryChunks);
|
27103
27298
|
__publicField(this, "sql");
|
27299
|
+
__publicField(this, "token");
|
27104
27300
|
__publicField(this, _a139, "PgCountBuilder");
|
27105
27301
|
__publicField(this, "session");
|
27106
27302
|
this.params = params;
|
@@ -27117,8 +27313,13 @@ var init_count = __esm({
|
|
27117
27313
|
static buildCount(source, filters) {
|
27118
27314
|
return sql`select count(*) as count from ${source}${sql.raw(" where ").if(filters)}${filters};`;
|
27119
27315
|
}
|
27316
|
+
/** @intrnal */
|
27317
|
+
setToken(token) {
|
27318
|
+
this.token = token;
|
27319
|
+
return this;
|
27320
|
+
}
|
27120
27321
|
then(onfulfilled, onrejected) {
|
27121
|
-
return Promise.resolve(this.session.count(this.sql)).then(
|
27322
|
+
return Promise.resolve(this.session.count(this.sql, this.token)).then(
|
27122
27323
|
onfulfilled,
|
27123
27324
|
onrejected
|
27124
27325
|
);
|
@@ -27195,6 +27396,7 @@ var init_query = __esm({
|
|
27195
27396
|
PgRelationalQuery = class extends (_b105 = QueryPromise, _a141 = entityKind, _b105) {
|
27196
27397
|
constructor(fullSchema, schema4, tableNamesMap, table4, tableConfig, dialect4, session, config, mode) {
|
27197
27398
|
super();
|
27399
|
+
__publicField(this, "authToken");
|
27198
27400
|
this.fullSchema = fullSchema;
|
27199
27401
|
this.schema = schema4;
|
27200
27402
|
this.tableNamesMap = tableNamesMap;
|
@@ -27252,9 +27454,14 @@ var init_query = __esm({
|
|
27252
27454
|
toSQL() {
|
27253
27455
|
return this._toSQL().builtQuery;
|
27254
27456
|
}
|
27457
|
+
/** @internal */
|
27458
|
+
setToken(token) {
|
27459
|
+
this.authToken = token;
|
27460
|
+
return this;
|
27461
|
+
}
|
27255
27462
|
execute() {
|
27256
27463
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
27257
|
-
return this._prepare().execute();
|
27464
|
+
return this._prepare().execute(void 0, this.authToken);
|
27258
27465
|
});
|
27259
27466
|
}
|
27260
27467
|
};
|
@@ -27317,6 +27524,7 @@ var init_db = __esm({
|
|
27317
27524
|
PgDatabase = class {
|
27318
27525
|
constructor(dialect4, session, schema4) {
|
27319
27526
|
__publicField(this, "query");
|
27527
|
+
__publicField(this, "authToken");
|
27320
27528
|
this.dialect = dialect4;
|
27321
27529
|
this.session = session;
|
27322
27530
|
this._ = schema4 ? {
|
@@ -27572,7 +27780,7 @@ var init_db = __esm({
|
|
27572
27780
|
false
|
27573
27781
|
);
|
27574
27782
|
return new PgRaw(
|
27575
|
-
() => prepared.execute(),
|
27783
|
+
() => prepared.execute(void 0, this.authToken),
|
27576
27784
|
sequel,
|
27577
27785
|
builtQuery,
|
27578
27786
|
(result) => prepared.mapResult(result, true)
|
@@ -28117,6 +28325,7 @@ var init_session = __esm({
|
|
28117
28325
|
_a159 = entityKind;
|
28118
28326
|
PgPreparedQuery = class {
|
28119
28327
|
constructor(query) {
|
28328
|
+
__publicField(this, "authToken");
|
28120
28329
|
/** @internal */
|
28121
28330
|
__publicField(this, "joinsNotNullableMap");
|
28122
28331
|
this.query = query;
|
@@ -28127,6 +28336,11 @@ var init_session = __esm({
|
|
28127
28336
|
mapResult(response, _isFromBatch) {
|
28128
28337
|
return response;
|
28129
28338
|
}
|
28339
|
+
/** @internal */
|
28340
|
+
setToken(token) {
|
28341
|
+
this.authToken = token;
|
28342
|
+
return this;
|
28343
|
+
}
|
28130
28344
|
};
|
28131
28345
|
__publicField(PgPreparedQuery, _a159, "PgPreparedQuery");
|
28132
28346
|
_a160 = entityKind;
|
@@ -28134,7 +28348,8 @@ var init_session = __esm({
|
|
28134
28348
|
constructor(dialect4) {
|
28135
28349
|
this.dialect = dialect4;
|
28136
28350
|
}
|
28137
|
-
|
28351
|
+
/** @internal */
|
28352
|
+
execute(query, token) {
|
28138
28353
|
return tracer.startActiveSpan("drizzle.operation", () => {
|
28139
28354
|
const prepared = tracer.startActiveSpan("drizzle.prepareQuery", () => {
|
28140
28355
|
return this.prepareQuery(
|
@@ -28144,7 +28359,7 @@ var init_session = __esm({
|
|
28144
28359
|
false
|
28145
28360
|
);
|
28146
28361
|
});
|
28147
|
-
return prepared.execute();
|
28362
|
+
return prepared.setToken(token).execute(void 0, token);
|
28148
28363
|
});
|
28149
28364
|
}
|
28150
28365
|
all(query) {
|
@@ -28155,8 +28370,9 @@ var init_session = __esm({
|
|
28155
28370
|
false
|
28156
28371
|
).all();
|
28157
28372
|
}
|
28158
|
-
|
28159
|
-
|
28373
|
+
/** @internal */
|
28374
|
+
async count(sql2, token) {
|
28375
|
+
const res = await this.execute(sql2, token);
|
28160
28376
|
return Number(
|
28161
28377
|
res[0]["count"]
|
28162
28378
|
);
|
@@ -30790,180 +31006,12 @@ var init_delete2 = __esm({
|
|
30790
31006
|
return this;
|
30791
31007
|
}
|
30792
31008
|
returning(fields = this.table[SQLiteTable.Symbol.Columns]) {
|
30793
|
-
this.config.returning = orderSelectedFields(fields);
|
30794
|
-
return this;
|
30795
|
-
}
|
30796
|
-
/** @internal */
|
30797
|
-
getSQL() {
|
30798
|
-
return this.dialect.buildDeleteQuery(this.config);
|
30799
|
-
}
|
30800
|
-
toSQL() {
|
30801
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
30802
|
-
return rest;
|
30803
|
-
}
|
30804
|
-
/** @internal */
|
30805
|
-
_prepare(isOneTimeQuery = true) {
|
30806
|
-
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
30807
|
-
this.dialect.sqlToQuery(this.getSQL()),
|
30808
|
-
this.config.returning,
|
30809
|
-
this.config.returning ? "all" : "run",
|
30810
|
-
true
|
30811
|
-
);
|
30812
|
-
}
|
30813
|
-
prepare() {
|
30814
|
-
return this._prepare(false);
|
30815
|
-
}
|
30816
|
-
async execute(placeholderValues) {
|
30817
|
-
return this._prepare().execute(placeholderValues);
|
30818
|
-
}
|
30819
|
-
$dynamic() {
|
30820
|
-
return this;
|
30821
|
-
}
|
30822
|
-
};
|
30823
|
-
__publicField(SQLiteDeleteBase, _a196, "SQLiteDelete");
|
30824
|
-
}
|
30825
|
-
});
|
30826
|
-
|
30827
|
-
// ../drizzle-orm/dist/sqlite-core/query-builders/insert.js
|
30828
|
-
var _a197, SQLiteInsertBuilder, _a198, _b142, SQLiteInsertBase;
|
30829
|
-
var init_insert2 = __esm({
|
30830
|
-
"../drizzle-orm/dist/sqlite-core/query-builders/insert.js"() {
|
30831
|
-
"use strict";
|
30832
|
-
init_entity();
|
30833
|
-
init_query_promise();
|
30834
|
-
init_sql();
|
30835
|
-
init_table3();
|
30836
|
-
init_table();
|
30837
|
-
init_utils2();
|
30838
|
-
_a197 = entityKind;
|
30839
|
-
SQLiteInsertBuilder = class {
|
30840
|
-
constructor(table4, session, dialect4, withList) {
|
30841
|
-
this.table = table4;
|
30842
|
-
this.session = session;
|
30843
|
-
this.dialect = dialect4;
|
30844
|
-
this.withList = withList;
|
30845
|
-
}
|
30846
|
-
values(values) {
|
30847
|
-
values = Array.isArray(values) ? values : [values];
|
30848
|
-
if (values.length === 0) {
|
30849
|
-
throw new Error("values() must be called with at least one value");
|
30850
|
-
}
|
30851
|
-
const mappedValues = values.map((entry) => {
|
30852
|
-
const result = {};
|
30853
|
-
const cols = this.table[Table2.Symbol.Columns];
|
30854
|
-
for (const colKey of Object.keys(entry)) {
|
30855
|
-
const colValue = entry[colKey];
|
30856
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
30857
|
-
}
|
30858
|
-
return result;
|
30859
|
-
});
|
30860
|
-
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
30861
|
-
}
|
30862
|
-
};
|
30863
|
-
__publicField(SQLiteInsertBuilder, _a197, "SQLiteInsertBuilder");
|
30864
|
-
SQLiteInsertBase = class extends (_b142 = QueryPromise, _a198 = entityKind, _b142) {
|
30865
|
-
constructor(table4, values, session, dialect4, withList) {
|
30866
|
-
super();
|
30867
|
-
/** @internal */
|
30868
|
-
__publicField(this, "config");
|
30869
|
-
__publicField(this, "run", (placeholderValues) => {
|
30870
|
-
return this._prepare().run(placeholderValues);
|
30871
|
-
});
|
30872
|
-
__publicField(this, "all", (placeholderValues) => {
|
30873
|
-
return this._prepare().all(placeholderValues);
|
30874
|
-
});
|
30875
|
-
__publicField(this, "get", (placeholderValues) => {
|
30876
|
-
return this._prepare().get(placeholderValues);
|
30877
|
-
});
|
30878
|
-
__publicField(this, "values", (placeholderValues) => {
|
30879
|
-
return this._prepare().values(placeholderValues);
|
30880
|
-
});
|
30881
|
-
this.session = session;
|
30882
|
-
this.dialect = dialect4;
|
30883
|
-
this.config = { table: table4, values, withList };
|
30884
|
-
}
|
30885
|
-
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
30886
|
-
this.config.returning = orderSelectedFields(fields);
|
30887
|
-
return this;
|
30888
|
-
}
|
30889
|
-
/**
|
30890
|
-
* Adds an `on conflict do nothing` clause to the query.
|
30891
|
-
*
|
30892
|
-
* Calling this method simply avoids inserting a row as its alternative action.
|
30893
|
-
*
|
30894
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
30895
|
-
*
|
30896
|
-
* @param config The `target` and `where` clauses.
|
30897
|
-
*
|
30898
|
-
* @example
|
30899
|
-
* ```ts
|
30900
|
-
* // Insert one row and cancel the insert if there's a conflict
|
30901
|
-
* await db.insert(cars)
|
30902
|
-
* .values({ id: 1, brand: 'BMW' })
|
30903
|
-
* .onConflictDoNothing();
|
30904
|
-
*
|
30905
|
-
* // Explicitly specify conflict target
|
30906
|
-
* await db.insert(cars)
|
30907
|
-
* .values({ id: 1, brand: 'BMW' })
|
30908
|
-
* .onConflictDoNothing({ target: cars.id });
|
30909
|
-
* ```
|
30910
|
-
*/
|
30911
|
-
onConflictDoNothing(config = {}) {
|
30912
|
-
if (config.target === void 0) {
|
30913
|
-
this.config.onConflict = sql`do nothing`;
|
30914
|
-
} else {
|
30915
|
-
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
30916
|
-
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
30917
|
-
this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
|
30918
|
-
}
|
30919
|
-
return this;
|
30920
|
-
}
|
30921
|
-
/**
|
30922
|
-
* Adds an `on conflict do update` clause to the query.
|
30923
|
-
*
|
30924
|
-
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
30925
|
-
*
|
30926
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
30927
|
-
*
|
30928
|
-
* @param config The `target`, `set` and `where` clauses.
|
30929
|
-
*
|
30930
|
-
* @example
|
30931
|
-
* ```ts
|
30932
|
-
* // Update the row if there's a conflict
|
30933
|
-
* await db.insert(cars)
|
30934
|
-
* .values({ id: 1, brand: 'BMW' })
|
30935
|
-
* .onConflictDoUpdate({
|
30936
|
-
* target: cars.id,
|
30937
|
-
* set: { brand: 'Porsche' }
|
30938
|
-
* });
|
30939
|
-
*
|
30940
|
-
* // Upsert with 'where' clause
|
30941
|
-
* await db.insert(cars)
|
30942
|
-
* .values({ id: 1, brand: 'BMW' })
|
30943
|
-
* .onConflictDoUpdate({
|
30944
|
-
* target: cars.id,
|
30945
|
-
* set: { brand: 'newBMW' },
|
30946
|
-
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
30947
|
-
* });
|
30948
|
-
* ```
|
30949
|
-
*/
|
30950
|
-
onConflictDoUpdate(config) {
|
30951
|
-
if (config.where && (config.targetWhere || config.setWhere)) {
|
30952
|
-
throw new Error(
|
30953
|
-
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
30954
|
-
);
|
30955
|
-
}
|
30956
|
-
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
30957
|
-
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
30958
|
-
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
30959
|
-
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
30960
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
30961
|
-
this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
31009
|
+
this.config.returning = orderSelectedFields(fields);
|
30962
31010
|
return this;
|
30963
31011
|
}
|
30964
31012
|
/** @internal */
|
30965
31013
|
getSQL() {
|
30966
|
-
return this.dialect.
|
31014
|
+
return this.dialect.buildDeleteQuery(this.config);
|
30967
31015
|
}
|
30968
31016
|
toSQL() {
|
30969
31017
|
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
@@ -30981,32 +31029,32 @@ var init_insert2 = __esm({
|
|
30981
31029
|
prepare() {
|
30982
31030
|
return this._prepare(false);
|
30983
31031
|
}
|
30984
|
-
async execute() {
|
30985
|
-
return this.
|
31032
|
+
async execute(placeholderValues) {
|
31033
|
+
return this._prepare().execute(placeholderValues);
|
30986
31034
|
}
|
30987
31035
|
$dynamic() {
|
30988
31036
|
return this;
|
30989
31037
|
}
|
30990
31038
|
};
|
30991
|
-
__publicField(
|
31039
|
+
__publicField(SQLiteDeleteBase, _a196, "SQLiteDelete");
|
30992
31040
|
}
|
30993
31041
|
});
|
30994
31042
|
|
30995
31043
|
// ../drizzle-orm/dist/sqlite-core/view-base.js
|
30996
|
-
var
|
31044
|
+
var _a197, _b142, SQLiteViewBase;
|
30997
31045
|
var init_view_base2 = __esm({
|
30998
31046
|
"../drizzle-orm/dist/sqlite-core/view-base.js"() {
|
30999
31047
|
"use strict";
|
31000
31048
|
init_entity();
|
31001
31049
|
init_sql();
|
31002
|
-
SQLiteViewBase = class extends (
|
31050
|
+
SQLiteViewBase = class extends (_b142 = View3, _a197 = entityKind, _b142) {
|
31003
31051
|
};
|
31004
|
-
__publicField(SQLiteViewBase,
|
31052
|
+
__publicField(SQLiteViewBase, _a197, "SQLiteViewBase");
|
31005
31053
|
}
|
31006
31054
|
});
|
31007
31055
|
|
31008
31056
|
// ../drizzle-orm/dist/sqlite-core/dialect.js
|
31009
|
-
var
|
31057
|
+
var _a198, SQLiteDialect, _a199, _b143, SQLiteSyncDialect, _a200, _b144, SQLiteAsyncDialect;
|
31010
31058
|
var init_dialect2 = __esm({
|
31011
31059
|
"../drizzle-orm/dist/sqlite-core/dialect.js"() {
|
31012
31060
|
"use strict";
|
@@ -31025,7 +31073,7 @@ var init_dialect2 = __esm({
|
|
31025
31073
|
init_utils2();
|
31026
31074
|
init_view_common();
|
31027
31075
|
init_view_base2();
|
31028
|
-
|
31076
|
+
_a198 = entityKind;
|
31029
31077
|
SQLiteDialect = class {
|
31030
31078
|
constructor(config) {
|
31031
31079
|
/** @internal */
|
@@ -31078,14 +31126,16 @@ var init_dialect2 = __esm({
|
|
31078
31126
|
return [res];
|
31079
31127
|
}));
|
31080
31128
|
}
|
31081
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList, limit, orderBy }) {
|
31129
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, joins, from, limit, orderBy }) {
|
31082
31130
|
const withSql = this.buildWithCTE(withList);
|
31083
31131
|
const setSql = this.buildUpdateSet(table4, set);
|
31132
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
31133
|
+
const joinsSql = this.buildJoins(joins);
|
31084
31134
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
31085
31135
|
const whereSql = where ? sql` where ${where}` : void 0;
|
31086
31136
|
const orderBySql = this.buildOrderBy(orderBy);
|
31087
31137
|
const limitSql = this.buildLimit(limit);
|
31088
|
-
return sql`${withSql}update ${table4} set ${setSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
31138
|
+
return sql`${withSql}update ${table4} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
31089
31139
|
}
|
31090
31140
|
/**
|
31091
31141
|
* Builds selection SQL with provided fields/expressions
|
@@ -31138,6 +31188,37 @@ var init_dialect2 = __esm({
|
|
31138
31188
|
});
|
31139
31189
|
return sql.join(chunks);
|
31140
31190
|
}
|
31191
|
+
buildJoins(joins) {
|
31192
|
+
if (!joins || joins.length === 0) {
|
31193
|
+
return void 0;
|
31194
|
+
}
|
31195
|
+
const joinsArray = [];
|
31196
|
+
if (joins) {
|
31197
|
+
for (const [index4, joinMeta] of joins.entries()) {
|
31198
|
+
if (index4 === 0) {
|
31199
|
+
joinsArray.push(sql` `);
|
31200
|
+
}
|
31201
|
+
const table4 = joinMeta.table;
|
31202
|
+
if (is(table4, SQLiteTable)) {
|
31203
|
+
const tableName = table4[SQLiteTable.Symbol.Name];
|
31204
|
+
const tableSchema = table4[SQLiteTable.Symbol.Schema];
|
31205
|
+
const origTableName = table4[SQLiteTable.Symbol.OriginalName];
|
31206
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
31207
|
+
joinsArray.push(
|
31208
|
+
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
31209
|
+
);
|
31210
|
+
} else {
|
31211
|
+
joinsArray.push(
|
31212
|
+
sql`${sql.raw(joinMeta.joinType)} join ${table4} on ${joinMeta.on}`
|
31213
|
+
);
|
31214
|
+
}
|
31215
|
+
if (index4 < joins.length - 1) {
|
31216
|
+
joinsArray.push(sql` `);
|
31217
|
+
}
|
31218
|
+
}
|
31219
|
+
}
|
31220
|
+
return sql.join(joinsArray);
|
31221
|
+
}
|
31141
31222
|
buildLimit(limit) {
|
31142
31223
|
return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
31143
31224
|
}
|
@@ -31153,6 +31234,12 @@ var init_dialect2 = __esm({
|
|
31153
31234
|
}
|
31154
31235
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
31155
31236
|
}
|
31237
|
+
buildFromTable(table4) {
|
31238
|
+
if (is(table4, Table2) && table4[Table2.Symbol.OriginalName] !== table4[Table2.Symbol.Name]) {
|
31239
|
+
return sql`${sql.identifier(table4[Table2.Symbol.OriginalName])} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
31240
|
+
}
|
31241
|
+
return table4;
|
31242
|
+
}
|
31156
31243
|
buildSelectQuery({
|
31157
31244
|
withList,
|
31158
31245
|
fields,
|
@@ -31183,38 +31270,8 @@ var init_dialect2 = __esm({
|
|
31183
31270
|
const withSql = this.buildWithCTE(withList);
|
31184
31271
|
const distinctSql = distinct ? sql` distinct` : void 0;
|
31185
31272
|
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
31186
|
-
const tableSql = (
|
31187
|
-
|
31188
|
-
return sql`${sql.identifier(table4[Table2.Symbol.OriginalName])} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
31189
|
-
}
|
31190
|
-
return table4;
|
31191
|
-
})();
|
31192
|
-
const joinsArray = [];
|
31193
|
-
if (joins) {
|
31194
|
-
for (const [index4, joinMeta] of joins.entries()) {
|
31195
|
-
if (index4 === 0) {
|
31196
|
-
joinsArray.push(sql` `);
|
31197
|
-
}
|
31198
|
-
const table22 = joinMeta.table;
|
31199
|
-
if (is(table22, SQLiteTable)) {
|
31200
|
-
const tableName = table22[SQLiteTable.Symbol.Name];
|
31201
|
-
const tableSchema = table22[SQLiteTable.Symbol.Schema];
|
31202
|
-
const origTableName = table22[SQLiteTable.Symbol.OriginalName];
|
31203
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
31204
|
-
joinsArray.push(
|
31205
|
-
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
31206
|
-
);
|
31207
|
-
} else {
|
31208
|
-
joinsArray.push(
|
31209
|
-
sql`${sql.raw(joinMeta.joinType)} join ${table22} on ${joinMeta.on}`
|
31210
|
-
);
|
31211
|
-
}
|
31212
|
-
if (index4 < joins.length - 1) {
|
31213
|
-
joinsArray.push(sql` `);
|
31214
|
-
}
|
31215
|
-
}
|
31216
|
-
}
|
31217
|
-
const joinsSql = sql.join(joinsArray);
|
31273
|
+
const tableSql = this.buildFromTable(table4);
|
31274
|
+
const joinsSql = this.buildJoins(joins);
|
31218
31275
|
const whereSql = where ? sql` where ${where}` : void 0;
|
31219
31276
|
const havingSql = having ? sql` having ${having}` : void 0;
|
31220
31277
|
const groupByList = [];
|
@@ -31280,45 +31337,56 @@ var init_dialect2 = __esm({
|
|
31280
31337
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
31281
31338
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
31282
31339
|
}
|
31283
|
-
buildInsertQuery({ table: table4, values, onConflict, returning, withList }) {
|
31340
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, onConflict, returning, withList, select }) {
|
31284
31341
|
const valuesSqlList = [];
|
31285
31342
|
const columns = table4[Table2.Symbol.Columns];
|
31286
31343
|
const colEntries = Object.entries(columns).filter(
|
31287
31344
|
([_2, col]) => !col.shouldDisableInsert()
|
31288
31345
|
);
|
31289
31346
|
const insertOrder = colEntries.map(([, column4]) => sql.identifier(this.casing.getColumnCasing(column4)));
|
31290
|
-
|
31291
|
-
const
|
31292
|
-
|
31293
|
-
|
31294
|
-
|
31295
|
-
|
31296
|
-
|
31297
|
-
|
31298
|
-
|
31299
|
-
|
31300
|
-
|
31301
|
-
|
31302
|
-
|
31303
|
-
|
31347
|
+
if (select) {
|
31348
|
+
const select2 = valuesOrSelect;
|
31349
|
+
if (is(select2, SQL)) {
|
31350
|
+
valuesSqlList.push(select2);
|
31351
|
+
} else {
|
31352
|
+
valuesSqlList.push(select2.getSQL());
|
31353
|
+
}
|
31354
|
+
} else {
|
31355
|
+
const values = valuesOrSelect;
|
31356
|
+
valuesSqlList.push(sql.raw("values "));
|
31357
|
+
for (const [valueIndex, value] of values.entries()) {
|
31358
|
+
const valueList = [];
|
31359
|
+
for (const [fieldName, col] of colEntries) {
|
31360
|
+
const colValue = value[fieldName];
|
31361
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
31362
|
+
let defaultValue;
|
31363
|
+
if (col.default !== null && col.default !== void 0) {
|
31364
|
+
defaultValue = is(col.default, SQL) ? col.default : sql.param(col.default, col);
|
31365
|
+
} else if (col.defaultFn !== void 0) {
|
31366
|
+
const defaultFnResult = col.defaultFn();
|
31367
|
+
defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
31368
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
31369
|
+
const onUpdateFnResult = col.onUpdateFn();
|
31370
|
+
defaultValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
31371
|
+
} else {
|
31372
|
+
defaultValue = sql`null`;
|
31373
|
+
}
|
31374
|
+
valueList.push(defaultValue);
|
31304
31375
|
} else {
|
31305
|
-
|
31376
|
+
valueList.push(colValue);
|
31306
31377
|
}
|
31307
|
-
valueList.push(defaultValue);
|
31308
|
-
} else {
|
31309
|
-
valueList.push(colValue);
|
31310
31378
|
}
|
31311
|
-
|
31312
|
-
|
31313
|
-
|
31314
|
-
|
31379
|
+
valuesSqlList.push(valueList);
|
31380
|
+
if (valueIndex < values.length - 1) {
|
31381
|
+
valuesSqlList.push(sql`, `);
|
31382
|
+
}
|
31315
31383
|
}
|
31316
31384
|
}
|
31317
31385
|
const withSql = this.buildWithCTE(withList);
|
31318
31386
|
const valuesSql = sql.join(valuesSqlList);
|
31319
31387
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
31320
31388
|
const onConflictSql = onConflict ? sql` on conflict ${onConflict}` : void 0;
|
31321
|
-
return sql`${withSql}insert into ${table4} ${insertOrder}
|
31389
|
+
return sql`${withSql}insert into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`;
|
31322
31390
|
}
|
31323
31391
|
sqlToQuery(sql2, invokeSource) {
|
31324
31392
|
return sql2.toQuery({
|
@@ -31547,8 +31615,8 @@ var init_dialect2 = __esm({
|
|
31547
31615
|
};
|
31548
31616
|
}
|
31549
31617
|
};
|
31550
|
-
__publicField(SQLiteDialect,
|
31551
|
-
SQLiteSyncDialect = class extends (
|
31618
|
+
__publicField(SQLiteDialect, _a198, "SQLiteDialect");
|
31619
|
+
SQLiteSyncDialect = class extends (_b143 = SQLiteDialect, _a199 = entityKind, _b143) {
|
31552
31620
|
migrate(migrations, session, config) {
|
31553
31621
|
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
31554
31622
|
const migrationTableCreate = sql`
|
@@ -31582,8 +31650,8 @@ var init_dialect2 = __esm({
|
|
31582
31650
|
}
|
31583
31651
|
}
|
31584
31652
|
};
|
31585
|
-
__publicField(SQLiteSyncDialect,
|
31586
|
-
SQLiteAsyncDialect = class extends (
|
31653
|
+
__publicField(SQLiteSyncDialect, _a199, "SQLiteSyncDialect");
|
31654
|
+
SQLiteAsyncDialect = class extends (_b144 = SQLiteDialect, _a200 = entityKind, _b144) {
|
31587
31655
|
async migrate(migrations, session, config) {
|
31588
31656
|
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
|
31589
31657
|
const migrationTableCreate = sql`
|
@@ -31612,7 +31680,7 @@ var init_dialect2 = __esm({
|
|
31612
31680
|
});
|
31613
31681
|
}
|
31614
31682
|
};
|
31615
|
-
__publicField(SQLiteAsyncDialect,
|
31683
|
+
__publicField(SQLiteAsyncDialect, _a200, "SQLiteAsyncDialect");
|
31616
31684
|
}
|
31617
31685
|
});
|
31618
31686
|
|
@@ -31634,7 +31702,7 @@ function createSetOperator2(type, isAll) {
|
|
31634
31702
|
return leftSelect.addSetOperators(setOperators);
|
31635
31703
|
};
|
31636
31704
|
}
|
31637
|
-
var
|
31705
|
+
var _a201, SQLiteSelectBuilder, _a202, _b145, SQLiteSelectQueryBuilderBase, _a203, _b146, SQLiteSelectBase, getSQLiteSetOperators, union2, unionAll2, intersect2, except2;
|
31638
31706
|
var init_select3 = __esm({
|
31639
31707
|
"../drizzle-orm/dist/sqlite-core/query-builders/select.js"() {
|
31640
31708
|
"use strict";
|
@@ -31648,7 +31716,7 @@ var init_select3 = __esm({
|
|
31648
31716
|
init_utils2();
|
31649
31717
|
init_view_common();
|
31650
31718
|
init_view_base2();
|
31651
|
-
|
31719
|
+
_a201 = entityKind;
|
31652
31720
|
SQLiteSelectBuilder = class {
|
31653
31721
|
constructor(config) {
|
31654
31722
|
__publicField(this, "fields");
|
@@ -31689,8 +31757,8 @@ var init_select3 = __esm({
|
|
31689
31757
|
});
|
31690
31758
|
}
|
31691
31759
|
};
|
31692
|
-
__publicField(SQLiteSelectBuilder,
|
31693
|
-
SQLiteSelectQueryBuilderBase = class extends (
|
31760
|
+
__publicField(SQLiteSelectBuilder, _a201, "SQLiteSelectBuilder");
|
31761
|
+
SQLiteSelectQueryBuilderBase = class extends (_b145 = TypedQueryBuilder, _a202 = entityKind, _b145) {
|
31694
31762
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
31695
31763
|
super();
|
31696
31764
|
__publicField(this, "_");
|
@@ -32195,8 +32263,8 @@ var init_select3 = __esm({
|
|
32195
32263
|
return this;
|
32196
32264
|
}
|
32197
32265
|
};
|
32198
|
-
__publicField(SQLiteSelectQueryBuilderBase,
|
32199
|
-
SQLiteSelectBase = class extends (
|
32266
|
+
__publicField(SQLiteSelectQueryBuilderBase, _a202, "SQLiteSelectQueryBuilder");
|
32267
|
+
SQLiteSelectBase = class extends (_b146 = SQLiteSelectQueryBuilderBase, _a203 = entityKind, _b146) {
|
32200
32268
|
constructor() {
|
32201
32269
|
super(...arguments);
|
32202
32270
|
__publicField(this, "run", (placeholderValues) => {
|
@@ -32234,7 +32302,7 @@ var init_select3 = __esm({
|
|
32234
32302
|
return this.all();
|
32235
32303
|
}
|
32236
32304
|
};
|
32237
|
-
__publicField(SQLiteSelectBase,
|
32305
|
+
__publicField(SQLiteSelectBase, _a203, "SQLiteSelect");
|
32238
32306
|
applyMixins(SQLiteSelectBase, [QueryPromise]);
|
32239
32307
|
getSQLiteSetOperators = () => ({
|
32240
32308
|
union: union2,
|
@@ -32250,7 +32318,7 @@ var init_select3 = __esm({
|
|
32250
32318
|
});
|
32251
32319
|
|
32252
32320
|
// ../drizzle-orm/dist/sqlite-core/query-builders/query-builder.js
|
32253
|
-
var
|
32321
|
+
var _a204, QueryBuilder2;
|
32254
32322
|
var init_query_builder3 = __esm({
|
32255
32323
|
"../drizzle-orm/dist/sqlite-core/query-builders/query-builder.js"() {
|
32256
32324
|
"use strict";
|
@@ -32259,7 +32327,7 @@ var init_query_builder3 = __esm({
|
|
32259
32327
|
init_dialect2();
|
32260
32328
|
init_subquery();
|
32261
32329
|
init_select3();
|
32262
|
-
|
32330
|
+
_a204 = entityKind;
|
32263
32331
|
QueryBuilder2 = class {
|
32264
32332
|
constructor(dialect4) {
|
32265
32333
|
__publicField(this, "dialect");
|
@@ -32321,7 +32389,185 @@ var init_query_builder3 = __esm({
|
|
32321
32389
|
return this.dialect;
|
32322
32390
|
}
|
32323
32391
|
};
|
32324
|
-
__publicField(QueryBuilder2,
|
32392
|
+
__publicField(QueryBuilder2, _a204, "SQLiteQueryBuilder");
|
32393
|
+
}
|
32394
|
+
});
|
32395
|
+
|
32396
|
+
// ../drizzle-orm/dist/sqlite-core/query-builders/insert.js
|
32397
|
+
var _a205, SQLiteInsertBuilder, _a206, _b147, SQLiteInsertBase;
|
32398
|
+
var init_insert2 = __esm({
|
32399
|
+
"../drizzle-orm/dist/sqlite-core/query-builders/insert.js"() {
|
32400
|
+
"use strict";
|
32401
|
+
init_entity();
|
32402
|
+
init_query_promise();
|
32403
|
+
init_sql();
|
32404
|
+
init_table3();
|
32405
|
+
init_table();
|
32406
|
+
init_utils2();
|
32407
|
+
init_query_builder3();
|
32408
|
+
_a205 = entityKind;
|
32409
|
+
SQLiteInsertBuilder = class {
|
32410
|
+
constructor(table4, session, dialect4, withList) {
|
32411
|
+
this.table = table4;
|
32412
|
+
this.session = session;
|
32413
|
+
this.dialect = dialect4;
|
32414
|
+
this.withList = withList;
|
32415
|
+
}
|
32416
|
+
values(values) {
|
32417
|
+
values = Array.isArray(values) ? values : [values];
|
32418
|
+
if (values.length === 0) {
|
32419
|
+
throw new Error("values() must be called with at least one value");
|
32420
|
+
}
|
32421
|
+
const mappedValues = values.map((entry) => {
|
32422
|
+
const result = {};
|
32423
|
+
const cols = this.table[Table2.Symbol.Columns];
|
32424
|
+
for (const colKey of Object.keys(entry)) {
|
32425
|
+
const colValue = entry[colKey];
|
32426
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
32427
|
+
}
|
32428
|
+
return result;
|
32429
|
+
});
|
32430
|
+
return new SQLiteInsertBase(this.table, mappedValues, this.session, this.dialect, this.withList);
|
32431
|
+
}
|
32432
|
+
select(selectQuery) {
|
32433
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder2()) : selectQuery;
|
32434
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
32435
|
+
throw new Error(
|
32436
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
32437
|
+
);
|
32438
|
+
}
|
32439
|
+
return new SQLiteInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
|
32440
|
+
}
|
32441
|
+
};
|
32442
|
+
__publicField(SQLiteInsertBuilder, _a205, "SQLiteInsertBuilder");
|
32443
|
+
SQLiteInsertBase = class extends (_b147 = QueryPromise, _a206 = entityKind, _b147) {
|
32444
|
+
constructor(table4, values, session, dialect4, withList, select) {
|
32445
|
+
super();
|
32446
|
+
/** @internal */
|
32447
|
+
__publicField(this, "config");
|
32448
|
+
__publicField(this, "run", (placeholderValues) => {
|
32449
|
+
return this._prepare().run(placeholderValues);
|
32450
|
+
});
|
32451
|
+
__publicField(this, "all", (placeholderValues) => {
|
32452
|
+
return this._prepare().all(placeholderValues);
|
32453
|
+
});
|
32454
|
+
__publicField(this, "get", (placeholderValues) => {
|
32455
|
+
return this._prepare().get(placeholderValues);
|
32456
|
+
});
|
32457
|
+
__publicField(this, "values", (placeholderValues) => {
|
32458
|
+
return this._prepare().values(placeholderValues);
|
32459
|
+
});
|
32460
|
+
this.session = session;
|
32461
|
+
this.dialect = dialect4;
|
32462
|
+
this.config = { table: table4, values, withList, select };
|
32463
|
+
}
|
32464
|
+
returning(fields = this.config.table[SQLiteTable.Symbol.Columns]) {
|
32465
|
+
this.config.returning = orderSelectedFields(fields);
|
32466
|
+
return this;
|
32467
|
+
}
|
32468
|
+
/**
|
32469
|
+
* Adds an `on conflict do nothing` clause to the query.
|
32470
|
+
*
|
32471
|
+
* Calling this method simply avoids inserting a row as its alternative action.
|
32472
|
+
*
|
32473
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-conflict-do-nothing}
|
32474
|
+
*
|
32475
|
+
* @param config The `target` and `where` clauses.
|
32476
|
+
*
|
32477
|
+
* @example
|
32478
|
+
* ```ts
|
32479
|
+
* // Insert one row and cancel the insert if there's a conflict
|
32480
|
+
* await db.insert(cars)
|
32481
|
+
* .values({ id: 1, brand: 'BMW' })
|
32482
|
+
* .onConflictDoNothing();
|
32483
|
+
*
|
32484
|
+
* // Explicitly specify conflict target
|
32485
|
+
* await db.insert(cars)
|
32486
|
+
* .values({ id: 1, brand: 'BMW' })
|
32487
|
+
* .onConflictDoNothing({ target: cars.id });
|
32488
|
+
* ```
|
32489
|
+
*/
|
32490
|
+
onConflictDoNothing(config = {}) {
|
32491
|
+
if (config.target === void 0) {
|
32492
|
+
this.config.onConflict = sql`do nothing`;
|
32493
|
+
} else {
|
32494
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
32495
|
+
const whereSql = config.where ? sql` where ${config.where}` : sql``;
|
32496
|
+
this.config.onConflict = sql`${targetSql} do nothing${whereSql}`;
|
32497
|
+
}
|
32498
|
+
return this;
|
32499
|
+
}
|
32500
|
+
/**
|
32501
|
+
* Adds an `on conflict do update` clause to the query.
|
32502
|
+
*
|
32503
|
+
* Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.
|
32504
|
+
*
|
32505
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#upserts-and-conflicts}
|
32506
|
+
*
|
32507
|
+
* @param config The `target`, `set` and `where` clauses.
|
32508
|
+
*
|
32509
|
+
* @example
|
32510
|
+
* ```ts
|
32511
|
+
* // Update the row if there's a conflict
|
32512
|
+
* await db.insert(cars)
|
32513
|
+
* .values({ id: 1, brand: 'BMW' })
|
32514
|
+
* .onConflictDoUpdate({
|
32515
|
+
* target: cars.id,
|
32516
|
+
* set: { brand: 'Porsche' }
|
32517
|
+
* });
|
32518
|
+
*
|
32519
|
+
* // Upsert with 'where' clause
|
32520
|
+
* await db.insert(cars)
|
32521
|
+
* .values({ id: 1, brand: 'BMW' })
|
32522
|
+
* .onConflictDoUpdate({
|
32523
|
+
* target: cars.id,
|
32524
|
+
* set: { brand: 'newBMW' },
|
32525
|
+
* where: sql`${cars.createdAt} > '2023-01-01'::date`,
|
32526
|
+
* });
|
32527
|
+
* ```
|
32528
|
+
*/
|
32529
|
+
onConflictDoUpdate(config) {
|
32530
|
+
if (config.where && (config.targetWhere || config.setWhere)) {
|
32531
|
+
throw new Error(
|
32532
|
+
'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.'
|
32533
|
+
);
|
32534
|
+
}
|
32535
|
+
const whereSql = config.where ? sql` where ${config.where}` : void 0;
|
32536
|
+
const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : void 0;
|
32537
|
+
const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : void 0;
|
32538
|
+
const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
|
32539
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
32540
|
+
this.config.onConflict = sql`${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`;
|
32541
|
+
return this;
|
32542
|
+
}
|
32543
|
+
/** @internal */
|
32544
|
+
getSQL() {
|
32545
|
+
return this.dialect.buildInsertQuery(this.config);
|
32546
|
+
}
|
32547
|
+
toSQL() {
|
32548
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
32549
|
+
return rest;
|
32550
|
+
}
|
32551
|
+
/** @internal */
|
32552
|
+
_prepare(isOneTimeQuery = true) {
|
32553
|
+
return this.session[isOneTimeQuery ? "prepareOneTimeQuery" : "prepareQuery"](
|
32554
|
+
this.dialect.sqlToQuery(this.getSQL()),
|
32555
|
+
this.config.returning,
|
32556
|
+
this.config.returning ? "all" : "run",
|
32557
|
+
true
|
32558
|
+
);
|
32559
|
+
}
|
32560
|
+
prepare() {
|
32561
|
+
return this._prepare(false);
|
32562
|
+
}
|
32563
|
+
async execute() {
|
32564
|
+
return this.config.returning ? this.all() : this.run();
|
32565
|
+
}
|
32566
|
+
$dynamic() {
|
32567
|
+
return this;
|
32568
|
+
}
|
32569
|
+
};
|
32570
|
+
__publicField(SQLiteInsertBase, _a206, "SQLiteInsert");
|
32325
32571
|
}
|
32326
32572
|
});
|
32327
32573
|
|
@@ -32341,8 +32587,11 @@ var init_update2 = __esm({
|
|
32341
32587
|
init_query_promise();
|
32342
32588
|
init_selection_proxy();
|
32343
32589
|
init_table3();
|
32590
|
+
init_subquery();
|
32344
32591
|
init_table();
|
32345
32592
|
init_utils2();
|
32593
|
+
init_view_common();
|
32594
|
+
init_view_base2();
|
32346
32595
|
_a207 = entityKind;
|
32347
32596
|
SQLiteUpdateBuilder = class {
|
32348
32597
|
constructor(table4, session, dialect4, withList) {
|
@@ -32367,6 +32616,10 @@ var init_update2 = __esm({
|
|
32367
32616
|
super();
|
32368
32617
|
/** @internal */
|
32369
32618
|
__publicField(this, "config");
|
32619
|
+
__publicField(this, "leftJoin", this.createJoin("left"));
|
32620
|
+
__publicField(this, "rightJoin", this.createJoin("right"));
|
32621
|
+
__publicField(this, "innerJoin", this.createJoin("inner"));
|
32622
|
+
__publicField(this, "fullJoin", this.createJoin("full"));
|
32370
32623
|
__publicField(this, "run", (placeholderValues) => {
|
32371
32624
|
return this._prepare().run(placeholderValues);
|
32372
32625
|
});
|
@@ -32381,7 +32634,34 @@ var init_update2 = __esm({
|
|
32381
32634
|
});
|
32382
32635
|
this.session = session;
|
32383
32636
|
this.dialect = dialect4;
|
32384
|
-
this.config = { set, table: table4, withList };
|
32637
|
+
this.config = { set, table: table4, withList, joins: [] };
|
32638
|
+
}
|
32639
|
+
from(source) {
|
32640
|
+
this.config.from = source;
|
32641
|
+
return this;
|
32642
|
+
}
|
32643
|
+
createJoin(joinType) {
|
32644
|
+
return (table4, on) => {
|
32645
|
+
const tableName = getTableLikeName(table4);
|
32646
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
32647
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
32648
|
+
}
|
32649
|
+
if (typeof on === "function") {
|
32650
|
+
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;
|
32651
|
+
on = on(
|
32652
|
+
new Proxy(
|
32653
|
+
this.config.table[Table2.Symbol.Columns],
|
32654
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
32655
|
+
),
|
32656
|
+
from && new Proxy(
|
32657
|
+
from,
|
32658
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
32659
|
+
)
|
32660
|
+
);
|
32661
|
+
}
|
32662
|
+
this.config.joins.push({ on, table: table4, joinType, alias: tableName });
|
32663
|
+
return this;
|
32664
|
+
};
|
32385
32665
|
}
|
32386
32666
|
/**
|
32387
32667
|
* Adds a 'where' clause to the query.
|
@@ -35679,131 +35959,6 @@ var init_delete3 = __esm({
|
|
35679
35959
|
}
|
35680
35960
|
});
|
35681
35961
|
|
35682
|
-
// ../drizzle-orm/dist/mysql-core/query-builders/insert.js
|
35683
|
-
var _a299, MySqlInsertBuilder, _a300, _b222, MySqlInsertBase;
|
35684
|
-
var init_insert3 = __esm({
|
35685
|
-
"../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
|
35686
|
-
"use strict";
|
35687
|
-
init_entity();
|
35688
|
-
init_query_promise();
|
35689
|
-
init_sql();
|
35690
|
-
init_table();
|
35691
|
-
init_utils2();
|
35692
|
-
_a299 = entityKind;
|
35693
|
-
MySqlInsertBuilder = class {
|
35694
|
-
constructor(table4, session, dialect4) {
|
35695
|
-
__publicField(this, "shouldIgnore", false);
|
35696
|
-
this.table = table4;
|
35697
|
-
this.session = session;
|
35698
|
-
this.dialect = dialect4;
|
35699
|
-
}
|
35700
|
-
ignore() {
|
35701
|
-
this.shouldIgnore = true;
|
35702
|
-
return this;
|
35703
|
-
}
|
35704
|
-
values(values) {
|
35705
|
-
values = Array.isArray(values) ? values : [values];
|
35706
|
-
if (values.length === 0) {
|
35707
|
-
throw new Error("values() must be called with at least one value");
|
35708
|
-
}
|
35709
|
-
const mappedValues = values.map((entry) => {
|
35710
|
-
const result = {};
|
35711
|
-
const cols = this.table[Table2.Symbol.Columns];
|
35712
|
-
for (const colKey of Object.keys(entry)) {
|
35713
|
-
const colValue = entry[colKey];
|
35714
|
-
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
35715
|
-
}
|
35716
|
-
return result;
|
35717
|
-
});
|
35718
|
-
return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
|
35719
|
-
}
|
35720
|
-
};
|
35721
|
-
__publicField(MySqlInsertBuilder, _a299, "MySqlInsertBuilder");
|
35722
|
-
MySqlInsertBase = class extends (_b222 = QueryPromise, _a300 = entityKind, _b222) {
|
35723
|
-
constructor(table4, values, ignore, session, dialect4) {
|
35724
|
-
super();
|
35725
|
-
__publicField(this, "config");
|
35726
|
-
__publicField(this, "execute", (placeholderValues) => {
|
35727
|
-
return this.prepare().execute(placeholderValues);
|
35728
|
-
});
|
35729
|
-
__publicField(this, "createIterator", () => {
|
35730
|
-
const self2 = this;
|
35731
|
-
return async function* (placeholderValues) {
|
35732
|
-
yield* self2.prepare().iterator(placeholderValues);
|
35733
|
-
};
|
35734
|
-
});
|
35735
|
-
__publicField(this, "iterator", this.createIterator());
|
35736
|
-
this.session = session;
|
35737
|
-
this.dialect = dialect4;
|
35738
|
-
this.config = { table: table4, values, ignore };
|
35739
|
-
}
|
35740
|
-
/**
|
35741
|
-
* Adds an `on duplicate key update` clause to the query.
|
35742
|
-
*
|
35743
|
-
* 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.
|
35744
|
-
*
|
35745
|
-
* See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
|
35746
|
-
*
|
35747
|
-
* @param config The `set` clause
|
35748
|
-
*
|
35749
|
-
* @example
|
35750
|
-
* ```ts
|
35751
|
-
* await db.insert(cars)
|
35752
|
-
* .values({ id: 1, brand: 'BMW'})
|
35753
|
-
* .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
|
35754
|
-
* ```
|
35755
|
-
*
|
35756
|
-
* 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:
|
35757
|
-
*
|
35758
|
-
* ```ts
|
35759
|
-
* import { sql } from 'drizzle-orm';
|
35760
|
-
*
|
35761
|
-
* await db.insert(cars)
|
35762
|
-
* .values({ id: 1, brand: 'BMW' })
|
35763
|
-
* .onDuplicateKeyUpdate({ set: { id: sql`id` } });
|
35764
|
-
* ```
|
35765
|
-
*/
|
35766
|
-
onDuplicateKeyUpdate(config) {
|
35767
|
-
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
35768
|
-
this.config.onConflict = sql`update ${setSql}`;
|
35769
|
-
return this;
|
35770
|
-
}
|
35771
|
-
$returningId() {
|
35772
|
-
const returning = [];
|
35773
|
-
for (const [key, value] of Object.entries(this.config.table[Table2.Symbol.Columns])) {
|
35774
|
-
if (value.primary) {
|
35775
|
-
returning.push({ field: value, path: [key] });
|
35776
|
-
}
|
35777
|
-
}
|
35778
|
-
this.config.returning = orderSelectedFields(this.config.table[Table2.Symbol.Columns]);
|
35779
|
-
return this;
|
35780
|
-
}
|
35781
|
-
/** @internal */
|
35782
|
-
getSQL() {
|
35783
|
-
return this.dialect.buildInsertQuery(this.config).sql;
|
35784
|
-
}
|
35785
|
-
toSQL() {
|
35786
|
-
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
35787
|
-
return rest;
|
35788
|
-
}
|
35789
|
-
prepare() {
|
35790
|
-
const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
|
35791
|
-
return this.session.prepareQuery(
|
35792
|
-
this.dialect.sqlToQuery(sql2),
|
35793
|
-
void 0,
|
35794
|
-
void 0,
|
35795
|
-
generatedIds,
|
35796
|
-
this.config.returning
|
35797
|
-
);
|
35798
|
-
}
|
35799
|
-
$dynamic() {
|
35800
|
-
return this;
|
35801
|
-
}
|
35802
|
-
};
|
35803
|
-
__publicField(MySqlInsertBase, _a300, "MySqlInsert");
|
35804
|
-
}
|
35805
|
-
});
|
35806
|
-
|
35807
35962
|
// ../drizzle-orm/dist/mysql-core/columns/all.js
|
35808
35963
|
function getMySqlColumnBuilders() {
|
35809
35964
|
return {
|
@@ -35884,7 +36039,7 @@ function mysqlTableWithSchema(name2, columns, extraConfig, schema4, baseName = n
|
|
35884
36039
|
}
|
35885
36040
|
return table4;
|
35886
36041
|
}
|
35887
|
-
var InlineForeignKeys3,
|
36042
|
+
var InlineForeignKeys3, _a299, _b222, _c9, _d4, _e4, MySqlTable, mysqlTable;
|
35888
36043
|
var init_table4 = __esm({
|
35889
36044
|
"../drizzle-orm/dist/mysql-core/table.js"() {
|
35890
36045
|
"use strict";
|
@@ -35892,15 +36047,15 @@ var init_table4 = __esm({
|
|
35892
36047
|
init_table();
|
35893
36048
|
init_all3();
|
35894
36049
|
InlineForeignKeys3 = Symbol.for("drizzle:MySqlInlineForeignKeys");
|
35895
|
-
MySqlTable = class extends (_e4 = Table2, _d4 = entityKind, _c9 = Table2.Symbol.Columns,
|
36050
|
+
MySqlTable = class extends (_e4 = Table2, _d4 = entityKind, _c9 = Table2.Symbol.Columns, _b222 = InlineForeignKeys3, _a299 = Table2.Symbol.ExtraConfigBuilder, _e4) {
|
35896
36051
|
constructor() {
|
35897
36052
|
super(...arguments);
|
35898
36053
|
/** @internal */
|
35899
36054
|
__publicField(this, _c9);
|
35900
36055
|
/** @internal */
|
35901
|
-
__publicField(this,
|
36056
|
+
__publicField(this, _b222, []);
|
35902
36057
|
/** @internal */
|
35903
|
-
__publicField(this,
|
36058
|
+
__publicField(this, _a299);
|
35904
36059
|
}
|
35905
36060
|
};
|
35906
36061
|
__publicField(MySqlTable, _d4, "MySqlTable");
|
@@ -35915,20 +36070,20 @@ var init_table4 = __esm({
|
|
35915
36070
|
});
|
35916
36071
|
|
35917
36072
|
// ../drizzle-orm/dist/mysql-core/view-base.js
|
35918
|
-
var
|
36073
|
+
var _a300, _b223, MySqlViewBase;
|
35919
36074
|
var init_view_base3 = __esm({
|
35920
36075
|
"../drizzle-orm/dist/mysql-core/view-base.js"() {
|
35921
36076
|
"use strict";
|
35922
36077
|
init_entity();
|
35923
36078
|
init_sql();
|
35924
|
-
MySqlViewBase = class extends (
|
36079
|
+
MySqlViewBase = class extends (_b223 = View3, _a300 = entityKind, _b223) {
|
35925
36080
|
};
|
35926
|
-
__publicField(MySqlViewBase,
|
36081
|
+
__publicField(MySqlViewBase, _a300, "MySqlViewBase");
|
35927
36082
|
}
|
35928
36083
|
});
|
35929
36084
|
|
35930
36085
|
// ../drizzle-orm/dist/mysql-core/dialect.js
|
35931
|
-
var
|
36086
|
+
var _a301, MySqlDialect;
|
35932
36087
|
var init_dialect3 = __esm({
|
35933
36088
|
"../drizzle-orm/dist/mysql-core/dialect.js"() {
|
35934
36089
|
"use strict";
|
@@ -35947,7 +36102,7 @@ var init_dialect3 = __esm({
|
|
35947
36102
|
init_common4();
|
35948
36103
|
init_table4();
|
35949
36104
|
init_view_base3();
|
35950
|
-
|
36105
|
+
_a301 = entityKind;
|
35951
36106
|
MySqlDialect = class {
|
35952
36107
|
constructor(config) {
|
35953
36108
|
/** @internal */
|
@@ -36230,7 +36385,7 @@ var init_dialect3 = __esm({
|
|
36230
36385
|
const offsetSql = offset ? sql` offset ${offset}` : void 0;
|
36231
36386
|
return sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;
|
36232
36387
|
}
|
36233
|
-
buildInsertQuery({ table: table4, values, ignore, onConflict }) {
|
36388
|
+
buildInsertQuery({ table: table4, values: valuesOrSelect, ignore, onConflict, select }) {
|
36234
36389
|
const valuesSqlList = [];
|
36235
36390
|
const columns = table4[Table2.Symbol.Columns];
|
36236
36391
|
const colEntries = Object.entries(columns).filter(
|
@@ -36238,42 +36393,53 @@ var init_dialect3 = __esm({
|
|
36238
36393
|
);
|
36239
36394
|
const insertOrder = colEntries.map(([, column4]) => sql.identifier(this.casing.getColumnCasing(column4)));
|
36240
36395
|
const generatedIdsResponse = [];
|
36241
|
-
|
36242
|
-
const
|
36243
|
-
|
36244
|
-
|
36245
|
-
|
36246
|
-
|
36247
|
-
|
36248
|
-
|
36249
|
-
|
36250
|
-
|
36251
|
-
|
36252
|
-
|
36253
|
-
|
36254
|
-
|
36255
|
-
|
36396
|
+
if (select) {
|
36397
|
+
const select2 = valuesOrSelect;
|
36398
|
+
if (is(select2, SQL)) {
|
36399
|
+
valuesSqlList.push(select2);
|
36400
|
+
} else {
|
36401
|
+
valuesSqlList.push(select2.getSQL());
|
36402
|
+
}
|
36403
|
+
} else {
|
36404
|
+
const values = valuesOrSelect;
|
36405
|
+
valuesSqlList.push(sql.raw("values "));
|
36406
|
+
for (const [valueIndex, value] of values.entries()) {
|
36407
|
+
const generatedIds = {};
|
36408
|
+
const valueList = [];
|
36409
|
+
for (const [fieldName, col] of colEntries) {
|
36410
|
+
const colValue = value[fieldName];
|
36411
|
+
if (colValue === void 0 || is(colValue, Param) && colValue.value === void 0) {
|
36412
|
+
if (col.defaultFn !== void 0) {
|
36413
|
+
const defaultFnResult = col.defaultFn();
|
36414
|
+
generatedIds[fieldName] = defaultFnResult;
|
36415
|
+
const defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);
|
36416
|
+
valueList.push(defaultValue);
|
36417
|
+
} else if (!col.default && col.onUpdateFn !== void 0) {
|
36418
|
+
const onUpdateFnResult = col.onUpdateFn();
|
36419
|
+
const newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);
|
36420
|
+
valueList.push(newValue);
|
36421
|
+
} else {
|
36422
|
+
valueList.push(sql`default`);
|
36423
|
+
}
|
36256
36424
|
} else {
|
36257
|
-
|
36258
|
-
|
36259
|
-
|
36260
|
-
|
36261
|
-
generatedIds[fieldName] = colValue.value;
|
36425
|
+
if (col.defaultFn && is(colValue, Param)) {
|
36426
|
+
generatedIds[fieldName] = colValue.value;
|
36427
|
+
}
|
36428
|
+
valueList.push(colValue);
|
36262
36429
|
}
|
36263
|
-
valueList.push(colValue);
|
36264
36430
|
}
|
36265
|
-
|
36266
|
-
|
36267
|
-
|
36268
|
-
|
36269
|
-
|
36431
|
+
generatedIdsResponse.push(generatedIds);
|
36432
|
+
valuesSqlList.push(valueList);
|
36433
|
+
if (valueIndex < values.length - 1) {
|
36434
|
+
valuesSqlList.push(sql`, `);
|
36435
|
+
}
|
36270
36436
|
}
|
36271
36437
|
}
|
36272
36438
|
const valuesSql = sql.join(valuesSqlList);
|
36273
36439
|
const ignoreSql = ignore ? sql` ignore` : void 0;
|
36274
36440
|
const onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : void 0;
|
36275
36441
|
return {
|
36276
|
-
sql: sql`insert${ignoreSql} into ${table4} ${insertOrder}
|
36442
|
+
sql: sql`insert${ignoreSql} into ${table4} ${insertOrder} ${valuesSql}${onConflictSql}`,
|
36277
36443
|
generatedIds: generatedIdsResponse
|
36278
36444
|
};
|
36279
36445
|
}
|
@@ -36733,7 +36899,7 @@ var init_dialect3 = __esm({
|
|
36733
36899
|
};
|
36734
36900
|
}
|
36735
36901
|
};
|
36736
|
-
__publicField(MySqlDialect,
|
36902
|
+
__publicField(MySqlDialect, _a301, "MySqlDialect");
|
36737
36903
|
}
|
36738
36904
|
});
|
36739
36905
|
|
@@ -36755,7 +36921,7 @@ function createSetOperator3(type, isAll) {
|
|
36755
36921
|
return leftSelect.addSetOperators(setOperators);
|
36756
36922
|
};
|
36757
36923
|
}
|
36758
|
-
var
|
36924
|
+
var _a302, MySqlSelectBuilder, _a303, _b224, MySqlSelectQueryBuilderBase, _a304, _b225, MySqlSelectBase, getMySqlSetOperators, union3, unionAll3, intersect3, intersectAll2, except3, exceptAll2;
|
36759
36925
|
var init_select4 = __esm({
|
36760
36926
|
"../drizzle-orm/dist/mysql-core/query-builders/select.js"() {
|
36761
36927
|
"use strict";
|
@@ -36770,7 +36936,7 @@ var init_select4 = __esm({
|
|
36770
36936
|
init_utils2();
|
36771
36937
|
init_view_common();
|
36772
36938
|
init_view_base3();
|
36773
|
-
|
36939
|
+
_a302 = entityKind;
|
36774
36940
|
MySqlSelectBuilder = class {
|
36775
36941
|
constructor(config) {
|
36776
36942
|
__publicField(this, "fields");
|
@@ -36815,8 +36981,8 @@ var init_select4 = __esm({
|
|
36815
36981
|
);
|
36816
36982
|
}
|
36817
36983
|
};
|
36818
|
-
__publicField(MySqlSelectBuilder,
|
36819
|
-
MySqlSelectQueryBuilderBase = class extends (
|
36984
|
+
__publicField(MySqlSelectBuilder, _a302, "MySqlSelectBuilder");
|
36985
|
+
MySqlSelectQueryBuilderBase = class extends (_b224 = TypedQueryBuilder, _a303 = entityKind, _b224) {
|
36820
36986
|
constructor({ table: table4, fields, isPartialSelect, session, dialect: dialect4, withList, distinct }) {
|
36821
36987
|
super();
|
36822
36988
|
__publicField(this, "_");
|
@@ -37417,8 +37583,8 @@ var init_select4 = __esm({
|
|
37417
37583
|
return this;
|
37418
37584
|
}
|
37419
37585
|
};
|
37420
|
-
__publicField(MySqlSelectQueryBuilderBase,
|
37421
|
-
MySqlSelectBase = class extends (
|
37586
|
+
__publicField(MySqlSelectQueryBuilderBase, _a303, "MySqlSelectQueryBuilder");
|
37587
|
+
MySqlSelectBase = class extends (_b225 = MySqlSelectQueryBuilderBase, _a304 = entityKind, _b225) {
|
37422
37588
|
constructor() {
|
37423
37589
|
super(...arguments);
|
37424
37590
|
__publicField(this, "execute", (placeholderValues) => {
|
@@ -37442,7 +37608,7 @@ var init_select4 = __esm({
|
|
37442
37608
|
return query;
|
37443
37609
|
}
|
37444
37610
|
};
|
37445
|
-
__publicField(MySqlSelectBase,
|
37611
|
+
__publicField(MySqlSelectBase, _a304, "MySqlSelect");
|
37446
37612
|
applyMixins(MySqlSelectBase, [QueryPromise]);
|
37447
37613
|
getMySqlSetOperators = () => ({
|
37448
37614
|
union: union3,
|
@@ -37462,7 +37628,7 @@ var init_select4 = __esm({
|
|
37462
37628
|
});
|
37463
37629
|
|
37464
37630
|
// ../drizzle-orm/dist/mysql-core/query-builders/query-builder.js
|
37465
|
-
var
|
37631
|
+
var _a305, QueryBuilder3;
|
37466
37632
|
var init_query_builder4 = __esm({
|
37467
37633
|
"../drizzle-orm/dist/mysql-core/query-builders/query-builder.js"() {
|
37468
37634
|
"use strict";
|
@@ -37471,7 +37637,7 @@ var init_query_builder4 = __esm({
|
|
37471
37637
|
init_selection_proxy();
|
37472
37638
|
init_subquery();
|
37473
37639
|
init_select4();
|
37474
|
-
|
37640
|
+
_a305 = entityKind;
|
37475
37641
|
QueryBuilder3 = class {
|
37476
37642
|
constructor(dialect4) {
|
37477
37643
|
__publicField(this, "dialect");
|
@@ -37533,7 +37699,142 @@ var init_query_builder4 = __esm({
|
|
37533
37699
|
return this.dialect;
|
37534
37700
|
}
|
37535
37701
|
};
|
37536
|
-
__publicField(QueryBuilder3,
|
37702
|
+
__publicField(QueryBuilder3, _a305, "MySqlQueryBuilder");
|
37703
|
+
}
|
37704
|
+
});
|
37705
|
+
|
37706
|
+
// ../drizzle-orm/dist/mysql-core/query-builders/insert.js
|
37707
|
+
var _a306, MySqlInsertBuilder, _a307, _b226, MySqlInsertBase;
|
37708
|
+
var init_insert3 = __esm({
|
37709
|
+
"../drizzle-orm/dist/mysql-core/query-builders/insert.js"() {
|
37710
|
+
"use strict";
|
37711
|
+
init_entity();
|
37712
|
+
init_query_promise();
|
37713
|
+
init_sql();
|
37714
|
+
init_table();
|
37715
|
+
init_utils2();
|
37716
|
+
init_query_builder4();
|
37717
|
+
_a306 = entityKind;
|
37718
|
+
MySqlInsertBuilder = class {
|
37719
|
+
constructor(table4, session, dialect4) {
|
37720
|
+
__publicField(this, "shouldIgnore", false);
|
37721
|
+
this.table = table4;
|
37722
|
+
this.session = session;
|
37723
|
+
this.dialect = dialect4;
|
37724
|
+
}
|
37725
|
+
ignore() {
|
37726
|
+
this.shouldIgnore = true;
|
37727
|
+
return this;
|
37728
|
+
}
|
37729
|
+
values(values) {
|
37730
|
+
values = Array.isArray(values) ? values : [values];
|
37731
|
+
if (values.length === 0) {
|
37732
|
+
throw new Error("values() must be called with at least one value");
|
37733
|
+
}
|
37734
|
+
const mappedValues = values.map((entry) => {
|
37735
|
+
const result = {};
|
37736
|
+
const cols = this.table[Table2.Symbol.Columns];
|
37737
|
+
for (const colKey of Object.keys(entry)) {
|
37738
|
+
const colValue = entry[colKey];
|
37739
|
+
result[colKey] = is(colValue, SQL) ? colValue : new Param(colValue, cols[colKey]);
|
37740
|
+
}
|
37741
|
+
return result;
|
37742
|
+
});
|
37743
|
+
return new MySqlInsertBase(this.table, mappedValues, this.shouldIgnore, this.session, this.dialect);
|
37744
|
+
}
|
37745
|
+
select(selectQuery) {
|
37746
|
+
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder3()) : selectQuery;
|
37747
|
+
if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
|
37748
|
+
throw new Error(
|
37749
|
+
"Insert select error: selected fields are not the same or are in a different order compared to the table definition"
|
37750
|
+
);
|
37751
|
+
}
|
37752
|
+
return new MySqlInsertBase(this.table, select, this.shouldIgnore, this.session, this.dialect, true);
|
37753
|
+
}
|
37754
|
+
};
|
37755
|
+
__publicField(MySqlInsertBuilder, _a306, "MySqlInsertBuilder");
|
37756
|
+
MySqlInsertBase = class extends (_b226 = QueryPromise, _a307 = entityKind, _b226) {
|
37757
|
+
constructor(table4, values, ignore, session, dialect4, select) {
|
37758
|
+
super();
|
37759
|
+
__publicField(this, "config");
|
37760
|
+
__publicField(this, "execute", (placeholderValues) => {
|
37761
|
+
return this.prepare().execute(placeholderValues);
|
37762
|
+
});
|
37763
|
+
__publicField(this, "createIterator", () => {
|
37764
|
+
const self2 = this;
|
37765
|
+
return async function* (placeholderValues) {
|
37766
|
+
yield* self2.prepare().iterator(placeholderValues);
|
37767
|
+
};
|
37768
|
+
});
|
37769
|
+
__publicField(this, "iterator", this.createIterator());
|
37770
|
+
this.session = session;
|
37771
|
+
this.dialect = dialect4;
|
37772
|
+
this.config = { table: table4, values, select, ignore };
|
37773
|
+
}
|
37774
|
+
/**
|
37775
|
+
* Adds an `on duplicate key update` clause to the query.
|
37776
|
+
*
|
37777
|
+
* 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.
|
37778
|
+
*
|
37779
|
+
* See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
|
37780
|
+
*
|
37781
|
+
* @param config The `set` clause
|
37782
|
+
*
|
37783
|
+
* @example
|
37784
|
+
* ```ts
|
37785
|
+
* await db.insert(cars)
|
37786
|
+
* .values({ id: 1, brand: 'BMW'})
|
37787
|
+
* .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
|
37788
|
+
* ```
|
37789
|
+
*
|
37790
|
+
* 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:
|
37791
|
+
*
|
37792
|
+
* ```ts
|
37793
|
+
* import { sql } from 'drizzle-orm';
|
37794
|
+
*
|
37795
|
+
* await db.insert(cars)
|
37796
|
+
* .values({ id: 1, brand: 'BMW' })
|
37797
|
+
* .onDuplicateKeyUpdate({ set: { id: sql`id` } });
|
37798
|
+
* ```
|
37799
|
+
*/
|
37800
|
+
onDuplicateKeyUpdate(config) {
|
37801
|
+
const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
|
37802
|
+
this.config.onConflict = sql`update ${setSql}`;
|
37803
|
+
return this;
|
37804
|
+
}
|
37805
|
+
$returningId() {
|
37806
|
+
const returning = [];
|
37807
|
+
for (const [key, value] of Object.entries(this.config.table[Table2.Symbol.Columns])) {
|
37808
|
+
if (value.primary) {
|
37809
|
+
returning.push({ field: value, path: [key] });
|
37810
|
+
}
|
37811
|
+
}
|
37812
|
+
this.config.returning = returning;
|
37813
|
+
return this;
|
37814
|
+
}
|
37815
|
+
/** @internal */
|
37816
|
+
getSQL() {
|
37817
|
+
return this.dialect.buildInsertQuery(this.config).sql;
|
37818
|
+
}
|
37819
|
+
toSQL() {
|
37820
|
+
const { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());
|
37821
|
+
return rest;
|
37822
|
+
}
|
37823
|
+
prepare() {
|
37824
|
+
const { sql: sql2, generatedIds } = this.dialect.buildInsertQuery(this.config);
|
37825
|
+
return this.session.prepareQuery(
|
37826
|
+
this.dialect.sqlToQuery(sql2),
|
37827
|
+
void 0,
|
37828
|
+
void 0,
|
37829
|
+
generatedIds,
|
37830
|
+
this.config.returning
|
37831
|
+
);
|
37832
|
+
}
|
37833
|
+
$dynamic() {
|
37834
|
+
return this;
|
37835
|
+
}
|
37836
|
+
};
|
37837
|
+
__publicField(MySqlInsertBase, _a307, "MySqlInsert");
|
37537
37838
|
}
|
37538
37839
|
});
|
37539
37840
|
|