drizzle-kit 0.28.0-cc4f208 → 0.28.1-d7e3535
Sign up to get free protection for your applications and to get access to all the features.
- package/api.js +240 -88
- package/api.mjs +240 -88
- package/bin.cjs +1 -1
- package/package.json +1 -1
package/api.js
CHANGED
@@ -21121,7 +21121,7 @@ var version;
|
|
21121
21121
|
var init_version = __esm({
|
21122
21122
|
"../drizzle-orm/dist/version.js"() {
|
21123
21123
|
"use strict";
|
21124
|
-
version = "0.36.
|
21124
|
+
version = "0.36.2";
|
21125
21125
|
}
|
21126
21126
|
});
|
21127
21127
|
|
@@ -22144,7 +22144,7 @@ function haveSameKeys(left, right) {
|
|
22144
22144
|
}
|
22145
22145
|
function mapUpdateSet(table4, values) {
|
22146
22146
|
const entries = Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => {
|
22147
|
-
if (is(value, SQL)) {
|
22147
|
+
if (is(value, SQL) || is(value, Column2)) {
|
22148
22148
|
return [key, value];
|
22149
22149
|
} else {
|
22150
22150
|
return [key, new Param(value, table4[Table2.Symbol.Columns][key])];
|
@@ -24985,12 +24985,19 @@ var init_dialect = __esm({
|
|
24985
24985
|
return [res];
|
24986
24986
|
}));
|
24987
24987
|
}
|
24988
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList }) {
|
24988
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, from, joins }) {
|
24989
24989
|
const withSql = this.buildWithCTE(withList);
|
24990
|
+
const tableName = table4[PgTable.Symbol.Name];
|
24991
|
+
const tableSchema = table4[PgTable.Symbol.Schema];
|
24992
|
+
const origTableName = table4[PgTable.Symbol.OriginalName];
|
24993
|
+
const alias = tableName === origTableName ? void 0 : tableName;
|
24994
|
+
const tableSql = sql`${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}`;
|
24990
24995
|
const setSql = this.buildUpdateSet(table4, set);
|
24991
|
-
const
|
24996
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
24997
|
+
const joinsSql = this.buildJoins(joins);
|
24998
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: !from })}` : void 0;
|
24992
24999
|
const whereSql = where ? sql` where ${where}` : void 0;
|
24993
|
-
return sql`${withSql}update ${
|
25000
|
+
return sql`${withSql}update ${tableSql} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}`;
|
24994
25001
|
}
|
24995
25002
|
/**
|
24996
25003
|
* Builds selection SQL with provided fields/expressions
|
@@ -25042,6 +25049,54 @@ var init_dialect = __esm({
|
|
25042
25049
|
});
|
25043
25050
|
return sql.join(chunks);
|
25044
25051
|
}
|
25052
|
+
buildJoins(joins) {
|
25053
|
+
if (!joins || joins.length === 0) {
|
25054
|
+
return void 0;
|
25055
|
+
}
|
25056
|
+
const joinsArray = [];
|
25057
|
+
for (const [index4, joinMeta] of joins.entries()) {
|
25058
|
+
if (index4 === 0) {
|
25059
|
+
joinsArray.push(sql` `);
|
25060
|
+
}
|
25061
|
+
const table4 = joinMeta.table;
|
25062
|
+
const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
|
25063
|
+
if (is(table4, PgTable)) {
|
25064
|
+
const tableName = table4[PgTable.Symbol.Name];
|
25065
|
+
const tableSchema = table4[PgTable.Symbol.Schema];
|
25066
|
+
const origTableName = table4[PgTable.Symbol.OriginalName];
|
25067
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
25068
|
+
joinsArray.push(
|
25069
|
+
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}`
|
25070
|
+
);
|
25071
|
+
} else if (is(table4, View3)) {
|
25072
|
+
const viewName = table4[ViewBaseConfig].name;
|
25073
|
+
const viewSchema = table4[ViewBaseConfig].schema;
|
25074
|
+
const origViewName = table4[ViewBaseConfig].originalName;
|
25075
|
+
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
25076
|
+
joinsArray.push(
|
25077
|
+
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}`
|
25078
|
+
);
|
25079
|
+
} else {
|
25080
|
+
joinsArray.push(
|
25081
|
+
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table4} on ${joinMeta.on}`
|
25082
|
+
);
|
25083
|
+
}
|
25084
|
+
if (index4 < joins.length - 1) {
|
25085
|
+
joinsArray.push(sql` `);
|
25086
|
+
}
|
25087
|
+
}
|
25088
|
+
return sql.join(joinsArray);
|
25089
|
+
}
|
25090
|
+
buildFromTable(table4) {
|
25091
|
+
if (is(table4, Table2) && table4[Table2.Symbol.OriginalName] !== table4[Table2.Symbol.Name]) {
|
25092
|
+
let fullName = sql`${sql.identifier(table4[Table2.Symbol.OriginalName])}`;
|
25093
|
+
if (table4[Table2.Symbol.Schema]) {
|
25094
|
+
fullName = sql`${sql.identifier(table4[Table2.Symbol.Schema])}.${fullName}`;
|
25095
|
+
}
|
25096
|
+
return sql`${fullName} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
25097
|
+
}
|
25098
|
+
return table4;
|
25099
|
+
}
|
25045
25100
|
buildSelectQuery({
|
25046
25101
|
withList,
|
25047
25102
|
fields,
|
@@ -25076,51 +25131,8 @@ var init_dialect = __esm({
|
|
25076
25131
|
distinctSql = distinct === true ? sql` distinct` : sql` distinct on (${sql.join(distinct.on, sql`, `)})`;
|
25077
25132
|
}
|
25078
25133
|
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
25079
|
-
const tableSql = (
|
25080
|
-
|
25081
|
-
let fullName = sql`${sql.identifier(table4[Table2.Symbol.OriginalName])}`;
|
25082
|
-
if (table4[Table2.Symbol.Schema]) {
|
25083
|
-
fullName = sql`${sql.identifier(table4[Table2.Symbol.Schema])}.${fullName}`;
|
25084
|
-
}
|
25085
|
-
return sql`${fullName} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
25086
|
-
}
|
25087
|
-
return table4;
|
25088
|
-
})();
|
25089
|
-
const joinsArray = [];
|
25090
|
-
if (joins) {
|
25091
|
-
for (const [index4, joinMeta] of joins.entries()) {
|
25092
|
-
if (index4 === 0) {
|
25093
|
-
joinsArray.push(sql` `);
|
25094
|
-
}
|
25095
|
-
const table22 = joinMeta.table;
|
25096
|
-
const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
|
25097
|
-
if (is(table22, PgTable)) {
|
25098
|
-
const tableName = table22[PgTable.Symbol.Name];
|
25099
|
-
const tableSchema = table22[PgTable.Symbol.Schema];
|
25100
|
-
const origTableName = table22[PgTable.Symbol.OriginalName];
|
25101
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
25102
|
-
joinsArray.push(
|
25103
|
-
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}`
|
25104
|
-
);
|
25105
|
-
} else if (is(table22, View3)) {
|
25106
|
-
const viewName = table22[ViewBaseConfig].name;
|
25107
|
-
const viewSchema = table22[ViewBaseConfig].schema;
|
25108
|
-
const origViewName = table22[ViewBaseConfig].originalName;
|
25109
|
-
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
25110
|
-
joinsArray.push(
|
25111
|
-
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}`
|
25112
|
-
);
|
25113
|
-
} else {
|
25114
|
-
joinsArray.push(
|
25115
|
-
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table22} on ${joinMeta.on}`
|
25116
|
-
);
|
25117
|
-
}
|
25118
|
-
if (index4 < joins.length - 1) {
|
25119
|
-
joinsArray.push(sql` `);
|
25120
|
-
}
|
25121
|
-
}
|
25122
|
-
}
|
25123
|
-
const joinsSql = sql.join(joinsArray);
|
25134
|
+
const tableSql = this.buildFromTable(table4);
|
25135
|
+
const joinsSql = this.buildJoins(joins);
|
25124
25136
|
const whereSql = where ? sql` where ${where}` : void 0;
|
25125
25137
|
const havingSql = having ? sql` having ${having}` : void 0;
|
25126
25138
|
let orderBySql;
|
@@ -26978,9 +26990,14 @@ var init_update = __esm({
|
|
26978
26990
|
"../drizzle-orm/dist/pg-core/query-builders/update.js"() {
|
26979
26991
|
"use strict";
|
26980
26992
|
init_entity();
|
26993
|
+
init_table2();
|
26981
26994
|
init_query_promise();
|
26995
|
+
init_selection_proxy();
|
26996
|
+
init_sql();
|
26997
|
+
init_subquery();
|
26982
26998
|
init_table();
|
26983
26999
|
init_utils2();
|
27000
|
+
init_view_common();
|
26984
27001
|
_a137 = entityKind;
|
26985
27002
|
PgUpdateBuilder = class {
|
26986
27003
|
constructor(table4, session, dialect4, withList) {
|
@@ -27004,12 +27021,85 @@ var init_update = __esm({
|
|
27004
27021
|
constructor(table4, set, session, dialect4, withList) {
|
27005
27022
|
super();
|
27006
27023
|
__publicField(this, "config");
|
27024
|
+
__publicField(this, "tableName");
|
27025
|
+
__publicField(this, "joinsNotNullableMap");
|
27026
|
+
__publicField(this, "leftJoin", this.createJoin("left"));
|
27027
|
+
__publicField(this, "rightJoin", this.createJoin("right"));
|
27028
|
+
__publicField(this, "innerJoin", this.createJoin("inner"));
|
27029
|
+
__publicField(this, "fullJoin", this.createJoin("full"));
|
27007
27030
|
__publicField(this, "execute", (placeholderValues) => {
|
27008
27031
|
return this._prepare().execute(placeholderValues);
|
27009
27032
|
});
|
27010
27033
|
this.session = session;
|
27011
27034
|
this.dialect = dialect4;
|
27012
|
-
this.config = { set, table: table4, withList };
|
27035
|
+
this.config = { set, table: table4, withList, joins: [] };
|
27036
|
+
this.tableName = getTableLikeName(table4);
|
27037
|
+
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
27038
|
+
}
|
27039
|
+
from(source) {
|
27040
|
+
const tableName = getTableLikeName(source);
|
27041
|
+
if (typeof tableName === "string") {
|
27042
|
+
this.joinsNotNullableMap[tableName] = true;
|
27043
|
+
}
|
27044
|
+
this.config.from = source;
|
27045
|
+
return this;
|
27046
|
+
}
|
27047
|
+
getTableLikeFields(table4) {
|
27048
|
+
if (is(table4, PgTable)) {
|
27049
|
+
return table4[Table2.Symbol.Columns];
|
27050
|
+
} else if (is(table4, Subquery)) {
|
27051
|
+
return table4._.selectedFields;
|
27052
|
+
}
|
27053
|
+
return table4[ViewBaseConfig].selectedFields;
|
27054
|
+
}
|
27055
|
+
createJoin(joinType) {
|
27056
|
+
return (table4, on) => {
|
27057
|
+
const tableName = getTableLikeName(table4);
|
27058
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
27059
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
27060
|
+
}
|
27061
|
+
if (typeof on === "function") {
|
27062
|
+
const from = this.config.from && !is(this.config.from, SQL) ? this.getTableLikeFields(this.config.from) : void 0;
|
27063
|
+
on = on(
|
27064
|
+
new Proxy(
|
27065
|
+
this.config.table[Table2.Symbol.Columns],
|
27066
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
27067
|
+
),
|
27068
|
+
from && new Proxy(
|
27069
|
+
from,
|
27070
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
27071
|
+
)
|
27072
|
+
);
|
27073
|
+
}
|
27074
|
+
this.config.joins.push({ on, table: table4, joinType, alias: tableName });
|
27075
|
+
if (typeof tableName === "string") {
|
27076
|
+
switch (joinType) {
|
27077
|
+
case "left": {
|
27078
|
+
this.joinsNotNullableMap[tableName] = false;
|
27079
|
+
break;
|
27080
|
+
}
|
27081
|
+
case "right": {
|
27082
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
27083
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
27084
|
+
);
|
27085
|
+
this.joinsNotNullableMap[tableName] = true;
|
27086
|
+
break;
|
27087
|
+
}
|
27088
|
+
case "inner": {
|
27089
|
+
this.joinsNotNullableMap[tableName] = true;
|
27090
|
+
break;
|
27091
|
+
}
|
27092
|
+
case "full": {
|
27093
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
27094
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
27095
|
+
);
|
27096
|
+
this.joinsNotNullableMap[tableName] = false;
|
27097
|
+
break;
|
27098
|
+
}
|
27099
|
+
}
|
27100
|
+
}
|
27101
|
+
return this;
|
27102
|
+
};
|
27013
27103
|
}
|
27014
27104
|
/**
|
27015
27105
|
* Adds a 'where' clause to the query.
|
@@ -27048,7 +27138,24 @@ var init_update = __esm({
|
|
27048
27138
|
this.config.where = where;
|
27049
27139
|
return this;
|
27050
27140
|
}
|
27051
|
-
returning(fields
|
27141
|
+
returning(fields) {
|
27142
|
+
if (!fields) {
|
27143
|
+
fields = Object.assign({}, this.config.table[Table2.Symbol.Columns]);
|
27144
|
+
if (this.config.from) {
|
27145
|
+
const tableName = getTableLikeName(this.config.from);
|
27146
|
+
if (typeof tableName === "string" && this.config.from && !is(this.config.from, SQL)) {
|
27147
|
+
const fromFields = this.getTableLikeFields(this.config.from);
|
27148
|
+
fields[tableName] = fromFields;
|
27149
|
+
}
|
27150
|
+
for (const join of this.config.joins) {
|
27151
|
+
const tableName2 = getTableLikeName(join.table);
|
27152
|
+
if (typeof tableName2 === "string" && !is(join.table, SQL)) {
|
27153
|
+
const fromFields = this.getTableLikeFields(join.table);
|
27154
|
+
fields[tableName2] = fromFields;
|
27155
|
+
}
|
27156
|
+
}
|
27157
|
+
}
|
27158
|
+
}
|
27052
27159
|
this.config.returning = orderSelectedFields(fields);
|
27053
27160
|
return this;
|
27054
27161
|
}
|
@@ -27062,7 +27169,9 @@ var init_update = __esm({
|
|
27062
27169
|
}
|
27063
27170
|
/** @internal */
|
27064
27171
|
_prepare(name2) {
|
27065
|
-
|
27172
|
+
const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
|
27173
|
+
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
27174
|
+
return query;
|
27066
27175
|
}
|
27067
27176
|
prepare(name2) {
|
27068
27177
|
return this._prepare(name2);
|
@@ -31077,14 +31186,16 @@ var init_dialect2 = __esm({
|
|
31077
31186
|
return [res];
|
31078
31187
|
}));
|
31079
31188
|
}
|
31080
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList, limit, orderBy }) {
|
31189
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, joins, from, limit, orderBy }) {
|
31081
31190
|
const withSql = this.buildWithCTE(withList);
|
31082
31191
|
const setSql = this.buildUpdateSet(table4, set);
|
31192
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
31193
|
+
const joinsSql = this.buildJoins(joins);
|
31083
31194
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
31084
31195
|
const whereSql = where ? sql` where ${where}` : void 0;
|
31085
31196
|
const orderBySql = this.buildOrderBy(orderBy);
|
31086
31197
|
const limitSql = this.buildLimit(limit);
|
31087
|
-
return sql`${withSql}update ${table4} set ${setSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
31198
|
+
return sql`${withSql}update ${table4} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
31088
31199
|
}
|
31089
31200
|
/**
|
31090
31201
|
* Builds selection SQL with provided fields/expressions
|
@@ -31137,6 +31248,37 @@ var init_dialect2 = __esm({
|
|
31137
31248
|
});
|
31138
31249
|
return sql.join(chunks);
|
31139
31250
|
}
|
31251
|
+
buildJoins(joins) {
|
31252
|
+
if (!joins || joins.length === 0) {
|
31253
|
+
return void 0;
|
31254
|
+
}
|
31255
|
+
const joinsArray = [];
|
31256
|
+
if (joins) {
|
31257
|
+
for (const [index4, joinMeta] of joins.entries()) {
|
31258
|
+
if (index4 === 0) {
|
31259
|
+
joinsArray.push(sql` `);
|
31260
|
+
}
|
31261
|
+
const table4 = joinMeta.table;
|
31262
|
+
if (is(table4, SQLiteTable)) {
|
31263
|
+
const tableName = table4[SQLiteTable.Symbol.Name];
|
31264
|
+
const tableSchema = table4[SQLiteTable.Symbol.Schema];
|
31265
|
+
const origTableName = table4[SQLiteTable.Symbol.OriginalName];
|
31266
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
31267
|
+
joinsArray.push(
|
31268
|
+
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
31269
|
+
);
|
31270
|
+
} else {
|
31271
|
+
joinsArray.push(
|
31272
|
+
sql`${sql.raw(joinMeta.joinType)} join ${table4} on ${joinMeta.on}`
|
31273
|
+
);
|
31274
|
+
}
|
31275
|
+
if (index4 < joins.length - 1) {
|
31276
|
+
joinsArray.push(sql` `);
|
31277
|
+
}
|
31278
|
+
}
|
31279
|
+
}
|
31280
|
+
return sql.join(joinsArray);
|
31281
|
+
}
|
31140
31282
|
buildLimit(limit) {
|
31141
31283
|
return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
31142
31284
|
}
|
@@ -31152,6 +31294,12 @@ var init_dialect2 = __esm({
|
|
31152
31294
|
}
|
31153
31295
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
31154
31296
|
}
|
31297
|
+
buildFromTable(table4) {
|
31298
|
+
if (is(table4, Table2) && table4[Table2.Symbol.OriginalName] !== table4[Table2.Symbol.Name]) {
|
31299
|
+
return sql`${sql.identifier(table4[Table2.Symbol.OriginalName])} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
31300
|
+
}
|
31301
|
+
return table4;
|
31302
|
+
}
|
31155
31303
|
buildSelectQuery({
|
31156
31304
|
withList,
|
31157
31305
|
fields,
|
@@ -31182,38 +31330,8 @@ var init_dialect2 = __esm({
|
|
31182
31330
|
const withSql = this.buildWithCTE(withList);
|
31183
31331
|
const distinctSql = distinct ? sql` distinct` : void 0;
|
31184
31332
|
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
31185
|
-
const tableSql = (
|
31186
|
-
|
31187
|
-
return sql`${sql.identifier(table4[Table2.Symbol.OriginalName])} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
31188
|
-
}
|
31189
|
-
return table4;
|
31190
|
-
})();
|
31191
|
-
const joinsArray = [];
|
31192
|
-
if (joins) {
|
31193
|
-
for (const [index4, joinMeta] of joins.entries()) {
|
31194
|
-
if (index4 === 0) {
|
31195
|
-
joinsArray.push(sql` `);
|
31196
|
-
}
|
31197
|
-
const table22 = joinMeta.table;
|
31198
|
-
if (is(table22, SQLiteTable)) {
|
31199
|
-
const tableName = table22[SQLiteTable.Symbol.Name];
|
31200
|
-
const tableSchema = table22[SQLiteTable.Symbol.Schema];
|
31201
|
-
const origTableName = table22[SQLiteTable.Symbol.OriginalName];
|
31202
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
31203
|
-
joinsArray.push(
|
31204
|
-
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
31205
|
-
);
|
31206
|
-
} else {
|
31207
|
-
joinsArray.push(
|
31208
|
-
sql`${sql.raw(joinMeta.joinType)} join ${table22} on ${joinMeta.on}`
|
31209
|
-
);
|
31210
|
-
}
|
31211
|
-
if (index4 < joins.length - 1) {
|
31212
|
-
joinsArray.push(sql` `);
|
31213
|
-
}
|
31214
|
-
}
|
31215
|
-
}
|
31216
|
-
const joinsSql = sql.join(joinsArray);
|
31333
|
+
const tableSql = this.buildFromTable(table4);
|
31334
|
+
const joinsSql = this.buildJoins(joins);
|
31217
31335
|
const whereSql = where ? sql` where ${where}` : void 0;
|
31218
31336
|
const havingSql = having ? sql` having ${having}` : void 0;
|
31219
31337
|
const groupByList = [];
|
@@ -32340,8 +32458,11 @@ var init_update2 = __esm({
|
|
32340
32458
|
init_query_promise();
|
32341
32459
|
init_selection_proxy();
|
32342
32460
|
init_table3();
|
32461
|
+
init_subquery();
|
32343
32462
|
init_table();
|
32344
32463
|
init_utils2();
|
32464
|
+
init_view_common();
|
32465
|
+
init_view_base2();
|
32345
32466
|
_a207 = entityKind;
|
32346
32467
|
SQLiteUpdateBuilder = class {
|
32347
32468
|
constructor(table4, session, dialect4, withList) {
|
@@ -32366,6 +32487,10 @@ var init_update2 = __esm({
|
|
32366
32487
|
super();
|
32367
32488
|
/** @internal */
|
32368
32489
|
__publicField(this, "config");
|
32490
|
+
__publicField(this, "leftJoin", this.createJoin("left"));
|
32491
|
+
__publicField(this, "rightJoin", this.createJoin("right"));
|
32492
|
+
__publicField(this, "innerJoin", this.createJoin("inner"));
|
32493
|
+
__publicField(this, "fullJoin", this.createJoin("full"));
|
32369
32494
|
__publicField(this, "run", (placeholderValues) => {
|
32370
32495
|
return this._prepare().run(placeholderValues);
|
32371
32496
|
});
|
@@ -32380,7 +32505,34 @@ var init_update2 = __esm({
|
|
32380
32505
|
});
|
32381
32506
|
this.session = session;
|
32382
32507
|
this.dialect = dialect4;
|
32383
|
-
this.config = { set, table: table4, withList };
|
32508
|
+
this.config = { set, table: table4, withList, joins: [] };
|
32509
|
+
}
|
32510
|
+
from(source) {
|
32511
|
+
this.config.from = source;
|
32512
|
+
return this;
|
32513
|
+
}
|
32514
|
+
createJoin(joinType) {
|
32515
|
+
return (table4, on) => {
|
32516
|
+
const tableName = getTableLikeName(table4);
|
32517
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
32518
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
32519
|
+
}
|
32520
|
+
if (typeof on === "function") {
|
32521
|
+
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;
|
32522
|
+
on = on(
|
32523
|
+
new Proxy(
|
32524
|
+
this.config.table[Table2.Symbol.Columns],
|
32525
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
32526
|
+
),
|
32527
|
+
from && new Proxy(
|
32528
|
+
from,
|
32529
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
32530
|
+
)
|
32531
|
+
);
|
32532
|
+
}
|
32533
|
+
this.config.joins.push({ on, table: table4, joinType, alias: tableName });
|
32534
|
+
return this;
|
32535
|
+
};
|
32384
32536
|
}
|
32385
32537
|
/**
|
32386
32538
|
* Adds a 'where' clause to the query.
|
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.2";
|
21130
21130
|
}
|
21131
21131
|
});
|
21132
21132
|
|
@@ -22149,7 +22149,7 @@ function haveSameKeys(left, right) {
|
|
22149
22149
|
}
|
22150
22150
|
function mapUpdateSet(table4, values) {
|
22151
22151
|
const entries = Object.entries(values).filter(([, value]) => value !== void 0).map(([key, value]) => {
|
22152
|
-
if (is(value, SQL)) {
|
22152
|
+
if (is(value, SQL) || is(value, Column2)) {
|
22153
22153
|
return [key, value];
|
22154
22154
|
} else {
|
22155
22155
|
return [key, new Param(value, table4[Table2.Symbol.Columns][key])];
|
@@ -24990,12 +24990,19 @@ var init_dialect = __esm({
|
|
24990
24990
|
return [res];
|
24991
24991
|
}));
|
24992
24992
|
}
|
24993
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList }) {
|
24993
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, from, joins }) {
|
24994
24994
|
const withSql = this.buildWithCTE(withList);
|
24995
|
+
const tableName = table4[PgTable.Symbol.Name];
|
24996
|
+
const tableSchema = table4[PgTable.Symbol.Schema];
|
24997
|
+
const origTableName = table4[PgTable.Symbol.OriginalName];
|
24998
|
+
const alias = tableName === origTableName ? void 0 : tableName;
|
24999
|
+
const tableSql = sql`${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}`;
|
24995
25000
|
const setSql = this.buildUpdateSet(table4, set);
|
24996
|
-
const
|
25001
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
25002
|
+
const joinsSql = this.buildJoins(joins);
|
25003
|
+
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: !from })}` : void 0;
|
24997
25004
|
const whereSql = where ? sql` where ${where}` : void 0;
|
24998
|
-
return sql`${withSql}update ${
|
25005
|
+
return sql`${withSql}update ${tableSql} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}`;
|
24999
25006
|
}
|
25000
25007
|
/**
|
25001
25008
|
* Builds selection SQL with provided fields/expressions
|
@@ -25047,6 +25054,54 @@ var init_dialect = __esm({
|
|
25047
25054
|
});
|
25048
25055
|
return sql.join(chunks);
|
25049
25056
|
}
|
25057
|
+
buildJoins(joins) {
|
25058
|
+
if (!joins || joins.length === 0) {
|
25059
|
+
return void 0;
|
25060
|
+
}
|
25061
|
+
const joinsArray = [];
|
25062
|
+
for (const [index4, joinMeta] of joins.entries()) {
|
25063
|
+
if (index4 === 0) {
|
25064
|
+
joinsArray.push(sql` `);
|
25065
|
+
}
|
25066
|
+
const table4 = joinMeta.table;
|
25067
|
+
const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
|
25068
|
+
if (is(table4, PgTable)) {
|
25069
|
+
const tableName = table4[PgTable.Symbol.Name];
|
25070
|
+
const tableSchema = table4[PgTable.Symbol.Schema];
|
25071
|
+
const origTableName = table4[PgTable.Symbol.OriginalName];
|
25072
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
25073
|
+
joinsArray.push(
|
25074
|
+
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}`
|
25075
|
+
);
|
25076
|
+
} else if (is(table4, View3)) {
|
25077
|
+
const viewName = table4[ViewBaseConfig].name;
|
25078
|
+
const viewSchema = table4[ViewBaseConfig].schema;
|
25079
|
+
const origViewName = table4[ViewBaseConfig].originalName;
|
25080
|
+
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
25081
|
+
joinsArray.push(
|
25082
|
+
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}`
|
25083
|
+
);
|
25084
|
+
} else {
|
25085
|
+
joinsArray.push(
|
25086
|
+
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table4} on ${joinMeta.on}`
|
25087
|
+
);
|
25088
|
+
}
|
25089
|
+
if (index4 < joins.length - 1) {
|
25090
|
+
joinsArray.push(sql` `);
|
25091
|
+
}
|
25092
|
+
}
|
25093
|
+
return sql.join(joinsArray);
|
25094
|
+
}
|
25095
|
+
buildFromTable(table4) {
|
25096
|
+
if (is(table4, Table2) && table4[Table2.Symbol.OriginalName] !== table4[Table2.Symbol.Name]) {
|
25097
|
+
let fullName = sql`${sql.identifier(table4[Table2.Symbol.OriginalName])}`;
|
25098
|
+
if (table4[Table2.Symbol.Schema]) {
|
25099
|
+
fullName = sql`${sql.identifier(table4[Table2.Symbol.Schema])}.${fullName}`;
|
25100
|
+
}
|
25101
|
+
return sql`${fullName} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
25102
|
+
}
|
25103
|
+
return table4;
|
25104
|
+
}
|
25050
25105
|
buildSelectQuery({
|
25051
25106
|
withList,
|
25052
25107
|
fields,
|
@@ -25081,51 +25136,8 @@ var init_dialect = __esm({
|
|
25081
25136
|
distinctSql = distinct === true ? sql` distinct` : sql` distinct on (${sql.join(distinct.on, sql`, `)})`;
|
25082
25137
|
}
|
25083
25138
|
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
25084
|
-
const tableSql = (
|
25085
|
-
|
25086
|
-
let fullName = sql`${sql.identifier(table4[Table2.Symbol.OriginalName])}`;
|
25087
|
-
if (table4[Table2.Symbol.Schema]) {
|
25088
|
-
fullName = sql`${sql.identifier(table4[Table2.Symbol.Schema])}.${fullName}`;
|
25089
|
-
}
|
25090
|
-
return sql`${fullName} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
25091
|
-
}
|
25092
|
-
return table4;
|
25093
|
-
})();
|
25094
|
-
const joinsArray = [];
|
25095
|
-
if (joins) {
|
25096
|
-
for (const [index4, joinMeta] of joins.entries()) {
|
25097
|
-
if (index4 === 0) {
|
25098
|
-
joinsArray.push(sql` `);
|
25099
|
-
}
|
25100
|
-
const table22 = joinMeta.table;
|
25101
|
-
const lateralSql = joinMeta.lateral ? sql` lateral` : void 0;
|
25102
|
-
if (is(table22, PgTable)) {
|
25103
|
-
const tableName = table22[PgTable.Symbol.Name];
|
25104
|
-
const tableSchema = table22[PgTable.Symbol.Schema];
|
25105
|
-
const origTableName = table22[PgTable.Symbol.OriginalName];
|
25106
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
25107
|
-
joinsArray.push(
|
25108
|
-
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
25109
|
-
);
|
25110
|
-
} else if (is(table22, View3)) {
|
25111
|
-
const viewName = table22[ViewBaseConfig].name;
|
25112
|
-
const viewSchema = table22[ViewBaseConfig].schema;
|
25113
|
-
const origViewName = table22[ViewBaseConfig].originalName;
|
25114
|
-
const alias = viewName === origViewName ? void 0 : joinMeta.alias;
|
25115
|
-
joinsArray.push(
|
25116
|
-
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${viewSchema ? sql`${sql.identifier(viewSchema)}.` : void 0}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
25117
|
-
);
|
25118
|
-
} else {
|
25119
|
-
joinsArray.push(
|
25120
|
-
sql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table22} on ${joinMeta.on}`
|
25121
|
-
);
|
25122
|
-
}
|
25123
|
-
if (index4 < joins.length - 1) {
|
25124
|
-
joinsArray.push(sql` `);
|
25125
|
-
}
|
25126
|
-
}
|
25127
|
-
}
|
25128
|
-
const joinsSql = sql.join(joinsArray);
|
25139
|
+
const tableSql = this.buildFromTable(table4);
|
25140
|
+
const joinsSql = this.buildJoins(joins);
|
25129
25141
|
const whereSql = where ? sql` where ${where}` : void 0;
|
25130
25142
|
const havingSql = having ? sql` having ${having}` : void 0;
|
25131
25143
|
let orderBySql;
|
@@ -26983,9 +26995,14 @@ var init_update = __esm({
|
|
26983
26995
|
"../drizzle-orm/dist/pg-core/query-builders/update.js"() {
|
26984
26996
|
"use strict";
|
26985
26997
|
init_entity();
|
26998
|
+
init_table2();
|
26986
26999
|
init_query_promise();
|
27000
|
+
init_selection_proxy();
|
27001
|
+
init_sql();
|
27002
|
+
init_subquery();
|
26987
27003
|
init_table();
|
26988
27004
|
init_utils2();
|
27005
|
+
init_view_common();
|
26989
27006
|
_a137 = entityKind;
|
26990
27007
|
PgUpdateBuilder = class {
|
26991
27008
|
constructor(table4, session, dialect4, withList) {
|
@@ -27009,12 +27026,85 @@ var init_update = __esm({
|
|
27009
27026
|
constructor(table4, set, session, dialect4, withList) {
|
27010
27027
|
super();
|
27011
27028
|
__publicField(this, "config");
|
27029
|
+
__publicField(this, "tableName");
|
27030
|
+
__publicField(this, "joinsNotNullableMap");
|
27031
|
+
__publicField(this, "leftJoin", this.createJoin("left"));
|
27032
|
+
__publicField(this, "rightJoin", this.createJoin("right"));
|
27033
|
+
__publicField(this, "innerJoin", this.createJoin("inner"));
|
27034
|
+
__publicField(this, "fullJoin", this.createJoin("full"));
|
27012
27035
|
__publicField(this, "execute", (placeholderValues) => {
|
27013
27036
|
return this._prepare().execute(placeholderValues);
|
27014
27037
|
});
|
27015
27038
|
this.session = session;
|
27016
27039
|
this.dialect = dialect4;
|
27017
|
-
this.config = { set, table: table4, withList };
|
27040
|
+
this.config = { set, table: table4, withList, joins: [] };
|
27041
|
+
this.tableName = getTableLikeName(table4);
|
27042
|
+
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
27043
|
+
}
|
27044
|
+
from(source) {
|
27045
|
+
const tableName = getTableLikeName(source);
|
27046
|
+
if (typeof tableName === "string") {
|
27047
|
+
this.joinsNotNullableMap[tableName] = true;
|
27048
|
+
}
|
27049
|
+
this.config.from = source;
|
27050
|
+
return this;
|
27051
|
+
}
|
27052
|
+
getTableLikeFields(table4) {
|
27053
|
+
if (is(table4, PgTable)) {
|
27054
|
+
return table4[Table2.Symbol.Columns];
|
27055
|
+
} else if (is(table4, Subquery)) {
|
27056
|
+
return table4._.selectedFields;
|
27057
|
+
}
|
27058
|
+
return table4[ViewBaseConfig].selectedFields;
|
27059
|
+
}
|
27060
|
+
createJoin(joinType) {
|
27061
|
+
return (table4, on) => {
|
27062
|
+
const tableName = getTableLikeName(table4);
|
27063
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
27064
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
27065
|
+
}
|
27066
|
+
if (typeof on === "function") {
|
27067
|
+
const from = this.config.from && !is(this.config.from, SQL) ? this.getTableLikeFields(this.config.from) : void 0;
|
27068
|
+
on = on(
|
27069
|
+
new Proxy(
|
27070
|
+
this.config.table[Table2.Symbol.Columns],
|
27071
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
27072
|
+
),
|
27073
|
+
from && new Proxy(
|
27074
|
+
from,
|
27075
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
27076
|
+
)
|
27077
|
+
);
|
27078
|
+
}
|
27079
|
+
this.config.joins.push({ on, table: table4, joinType, alias: tableName });
|
27080
|
+
if (typeof tableName === "string") {
|
27081
|
+
switch (joinType) {
|
27082
|
+
case "left": {
|
27083
|
+
this.joinsNotNullableMap[tableName] = false;
|
27084
|
+
break;
|
27085
|
+
}
|
27086
|
+
case "right": {
|
27087
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
27088
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
27089
|
+
);
|
27090
|
+
this.joinsNotNullableMap[tableName] = true;
|
27091
|
+
break;
|
27092
|
+
}
|
27093
|
+
case "inner": {
|
27094
|
+
this.joinsNotNullableMap[tableName] = true;
|
27095
|
+
break;
|
27096
|
+
}
|
27097
|
+
case "full": {
|
27098
|
+
this.joinsNotNullableMap = Object.fromEntries(
|
27099
|
+
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
27100
|
+
);
|
27101
|
+
this.joinsNotNullableMap[tableName] = false;
|
27102
|
+
break;
|
27103
|
+
}
|
27104
|
+
}
|
27105
|
+
}
|
27106
|
+
return this;
|
27107
|
+
};
|
27018
27108
|
}
|
27019
27109
|
/**
|
27020
27110
|
* Adds a 'where' clause to the query.
|
@@ -27053,7 +27143,24 @@ var init_update = __esm({
|
|
27053
27143
|
this.config.where = where;
|
27054
27144
|
return this;
|
27055
27145
|
}
|
27056
|
-
returning(fields
|
27146
|
+
returning(fields) {
|
27147
|
+
if (!fields) {
|
27148
|
+
fields = Object.assign({}, this.config.table[Table2.Symbol.Columns]);
|
27149
|
+
if (this.config.from) {
|
27150
|
+
const tableName = getTableLikeName(this.config.from);
|
27151
|
+
if (typeof tableName === "string" && this.config.from && !is(this.config.from, SQL)) {
|
27152
|
+
const fromFields = this.getTableLikeFields(this.config.from);
|
27153
|
+
fields[tableName] = fromFields;
|
27154
|
+
}
|
27155
|
+
for (const join of this.config.joins) {
|
27156
|
+
const tableName2 = getTableLikeName(join.table);
|
27157
|
+
if (typeof tableName2 === "string" && !is(join.table, SQL)) {
|
27158
|
+
const fromFields = this.getTableLikeFields(join.table);
|
27159
|
+
fields[tableName2] = fromFields;
|
27160
|
+
}
|
27161
|
+
}
|
27162
|
+
}
|
27163
|
+
}
|
27057
27164
|
this.config.returning = orderSelectedFields(fields);
|
27058
27165
|
return this;
|
27059
27166
|
}
|
@@ -27067,7 +27174,9 @@ var init_update = __esm({
|
|
27067
27174
|
}
|
27068
27175
|
/** @internal */
|
27069
27176
|
_prepare(name2) {
|
27070
|
-
|
27177
|
+
const query = this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()), this.config.returning, name2, true);
|
27178
|
+
query.joinsNotNullableMap = this.joinsNotNullableMap;
|
27179
|
+
return query;
|
27071
27180
|
}
|
27072
27181
|
prepare(name2) {
|
27073
27182
|
return this._prepare(name2);
|
@@ -31082,14 +31191,16 @@ var init_dialect2 = __esm({
|
|
31082
31191
|
return [res];
|
31083
31192
|
}));
|
31084
31193
|
}
|
31085
|
-
buildUpdateQuery({ table: table4, set, where, returning, withList, limit, orderBy }) {
|
31194
|
+
buildUpdateQuery({ table: table4, set, where, returning, withList, joins, from, limit, orderBy }) {
|
31086
31195
|
const withSql = this.buildWithCTE(withList);
|
31087
31196
|
const setSql = this.buildUpdateSet(table4, set);
|
31197
|
+
const fromSql = from && sql.join([sql.raw(" from "), this.buildFromTable(from)]);
|
31198
|
+
const joinsSql = this.buildJoins(joins);
|
31088
31199
|
const returningSql = returning ? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0;
|
31089
31200
|
const whereSql = where ? sql` where ${where}` : void 0;
|
31090
31201
|
const orderBySql = this.buildOrderBy(orderBy);
|
31091
31202
|
const limitSql = this.buildLimit(limit);
|
31092
|
-
return sql`${withSql}update ${table4} set ${setSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
31203
|
+
return sql`${withSql}update ${table4} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}${orderBySql}${limitSql}`;
|
31093
31204
|
}
|
31094
31205
|
/**
|
31095
31206
|
* Builds selection SQL with provided fields/expressions
|
@@ -31142,6 +31253,37 @@ var init_dialect2 = __esm({
|
|
31142
31253
|
});
|
31143
31254
|
return sql.join(chunks);
|
31144
31255
|
}
|
31256
|
+
buildJoins(joins) {
|
31257
|
+
if (!joins || joins.length === 0) {
|
31258
|
+
return void 0;
|
31259
|
+
}
|
31260
|
+
const joinsArray = [];
|
31261
|
+
if (joins) {
|
31262
|
+
for (const [index4, joinMeta] of joins.entries()) {
|
31263
|
+
if (index4 === 0) {
|
31264
|
+
joinsArray.push(sql` `);
|
31265
|
+
}
|
31266
|
+
const table4 = joinMeta.table;
|
31267
|
+
if (is(table4, SQLiteTable)) {
|
31268
|
+
const tableName = table4[SQLiteTable.Symbol.Name];
|
31269
|
+
const tableSchema = table4[SQLiteTable.Symbol.Schema];
|
31270
|
+
const origTableName = table4[SQLiteTable.Symbol.OriginalName];
|
31271
|
+
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
31272
|
+
joinsArray.push(
|
31273
|
+
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
31274
|
+
);
|
31275
|
+
} else {
|
31276
|
+
joinsArray.push(
|
31277
|
+
sql`${sql.raw(joinMeta.joinType)} join ${table4} on ${joinMeta.on}`
|
31278
|
+
);
|
31279
|
+
}
|
31280
|
+
if (index4 < joins.length - 1) {
|
31281
|
+
joinsArray.push(sql` `);
|
31282
|
+
}
|
31283
|
+
}
|
31284
|
+
}
|
31285
|
+
return sql.join(joinsArray);
|
31286
|
+
}
|
31145
31287
|
buildLimit(limit) {
|
31146
31288
|
return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? sql` limit ${limit}` : void 0;
|
31147
31289
|
}
|
@@ -31157,6 +31299,12 @@ var init_dialect2 = __esm({
|
|
31157
31299
|
}
|
31158
31300
|
return orderByList.length > 0 ? sql` order by ${sql.join(orderByList)}` : void 0;
|
31159
31301
|
}
|
31302
|
+
buildFromTable(table4) {
|
31303
|
+
if (is(table4, Table2) && table4[Table2.Symbol.OriginalName] !== table4[Table2.Symbol.Name]) {
|
31304
|
+
return sql`${sql.identifier(table4[Table2.Symbol.OriginalName])} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
31305
|
+
}
|
31306
|
+
return table4;
|
31307
|
+
}
|
31160
31308
|
buildSelectQuery({
|
31161
31309
|
withList,
|
31162
31310
|
fields,
|
@@ -31187,38 +31335,8 @@ var init_dialect2 = __esm({
|
|
31187
31335
|
const withSql = this.buildWithCTE(withList);
|
31188
31336
|
const distinctSql = distinct ? sql` distinct` : void 0;
|
31189
31337
|
const selection = this.buildSelection(fieldsList, { isSingleTable });
|
31190
|
-
const tableSql = (
|
31191
|
-
|
31192
|
-
return sql`${sql.identifier(table4[Table2.Symbol.OriginalName])} ${sql.identifier(table4[Table2.Symbol.Name])}`;
|
31193
|
-
}
|
31194
|
-
return table4;
|
31195
|
-
})();
|
31196
|
-
const joinsArray = [];
|
31197
|
-
if (joins) {
|
31198
|
-
for (const [index4, joinMeta] of joins.entries()) {
|
31199
|
-
if (index4 === 0) {
|
31200
|
-
joinsArray.push(sql` `);
|
31201
|
-
}
|
31202
|
-
const table22 = joinMeta.table;
|
31203
|
-
if (is(table22, SQLiteTable)) {
|
31204
|
-
const tableName = table22[SQLiteTable.Symbol.Name];
|
31205
|
-
const tableSchema = table22[SQLiteTable.Symbol.Schema];
|
31206
|
-
const origTableName = table22[SQLiteTable.Symbol.OriginalName];
|
31207
|
-
const alias = tableName === origTableName ? void 0 : joinMeta.alias;
|
31208
|
-
joinsArray.push(
|
31209
|
-
sql`${sql.raw(joinMeta.joinType)} join ${tableSchema ? sql`${sql.identifier(tableSchema)}.` : void 0}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`} on ${joinMeta.on}`
|
31210
|
-
);
|
31211
|
-
} else {
|
31212
|
-
joinsArray.push(
|
31213
|
-
sql`${sql.raw(joinMeta.joinType)} join ${table22} on ${joinMeta.on}`
|
31214
|
-
);
|
31215
|
-
}
|
31216
|
-
if (index4 < joins.length - 1) {
|
31217
|
-
joinsArray.push(sql` `);
|
31218
|
-
}
|
31219
|
-
}
|
31220
|
-
}
|
31221
|
-
const joinsSql = sql.join(joinsArray);
|
31338
|
+
const tableSql = this.buildFromTable(table4);
|
31339
|
+
const joinsSql = this.buildJoins(joins);
|
31222
31340
|
const whereSql = where ? sql` where ${where}` : void 0;
|
31223
31341
|
const havingSql = having ? sql` having ${having}` : void 0;
|
31224
31342
|
const groupByList = [];
|
@@ -32345,8 +32463,11 @@ var init_update2 = __esm({
|
|
32345
32463
|
init_query_promise();
|
32346
32464
|
init_selection_proxy();
|
32347
32465
|
init_table3();
|
32466
|
+
init_subquery();
|
32348
32467
|
init_table();
|
32349
32468
|
init_utils2();
|
32469
|
+
init_view_common();
|
32470
|
+
init_view_base2();
|
32350
32471
|
_a207 = entityKind;
|
32351
32472
|
SQLiteUpdateBuilder = class {
|
32352
32473
|
constructor(table4, session, dialect4, withList) {
|
@@ -32371,6 +32492,10 @@ var init_update2 = __esm({
|
|
32371
32492
|
super();
|
32372
32493
|
/** @internal */
|
32373
32494
|
__publicField(this, "config");
|
32495
|
+
__publicField(this, "leftJoin", this.createJoin("left"));
|
32496
|
+
__publicField(this, "rightJoin", this.createJoin("right"));
|
32497
|
+
__publicField(this, "innerJoin", this.createJoin("inner"));
|
32498
|
+
__publicField(this, "fullJoin", this.createJoin("full"));
|
32374
32499
|
__publicField(this, "run", (placeholderValues) => {
|
32375
32500
|
return this._prepare().run(placeholderValues);
|
32376
32501
|
});
|
@@ -32385,7 +32510,34 @@ var init_update2 = __esm({
|
|
32385
32510
|
});
|
32386
32511
|
this.session = session;
|
32387
32512
|
this.dialect = dialect4;
|
32388
|
-
this.config = { set, table: table4, withList };
|
32513
|
+
this.config = { set, table: table4, withList, joins: [] };
|
32514
|
+
}
|
32515
|
+
from(source) {
|
32516
|
+
this.config.from = source;
|
32517
|
+
return this;
|
32518
|
+
}
|
32519
|
+
createJoin(joinType) {
|
32520
|
+
return (table4, on) => {
|
32521
|
+
const tableName = getTableLikeName(table4);
|
32522
|
+
if (typeof tableName === "string" && this.config.joins.some((join) => join.alias === tableName)) {
|
32523
|
+
throw new Error(`Alias "${tableName}" is already used in this query`);
|
32524
|
+
}
|
32525
|
+
if (typeof on === "function") {
|
32526
|
+
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;
|
32527
|
+
on = on(
|
32528
|
+
new Proxy(
|
32529
|
+
this.config.table[Table2.Symbol.Columns],
|
32530
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
32531
|
+
),
|
32532
|
+
from && new Proxy(
|
32533
|
+
from,
|
32534
|
+
new SelectionProxyHandler({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" })
|
32535
|
+
)
|
32536
|
+
);
|
32537
|
+
}
|
32538
|
+
this.config.joins.push({ on, table: table4, joinType, alias: tableName });
|
32539
|
+
return this;
|
32540
|
+
};
|
32389
32541
|
}
|
32390
32542
|
/**
|
32391
32543
|
* Adds a 'where' clause to the query.
|
package/bin.cjs
CHANGED
@@ -89049,7 +89049,7 @@ init_utils2();
|
|
89049
89049
|
var version2 = async () => {
|
89050
89050
|
const { npmVersion } = await ormCoreVersions();
|
89051
89051
|
const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
|
89052
|
-
const envVersion = "0.28.
|
89052
|
+
const envVersion = "0.28.1-d7e3535";
|
89053
89053
|
const kitVersion = envVersion ? `v${envVersion}` : "--";
|
89054
89054
|
const versions = `drizzle-kit: ${kitVersion}
|
89055
89055
|
${ormVersion}`;
|