Skip to content

Commit 2b88ce8

Browse files
fix(docs): improve discussion of prepared statements support (#2604)
1 parent 867b8e0 commit 2b88ce8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

docs/howto/prepared_query.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Preparing queries
22

3+
If you're using `pgx/v5` you get its
4+
[implicit support](https://github.com/jackc/pgx/wiki/Automatic-Prepared-Statement-Caching)
5+
for prepared statements. No additional `sqlc` configuration is required.
6+
7+
For other drivers, `sqlc` can give you the option to explicitly use prepared
8+
queries. These prepared queries also work with transactions.
9+
10+
You'll need to set `emit_prepared_queries` to `true` in your `sqlc` configuration
11+
to generate code similar to the example below.
12+
313
```sql
414
CREATE TABLE records (
515
id SERIAL PRIMARY KEY
@@ -10,9 +20,6 @@ SELECT * FROM records
1020
WHERE id = $1;
1121
```
1222

13-
sqlc has an option to use prepared queries. These prepared queries also work
14-
with transactions.
15-
1623
```go
1724
package db
1825

@@ -80,4 +87,3 @@ func (q *Queries) GetRecord(ctx context.Context, id int32) (int32, error) {
8087
return id, err
8188
}
8289
```
83-

0 commit comments

Comments
 (0)