Skip to content

Commit 5e554e1

Browse files
authored
Use queryConfig API for query in pgtyped-runtime (#7)
* update rescript-embed-lang to make it work with macos x86_64 * use queryConfig API of pg.Client/Pool query
1 parent 382ad8c commit 5e554e1

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"pgtyped-rescript": "^2.4.0",
2929
"pgtyped-rescript-query": "^2.3.0",
3030
"rescript": "11.1.0",
31-
"rescript-embed-lang": "^0.5.1",
31+
"rescript-embed-lang": "^0.5.2",
3232
"typescript": "4.9.4"
3333
},
3434
"devDependencies": {

packages/runtime/src/tag.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export interface ICursor<T> {
88
}
99

1010
export interface IDatabaseConnection {
11-
query: (query: string, bindings: any[]) => Promise<{ rows: any[] }>;
12-
stream?: (query: string, bindings: any[]) => ICursor<any[]>;
11+
query: (config: { text: string; values: any[] }) => Promise<{ rows: any[] }>;
12+
stream?: (config: { text: string; values: any[] }) => ICursor<any[]>;
1313
}
1414

1515
/** Check for column modifier suffixes (exclamation and question marks). */
@@ -55,7 +55,10 @@ export class TaggedQuery<TTypePair extends { params: any; result: any }> {
5555
this.query,
5656
params as any,
5757
);
58-
const result = await connection.query(processedQuery, bindings);
58+
const result = await connection.query({
59+
text: processedQuery,
60+
values: bindings,
61+
});
5962
return mapQueryResultRows(result.rows);
6063
};
6164
this.stream = (params, connection) => {
@@ -65,7 +68,10 @@ export class TaggedQuery<TTypePair extends { params: any; result: any }> {
6568
);
6669
if (connection.stream == null)
6770
throw new Error("Connection doesn't support streaming.");
68-
const cursor = connection.stream(processedQuery, bindings);
71+
const cursor = connection.stream({
72+
text: processedQuery,
73+
values: bindings,
74+
});
6975
return {
7076
async read(rowCount: number) {
7177
const rows = await cursor.read(rowCount);
@@ -112,7 +118,10 @@ export class PreparedQuery<TParamType, TResultType> {
112118
this.queryIR,
113119
params as any,
114120
);
115-
const result = await connection.query(processedQuery, bindings);
121+
const result = await connection.query({
122+
text: processedQuery,
123+
values: bindings,
124+
});
116125
return mapQueryResultRows(result.rows);
117126
};
118127
this.stream = (params, connection) => {
@@ -122,7 +131,10 @@ export class PreparedQuery<TParamType, TResultType> {
122131
);
123132
if (connection.stream == null)
124133
throw new Error("Connection doesn't support streaming.");
125-
const cursor = connection.stream(processedQuery, bindings);
134+
const cursor = connection.stream({
135+
text: processedQuery,
136+
values: bindings,
137+
});
126138
return {
127139
async read(rowCount: number) {
128140
const rows = await cursor.read(rowCount);

0 commit comments

Comments
 (0)