Skip to content

Commit 3a49219

Browse files
committed
fixes
1 parent 0db28f1 commit 3a49219

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

packages/runtime/src/client/client-impl.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export class ClientImpl<Schema extends SchemaDef> {
221221

222222
$executeRawUnsafe(query: string, ...values: any[]) {
223223
return createDeferredPromise(async () => {
224-
const compiledQuery = CompiledQuery.raw(query, values);
224+
const compiledQuery = this.createRawCompiledQuery(query, values);
225225
const result = await this.kysely.executeQuery(compiledQuery);
226226
return Number(result.numAffectedRows ?? 0);
227227
});
@@ -236,11 +236,16 @@ export class ClientImpl<Schema extends SchemaDef> {
236236

237237
$queryRawUnsafe<T = unknown>(query: string, ...values: any[]) {
238238
return createDeferredPromise(async () => {
239-
const compiledQuery = CompiledQuery.raw(query, values);
239+
const compiledQuery = this.createRawCompiledQuery(query, values);
240240
const result = await this.kysely.executeQuery(compiledQuery);
241241
return result.rows as T;
242242
});
243243
}
244+
245+
private createRawCompiledQuery(query: string, values: any[]) {
246+
const q = CompiledQuery.raw(query, values);
247+
return { ...q, $raw: true } as CompiledQuery;
248+
}
244249
}
245250

246251
function createClientProxy<Schema extends SchemaDef>(client: ClientImpl<Schema>): ClientImpl<Schema> {

packages/runtime/src/client/executor/zenstack-query-executor.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
8181
}
8282

8383
// proceed with the query with kysely interceptors
84-
const result = await this.proceedQueryWithKyselyInterceptors(queryNode, compiledQuery.parameters, queryId);
84+
// if the query is a raw query, we need to carry over the parameters
85+
const queryParams = (compiledQuery as any).$raw ? compiledQuery.parameters : undefined;
86+
const result = await this.proceedQueryWithKyselyInterceptors(queryNode, queryParams, queryId);
8587

8688
// call after mutation hooks
8789
await this.callAfterQueryInterceptionFilters(result, queryNode, mutationInterceptionInfo);
@@ -98,7 +100,7 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
98100

99101
private proceedQueryWithKyselyInterceptors(
100102
queryNode: RootOperationNode,
101-
parameters: readonly unknown[],
103+
parameters: readonly unknown[] | undefined,
102104
queryId: QueryId,
103105
) {
104106
let proceed = (q: RootOperationNode) => this.proceedQuery(q, parameters, queryId);
@@ -129,10 +131,13 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
129131
return proceed(queryNode);
130132
}
131133

132-
private async proceedQuery(query: RootOperationNode, parameters: readonly unknown[], queryId: QueryId) {
134+
private async proceedQuery(query: RootOperationNode, parameters: readonly unknown[] | undefined, queryId: QueryId) {
133135
// run built-in transformers
134136
const finalQuery = this.nameMapper.transformNode(query);
135-
const compiled: CompiledQuery = { ...this.compileQuery(finalQuery), parameters };
137+
let compiled = this.compileQuery(finalQuery);
138+
if (parameters) {
139+
compiled = { ...compiled, parameters };
140+
}
136141
try {
137142
return this.driver.txConnection
138143
? await super

0 commit comments

Comments
 (0)