Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(docs): improve discussion of prepared statements support #2604

Merged
merged 1 commit into from
Aug 11, 2023
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
}
```

Loading