forked from go-squads/saga-scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoperation.go
37 lines (31 loc) · 838 Bytes
/
operation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"github.com/jmoiron/sqlx"
)
type operation struct {
ID string `db:"id" json:"id"`
LxcID string `db:"lxc_id" json:"lxc_id"`
Status string `db:"status" json:"status"`
StatusCode int `db:"status_code" json:"status_code"`
Description string `db:"description" json:"description"`
}
func (op *operation) getOperation(db *sqlx.DB) error {
rows, err := db.Queryx("SELECT * FROM operation WHERE id=$1 LIMIT 1", op.ID)
if err != nil {
return err
}
if rows.Next() {
err = rows.StructScan(&op)
if err != nil {
return err
}
}
return nil
}
func (op *operation) insertOperation(db *sqlx.DB) error {
_, err := db.NamedExec("INSERT INTO operation (id, lxc_id, status, status_code) VALUES (:id, :lxc_id, :status, :status_code)", op)
if err != nil {
return err
}
return nil
}