Skip to content

Export models to a different package #835

Description

@td0m

Hi! Great work on this project!

I was wondering if it's currently possible to export Go model structs to a different folder package.

I think this could be a good feature for anyone who would like to make their code independent of the database backend but still use the automatically generated models.

For example:

internal/
  model/
    models.go
  db/
    postgres/
      db.go
      user.sql.go
      querier.go

This way you could e.g. also have a mongodb provider that uses these models, but without depending on the postgres package. I'm sure you'd agree that it would be odd for mongo to use postgres.User as a type.

Is this something that's possible to do? If not, would you possibly accept a PR that adds support for it? Or it it something you're not planning on supporting for now?

Thanks

Activity

  1. johan-lejdung commented on Feb 22, 2023

    @johan-lejdung

    We just tried this out at our company, for context we are using go-migrate so we have a single folder with all of our database migrations. Without a feature like this the, otherwise excellent sqlc, isn't a viable option for us.

    As it stands (unless I've missed some configuration?) each generated package has a models.go file containing all models from our entire database.

    Having an option to decide where to generate the models file, and read from it on the subsequent generated packages OR being able to remove unused models would be a much needed feature.

    I see this has been left untouched since 2020, is there anything I can do to help speed this along?

  2. mpyw commented on Jul 6, 2023

    @mpyw
    Contributor
  3. anhnmt commented on Jan 3, 2024

    @anhnmt

    +1

  4. moved this to 🔍 Exploring in sqlc Roadmapon Jun 5, 2024
  5. mmierzwa commented on Dec 16, 2024

    @mmierzwa

    Still waiting for this at the end of 2024 😊

  6. vivere-dally commented on Feb 4, 2026

    @vivere-dally

    Up

  7. kyleconroy commented on Apr 30, 2026

    @kyleconroy
    Collaborator
  8. added a commit that references this issue on May 5, 2026
    b84b1d6
  9. moved this from 🔍 Exploring to 🛳 Shipped in sqlc Roadmapon May 5, 2026
  10. kyleconroy commented on May 5, 2026

    @kyleconroy
    Collaborator

    Fixed here #4421

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions