Write data in database table

This commit is contained in:
2020-09-02 09:02:30 +02:00
parent 8f7a285289
commit ac3bb1ebe9
7 changed files with 106 additions and 74 deletions

View File

@@ -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
}