aboutsummaryrefslogtreecommitdiff
path: root/dbstore/dbstore.go
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-05 17:59:24 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-05 17:59:24 -0500
commitd33541ff79e5d81959900b757e4857af14e4f4b2 (patch)
tree8674398bec363062569a53427fbf71ceffe2592f /dbstore/dbstore.go
parentc89f404a0176415130089201a176a3ff76a02829 (diff)
downloadcvez-d33541ff79e5d81959900b757e4857af14e4f4b2.tar.bz2
cvez-d33541ff79e5d81959900b757e4857af14e4f4b2.zip
dbscore: add openFull and test
Diffstat (limited to 'dbstore/dbstore.go')
-rw-r--r--dbstore/dbstore.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/dbstore/dbstore.go b/dbstore/dbstore.go
index 0ab6fcf..11ad02c 100644
--- a/dbstore/dbstore.go
+++ b/dbstore/dbstore.go
@@ -13,22 +13,33 @@ import (
//go:embed sql
var sqlFs embed.FS
+// sqlite3 backing store
type DbStore struct {
db *db_sql.DB
}
-// open database
-func Open(path string) (DbStore, error) {
+// Open database.
+//
+// This function is called by Open(). It is a separate package-private
+// function to make Open() easier to test.
+func openFull(dbType, path string) (DbStore, error) {
var r DbStore
+
// init db
- if db, err := db_sql.Open("sqlite3", path); err != nil {
+ if db, err := db_sql.Open(dbType, path); err != nil {
return r, err
} else {
+ // save handle
r.db = db
return r, nil
}
}
+// Open database
+func Open(path string) (DbStore, error) {
+ return openFull("sqlite3", path)
+}
+
// initialized database version
const initDbVersion = 314159