about summary refs log tree commit diff stats
path: root/subx/ex3.subx
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-08-09 21:28:35 -0700
committerKartik Agaram <vc@akkartik.com>2018-08-09 21:28:35 -0700
commitf2889b002ab36e13ac5771cf33635ec35cfc3b34 (patch)
treefeeff663ebfa2c24424e2d33e02acb81b3145402 /subx/ex3.subx
parent5852bb94373c7b8dddd7c4b0b5a105b2d769d4ac (diff)
downloadmu-f2889b002ab36e13ac5771cf33635ec35cfc3b34.tar.gz
4498
Diffstat (limited to 'subx/ex3.subx')
0 files changed, 0 insertions, 0 deletions
href='/gbmor/getwtxt/commit/svc/db.go?id=fdd9bd02f9ec37d25104dce8c1279a007aa980fc'>fdd9bd0 ^
439695f ^

439695f ^
a5a32e7 ^


439695f ^


a5a32e7 ^
78f4d8a ^
439695f ^


78f4d8a ^
e9d4a6b ^
439695f ^
439695f ^
439695f ^
1a15258 ^
439695f ^

fdd9bd0 ^








c8fddff ^

fdd9bd0 ^

1a15258 ^
c8fddff ^
e9d4a6b ^
c8fddff ^

930ef34 ^

e9d4a6b ^
c8fddff ^

fdd9bd0 ^
1a15258 ^
c8fddff ^
c8fddff ^
e9d4a6b ^
c8fddff ^
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
                                                      

        
                                             
                               

 








                                                




                      

                                          

                     
                          


                                


                               
                                                         
                                 


                                      
                                 
 
         
 
                    
                

 








                                             

 

                                        
                     
                      
                        

                    

                   
                  

 
                                            
               
                      
                 
                    
 
package svc // import "github.com/getwtxt/getwtxt/svc"

import (
	"github.com/syndtr/goleveldb/leveldb"
	"golang.org/x/sys/unix"
)

// Everything in this file is database-agnostic.
// Functions and types related to specific kinds
// of databases will be in their own respective
// files, such as:
//  - leveldb.go
//  - sqlite.go

// Abstraction to allow several different
// databases to be used interchangeably.
type dbase interface {
	push() error
	pull()
}

// Opens a new connection to the specified
// database, then reads it into memory.
func initDatabase() {
	var db dbase
	confObj.Mu.RLock()
	dbpath := confObj.DBPath
	confObj.Mu.RUnlock()

	switch confObj.DBType {

	case "leveldb":
		lvl, err := leveldb.OpenFile(dbpath, nil)
		errFatal("", err)
		db = &dbLevel{db: lvl}

	case "sqlite":
		db = initSqlite()

	}

	dbChan <- db
	pullDB()
}

// Close the database connection.
func killDB() {
	db := <-dbChan
	switch dbType := db.(type) {
	case *dbLevel:
		errLog("", dbType.db.Close())
	case *dbSqlite:
		errLog("", dbType.db.Close())
	}
}

// Pushes the registry's cache data
// to a local database for safe keeping.
func pushDB() error {
	db := <-dbChan
	err := db.push()
	dbChan <- db

	unix.Sync()

	return err
}

// Reads the database from disk into memory.
func pullDB() {
	db := <-dbChan
	db.pull()
	dbChan <- db
}