mirror of
https://github.com/hazemKrimi/crimson-vault.git
synced 2026-05-01 18:20:27 +00:00
wip: testing gorm
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package models
|
||||
|
||||
import "gorm.io/gorm"
|
||||
|
||||
type Client struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
Country string
|
||||
Phone string
|
||||
}
|
||||
|
||||
func (wrapper *DBWrapper) MigrateClients() {
|
||||
wrapper.db.AutoMigrate(&Client{})
|
||||
}
|
||||
|
||||
func (wrapper *DBWrapper) CreateClient(name string, country string, phone string) {
|
||||
wrapper.db.Create(&Client{Name: name, Country: country, Phone: phone})
|
||||
}
|
||||
|
||||
func (wrapper *DBWrapper) GetClient(id int) (Client) {
|
||||
var client Client
|
||||
wrapper.db.First(&client, id)
|
||||
return client
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DBWrapper struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
func (wrapper *DBWrapper) Initialize() {
|
||||
db, err := gorm.Open(sqlite.Open("crimson_vault.db"), &gorm.Config{})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
wrapper.db = db
|
||||
}
|
||||
Reference in New Issue
Block a user