about summary refs log tree commit diff stats
path: root/configure-plugins
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-05-06 02:31:55 +0100
committerJames Booth <boothj5@gmail.com>2016-05-06 02:31:55 +0100
commit7f1beadea9ee1d3b0ba60270db43b112e8858cec (patch)
tree1c453893fc6e890e4fa93456571d1a3c365e12eb /configure-plugins
parent81e95966cfd4313606d9b45ec1565f1e1a63a497 (diff)
downloadprofani-tty-7f1beadea9ee1d3b0ba60270db43b112e8858cec.tar.gz
Rename xmpp types
Diffstat (limited to 'configure-plugins')
0 files changed, 0 insertions, 0 deletions
commit/svc/db.go?h=v0.4.12&id=e9d4a6b0e8624c6425d467f0efe14be1bc683bd9'>e9d4a6b ^
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
}