From c8ca77ad65e9c0b31c6bd5289de0c1d332c06e63 Mon Sep 17 00:00:00 2001 From: Emile Date: Thu, 7 Mar 2019 16:14:12 +0100 Subject: subdivided the project into multiple logical compartments --- backend/delete.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 backend/delete.go (limited to 'backend/delete.go') diff --git a/backend/delete.go b/backend/delete.go new file mode 100644 index 0000000..bc463dd --- /dev/null +++ b/backend/delete.go @@ -0,0 +1,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) + } +} -- cgit 1.4.1