feat: initial commit
This commit is contained in:
32
internal/setup/store.go
Normal file
32
internal/setup/store.go
Normal file
@ -0,0 +1,32 @@
|
||||
package setup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/config"
|
||||
"forge.cadoles.com/wpetit/kouiz/internal/store"
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/pkg/errors"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var getStoreFromConfig = createFromConfigOnce(func(ctx context.Context, conf *config.Config) (*store.Store, error) {
|
||||
db, err := gorm.Open(sqlite.Open(string(conf.Store.DSN)), &gorm.Config{
|
||||
NowFunc: func() time.Time {
|
||||
return time.Now().UTC()
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
if conf.Store.Debug {
|
||||
db = db.Debug()
|
||||
}
|
||||
|
||||
store := store.New(db)
|
||||
|
||||
return store, nil
|
||||
|
||||
})
|
Reference in New Issue
Block a user