-
Notifications
You must be signed in to change notification settings - Fork 998
Description
What do you want to change?
In Short
I would like additional configurability for Go code generation:
- Option to disable generation of db.go
- Ability to rename the generated Queries type
- Ability to specify a prefix for generated output files
Use case/Motivation
I am building a small wrapper package (database) around SQLite to strictly control what is exposed to consumers.
Currently, I structure it like this:
package database
func NewDatabaseConnection(...) (*Database, error)
func (d *Database) Close()
func (d *Database) Migrate()
func (d *Database) Begin() (*Queries, error) // begin a transaction with &Queries{db: tx}
func (q *Queries) Commit()
func (q *Queries) Rollback()
// sqlc generated:
func (q *Queries) WithTx() // I would prefer this NOT to be generated
func (q *Queries) ... // the generated queriesProblem 1 - db.go generation
The generated db.go file introduces New(db DBTX) *Queries, WithTx(tx *sql.Tx) *Queries and DBTX interface. For my use case, I do not want these, so I manually delete the file after each code generation.
It would be great to have something like:
gen:
go:
emit_db_file: falseProblem 2 - Naming Queries
Currently, sqlc generates Queries. This now 'leaks' into the rest of the public API. It would be great to be able to configure it via:
gen:
go:
queries_type_name: TransactionThe methods generated by sqlc would then attach to type Transaction struct { ... } defined in another file in the same package.
Problem 3 - Prefix file names
There is already output_files_suffix:, but no equivalent for prefix. I would like something like:
gen:
go:
output_files_prefix: generated_This makes generated files visually grouped and easier to distinguish from handwritten code.
If you’d like, I recently picked up Golang and I think this might be a doable issue for me.
What database engines need to be changed?
No response
What programming language backends need to be changed?
Go