Skip to content

Commit 273829f

Browse files
committed
Fixed counts
1 parent f6c8f47 commit 273829f

5 files changed

Lines changed: 32 additions & 4 deletions

File tree

changelogs/drizzle-orm/1.0.0-rc.4.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
- Fixed codecs not getting applied to `SQL` field when `.mapWith(column)` is set (fixes [#5724](https://github.com/drizzle-team/drizzle-orm/issues/5724))
66
- Fixed `Subquery` fields' columns' codecs not being applied to subquery
77
- Fixed broken in `rc.3` `db.select` in `bun-sql/pg` driver
8-
- Updated SQLite `db.$count` builder to include `.sync()` executor for sync drivers
8+
- Updated SQLite `db.$count` builder to include `.sync()` executor for sync drivers
9+
- Fixed missing `customResultMapper` (RQBv1, temporarily `$count`) code paths in `sql-js`, `sqlite-cloud`, `tursodatabase` drivers

drizzle-orm/src/sql-js/session.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class SQLJsSession<
5252
query: Query,
5353
fields: SelectedFieldsOrdered | undefined,
5454
executeMethod: SQLiteExecuteMethod,
55+
customResultMapper: (rows: unknown[][]) => unknown,
5556
): PreparedQuery<T> {
5657
return new PreparedQuery(
5758
this.client,
@@ -60,6 +61,7 @@ export class SQLJsSession<
6061
fields,
6162
executeMethod,
6263
this.options.useJitMappers,
64+
customResultMapper,
6365
);
6466
}
6567

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ export class SQLiteCloudPreparedQuery<
273273
}
274274

275275
const rows = await this.values(placeholderValues) as unknown[][];
276+
if (customResultMapper) {
277+
return (customResultMapper as (
278+
rows: unknown[][],
279+
mapColumnValue?: (value: unknown) => unknown,
280+
) => unknown)([rows]);
281+
}
276282

277283
return this.useJitMappers
278284
? (this.jitMapper = this.jitMapper as RowsMapper<T['all']>
@@ -333,6 +339,12 @@ export class SQLiteCloudPreparedQuery<
333339
});
334340

335341
if (row === undefined) return row;
342+
if (customResultMapper) {
343+
return (customResultMapper as (
344+
rows: unknown[][],
345+
mapColumnValue?: (value: unknown) => unknown,
346+
) => unknown)([row]);
347+
}
336348

337349
return this.useJitMappers
338350
? (this.jitMapper = this.jitMapper as RowsMapper<T['get'][]>

drizzle-orm/src/sqlite-core/query-builders/count.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ export class SQLiteCountBuilder extends SQL<number> implements SQLWrapper<number
7070
if (typeof v === 'number') return v;
7171
return v ? Number(v) : 0;
7272
},
73-
).execute(placeholderValues) as any;
73+
).get(placeholderValues) as any;
7474
}
7575

76-
execute(placeholderValues?: Record<string, unknown>): Promise<number> {
77-
return this.executeRaw(placeholderValues) as Promise<number>;
76+
// async-await to avoid crashing when used on sync drivers with .then(), .catch() for compatibility
77+
async execute(placeholderValues?: Record<string, unknown>): Promise<number> {
78+
return await (this.executeRaw(placeholderValues));
7879
}
7980
}
8081

drizzle-orm/src/tursodatabase/session.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ export class TursoDatabasePreparedQuery<
271271
}
272272

273273
const rows = await this.values(placeholderValues) as unknown[][];
274+
if (customResultMapper) {
275+
return (customResultMapper as (
276+
rows: unknown[][],
277+
mapColumnValue?: (value: unknown) => unknown,
278+
) => unknown)(rows);
279+
}
274280

275281
return this.useJitMappers
276282
? (this.jitMapper = this.jitMapper as RowsMapper<T['all']>
@@ -313,6 +319,12 @@ export class TursoDatabasePreparedQuery<
313319
});
314320

315321
if (row === undefined) return row;
322+
if (customResultMapper) {
323+
return (customResultMapper as (
324+
rows: unknown[][],
325+
mapColumnValue?: (value: unknown) => unknown,
326+
) => unknown)([row]);
327+
}
316328

317329
return this.useJitMappers
318330
? (this.jitMapper = this.jitMapper as RowsMapper<T['get'][]>

0 commit comments

Comments
 (0)