Added Gorm for database handling

This commit is contained in:
2022-12-07 22:07:33 -05:00
parent e1b64766b6
commit ba0eb8649b
5 changed files with 61 additions and 1 deletions

20
app/db/init.go Normal file
View File

@ -0,0 +1,20 @@
package db
import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
var (
DB gorm.DB
)
func InitDatabase() {
DB, err := gorm.Open(sqlite.Open("data/raven.db"), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
// Migrate the schema
DB.AutoMigrate(&Item{})
}

18
app/db/item.go Normal file
View File

@ -0,0 +1,18 @@
package db
import (
"time"
"gorm.io/gorm"
)
type Item struct {
gorm.Model
Name string
Manufacturer string
Type string
SerialNumber string
SkuNumber string
PurchasedFrom string
PurchasedAt time.Time
}