ipld-eth-server/pkg/repositories/postgres/node_repository.go
Matt K aea9c7b5e2 Separate repositories (#25)
* Separate Repository into multiple Repositories

* Use struct scan for transactions

* Use struct scan for blocks

* Remove unused block repo methods

* Update naming

* Rename / Cleanup repository related fields
2018-02-02 15:53:16 -06:00

28 lines
790 B
Go

package postgres
import "github.com/vulcanize/vulcanizedb/pkg/core"
type NodeRepository interface {
CreateNode(node *core.Node) error
}
func (db *DB) CreateNode(node *core.Node) error {
var nodeId int64
err := db.DB.QueryRow(
`INSERT INTO nodes (genesis_block, network_id, node_id, client_name)
VALUES ($1, $2, $3, $4)
ON CONFLICT (genesis_block, network_id, node_id)
DO UPDATE
SET genesis_block = $1,
network_id = $2,
node_id = $3,
client_name = $4
RETURNING id`,
node.GenesisBlock, node.NetworkId, node.Id, node.ClientName).Scan(&nodeId)
if err != nil {
return ErrUnableToSetNode
}
db.nodeId = nodeId
return nil
}