21 lines
410 B
Go
21 lines
410 B
Go
package database
|
|
|
|
import (
|
|
"git.schreifuchs.ch/schreifuchs/warehouse/model"
|
|
"gorm.io/driver/sqlite" // Sqlite driver based on CGO
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type DB struct {
|
|
conn *gorm.DB
|
|
}
|
|
|
|
func Init(file string) (*DB, error) {
|
|
if db, err := gorm.Open(sqlite.Open(file), &gorm.Config{}); err != nil {
|
|
return nil, err
|
|
} else {
|
|
db.AutoMigrate(&model.Bucket{}, &model.Object{})
|
|
return &DB{conn: db}, nil
|
|
}
|
|
}
|