Skip to content

cannot use tx (variable of type *sql.Tx) as DBTX value in struct literal: wrong type for method ExecContext #1822

@varian97

Description

@varian97

Version

1.15.0

What happened?

I use https://github.com/golang-migrate/migrate to create database migrations and sqlc to compile query into go code.

Here is my folder structure:

- db
  - dbutils // the generated go code from sqlc
  - migrations  // migration files from golang-migrate
  - queries // sql query for sqlc to generate
- go.mod
- go.sum
- main.go
- sqlc.yaml

Currently there is only 1 migration file inside db/migrations and 1 sql file inside db/queries. When I run sqlc generate, it succeed without error. However the generated db/dbutils/db.go contains highlighted error: cannot use tx (variable of type *sql.Tx) as DBTX value in struct literal: wrong type for method ExecContext

image

Relevant log output

No response

Database schema

CREATE TABLE IF NOT EXISTS review (
  id SERIAL PRIMARY KEY,
  url varchar NOT NULL,
  title varchar(512) NOT NULL,
  difficulty varchar(10) NOT NULL,
  due_date timestamptz NOT NULL,
  notes text,
  active boolean DEFAULT true,
  date_created timestamptz DEFAULT CURRENT_TIMESTAMP,
  date_updated timestamptz DEFAULT CURRENT_TIMESTAMP
);

SQL queries

-- name: GetReview :one
SELECT * FROM review
WHERE id = $1 LIMIT 1;

-- name: ListReviews :many
SELECT * FROM review
ORDER BY due_date ASC;

-- name: CreateReview :one
INSERT INTO review (
  url, title, difficulty, due_date, notes
) VALUES (
  $1, $2, $3, $4, $5
)
RETURNING *;

-- name: DeleteReview :exec
DELETE FROM review
WHERE id = $1;

Configuration

version: "1"
packages:
  - path: "db/dbutils"
    name: "dbutils"
    engine: "postgresql"
    schema: "db/migrations"
    queries: "db/queries"
    emit_json_tags: true
    emit_prepared_queries: false
    emit_interface: false
    emit_exact_table_names: false

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions