2015-10-21 23:14:02 +00:00
|
|
|
package datastore
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/drone/drone/model"
|
|
|
|
"github.com/russross/meddler"
|
|
|
|
)
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
func (db *datastore) GetNode(id int64) (*model.Node, error) {
|
2015-10-21 23:14:02 +00:00
|
|
|
var node = new(model.Node)
|
|
|
|
var err = meddler.Load(db, nodeTable, node, id)
|
|
|
|
return node, err
|
|
|
|
}
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
func (db *datastore) GetNodeList() ([]*model.Node, error) {
|
2015-10-21 23:14:02 +00:00
|
|
|
var nodes = []*model.Node{}
|
|
|
|
var err = meddler.QueryAll(db, &nodes, rebind(nodeListQuery))
|
|
|
|
return nodes, err
|
|
|
|
}
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
func (db *datastore) CreateNode(node *model.Node) error {
|
2015-10-21 23:14:02 +00:00
|
|
|
return meddler.Insert(db, nodeTable, node)
|
|
|
|
}
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
func (db *datastore) UpdateNode(node *model.Node) error {
|
2015-10-21 23:14:02 +00:00
|
|
|
return meddler.Update(db, nodeTable, node)
|
|
|
|
}
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
func (db *datastore) DeleteNode(node *model.Node) error {
|
2015-10-21 23:14:02 +00:00
|
|
|
var _, err = db.Exec(rebind(nodeDeleteStmt), node.ID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const nodeTable = "nodes"
|
|
|
|
|
|
|
|
const nodeListQuery = `
|
|
|
|
SELECT *
|
|
|
|
FROM nodes
|
|
|
|
ORDER BY node_addr
|
|
|
|
`
|
|
|
|
|
|
|
|
const nodeCountQuery = `
|
|
|
|
SELECT COUNT(*) FROM nodes
|
|
|
|
`
|
|
|
|
|
|
|
|
const nodeDeleteStmt = `
|
|
|
|
DELETE FROM nodes
|
|
|
|
WHERE node_id=?
|
|
|
|
`
|