Skip to content

Commit c6971b2

Browse files
committed
D1 Buffer mapping fix, tests fix
1 parent 4084208 commit c6971b2

File tree

6 files changed

+32
-18
lines changed

6 files changed

+32
-18
lines changed

changelogs/drizzle-orm/0.41.0.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
- Fixed `isConfig` utility function checking types of wrong fields
88
- Enabled `supportBigNumbers` in auto-created `mysql2` driver instances
99
- Fixed custom schema tables querying in RQBv1: [#4060](https://github.com/drizzle-team/drizzle-orm/issues/4060)
10-
- Removed in-driver mapping for postgres types `1231` (`numeric[]`), `1115` (`timestamp[]`), `1185` (`timestamp_with_timezone[]`), `1187` (`interval[]`), `1182` (`date[]`), preventing precision loss and data\\type mismatches
10+
- Removed in-driver mapping for postgres types `1231` (`numeric[]`), `1115` (`timestamp[]`), `1185` (`timestamp_with_timezone[]`), `1187` (`interval[]`), `1182` (`date[]`), preventing precision loss and data\\type mismatches
11+
- Fixed `SQLite` `buffer`-mode `blob` sometimes returning `number[]`

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

+8
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ export class SQLiteBlobBufferBuilder<T extends ColumnBuilderBaseConfig<'buffer',
145145
export class SQLiteBlobBuffer<T extends ColumnBaseConfig<'buffer', 'SQLiteBlobBuffer'>> extends SQLiteColumn<T> {
146146
static override readonly [entityKind]: string = 'SQLiteBlobBuffer';
147147

148+
override mapFromDriverValue(value: Buffer | Uint8Array | ArrayBuffer): T['data'] {
149+
if (Buffer.isBuffer(value)) {
150+
return value;
151+
}
152+
153+
return Buffer.from(value as Uint8Array);
154+
}
155+
148156
getSQLType(): string {
149157
return 'blob';
150158
}

integration-tests/tests/mysql/mysql-custom.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ test('custom binary', async (ctx) => {
811811

812812
expect(res).toEqual([{
813813
id,
814-
sqlId: Buffer.from(id, 'hex'),
814+
sqlId: Buffer.from(id, 'hex').toString(),
815815
rawId: id,
816816
}]);
817817
});

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

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ class ServerSimulator {
1818
types.setTypeParser(types.builtins.TIMESTAMP, (val) => val);
1919
types.setTypeParser(types.builtins.DATE, (val) => val);
2020
types.setTypeParser(types.builtins.INTERVAL, (val) => val);
21+
types.setTypeParser(1231, (val) => val);
22+
types.setTypeParser(1115, (val) => val);
23+
types.setTypeParser(1185, (val) => val);
24+
types.setTypeParser(1187, (val) => val);
25+
types.setTypeParser(1182, (val) => val);
2126
}
2227

2328
async query(sql: string, params: any[], method: 'all' | 'execute') {

integration-tests/tests/relational/mysql.schema.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ export const usersTable = mysqlTable('users', {
2424
const schemaV1 = mysqlSchema('schemaV1');
2525

2626
export const usersV1 = schemaV1.table('usersV1', {
27-
id: serial().primaryKey(),
28-
name: text().notNull(),
29-
verified: boolean().notNull().default(false),
30-
invitedBy: bigint({ mode: 'number' }),
27+
id: serial('id').primaryKey(),
28+
name: text('name').notNull(),
29+
verified: boolean('verified').notNull().default(false),
30+
invitedBy: bigint('invited_by', { mode: 'number' }),
3131
});
3232

3333
export const usersTableV1 = schemaV1.table('users_table_V1', {
34-
id: serial().primaryKey(),
35-
name: text().notNull(),
36-
verified: boolean().notNull().default(false),
37-
invitedBy: bigint({ mode: 'number' }),
34+
id: serial('id').primaryKey(),
35+
name: text('name').notNull(),
36+
verified: boolean('verified').notNull().default(false),
37+
invitedBy: bigint('invited_by', { mode: 'number' }),
3838
});
3939

4040
export const usersConfig = relations(usersTable, ({ one, many }) => ({

integration-tests/tests/relational/pg.schema.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ export const usersTable = pgTable('users', {
2222
export const schemaV1 = pgSchema('schemaV1');
2323

2424
export const usersV1 = schemaV1.table('usersV1', {
25-
id: serial().primaryKey(),
26-
name: text().notNull(),
27-
verified: boolean().notNull().default(false),
28-
invitedBy: integer(),
25+
id: serial('id').primaryKey(),
26+
name: text('name').notNull(),
27+
verified: boolean('verified').notNull().default(false),
28+
invitedBy: integer('invited_by'),
2929
});
3030

3131
export const usersTableV1 = schemaV1.table('users_table_V1', {
32-
id: serial().primaryKey(),
33-
name: text().notNull(),
34-
verified: boolean().notNull().default(false),
35-
invitedBy: integer(),
32+
id: serial('id').primaryKey(),
33+
name: text('name').notNull(),
34+
verified: boolean('verified').notNull().default(false),
35+
invitedBy: integer('invited_by'),
3636
});
3737

3838
export const usersConfig = relations(usersTable, ({ one, many }) => ({

0 commit comments

Comments
 (0)