sqlc-dev / sqlc

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

Return `Querier` interface from `WithTx` when interface is emitted. #3701

Open 0xstepit opened 2 weeks ago

0xstepit commented 2 weeks ago

What do you want to change?

When you specify the flag: emit_interface: true in the sqlc.yaml, the Querier interface is generated. This is a great feature, however, the WithTx method returns a *Queries pointer, making the use of the interface hard:

func (q *Queries) WithTx(tx *sql.Tx) *Queries {
    return &Queries{
        db: tx,
    }
}

It would be great to return the interface when the previously mentioned flag is set to true:

func (q *Queries) WithTx(tx *sql.Tx) Querier {
    return &Queries{
        db: tx,
    }
}

Happy to create a PR for it if you like the idea.

What database engines need to be changed?

No response

What programming language backends need to be changed?

Go