Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: drop support for executing raw SQL strings in execute() methods for all dialects #3761

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion drizzle-orm/src/aws-data-api/pg/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AwsDataApiPgDatabase<

override execute<
TRow extends Record<string, unknown> = Record<string, unknown>,
>(query: SQLWrapper | string): PgRaw<AwsDataApiPgQueryResult<TRow>> {
>(query: SQLWrapper): PgRaw<AwsDataApiPgQueryResult<TRow>> {
return super.execute(query);
}
}
Expand Down
4 changes: 2 additions & 2 deletions drizzle-orm/src/mysql-core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ export class MySqlDatabase<
}

execute<T extends { [column: string]: any } = ResultSetHeader>(
query: SQLWrapper | string,
query: SQLWrapper,
): Promise<MySqlQueryResultKind<TQueryResult, T>> {
return this.session.execute(typeof query === 'string' ? sql.raw(query) : query.getSQL());
return this.session.execute(query.getSQL());
}

transaction<T>(
Expand Down
4 changes: 2 additions & 2 deletions drizzle-orm/src/pg-core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,9 +600,9 @@ export class PgDatabase<
protected authToken?: NeonAuthToken;

execute<TRow extends Record<string, unknown> = Record<string, unknown>>(
query: SQLWrapper | string,
query: SQLWrapper,
): PgRaw<PgQueryResultKind<TQueryResult, TRow>> {
const sequel = typeof query === 'string' ? sql.raw(query) : query.getSQL();
const sequel = query.getSQL();
const builtQuery = this.dialect.sqlToQuery(sequel);
const prepared = this.session.prepareQuery<
PreparedQueryConfig & { execute: PgQueryResultKind<TQueryResult, TRow> }
Expand Down
4 changes: 2 additions & 2 deletions drizzle-orm/src/singlestore-core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,9 @@ export class SingleStoreDatabase<
}

execute<T extends { [column: string]: any } = ResultSetHeader>(
query: SQLWrapper | string,
query: SQLWrapper,
): Promise<SingleStoreQueryResultKind<TQueryResult, T>> {
return this.session.execute(typeof query === 'string' ? sql.raw(query) : query.getSQL());
return this.session.execute(query.getSQL());
}

transaction<T>(
Expand Down
16 changes: 8 additions & 8 deletions drizzle-orm/src/sqlite-core/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ export class BaseSQLiteDatabase<
return new SQLiteDeleteBase(from, this.session, this.dialect);
}

run(query: SQLWrapper | string): DBResult<TResultKind, TRunResult> {
const sequel = typeof query === 'string' ? sql.raw(query) : query.getSQL();
run(query: SQLWrapper): DBResult<TResultKind, TRunResult> {
const sequel = query.getSQL();
if (this.resultKind === 'async') {
return new SQLiteRaw(
async () => this.session.run(sequel),
Expand All @@ -533,8 +533,8 @@ export class BaseSQLiteDatabase<
return this.session.run(sequel) as DBResult<TResultKind, TRunResult>;
}

all<T = unknown>(query: SQLWrapper | string): DBResult<TResultKind, T[]> {
const sequel = typeof query === 'string' ? sql.raw(query) : query.getSQL();
all<T = unknown>(query: SQLWrapper): DBResult<TResultKind, T[]> {
const sequel = query.getSQL();
if (this.resultKind === 'async') {
return new SQLiteRaw(
async () => this.session.all(sequel),
Expand All @@ -547,8 +547,8 @@ export class BaseSQLiteDatabase<
return this.session.all(sequel) as DBResult<TResultKind, T[]>;
}

get<T = unknown>(query: SQLWrapper | string): DBResult<TResultKind, T> {
const sequel = typeof query === 'string' ? sql.raw(query) : query.getSQL();
get<T = unknown>(query: SQLWrapper): DBResult<TResultKind, T> {
const sequel = query.getSQL();
if (this.resultKind === 'async') {
return new SQLiteRaw(
async () => this.session.get(sequel),
Expand All @@ -561,8 +561,8 @@ export class BaseSQLiteDatabase<
return this.session.get(sequel) as DBResult<TResultKind, T>;
}

values<T extends unknown[] = unknown[]>(query: SQLWrapper | string): DBResult<TResultKind, T[]> {
const sequel = typeof query === 'string' ? sql.raw(query) : query.getSQL();
values<T extends unknown[] = unknown[]>(query: SQLWrapper): DBResult<TResultKind, T[]> {
const sequel = query.getSQL();
if (this.resultKind === 'async') {
return new SQLiteRaw(
async () => this.session.values(sequel),
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/tests/pg/neon-http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ describe('$withAuth tests', (it) => {
});

it('exec', async () => {
await db.$withAuth('exec').execute(`SELECT 1`).catch(() => null);
await db.$withAuth('exec').execute(sql.raw('SELECT 1')).catch(() => null);

expect(client.mock.lastCall?.[2]).toStrictEqual({ arrayMode: false, fullResults: true, authToken: 'exec' });
});
Expand Down Expand Up @@ -659,7 +659,7 @@ describe('$withAuth callback tests', (it) => {
});

it('exec', async () => {
await db.$withAuth(auth('exec')).execute(`SELECT 1`).catch(() => null);
await db.$withAuth(auth('exec')).execute(sql.raw('SELECT 1')).catch(() => null);

expect(client.mock.lastCall?.[2]['authToken']()).toStrictEqual('exec');
});
Expand Down Expand Up @@ -763,7 +763,7 @@ describe('$withAuth async callback tests', (it) => {
});

it('exec', async () => {
await db.$withAuth(auth('exec')).execute(`SELECT 1`).catch(() => null);
await db.$withAuth(auth('exec')).execute(sql.raw('SELECT 1')).catch(() => null);

expect(client.mock.lastCall?.[2]['authToken']()).toBeInstanceOf(Promise);
expect(await client.mock.lastCall?.[2]['authToken']()).toStrictEqual('exec');
Expand Down