go_echo_wol/database/database.go

66 lines
1.0 KiB
Go

package database
import (
_ "github.com/mattn/go-sqlite3"
"xorm.io/xorm"
)
var engine *xorm.Engine
type Wol struct {
ID int
Name string `xorm:"varchar(64)"`
Mac string `xorm:"varchar(64)"`
}
func init() {
var err error
file := "./wol.db"
engine, err = xorm.NewEngine("sqlite3", file)
if err != nil {
println(err)
}
}
func CreateTable() int {
err := engine.Sync2(new(Wol))
if err != nil {
println(err)
}
return 0
}
func Getallwol(everyone *[]Wol) {
err := engine.Find(&(*everyone))
if err != nil {
println("Getallwol err", err)
}
}
func Getallwoltext() {
everyone := make([]Wol, 0)
err := engine.Find(&everyone)
if err != nil {
println("Getallwoltext", err)
}
println(len(everyone))
}
func Insert(wol *Wol) {
affected, err := engine.Insert(&wol)
if err != nil {
println(err)
}
println(affected)
}
func Del() {
println("del orm")
wol1 := new(Wol)
wol1.Name = "00:70:0a:f5:9a:a3"
affected, err := engine.Delete(&wol1)
if err != nil {
println(err)
}
println(affected, "ok")
}