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
	}
}
