-
Notifications
You must be signed in to change notification settings - Fork 8
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
Migrate to ORM #17
Comments
My approach is to use GORM orm and handle migration and database connections using the orm. It will also enable us to use scalable databases over sqlite. |
Thank you for your interest in contributing to KeyPub! I really appreciate you taking the initiative to help improve the project's database infrastructure. After thinking about your proposal, I wanted to share some thoughts about the direction I'm envisioning for the project:
That said, I see you're interested in database infrastructure improvements! There are several other valuable areas where contributions would be extremely helpful:
Would any of these areas interest you? I'm happy to provide more details about any of these tasks or discuss other ideas you might have for improving the project. Thanks again for your enthusiasm to contribute! |
I've had good luck with package store
import (
"context"
"database/sql"
"embed"
_ "embed"
"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/sqlite"
"github.com/golang-migrate/migrate/v4/source/iofs"
_ "modernc.org/sqlite"
)
//go:embed schema/*.sql
var migrations embed.FS
func InitDB(path string) (*sql.DB, error) {
d, err := iofs.New(migrations, "schema")
if err != nil {
return nil, err
}
dsn := "sqlite://" + path
m, err := migrate.NewWithSourceInstance("iofs", d, dsn)
if err != nil {
return nil, err
}
if err := m.Up(); err != nil && err != migrate.ErrNoChange {
return nil, err
}
db, err := sql.Open("sqlite", path)
if err != nil {
return nil, err
}
return db, nil
} The
100% agree about GORM. |
Thanks @wizardishungry @skariel, I'll send a PR based on your decisions |
I'm going to take these TODOs:
This issue is for tracking and discussions about it.
The text was updated successfully, but these errors were encountered: