Skip to content

Commit

Permalink
Merge pull request #14 from chientrm/9-d1-query-bugs
Browse files Browse the repository at this point in the history
D1 Query Bugs
  • Loading branch information
chientrm authored Nov 30, 2023
2 parents 9317d0e + 90482b8 commit 7c08e36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/proxies/d1_database/prepared_statement/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ class D1DatabasePreparedStatementProxy
}
async raw<T = unknown>(): Promise<T[]> {
const { host, metadata, name } = this,
{ query } = metadata,
{ query, values } = metadata,
proxy = new D1DatabasePreparedStatementRawProxy({
host,
name,
metadata: { query },
metadata: { query, values },
});
return proxy.post();
}
Expand Down
7 changes: 5 additions & 2 deletions src/proxies/d1_database/prepared_statement/raw/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Proxy } from '../../../proxy';

interface Metadata {
query: string;
values?: any[];
}

class D1DatabasePreparedStatementRawProxy extends Proxy<Metadata> {
Expand All @@ -22,8 +23,10 @@ class D1DatabasePreparedStatementRawProxy extends Proxy<Metadata> {
async execute(env: any) {
const { name, metadata } = this,
d1 = env[name] as D1Database,
{ query } = metadata,
result = await d1.prepare(query).raw();
{ query, values } = metadata,
statement1 = d1.prepare(query),
statement2 = values ? statement1.bind(...values) : statement1,
result = await statement2.raw();
return new Response(JSON.stringify(result), jsonInit);
}
async receive(response: Response): Promise<any> {
Expand Down

0 comments on commit 7c08e36

Please sign in to comment.