summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-05-07 21:25:19 +0200
committerxengineering <me@xengineering.eu>2024-05-07 21:25:19 +0200
commit75c1270c86ac17d056161714ac32a57113696d21 (patch)
treedbf6d7c517331ff1cdf0b9502fd69729c6f6d599
parentebb446f6115b4ca690ea354fa4275e33a0d9976b (diff)
downloadceres-75c1270c86ac17d056161714ac32a57113696d21.tar
ceres-75c1270c86ac17d056161714ac32a57113696d21.tar.zst
ceres-75c1270c86ac17d056161714ac32a57113696d21.zip
model: Init database with database path
-rw-r--r--main.go3
-rw-r--r--model/database.go7
2 files changed, 4 insertions, 6 deletions
diff --git a/main.go b/main.go
index bc8e75a..b887981 100644
--- a/main.go
+++ b/main.go
@@ -7,6 +7,7 @@ import (
"os"
"os/signal"
"syscall"
+ "path/filepath"
"xengineering.eu/ceres/model"
"xengineering.eu/ceres/view"
@@ -33,7 +34,7 @@ func main() {
}
log.Printf("Storage directory: %s\n", storage.Path)
- model.InitDatabase(config.StorageFilePath)
+ model.InitDatabase(filepath.Join(storage.Path, "ceres.sqlite3"))
defer model.CloseDatabase()
model.InjectTestRecipes()
diff --git a/model/database.go b/model/database.go
index 36190ff..d816163 100644
--- a/model/database.go
+++ b/model/database.go
@@ -4,7 +4,6 @@ import (
"database/sql"
"embed"
"log"
- "path/filepath"
_ "github.com/mattn/go-sqlite3"
)
@@ -23,12 +22,10 @@ func GetSql(code string) (string, error) {
return string(query), nil
}
-func InitDatabase(storage string) {
+func InitDatabase(path string) {
var err error
- fn := filepath.Join(storage, "ceres.sqlite3")
-
- db, err = sql.Open("sqlite3", fn)
+ db, err = sql.Open("sqlite3", path)
if err != nil {
log.Fatal(err)
}