Skip to content

Commit 515afb0

Browse files
authored
Merge branch 'beta' into main
2 parents 474f834 + 07400cc commit 515afb0

File tree

28 files changed

+1113
-2482
lines changed

28 files changed

+1113
-2482
lines changed

drizzle-orm/src/better-sqlite3/session.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ import { fillPlaceholders, type Query, sql } from '~/sql';
77
import { SQLiteTransaction } from '~/sqlite-core';
88
import type { SQLiteSyncDialect } from '~/sqlite-core/dialect';
99
import type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types';
10-
import type { PreparedQueryConfig as PreparedQueryConfigBase, SQLiteTransactionConfig } from '~/sqlite-core/session';
11-
import { PreparedQuery as PreparedQueryBase, SQLiteSession } from '~/sqlite-core/session';
10+
import {
11+
PreparedQuery as PreparedQueryBase,
12+
type PreparedQueryConfig as PreparedQueryConfigBase,
13+
type SQLiteExecuteMethod,
14+
SQLiteSession,
15+
type SQLiteTransactionConfig,
16+
} from '~/sqlite-core/session';
1217
import { mapResultRow } from '~/utils';
1318

1419
export interface BetterSQLiteSessionOptions {
@@ -38,10 +43,11 @@ export class BetterSQLiteSession<
3843
prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(
3944
query: Query,
4045
fields: SelectedFieldsOrdered | undefined,
46+
executeMethod: SQLiteExecuteMethod,
4147
customResultMapper?: (rows: unknown[][]) => unknown,
4248
): PreparedQuery<T> {
4349
const stmt = this.client.prepare(query.sql);
44-
return new PreparedQuery(stmt, query.sql, query.params, this.logger, fields, customResultMapper);
50+
return new PreparedQuery(stmt, query.sql, query.params, this.logger, fields, executeMethod, customResultMapper);
4551
}
4652

4753
override transaction<T>(
@@ -76,7 +82,7 @@ export class BetterSQLiteTransaction<
7682
}
7783

7884
export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends PreparedQueryBase<
79-
{ type: 'sync'; run: RunResult; all: T['all']; get: T['get']; values: T['values'] }
85+
{ type: 'sync'; run: RunResult; all: T['all']; get: T['get']; values: T['values']; execute: T['execute'] }
8086
> {
8187
static readonly [entityKind]: string = 'BetterSQLitePreparedQuery';
8288

@@ -86,9 +92,10 @@ export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig>
8692
private params: unknown[],
8793
private logger: Logger,
8894
private fields: SelectedFieldsOrdered | undefined,
95+
executeMethod: SQLiteExecuteMethod,
8996
private customResultMapper?: (rows: unknown[][]) => unknown,
9097
) {
91-
super();
98+
super('sync', executeMethod);
9299
}
93100

94101
run(placeholderValues?: Record<string, unknown>): RunResult {
@@ -105,7 +112,7 @@ export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig>
105112
return stmt.all(...params);
106113
}
107114

108-
const rows = this.values(placeholderValues);
115+
const rows = this.values(placeholderValues) as unknown[][];
109116
if (customResultMapper) {
110117
return customResultMapper(rows) as T['all'];
111118
}

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import { fillPlaceholders, type Query, sql } from '~/sql';
99
import { SQLiteTransaction } from '~/sqlite-core';
1010
import type { SQLiteSyncDialect } from '~/sqlite-core/dialect';
1111
import type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types';
12-
import type { PreparedQueryConfig as PreparedQueryConfigBase, SQLiteTransactionConfig } from '~/sqlite-core/session';
12+
import type {
13+
PreparedQueryConfig as PreparedQueryConfigBase,
14+
SQLiteExecuteMethod,
15+
SQLiteTransactionConfig,
16+
} from '~/sqlite-core/session';
1317
import { PreparedQuery as PreparedQueryBase, SQLiteSession } from '~/sqlite-core/session';
1418
import { mapResultRow } from '~/utils';
1519

@@ -44,11 +48,12 @@ export class SQLiteBunSession<
4448

4549
prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(
4650
query: Query,
47-
fields?: SelectedFieldsOrdered,
51+
fields: SelectedFieldsOrdered | undefined,
52+
executeMethod: SQLiteExecuteMethod,
4853
customResultMapper?: (rows: unknown[][]) => unknown,
4954
): PreparedQuery<T> {
5055
const stmt = this.client.prepare(query.sql);
51-
return new PreparedQuery(stmt, query.sql, query.params, this.logger, fields, customResultMapper);
56+
return new PreparedQuery(stmt, query.sql, query.params, this.logger, fields, executeMethod, customResultMapper);
5257
}
5358

5459
override transaction<T>(
@@ -87,7 +92,7 @@ export class SQLiteBunTransaction<
8792
}
8893

8994
export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends PreparedQueryBase<
90-
{ type: 'sync'; run: void; all: T['all']; get: T['get']; values: T['values'] }
95+
{ type: 'sync'; run: void; all: T['all']; get: T['get']; values: T['values']; execute: T['execute'] }
9196
> {
9297
static readonly [entityKind]: string = 'SQLiteBunPreparedQuery';
9398

@@ -97,9 +102,10 @@ export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig>
97102
private params: unknown[],
98103
private logger: Logger,
99104
private fields: SelectedFieldsOrdered | undefined,
105+
executeMethod: SQLiteExecuteMethod,
100106
private customResultMapper?: (rows: unknown[][]) => unknown,
101107
) {
102-
super();
108+
super('sync', executeMethod);
103109
}
104110

105111
run(placeholderValues?: Record<string, unknown>): void {
@@ -116,7 +122,7 @@ export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig>
116122
return stmt.all(...params);
117123
}
118124

119-
const rows = this.values(placeholderValues);
125+
const rows = this.values(placeholderValues) as unknown[][];
120126

121127
if (customResultMapper) {
122128
return customResultMapper(rows) as T['all'];

drizzle-orm/src/d1/session.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { SQLiteAsyncDialect } from '~/sqlite-core/dialect';
1111
import type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types';
1212
import {
1313
type PreparedQueryConfig as PreparedQueryConfigBase,
14+
type SQLiteExecuteMethod,
1415
type SQLiteTransactionConfig,
1516
} from '~/sqlite-core/session';
1617
import { PreparedQuery as PreparedQueryBase, SQLiteSession } from '~/sqlite-core/session';
@@ -42,11 +43,12 @@ export class SQLiteD1Session<
4243

4344
prepareQuery(
4445
query: Query,
45-
fields?: SelectedFieldsOrdered,
46+
fields: SelectedFieldsOrdered | undefined,
47+
executeMethod: SQLiteExecuteMethod,
4648
customResultMapper?: (rows: unknown[][]) => unknown,
4749
): PreparedQuery {
4850
const stmt = this.client.prepare(query.sql);
49-
return new PreparedQuery(stmt, query.sql, query.params, this.logger, fields, customResultMapper);
51+
return new PreparedQuery(stmt, query.sql, query.params, this.logger, fields, executeMethod, customResultMapper);
5052
}
5153

5254
override async transaction<T>(
@@ -88,7 +90,7 @@ export class D1Transaction<
8890
}
8991

9092
export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends PreparedQueryBase<
91-
{ type: 'async'; run: D1Result; all: T['all']; get: T['get']; values: T['values'] }
93+
{ type: 'async'; run: D1Result; all: T['all']; get: T['get']; values: T['values']; execute: T['execute'] }
9294
> {
9395
static readonly [entityKind]: string = 'D1PreparedQuery';
9496

@@ -98,9 +100,10 @@ export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig>
98100
private params: unknown[],
99101
private logger: Logger,
100102
private fields: SelectedFieldsOrdered | undefined,
103+
executeMethod: SQLiteExecuteMethod,
101104
private customResultMapper?: (rows: unknown[][]) => unknown,
102105
) {
103-
super();
106+
super('async', executeMethod);
104107
}
105108

106109
run(placeholderValues?: Record<string, unknown>): Promise<D1Result> {

drizzle-orm/src/libsql/session.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { SQLiteAsyncDialect } from '~/sqlite-core/dialect';
99
import type { SelectedFieldsOrdered } from '~/sqlite-core/query-builders/select.types';
1010
import {
1111
type PreparedQueryConfig as PreparedQueryConfigBase,
12+
type SQLiteExecuteMethod,
1213
type SQLiteTransactionConfig,
1314
} from '~/sqlite-core/session';
1415
import { PreparedQuery as PreparedQueryBase, SQLiteSession } from '~/sqlite-core/session';
@@ -41,10 +42,20 @@ export class LibSQLSession<
4142

4243
prepareQuery<T extends Omit<PreparedQueryConfig, 'run'>>(
4344
query: Query,
44-
fields: SelectedFieldsOrdered,
45+
fields: SelectedFieldsOrdered | undefined,
46+
executeMethod: SQLiteExecuteMethod,
4547
customResultMapper?: (rows: unknown[][]) => unknown,
4648
): PreparedQuery<T> {
47-
return new PreparedQuery(this.client, query.sql, query.params, this.logger, fields, this.tx, customResultMapper);
49+
return new PreparedQuery(
50+
this.client,
51+
query.sql,
52+
query.params,
53+
this.logger,
54+
fields,
55+
this.tx,
56+
executeMethod,
57+
customResultMapper,
58+
);
4859
}
4960

5061
/*override */ batch(queries: SQL[]): Promise<ResultSet[]> {
@@ -96,7 +107,7 @@ export class LibSQLTransaction<
96107
}
97108

98109
export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig> extends PreparedQueryBase<
99-
{ type: 'async'; run: ResultSet; all: T['all']; get: T['get']; values: T['values'] }
110+
{ type: 'async'; run: ResultSet; all: T['all']; get: T['get']; values: T['values']; execute: T['execute'] }
100111
> {
101112
static readonly [entityKind]: string = 'LibSQLPreparedQuery';
102113

@@ -107,9 +118,10 @@ export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig>
107118
private logger: Logger,
108119
private fields: SelectedFieldsOrdered | undefined,
109120
private tx: Transaction | undefined,
121+
executeMethod: SQLiteExecuteMethod,
110122
private customResultMapper?: (rows: unknown[][], mapColumnValue?: (value: unknown) => unknown) => unknown,
111123
) {
112-
super();
124+
super('async', executeMethod);
113125
}
114126

115127
run(placeholderValues?: Record<string, unknown>): Promise<ResultSet> {
@@ -128,7 +140,7 @@ export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig>
128140
return (tx ? tx.execute(stmt) : client.execute(stmt)).then(({ rows }) => rows.map((row) => normalizeRow(row)));
129141
}
130142

131-
const rows = await this.values(placeholderValues);
143+
const rows = await this.values(placeholderValues) as unknown[][];
132144

133145
if (customResultMapper) {
134146
return customResultMapper(rows, normalizeFieldValue) as T['all'];
@@ -152,7 +164,7 @@ export class PreparedQuery<T extends PreparedQueryConfig = PreparedQueryConfig>
152164
return (tx ? tx.execute(stmt) : client.execute(stmt)).then(({ rows }) => normalizeRow(rows[0]));
153165
}
154166

155-
const rows = await this.values(placeholderValues);
167+
const rows = await this.values(placeholderValues) as unknown[][];
156168

157169
if (!rows[0]) {
158170
return undefined;

0 commit comments

Comments
 (0)