Let users customize the path to the scouting database
I want to write a script that runs the scouting webserver. For that to
work elegantly, I need to be able to customize the database path.
Otherwise it gets created in the runfiles tree.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I6f06f9b82ca2d3476c76d795ad57b06f7b360ba8
diff --git a/scouting/db/db.go b/scouting/db/db.go
index 86d332e..1d0081b 100644
--- a/scouting/db/db.go
+++ b/scouting/db/db.go
@@ -26,9 +26,11 @@
climbing int
}
-func NewDatabase() (*Database, error) {
+// Opens a database at the specified path. If the path refers to a non-existent
+// file, the database will be created and initialized with empty tables.
+func NewDatabase(path string) (*Database, error) {
database := new(Database)
- database.DB, _ = sql.Open("sqlite3", "./scouting.db")
+ database.DB, _ = sql.Open("sqlite3", path)
statement, error_ := database.Prepare("CREATE TABLE IF NOT EXISTS matches " +
"(id INTEGER PRIMARY KEY, matchNumber INTEGER, round INTEGER, compLevel INTEGER, r1 INTEGER, r2 INTEGER, r3 INTEGER, b1 INTEGER, b2 INTEGER, b3 INTEGER, r1ID INTEGER, r2ID INTEGER, r3ID INTEGER, b1ID INTEGER, b2ID INTEGER, b3ID INTEGER)")
defer statement.Close()