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
pan class='oid'>33352536 ^
ca358b17 ^
33352536 ^



15b98801 ^
bc20cc3d ^
33352536 ^
6070c23e ^
33352536 ^

ca358b17 ^
33352536 ^
546a9298 ^
bc20cc3d ^
546a9298 ^
33352536 ^

bc20cc3d ^


546a9298 ^





ca358b17 ^
33352536 ^

bc20cc3d ^
33352536 ^
bc20cc3d ^


33352536 ^
bc20cc3d ^

33352536 ^
546a9298 ^
7a583220 ^
33352536 ^

bc20cc3d ^


0e9503d7 ^
bc20cc3d ^


7a583220 ^
33352536 ^

71e4f381 ^






33352536 ^
71e4f381 ^

33352536 ^

546a9298 ^



71e4f381 ^
bc20cc3d ^
546a9298 ^
bc20cc3d ^

33352536 ^
bc20cc3d ^


546a9298 ^


33352536 ^
bc20cc3d ^

33352536 ^

bc20cc3d ^


33352536 ^
546a9298 ^

bfcc0f85 ^
bc20cc3d ^
bfcc0f85 ^
bc20cc3d ^
33352536 ^
bc20cc3d ^


33352536 ^
bc20cc3d ^
546a9298 ^
71e4f381 ^
7a583220 ^
33352536 ^

bc20cc3d ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124