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

Gorm connection from Existing SQLite connection #6777

Open
lesichkovm opened this issue Jan 5, 2024 · 3 comments
Open

Gorm connection from Existing SQLite connection #6777

lesichkovm opened this issue Jan 5, 2024 · 3 comments
Assignees
Labels
type:feature_request feature request

Comments

@lesichkovm
Copy link

Describe the feature

To be able to use an already opened SQLite DB by Gorm

Motivation

The Gorm for MySQL and Postgres support existing database connections to be reused.

However none of the other databases support the same.

It should be unified accross the board.

Even probably add a special method that accepts a database/sql instance

gorm.FromDB(db *sql.DB)

Related Issues

@github-actions github-actions bot added the type:feature_request feature request label Jan 5, 2024
@lesichkovm
Copy link
Author

@jinzhu any updates on this issue?

@manuelarte
Copy link

manuelarte commented Feb 6, 2025

@lesichkovm did you manage to do it?

I managed to have something working like this:

"gorm.io/driver/sqlite"
"gorm.io/gorm"

gormDB, err := gorm.Open(sqlite.New(sqlite.Config{Conn: db}), &gorm.Config{})

@lesichkovm
Copy link
Author

@manuelarte thank you for chipping in. Looks like a nice way of accomplishing it.

@jinzhu can this be made part of the standard functions, to not require workarounds.

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

No branches or pull requests

3 participants