mirror of
https://github.com/1f349/site-hosting.git
synced 2025-01-20 22:26:37 +00:00
Separate into InitDB and InitRawDB
This commit is contained in:
parent
fbe0863d36
commit
40a52773f7
12
initdb.go
12
initdb.go
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user