From 77334ed9df50e8bce53cd47638619ff3b2a43e69 Mon Sep 17 00:00:00 2001 From: Jack Williamson <53199061+JackWilli@users.noreply.github.com> Date: Sun, 8 Dec 2024 18:09:05 -0500 Subject: [PATCH] feat: update db path to be ~/.config/oolong/oolong.db should create the dir if it doesn't exist --- internal/db/db.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/db/db.go b/internal/db/db.go index cfffc86..17efd97 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -1,17 +1,30 @@ package db import ( + "os" + "path/filepath" + "go.etcd.io/bbolt" ) var Database *bbolt.DB const PinnedBucket = "PinnedNotes" -const db_path = "pinned_notes.db" // Initialize the database and ensure the bucket exists func InitializeDB() error { - var err error + homeDir, err := os.UserHomeDir() + if err != nil { + return err + } + + db_path := filepath.Join(homeDir, ".config", "oolong", "oolong.db") + + err = os.MkdirAll(filepath.Dir(db_path), 0755) + if err != nil { + return err + } + Database, err = bbolt.Open(db_path, 0666, nil) if err != nil { return err