Separate into InitDB and InitRawDB

This commit is contained in:
Melon 2025-01-08 17:49:41 +00:00
parent fbe0863d36
commit 40a52773f7
Signed by: melon
GPG Key ID: 6C9D970C50D26A25

View File

@ -14,18 +14,22 @@ import (
var migrations embed.FS var migrations embed.FS
func InitDB(p string) (*database.Queries, error) { func InitDB(p string) (*database.Queries, error) {
migDrv, err := iofs.New(migrations, "database/migrations")
if err != nil {
return nil, err
}
dbOpen, err := sql.Open("sqlite3", p) dbOpen, err := sql.Open("sqlite3", p)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return InitRawDB(dbOpen)
}
func InitRawDB(dbOpen *sql.DB) (*database.Queries, error) {
dbDrv, err := sqlite3.WithInstance(dbOpen, &sqlite3.Config{}) dbDrv, err := sqlite3.WithInstance(dbOpen, &sqlite3.Config{})
if err != nil { if err != nil {
return nil, err return nil, err
} }
migDrv, err := iofs.New(migrations, "database/migrations")
if err != nil {
return nil, err
}
mig, err := migrate.NewWithInstance("iofs", migDrv, "sqlite3", dbDrv) mig, err := migrate.NewWithInstance("iofs", migDrv, "sqlite3", dbDrv)
if err != nil { if err != nil {
return nil, err return nil, err