aboutsummaryrefslogtreecommitdiff
path: root/dbstore/dbstore.go
diff options
context:
space:
mode:
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