DB锁,sqlite限制了解

This commit is contained in:
suguo.yao 2021-12-16 16:45:26 +08:00
parent b94764fcff
commit 3064e13c4f
1 changed files with 9 additions and 3 deletions

12
main.go
View File

@ -11,6 +11,7 @@ import (
"github.com/paypal/gatt"
"github.com/paypal/gatt/examples/option"
"gorm.io/gorm"
"myschools.me/suguo/ble-ibeacon/model"
"myschools.me/suguo/ble-ibeacon/sqlite"
)
@ -32,6 +33,8 @@ func NewiBeacon(data []byte) (*IBeancon, error) {
return beacon, nil
}
var db *gorm.DB
func onPerhipheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
// if p.ID() != "78:2C:29:16:F2:78" {
// return
@ -43,9 +46,12 @@ func onPerhipheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int)
// return
// }
fmt.Println("NAME:", a.LocalName, "T:", time.Now(), "MAC:", p.ID(), "RSSI:", rssi, "LEN:", len(a.ManufacturerData))
db, err := sqlite.New()
if err != nil {
log.Fatalln(err.Error())
if db == nil {
var err error
db, err = sqlite.New()
if err != nil {
log.Fatalln(err.Error())
}
}
if err := db.Save(&model.Rssi{
MAC: p.ID(),