generated from schreifuchs/wails-template
Initial commit
This commit is contained in:
33
things/resource.go
Normal file
33
things/resource.go
Normal file
@ -0,0 +1,33 @@
|
||||
package things
|
||||
|
||||
import (
|
||||
"log"
|
||||
"wails-template/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func (s *Service) NewThing(name string) {
|
||||
if err := s.DB.Save(&model.Thing{Name: name}).Error; err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
print(name)
|
||||
}
|
||||
|
||||
func (s *Service) GetThings() (things []model.Thing) {
|
||||
if err := s.DB.Find(&things).Error; err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return things
|
||||
}
|
||||
|
||||
func (s *Service) DeleteThing(id int) {
|
||||
if err := s.DB.Delete(model.Thing{}, id).Error; err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user