sqlc-dev / sqlc

Generate type-safe code from SQL
https://sqlc.dev
MIT License
12.33k stars 779 forks source link

Add explicit statement preparation for pgx #1998

Open davideimola opened 1 year ago

davideimola commented 1 year ago

Version

Other

What happened?

As I want to use batch queries I switched to the pgx/v4 engine.

Once I set this up, the Prepare statement is no more generated as expected.

Relevant log output

No response

Database schema

CREATE TABLE test_thing (
column_a VARCHAR NOT NULL,
column_b VARCHAR NOT NULL,
PRIMARY KEY (column_a, column_b)
);

SQL queries

-- name: CreateTestThing :batchexec
INSERT INTO test_thing (column_a, column_b)
VALUES (@column_a, @column_b)
ON CONFLICT DO NOTHING;

Configuration

version: "1"
packages:
  - name: "db"
    path: "internal/db"
    queries: "./internal/db/"
    schema: "./db/migrations/"
    engine: "postgresql"
    emit_prepared_queries: true
    emit_interface: false
    emit_exact_table_names: false
    emit_empty_slices: false
    emit_json_tags: true
    sql_package: "pgx/v4"

Playground URL

https://play.sqlc.dev/p/6b8769d26c96df84b1b92b8cc89ff6d47a2a530587e4b5bde6e75ada24c1704e

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

peterwillis commented 1 year ago

Statement caching happens automatically in pgx as documented here, so the prepare functions are not generated

andrewmbenton commented 1 year ago

I've changed this to a feature enhancement request, to add support for explicit prepare statement functions when using pgx.