-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pinned notes using bbolt (#9)
- Loading branch information
Showing
8 changed files
with
204 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package db | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"go.etcd.io/bbolt" | ||
) | ||
|
||
var Database *bbolt.DB | ||
|
||
const PinnedBucket = "PinnedNotes" | ||
|
||
// Initialize the database and ensure the bucket exists | ||
func InitializeDB() error { | ||
homeDir, err := os.UserHomeDir() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var db_path string | ||
if runtime.GOOS == "windows" { | ||
db_path = filepath.Join(homeDir, "AppData", "Local", "oolong", "oolong.db") | ||
} else { | ||
db_path = filepath.Join(homeDir, ".local", "share", "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 | ||
} | ||
|
||
return Database.Update(func(tx *bbolt.Tx) error { | ||
_, err := tx.CreateBucketIfNotExists([]byte(PinnedBucket)) | ||
return err | ||
}) | ||
} | ||
|
||
// Close the database when the server shuts down | ||
func CloseDB() { | ||
if Database != nil { | ||
Database.Close() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters