blob: bc463dd05909eb6158900eee9037555224188c08 (
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)
}
}
|