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

generator/sqlite: add function to generate using an existing *sql.DB #441

Open
TotallyGamerJet opened this issue Jan 15, 2025 · 3 comments · May be fixed by #443
Open

generator/sqlite: add function to generate using an existing *sql.DB #441

TotallyGamerJet opened this issue Jan 15, 2025 · 3 comments · May be fixed by #443
Labels

Comments

@TotallyGamerJet
Copy link

TotallyGamerJet commented Jan 15, 2025

Is your feature request related to a problem? Please describe.
I want to apply my migrations to an in-memory sqlite db and then generate the go-jet structures using that. However, right now it's not possible as GenerateDSN takes a connection string instead of an existing DB connection. My workaround is to write the DB to a temporary file and use that. I am aware that I can make the DB global in-memory to the process and then connect to it. However, this ruins isolation from other DBs in the process.

I also use alternative sqlite implementations like "modernc.org/sqlite" which are registered as "sqlite" instead of "sqlite3" which the GenerateDSN expects so I have to reregister the driver I want as "sqlite3" before calling the generator.

Describe the solution you'd like

Add the following function that behaves the same as GenerateDSN except it applies directly to the supplied *sql.DB.

func GenerateDB(db *sql.DB, destDir string, templates ...template.Template) error
@go-jet
Copy link
Owner

go-jet commented Jan 15, 2025

Yeah, I agree.

@go-jet go-jet added the good first issue Good for newcomers label Jan 15, 2025
@TotallyGamerJet
Copy link
Author

Yeah, I agree.

I can code this up. One question is should the other drivers have this function too? I don't use any of them so I'm not sure if it would be beneficial

@go-jet
Copy link
Owner

go-jet commented Jan 17, 2025

Yeah, it would be good to have this feature available across all dialects.

TotallyGamerJet added a commit to TotallyGamerJet/jet that referenced this issue Jan 17, 2025
TotallyGamerJet added a commit to TotallyGamerJet/jet that referenced this issue Jan 17, 2025
@TotallyGamerJet TotallyGamerJet linked a pull request Jan 17, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants