Write data in database table
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
ID string
|
||||
MAC string
|
||||
@@ -30,12 +34,15 @@ func (db *DB) AllDevices() ([]*Device, error) {
|
||||
}
|
||||
|
||||
func (db *DB) InsertDevice(device *Device) error {
|
||||
sqlStmt := `INSERT OR REPLACE INTO table (id, mac, sn, lastMsg)
|
||||
sqlStmt := `INSERT OR REPLACE INTO devices (id, mac, sn, lastMsg)
|
||||
VALUES($1, $2, $3, $4);`
|
||||
_, err := db.Exec(sqlStmt, device.ID, device.MAC, device.SN, device.LastMsg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
fmt.Printf("Sucessfully inserted device with ID %s to database\n", device.ID)
|
||||
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user