Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support selecting a PostgreSQL DB schema if found #74

Open
1saifj opened this issue Oct 17, 2024 · 2 comments · May be fixed by #76
Open

Support selecting a PostgreSQL DB schema if found #74

1saifj opened this issue Oct 17, 2024 · 2 comments · May be fixed by #76

Comments

@1saifj
Copy link

1saifj commented Oct 17, 2024

Is your feature request related to a problem? Please describe.
I'm always frustrated when the current DSN (Data Source Name) for PostgreSQL database as it does not support specifying a schema for databases that require schema selection. This results in needing to manually set the schema after establishing a connection or handling it separately in the code.

Describe the solution you'd like
I would like to have the ability to specify a schema directly within the DSN so that when a connection is established, the appropriate schema is selected automatically.

Describe alternatives you've considered
An alternative solution would be to execute a query to set the schema immediately after the connection is established, but this adds complexity and overhead to the connection process.

Additional context
This feature would streamline connections for databases with multiple schemas and reduce manual configuration.

@1saifj 1saifj changed the title support selecting a db schema if found Support selecting a DB schema if found Oct 17, 2024
@1saifj 1saifj changed the title Support selecting a DB schema if found Support selecting a PostgreSQL DB schema if found Oct 17, 2024
@zhufuyi
Copy link
Owner

zhufuyi commented Oct 18, 2024

On the generate code page, the next Sponge release adds the specified schema parameters, such as root:123456@(192.168.3.37:5432)/account?search_path=job

@1saifj 1saifj linked a pull request Oct 20, 2024 that will close this issue
@southwolf
Copy link

southwolf commented Dec 7, 2024

Hi @zhufuyi @1saifj thanks for this, but what if I do need to generate code from multiple schemas?

Maybe adding schema name would be a better approach?

func (Partner) TableName() string {
	return "token.partner"
}

func (TokenType) TableName() string {
	return "token.token_type"
}

func (Token) TableName() string {
	return "token.token"
}

My plan is to add a toggle switch to enable/disable scanning multiple schemas, and if it's enabled, a schema prefix should be added when generating GORM code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants