Skip to content

go: expose DBTX inside Queries (via flag) #3273

Open
@toqueteos

Description

@toqueteos

What do you want to change?

Currently the autogenerated db.go file contains this two types:

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

// [..]

type Queries struct {
	db DBTX
}

Sometimes, because of ✨ questionable business reasons ✨ we would like to use the DBTX inside a *Queries to write some raw SQL but currently that's not possible.

An escape hatch behind a flag, something like emit_public_dbtx, to allow this would be very welcome.

Options for the changes required:

  • A) Embed DBTX inside Queries
type Queries struct {
	DBTX
}
  • B) Make db public by renaming it to DB
type Queries struct {
	DB DBTX
}
  • C) Add a new method to Queries which exposes the DBTX (this option requires the least changes)
// There might be better names than Conn, I'm open to suggestions
func (q *Queries) Conn() DBTX {
	return q.db
}

What database engines need to be changed?

None

What programming language backends need to be changed?

Go

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions