diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/database.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/model/database.go b/model/database.go new file mode 100644 index 0000000..ed9a985 --- /dev/null +++ b/model/database.go @@ -0,0 +1,36 @@ +package model + +import ( + "database/sql" + "log" + "path/filepath" + + _ "github.com/mattn/go-sqlite3" +) + +var db *sql.DB + +func InitDatabase() { + var err error + + fn := filepath.Join(storage, "ceres.sqlite3") + + db, err = sql.Open("sqlite3", fn) + if err != nil { + log.Fatal(err) + } + + err = db.Ping() + if err != nil { + log.Fatal(err) + } +} + +func CloseDatabase() { + var err error = db.Close() + if err != nil { + log.Printf("Failed to close database: %v\n", err) + } else { + log.Println("Closed database") + } +} |