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

Use queryConfig API for query in pgtyped-runtime #7

Open
wants to merge 2 commits into
base: rescript
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
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"pgtyped-rescript": "^2.4.0",
"pgtyped-rescript-query": "^2.3.0",
"rescript": "11.1.0",
"rescript-embed-lang": "^0.5.1",
"rescript-embed-lang": "^0.5.2",
"typescript": "4.9.4"
},
"devDependencies": {
Expand Down
24 changes: 18 additions & 6 deletions packages/runtime/src/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export interface ICursor<T> {
}

export interface IDatabaseConnection {
query: (query: string, bindings: any[]) => Promise<{ rows: any[] }>;
stream?: (query: string, bindings: any[]) => ICursor<any[]>;
query: (config: { text: string; values: any[] }) => Promise<{ rows: any[] }>;
stream?: (config: { text: string; values: any[] }) => ICursor<any[]>;
}

/** Check for column modifier suffixes (exclamation and question marks). */
Expand Down Expand Up @@ -55,7 +55,10 @@ export class TaggedQuery<TTypePair extends { params: any; result: any }> {
this.query,
params as any,
);
const result = await connection.query(processedQuery, bindings);
const result = await connection.query({
text: processedQuery,
values: bindings,
});
return mapQueryResultRows(result.rows);
};
this.stream = (params, connection) => {
Expand All @@ -65,7 +68,10 @@ export class TaggedQuery<TTypePair extends { params: any; result: any }> {
);
if (connection.stream == null)
throw new Error("Connection doesn't support streaming.");
const cursor = connection.stream(processedQuery, bindings);
const cursor = connection.stream({
text: processedQuery,
values: bindings,
});
return {
async read(rowCount: number) {
const rows = await cursor.read(rowCount);
Expand Down Expand Up @@ -112,7 +118,10 @@ export class PreparedQuery<TParamType, TResultType> {
this.queryIR,
params as any,
);
const result = await connection.query(processedQuery, bindings);
const result = await connection.query({
text: processedQuery,
values: bindings,
});
return mapQueryResultRows(result.rows);
};
this.stream = (params, connection) => {
Expand All @@ -122,7 +131,10 @@ export class PreparedQuery<TParamType, TResultType> {
);
if (connection.stream == null)
throw new Error("Connection doesn't support streaming.");
const cursor = connection.stream(processedQuery, bindings);
const cursor = connection.stream({
text: processedQuery,
values: bindings,
});
return {
async read(rowCount: number) {
const rows = await cursor.read(rowCount);
Expand Down
Loading