Skip to content
Snippets Groups Projects
db.go 435 B
Newer Older
  • Learn to ignore specific revisions
  • meskio's avatar
    meskio committed
    package db
    
    import (
    	"gorm.io/driver/sqlite"
    	"gorm.io/gorm"
    )
    
    type DB struct {
    	db *gorm.DB
    }
    
    func Init(dbPath string) (*DB, error) {
    	db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
    	if err != nil {
    		return nil, err
    	}
    
    	db.AutoMigrate(&Member{}, &Product{}, &Purchase{}, &Topup{}, &Transaction{},
    
    meskio's avatar
    meskio committed
    		&OrderPurchase{}, &Order{}, &PasswordReset{}, &Supplier{},
    		&Inventary{}, &InventaryProduct{})
    
    meskio's avatar
    meskio committed
    	return &DB{db}, err
    }