Skip to content

Commit 378b043

Browse files
authored
Merge pull request #5002 from drizzle-team/main-next-pack
Updates for `main` branch
2 parents 47ba9c8 + 5abed3d commit 378b043

File tree

30 files changed

+1365
-92
lines changed

30 files changed

+1365
-92
lines changed

changelogs/drizzle-kit/0.31.8.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Bug fixes
2+
3+
- Fixed `algorythm` => `algorithm` typo

changelogs/drizzle-orm/0.45.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- Fixed pg-native Pool detection in node-postgres transactions
2+
- Allowed subqueries in select fields
3+
- Updated typo algorythm => algorithm
4+
- Fixed `$onUpdate` not handling `SQL` values (fixes [#2388](https://github.com/drizzle-team/drizzle-orm/issues/2388), tests implemented by [L-Mario564](https://github.com/L-Mario564) in [#2911](https://github.com/drizzle-team/drizzle-orm/pull/2911))
5+
- Fixed `pg` mappers not handling `Date` instances in `bun-sql:postgresql` driver responses for `date`, `timestamp` types (fixes [#4493](https://github.com/drizzle-team/drizzle-orm/issues/4493))

drizzle-kit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-kit",
3-
"version": "0.31.7",
3+
"version": "0.31.8",
44
"homepage": "https://orm.drizzle.team",
55
"keywords": [
66
"drizzle",

drizzle-kit/src/serializer/mysqlSerializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ export const generateMySqlSnapshot = (
365365
columns: indexColumns,
366366
isUnique: value.config.unique ?? false,
367367
using: value.config.using,
368-
algorithm: value.config.algorythm,
368+
algorithm: value.config.algorithm,
369369
lock: value.config.lock,
370370
};
371371
});

drizzle-kit/src/serializer/singlestoreSerializer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export const generateSingleStoreSnapshot = (
274274
columns: indexColumns,
275275
isUnique: value.config.unique ?? false,
276276
using: value.config.using,
277-
algorithm: value.config.algorythm,
277+
algorithm: value.config.algorithm,
278278
lock: value.config.lock,
279279
};
280280
});

drizzle-orm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-orm",
3-
"version": "0.44.7",
3+
"version": "0.45.0",
44
"description": "Drizzle ORM package for SQL databases",
55
"type": "module",
66
"scripts": {

drizzle-orm/src/gel-core/dialect.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ export class GelDialect {
149149
return sql.join(columnNames.flatMap((colName, i) => {
150150
const col = tableColumns[colName]!;
151151

152-
const value = set[colName] ?? sql.param(col.onUpdateFn!(), col);
152+
const onUpdateFnResult = col.onUpdateFn?.();
153+
const value = set[colName] ?? (is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col));
153154
const res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;
154155

155156
if (i < setSize - 1) {
@@ -241,6 +242,23 @@ export class GelDialect {
241242
// } else {
242243
chunk.push(field);
243244
// }
245+
} else if (is(field, Subquery)) {
246+
const entries = Object.entries(field._.selectedFields) as [string, SQL.Aliased | Column | SQL][];
247+
248+
if (entries.length === 1) {
249+
const entry = entries[0]![1];
250+
251+
const fieldDecoder = is(entry, SQL)
252+
? entry.decoder
253+
: is(entry, Column)
254+
? { mapFromDriverValue: (v: any) => entry.mapFromDriverValue(v) }
255+
: entry.sql.decoder;
256+
257+
if (fieldDecoder) {
258+
field._.sql.decoder = fieldDecoder;
259+
}
260+
}
261+
chunk.push(field);
244262
}
245263

246264
if (i < columnsLen - 1) {

drizzle-orm/src/mysql-core/dialect.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ export class MySqlDialect {
144144
return sql.join(columnNames.flatMap((colName, i) => {
145145
const col = tableColumns[colName]!;
146146

147-
const value = set[colName] ?? sql.param(col.onUpdateFn!(), col);
147+
const onUpdateFnResult = col.onUpdateFn?.();
148+
const value = set[colName] ?? (is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col));
148149
const res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;
149150

150151
if (i < setSize - 1) {
@@ -222,6 +223,23 @@ export class MySqlDialect {
222223
} else {
223224
chunk.push(field);
224225
}
226+
} else if (is(field, Subquery)) {
227+
const entries = Object.entries(field._.selectedFields) as [string, SQL.Aliased | Column | SQL][];
228+
229+
if (entries.length === 1) {
230+
const entry = entries[0]![1];
231+
232+
const fieldDecoder = is(entry, SQL)
233+
? entry.decoder
234+
: is(entry, Column)
235+
? { mapFromDriverValue: (v: any) => entry.mapFromDriverValue(v) }
236+
: entry.sql.decoder;
237+
238+
if (fieldDecoder) {
239+
field._.sql.decoder = fieldDecoder;
240+
}
241+
}
242+
chunk.push(field);
225243
}
226244

227245
if (i < columnsLen - 1) {

drizzle-orm/src/mysql-core/indexes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ interface IndexConfig {
1919
using?: 'btree' | 'hash';
2020

2121
/**
22-
* If set, the index will be created as `create index ... algorythm { 'default' | 'inplace' | 'copy' }`.
22+
* If set, the index will be created as `create index ... algorithm { 'default' | 'inplace' | 'copy' }`.
2323
*/
24-
algorythm?: 'default' | 'inplace' | 'copy';
24+
algorithm?: 'default' | 'inplace' | 'copy';
2525

2626
/**
2727
* If set, adds locks to the index creation.
@@ -67,8 +67,8 @@ export class IndexBuilder implements AnyIndexBuilder {
6767
return this;
6868
}
6969

70-
algorythm(algorythm: IndexConfig['algorythm']): this {
71-
this.config.algorythm = algorythm;
70+
algorithm(algorithm: IndexConfig['algorithm']): this {
71+
this.config.algorithm = algorithm;
7272
return this;
7373
}
7474

drizzle-orm/src/node-postgres/session.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { tracer } from '~/tracing.ts';
1515
import { type Assume, mapResultRow } from '~/utils.ts';
1616

1717
const { Pool, types } = pg;
18+
const NativePool = (<any> pg).native ? (<{ Pool: typeof Pool }> (<any> pg).native).Pool : undefined;
1819

1920
export type NodePgClient = pg.Pool | PoolClient | Client;
2021

@@ -249,7 +250,7 @@ export class NodePgSession<
249250
transaction: (tx: NodePgTransaction<TFullSchema, TSchema>) => Promise<T>,
250251
config?: PgTransactionConfig | undefined,
251252
): Promise<T> {
252-
const session = this.client instanceof Pool // eslint-disable-line no-instanceof/no-instanceof
253+
const session = (this.client instanceof Pool || (NativePool && this.client instanceof NativePool)) // eslint-disable-line no-instanceof/no-instanceof
253254
? new NodePgSession(await this.client.connect(), this.dialect, this.schema, this.options)
254255
: this;
255256
const tx = new NodePgTransaction<TFullSchema, TSchema>(this.dialect, session, this.schema);
@@ -262,7 +263,7 @@ export class NodePgSession<
262263
await tx.execute(sql`rollback`);
263264
throw error;
264265
} finally {
265-
if (this.client instanceof Pool) { // eslint-disable-line no-instanceof/no-instanceof
266+
if (this.client instanceof Pool || (NativePool && this.client instanceof NativePool)) { // eslint-disable-line no-instanceof/no-instanceof
266267
(session.client as PoolClient).release();
267268
}
268269
}

0 commit comments

Comments
 (0)