jschaf / pggen

Generate type-safe Go for any Postgres query. If Postgres can run the query, pggen can generate code for it.
MIT License
287 stars 26 forks source link

question about moving querier and connection related codes #19

Closed sadmansakib closed 3 years ago

sadmansakib commented 3 years ago

In future release, will pggen move querier interface and all connection related code out of *.sql.go file? It looks kind of ugly if i have multiple .sql.go files

jschaf commented 3 years ago

Which code would you want moved? In general, having code in different locations complicates the implementation and makes pggen less predictable to use.

sadmansakib commented 3 years ago

it would be very convenient if type Querier interface{}, type DBQuerier struct {} type genericConn interface {} blocks and related new function as well as WithTx functions are moved to a separate go file. For example, sqlc separates them to to two different go file named {package name}.go and querier.go. Maybe on pggen you can move these to a separate to something like pggen.go on the output directory. i believe this will make sql.go files look a lot cleaner because it'll only contain query related implementations.

jschaf commented 3 years ago

I understand it might look neater but it also means more generated files per directory. I've heard folks express preferences for both approaches. My preference is for 1 query file means 1 go file because it's predictable. Given that it's generated code, the less people need to think about it, the better.

I'm going to close this because:

If you feel strongly about this, you could probably hack up an awk script to do the transformation for you.