warehouse/database/resource.go

21 lines
410 B
Go
Raw Normal View History

2024-11-13 21:16:22 +01:00
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
}
}