@@ -75,7 +75,7 @@ If the query fails, an exception is thrown.
75
75
### Connection options
76
76
77
77
The client constructor takes an optional
78
- [ Configuration] ( src/client.ts#L88 ) object.
78
+ [ Configuration] ( https://malthe.github.io/ts-postgres/interfaces/Configuration.html ) object.
79
79
80
80
For example, to connect to a remote host use the _ host_ configuration key:
81
81
@@ -108,17 +108,20 @@ variable "PGSSLMODE" as "disable".
108
108
109
109
### Querying
110
110
111
- The ` query ` method accepts a ` Query ` object or a number of arguments
112
- that together define the query, the first argument (query text) being
113
- the only required one.
111
+ The ` query ` method accepts a text string or a
112
+ [ Query ] ( https://malthe.github.io/ts-postgres/interfaces/Query.html ) object
113
+ as the first parameter, and a tuple of values as the second parameter.
114
114
115
115
The initial example above could be written as:
116
116
117
117
``` typescript
118
- const query = new Query ( " SELECT 'Hello ' || $1 || '!' AS message" , [ ' world ' ]) ;
119
- const result = await client .execute <Greeting >(query );
118
+ const query = {text: " SELECT 'Hello ' || $1 || '!' AS message" } ;
119
+ const result = await client .query <Greeting >(query , [ ' world ' ] );
120
120
```
121
121
122
+ The ` Query ` object has a number of optional properties that can change
123
+ how the query is carried out, including column name transformation.
124
+
122
125
If the object type is omitted, it defaults to ` Record<string, any> ` , but
123
126
providing a type ensures that the object values are typed, both when
124
127
accessed via the iterator or record interface (see below).
@@ -204,10 +207,10 @@ asynchronous stream such as a network socket, or a file.
204
207
Assuming that ` socket ` is a writable stream:
205
208
206
209
``` typescript
207
- const query = new Query (' SELECT some_bytea_column' , {
210
+ const result = await client .query ({
211
+ text: ' SELECT some_bytea_column' ,
208
212
streams: { some_bytea_column: socket },
209
213
});
210
- const result = await client .execute (query );
211
214
```
212
215
213
216
This can for example be used to reduce time to first byte and memory use.
0 commit comments