Rudimentary creating of nodes
This commit is contained in:
parent
08fd2cf4e9
commit
c0255fadb8
7 changed files with 363 additions and 55 deletions
21
node.go
21
node.go
|
|
@ -165,3 +165,24 @@ func UpdateNode(nodeID int, data []byte) (err error) {
|
|||
_, err = db.Exec(`UPDATE public.node SET data=$2 WHERE id=$1`, nodeID, data)
|
||||
return
|
||||
}
|
||||
|
||||
func CreateNode(parentNodeID, typeID int, name string) (err error) {
|
||||
j, _ := json.Marshal(struct { Name string }{name})
|
||||
|
||||
row := db.QueryRow(`
|
||||
INSERT INTO node(type_id, name, data)
|
||||
VALUES($1, $2, $3::jsonb)
|
||||
RETURNING id
|
||||
`,
|
||||
typeID, name, j)
|
||||
|
||||
var id int
|
||||
err = row.Scan(&id)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = db.Exec(`INSERT INTO connection("parent", "child") VALUES($1, $2)`, parentNodeID, id)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue