Skip to content

Commit 426e932

Browse files
authored
Merge pull request #113 from malthe/issue-111-readme-example
Update README with recent API changes
2 parents 9051f3d + 34d5788 commit 426e932

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ If the query fails, an exception is thrown.
7575
### Connection options
7676

7777
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.
7979

8080
For example, to connect to a remote host use the _host_ configuration key:
8181

@@ -108,17 +108,20 @@ variable "PGSSLMODE" as "disable".
108108

109109
### Querying
110110

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.
114114

115115
The initial example above could be written as:
116116

117117
```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']);
120120
```
121121

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+
122125
If the object type is omitted, it defaults to `Record<string, any>`, but
123126
providing a type ensures that the object values are typed, both when
124127
accessed via the iterator or record interface (see below).
@@ -204,10 +207,10 @@ asynchronous stream such as a network socket, or a file.
204207
Assuming that `socket` is a writable stream:
205208

206209
```typescript
207-
const query = new Query('SELECT some_bytea_column', {
210+
const result = await client.query({
211+
text: 'SELECT some_bytea_column',
208212
streams: { some_bytea_column: socket },
209213
});
210-
const result = await client.execute(query);
211214
```
212215

213216
This can for example be used to reduce time to first byte and memory use.

0 commit comments

Comments
 (0)