Skip to content

How to switch the database connection at runtime (Multi-tenancy) #1105

Description

@eborst

Hi, I just started using SQLC and this seems promising! It really helps in separating the boiler plate code with strong typed methods!

Now I do have a question: How should I implement switching the database connection at runtime?
I do have a map of db pools (one for each tenant) and want to switch based on the tenantID in the JWT.
Do I need to initialise every time again? That feels wrong to me...

func New(db DBTX) *Queries {
	return &Queries{db: db}
}

What are your ideas? A small example would be really helpful.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions