sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Config option to split generation paths

Open taylow opened this issue 3 years ago • 4 comments

What do you want to change?

I use SQLC to generate data storage model, repository interfaces, and their implementations from SQL files (obviously!), and absolutely love what the tool offers. I'm constantly recommending it.

I have recently started the transition towards Clean Architecture in the project I'm work on, using a layered approach to separate concerns (e.g. domain, application, infrastructure, presentation, etc.), and unfortunately have hit a small problem with the generated SQLC files.

The interface definition of repositories (Querier in SQLC) and DSOs should live in the application layer, whereas the implementations of the repositories should live in the infrastructure layer.

At the moment, SQLC generates all files into one folder determined by the path parameter of the config.

My proposal is to allow overrides for each of the generated files. This would fix my problem, as I could generate the Querier and models in application/repository, and the SQL query strings and implementations in infrastructure/repository.

I could wrap SQLC in a custom repository interface, but I really like the fact that the repository interface and models are generated from our SQL. My temporary solution is defining a new interface that embeds the Querier, but the direction of inversion is broken, as my application layer now points to the infrastructure layer, which is incorrect in Clean Architecture. I could also just suck it up and keep SQLC files in the application layer, but then we have infrastructure concerns in the application, which is also incorrect.

Any thoughts on this? If this is something that other want/see a use for, I can take a look at opening a PR (eventually). Any input is appreciated 🙏

What database engines need to be changed?

No response

What programming language backends need to be changed?

No response

taylow avatar Nov 10 '22 13:11 taylow

Looks like there are two issues that want a similar feature for models (#835 and #1941), whereas this is about breaking out all generation paths

taylow avatar Nov 10 '22 13:11 taylow

https://github.com/kyleconroy/sqlc/issues/1941#issuecomment-1623408555

mpyw avatar Jul 06 '23 10:07 mpyw

I'd like that too!

vezzalinistefano avatar Jul 07 '23 15:07 vezzalinistefano

I hope this is done soon

anhnmt avatar Jan 02 '24 16:01 anhnmt