summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--svc/db.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/svc/db.go b/svc/db.go
index 8c3f278..10ea28d 100644
--- a/svc/db.go
+++ b/svc/db.go
@@ -1,6 +1,7 @@
 package svc // import "github.com/getwtxt/getwtxt/svc"
 
 import (
+	"database/sql"
 	"log"
 	"net"
 	"strings"
@@ -10,6 +11,35 @@ import (
 	"github.com/syndtr/goleveldb/leveldb"
 )
 
+// Pull DB data into cache, if available.
+func initDatabase() {
+	var db dbase
+	var err error
+
+	confObj.Mu.RLock()
+	switch confObj.DBType {
+
+	case "leveldb":
+		var lvl *leveldb.DB
+		lvl, err = leveldb.OpenFile(confObj.DBPath, nil)
+		db = &dbLevel{db: lvl}
+
+	case "sqlite":
+		var lite *sql.DB
+		db = &dbSqlite{db: lite}
+
+	}
+	confObj.Mu.RUnlock()
+
+	if err != nil {
+		log.Fatalf("%v\n", err.Error())
+	}
+
+	dbChan <- db
+
+	pullDatabase()
+}
+
 func checkDBtime() bool {
 	confObj.Mu.RLock()
 	answer := time.Since(confObj.LastPush) > confObj.DBInterval
117' href='#n117'>117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145