Skip to content
Merged
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
14 changes: 10 additions & 4 deletions docs/howto/prepared_query.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Preparing queries

If you're using `pgx/v5` you get its
[implicit support](https://github.com/jackc/pgx/wiki/Automatic-Prepared-Statement-Caching)
for prepared statements. No additional `sqlc` configuration is required.

For other drivers, `sqlc` can give you the option to explicitly use prepared
queries. These prepared queries also work with transactions.

You'll need to set `emit_prepared_queries` to `true` in your `sqlc` configuration
to generate code similar to the example below.

```sql
CREATE TABLE records (
id SERIAL PRIMARY KEY
Expand All @@ -10,9 +20,6 @@ SELECT * FROM records
WHERE id = $1;
```

sqlc has an option to use prepared queries. These prepared queries also work
with transactions.

```go
package db

Expand Down Expand Up @@ -80,4 +87,3 @@ func (q *Queries) GetRecord(ctx context.Context, id int32) (int32, error) {
return id, err
}
```