Kyoo/api/patches/drizzle-orm@0.39.0.patch
2025-04-07 21:24:04 +02:00

252 lines
12 KiB
Diff

diff --git a/node_modules/drizzle-orm/.bun-tag-3622ae30f31c0d9a b/.bun-tag-3622ae30f31c0d9a
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/node_modules/drizzle-orm/.bun-tag-36446a2521398ee8 b/.bun-tag-36446a2521398ee8
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/node_modules/drizzle-orm/.bun-tag-844efc51a55b820c b/.bun-tag-844efc51a55b820c
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/node_modules/drizzle-orm/.bun-tag-9fae835e61d5cc75 b/.bun-tag-9fae835e61d5cc75
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/node_modules/drizzle-orm/.bun-tag-ce8efc9a806990a3 b/.bun-tag-ce8efc9a806990a3
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/pg-core/dialect.cjs b/pg-core/dialect.cjs
index 52acbfb6038fb1bbba4e34115d75a22bb0f9ab1a..1f10884caf05329ab98b06a68c8e7803e5283d32 100644
--- a/pg-core/dialect.cjs
+++ b/pg-core/dialect.cjs
@@ -347,7 +347,14 @@ class PgDialect {
buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select, overridingSystemValue_ }) {
const valuesSqlList = [];
const columns = table[import_table2.Table.Symbol.Columns];
- const colEntries = Object.entries(columns).filter(([_, col]) => !col.shouldDisableInsert());
+ let colEntries = Object.entries(columns);
+ colEntries = select && !is(valuesOrSelect, SQL)
+ ? Object
+ .keys(valuesOrSelect._.selectedFields)
+ .map((key) => [key, columns[key]])
+ : overridingSystemValue_
+ ? colEntries
+ : colEntries.filter(([_, col]) => !col.shouldDisableInsert());
const insertOrder = colEntries.map(
([, column]) => import_sql2.sql.identifier(this.casing.getColumnCasing(column))
);
diff --git a/pg-core/dialect.js b/pg-core/dialect.js
index d7985c81f3d224f7671efe72e79b14153d5ca8ce..91d99ccd2ebda807a7d45c76f7164e571b922159 100644
--- a/pg-core/dialect.js
+++ b/pg-core/dialect.js
@@ -345,7 +345,14 @@ class PgDialect {
buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select, overridingSystemValue_ }) {
const valuesSqlList = [];
const columns = table[Table.Symbol.Columns];
- const colEntries = Object.entries(columns).filter(([_, col]) => !col.shouldDisableInsert());
+ let colEntries = Object.entries(columns);
+ colEntries = select && !is(valuesOrSelect, SQL)
+ ? Object
+ .keys(valuesOrSelect._.selectedFields)
+ .map((key) => [key, columns[key]])
+ : overridingSystemValue_
+ ? colEntries
+ : colEntries.filter(([_, col]) => !col.shouldDisableInsert());
const insertOrder = colEntries.map(
([, column]) => sql.identifier(this.casing.getColumnCasing(column))
);
diff --git a/pg-core/query-builders/insert.cjs b/pg-core/query-builders/insert.cjs
index 08bb0d7485ebf997e3f081e2254ea8fd8bc20f65..341d2513d4377acc33ee0606d05580566fd4b88c 100644
--- a/pg-core/query-builders/insert.cjs
+++ b/pg-core/query-builders/insert.cjs
@@ -75,11 +75,6 @@ class PgInsertBuilder {
}
select(selectQuery) {
const select = typeof selectQuery === "function" ? selectQuery(new import_query_builder.QueryBuilder()) : selectQuery;
- if (!(0, import_entity.is)(select, import_sql.SQL) && !(0, import_utils.haveSameKeys)(this.table[import_table.Columns], select._.selectedFields)) {
- throw new Error(
- "Insert select error: selected fields are not the same or are in a different order compared to the table definition"
- );
- }
return new PgInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
}
}
diff --git a/pg-core/query-builders/insert.js b/pg-core/query-builders/insert.js
index 0fc8eeb80f4a5512f6c84f3d596832623a33b748..b993f226daf16f423db012dff828d89c522603c3 100644
--- a/pg-core/query-builders/insert.js
+++ b/pg-core/query-builders/insert.js
@@ -51,11 +51,6 @@ class PgInsertBuilder {
}
select(selectQuery) {
const select = typeof selectQuery === "function" ? selectQuery(new QueryBuilder()) : selectQuery;
- if (!is(select, SQL) && !haveSameKeys(this.table[Columns], select._.selectedFields)) {
- throw new Error(
- "Insert select error: selected fields are not the same or are in a different order compared to the table definition"
- );
- }
return new PgInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
}
}
diff --git a/pg-core/query-builders/select.d.cts b/pg-core/query-builders/select.d.cts
index b968ebb3f563f37c8c36221dd17cc6f3603270ec..3fda6d0a97997f6bd07ec6a0c83397c0fdd2e97e 100644
--- a/pg-core/query-builders/select.d.cts
+++ b/pg-core/query-builders/select.d.cts
@@ -98,7 +98,16 @@ export declare abstract class PgSelectQueryBuilderBase<THKT extends PgSelectHKTB
* .leftJoin(pets, eq(users.id, pets.ownerId))
* ```
*/
- leftJoin: PgSelectJoinFn<this, TDynamic, "left">;
+ leftJoin: PgSelectJoinFn<this, TDynamic, "left", false>;
+ /**
+ * For each row of the table, include
+ * values from a matching row of the joined
+ * subquery, if there is a matching row. If not,
+ * all of the columns of the joined subquery
+ * will be set to null. The lateral keyword allows
+ * access to columns after the FROM statement.
+ */
+ leftJoinLateral: PgSelectJoinFn<this, TDynamic, "left", true>;
/**
* Executes a `right join` operation by adding another table to the current query.
*
@@ -126,7 +135,7 @@ export declare abstract class PgSelectQueryBuilderBase<THKT extends PgSelectHKTB
* .rightJoin(pets, eq(users.id, pets.ownerId))
* ```
*/
- rightJoin: PgSelectJoinFn<this, TDynamic, "right">;
+ rightJoin: PgSelectJoinFn<this, TDynamic, "right", false>;
/**
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
*
@@ -154,7 +163,14 @@ export declare abstract class PgSelectQueryBuilderBase<THKT extends PgSelectHKTB
* .innerJoin(pets, eq(users.id, pets.ownerId))
* ```
*/
- innerJoin: PgSelectJoinFn<this, TDynamic, "inner">;
+ innerJoin: PgSelectJoinFn<this, TDynamic, "inner", false>;
+ /**
+ * For each row of the table, the joined subquery
+ * needs to have a matching row, or it will
+ * be excluded from results. The lateral keyword allows
+ * access to columns after the FROM statement.
+ */
+ innerJoinLateral: PgSelectJoinFn<this, TDynamic, "inner", true>;
/**
* Executes a `full join` operation by combining rows from two tables into a new table.
*
@@ -182,7 +198,7 @@ export declare abstract class PgSelectQueryBuilderBase<THKT extends PgSelectHKTB
* .fullJoin(pets, eq(users.id, pets.ownerId))
* ```
*/
- fullJoin: PgSelectJoinFn<this, TDynamic, "full">;
+ fullJoin: PgSelectJoinFn<this, TDynamic, "full", false>;
private createSetOperator;
/**
* Adds `union` set operator to the query.
diff --git a/pg-core/query-builders/select.d.ts b/pg-core/query-builders/select.d.ts
index d44256289ffe7bd19d3f3af98cbd9ba0fc7efc57..f106eb28a919e0182f833632ace36ea7f87f9a88 100644
--- a/pg-core/query-builders/select.d.ts
+++ b/pg-core/query-builders/select.d.ts
@@ -98,7 +98,16 @@ export declare abstract class PgSelectQueryBuilderBase<THKT extends PgSelectHKTB
* .leftJoin(pets, eq(users.id, pets.ownerId))
* ```
*/
- leftJoin: PgSelectJoinFn<this, TDynamic, "left">;
+ leftJoin: PgSelectJoinFn<this, TDynamic, "left", false>;
+ /**
+ * For each row of the table, include
+ * values from a matching row of the joined
+ * subquery, if there is a matching row. If not,
+ * all of the columns of the joined subquery
+ * will be set to null. The lateral keyword allows
+ * access to columns after the FROM statement.
+ */
+ leftJoinLateral: PgSelectJoinFn<this, TDynamic, "left", true>;
/**
* Executes a `right join` operation by adding another table to the current query.
*
@@ -126,7 +135,7 @@ export declare abstract class PgSelectQueryBuilderBase<THKT extends PgSelectHKTB
* .rightJoin(pets, eq(users.id, pets.ownerId))
* ```
*/
- rightJoin: PgSelectJoinFn<this, TDynamic, "right">;
+ rightJoin: PgSelectJoinFn<this, TDynamic, "right", false>;
/**
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
*
@@ -154,7 +163,14 @@ export declare abstract class PgSelectQueryBuilderBase<THKT extends PgSelectHKTB
* .innerJoin(pets, eq(users.id, pets.ownerId))
* ```
*/
- innerJoin: PgSelectJoinFn<this, TDynamic, "inner">;
+ innerJoin: PgSelectJoinFn<this, TDynamic, "inner", false>;
+ /**
+ * For each row of the table, the joined subquery
+ * needs to have a matching row, or it will
+ * be excluded from results. The lateral keyword allows
+ * access to columns after the FROM statement.
+ */
+ innerJoinLateral: PgSelectJoinFn<this, TDynamic, "inner", true>;
/**
* Executes a `full join` operation by combining rows from two tables into a new table.
*
@@ -182,7 +198,7 @@ export declare abstract class PgSelectQueryBuilderBase<THKT extends PgSelectHKTB
* .fullJoin(pets, eq(users.id, pets.ownerId))
* ```
*/
- fullJoin: PgSelectJoinFn<this, TDynamic, "full">;
+ fullJoin: PgSelectJoinFn<this, TDynamic, "full", false>;
private createSetOperator;
/**
* Adds `union` set operator to the query.
diff --git a/pg-core/query-builders/select.js b/pg-core/query-builders/select.js
index e54406fcaf68ccfdaf32c8945d4d432212c4cf3f..5c514132f30366ee600b9530c284932d54f481f3 100644
--- a/pg-core/query-builders/select.js
+++ b/pg-core/query-builders/select.js
@@ -98,7 +98,7 @@ class PgSelectQueryBuilderBase extends TypedQueryBuilder {
this.tableName = getTableLikeName(table);
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
}
- createJoin(joinType) {
+ createJoin(joinType, lateral = false) {
return (table, on) => {
const baseTableName = this.tableName;
const tableName = getTableLikeName(table);
@@ -127,7 +127,7 @@ class PgSelectQueryBuilderBase extends TypedQueryBuilder {
if (!this.config.joins) {
this.config.joins = [];
}
- this.config.joins.push({ on, table, joinType, alias: tableName });
+ this.config.joins.push({ on, table, joinType, alias: tableName, lateral });
if (typeof tableName === "string") {
switch (joinType) {
case "left": {
@@ -185,6 +185,15 @@ class PgSelectQueryBuilderBase extends TypedQueryBuilder {
* ```
*/
leftJoin = this.createJoin("left");
+ /**
+ * For each row of the table, include
+ * values from a matching row of the joined
+ * subquery, if there is a matching row. If not,
+ * all of the columns of the joined subquery
+ * will be set to null. The lateral keyword allows
+ * access to columns after the FROM statement.
+ */
+ leftJoinLateral = this.createJoin("left", true);
/**
* Executes a `right join` operation by adding another table to the current query.
*
@@ -241,6 +250,13 @@ class PgSelectQueryBuilderBase extends TypedQueryBuilder {
* ```
*/
innerJoin = this.createJoin("inner");
+ /**
+ * For each row of the table, the joined subquery
+ * needs to have a matching row, or it will
+ * be excluded from results. The lateral keyword allows
+ * access to columns after the FROM statement.
+ */
+ innerJoinLateral = this.createJoin("inner", true);
/**
* Executes a `full join` operation by combining rows from two tables into a new table.
*