Skip to content

Commit 37d059f

Browse files
authored
v0.44.5 (#4849)
* Fixed invalid usage of `.one()` in `durable-sqlite` * Bump version, changelogs * Improved `blob` in `sqlite` * Removed unnecessary default encoding argument * Fixed D1 incompatibility * Changed `HST` to `-10` in broken timezone tests * Documented changes
1 parent 33f0374 commit 37d059f

File tree

8 files changed

+34
-26
lines changed

8 files changed

+34
-26
lines changed

changelogs/drizzle-orm/0.44.5.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Fixed invalid usage of `.one()` in `durable-sqlite` session
2+
- Fixed spread operator related crash in sqlite `blob` columns
3+
- Better browser support for sqlite `blob` columns
4+
- Improved sqlite `blob` mapping

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.4",
3+
"version": "0.44.5",
44
"description": "Drizzle ORM package for SQL databases",
55
"type": "module",
66
"scripts": {

drizzle-orm/src/durable-sqlite/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class SQLiteDOPreparedQuery<T extends PreparedQueryConfig = PreparedQuery
146146

147147
const { fields, client, joinsNotNullableMap, customResultMapper, query } = this;
148148
if (!fields && !customResultMapper) {
149-
return params.length > 0 ? client.sql.exec(query.sql, ...params).one() : client.sql.exec(query.sql).one();
149+
return (params.length > 0 ? client.sql.exec(query.sql, ...params) : client.sql.exec(query.sql)).next().value;
150150
}
151151

152152
const rows = this.values(placeholderValues) as unknown[][];

drizzle-orm/src/sqlite-core/columns/blob.ts

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnCon
22
import type { ColumnBaseConfig } from '~/column.ts';
33
import { entityKind } from '~/entity.ts';
44
import type { AnySQLiteTable } from '~/sqlite-core/table.ts';
5-
import { type Equal, getColumnNameAndConfig } from '~/utils.ts';
5+
import { type Equal, getColumnNameAndConfig, textDecoder } from '~/utils.ts';
66
import { SQLiteColumn, SQLiteColumnBuilder } from './common.ts';
77

88
type BlobMode = 'buffer' | 'json' | 'bigint';
@@ -41,18 +41,19 @@ export class SQLiteBigInt<T extends ColumnBaseConfig<'bigint', 'SQLiteBigInt'>>
4141
}
4242

4343
override mapFromDriverValue(value: Buffer | Uint8Array | ArrayBuffer): bigint {
44-
if (Buffer.isBuffer(value)) {
45-
return BigInt(value.toString());
46-
}
47-
48-
// for sqlite durable objects
49-
// eslint-disable-next-line no-instanceof/no-instanceof
50-
if (value instanceof ArrayBuffer) {
51-
const decoder = new TextDecoder();
52-
return BigInt(decoder.decode(value));
44+
if (typeof Buffer !== 'undefined' && Buffer.from) {
45+
const buf = Buffer.isBuffer(value)
46+
? value
47+
// eslint-disable-next-line no-instanceof/no-instanceof
48+
: value instanceof ArrayBuffer
49+
? Buffer.from(value)
50+
: value.buffer
51+
? Buffer.from(value.buffer, value.byteOffset, value.byteLength)
52+
: Buffer.from(value);
53+
return BigInt(buf.toString('utf8'));
5354
}
5455

55-
return BigInt(String.fromCodePoint(...value));
56+
return BigInt(textDecoder!.decode(value));
5657
}
5758

5859
override mapToDriverValue(value: bigint): Buffer {
@@ -97,18 +98,19 @@ export class SQLiteBlobJson<T extends ColumnBaseConfig<'json', 'SQLiteBlobJson'>
9798
}
9899

99100
override mapFromDriverValue(value: Buffer | Uint8Array | ArrayBuffer): T['data'] {
100-
if (Buffer.isBuffer(value)) {
101-
return JSON.parse(value.toString());
102-
}
103-
104-
// for sqlite durable objects
105-
// eslint-disable-next-line no-instanceof/no-instanceof
106-
if (value instanceof ArrayBuffer) {
107-
const decoder = new TextDecoder();
108-
return JSON.parse(decoder.decode(value));
101+
if (typeof Buffer !== 'undefined' && Buffer.from) {
102+
const buf = Buffer.isBuffer(value)
103+
? value
104+
// eslint-disable-next-line no-instanceof/no-instanceof
105+
: value instanceof ArrayBuffer
106+
? Buffer.from(value)
107+
: value.buffer
108+
? Buffer.from(value.buffer, value.byteOffset, value.byteLength)
109+
: Buffer.from(value);
110+
return JSON.parse(buf.toString('utf8'));
109111
}
110112

111-
return JSON.parse(String.fromCodePoint(...value));
113+
return JSON.parse(textDecoder!.decode(value));
112114
}
113115

114116
override mapToDriverValue(value: T['data']): Buffer {

drizzle-orm/src/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,5 @@ export function isConfig(data: any): boolean {
321321
}
322322

323323
export type NeonAuthToken = string | (() => string | Promise<string>);
324+
325+
export const textDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder();

integration-tests/tests/pg/node-postgres.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ test('test mode string for timestamp with timezone in different timezone', async
384384
const timezone = await db.execute<{ TimeZone: string }>(sql`show timezone`);
385385

386386
// set timezone to HST (UTC - 10)
387-
await db.execute(sql`set time zone 'HST'`);
387+
await db.execute(sql`set time zone '-10'`);
388388

389389
const table = pgTable('all_columns', {
390390
id: serial('id').primaryKey(),

integration-tests/tests/pg/pg-proxy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ test('test mode string for timestamp with timezone in different timezone', async
398398
const timezone = await db.execute<{ TimeZone: string }>(sql`show timezone`);
399399

400400
// set timezone to HST (UTC - 10)
401-
await db.execute(sql`set time zone 'HST'`);
401+
await db.execute(sql`set time zone '-10'`);
402402

403403
const table = pgTable('all_columns', {
404404
id: serial('id').primaryKey(),

integration-tests/tests/pg/postgres-js.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ test('test mode string for timestamp with timezone in different timezone', async
390390
const [timezone] = await db.execute<{ TimeZone: string }>(sql`show timezone`);
391391

392392
// set timezone to HST (UTC - 10)
393-
await db.execute(sql`set time zone 'HST'`);
393+
await db.execute(sql`set time zone '-10'`);
394394

395395
const table = pgTable('all_columns', {
396396
id: serial('id').primaryKey(),

0 commit comments

Comments
 (0)