blob: d90559d4bc5ce5f17798add588180621f3bb8ea3 (
plain)
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
38
39
40
41
42
43
44
45
46
47
|
package backend
import (
"database/sql"
"fmt"
"log"
)
// DeleteAll Stars deletes all the rows in the stars table
func DeleteAllStars(database *sql.DB) {
db = database
// build the query creating a new node
query := "DELETE FROM stars WHERE TRUE"
// execute the query
rows, err := db.Query(query)
defer rows.Close()
if err != nil {
log.Fatalf("[ E ] deleteAllStars query: %v\n\t\t\t query: %s\n", err, query)
}
}
// DeleteAll Stars deletes all the rows in the nodes table
func DeleteAllNodes(database *sql.DB) {
db = database
// build the query creating a new node
query := "DELETE FROM nodes WHERE TRUE"
// execute the query
_, err := db.Query(query)
if err != nil {
log.Fatalf("[ E ] deleteAllStars query: %v\n\t\t\t query: %s\n", err, query)
}
}
// removeStarFromNode removes the star from the node with the given ID
func removeStarFromNode(nodeID int64) {
// build the query
query := fmt.Sprintf("UPDATE nodes SET star_id=0 WHERE node_id=%d", nodeID)
// Execute the query
rows, err := db.Query(query)
defer rows.Close()
if err != nil {
log.Fatalf("[ E ] removeStarFromNode query: %v\n\t\t\t query: %s\n", err, query)
}
}
|