-
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.
- Loading branch information
Showing
6 changed files
with
170 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package db | ||
|
||
import ( | ||
"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 | ||
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