Added Gorm for database handling
This commit is contained in:
20
app/db/init.go
Normal file
20
app/db/init.go
Normal 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
18
app/db/item.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user