forked from jsimonetti/berkeleydb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.go
38 lines (31 loc) · 814 Bytes
/
environment.go
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
package berkeleydb
/*
#cgo LDFLAGS: -ldb
#include <db.h>
#include "bdb.h"
*/
import "C"
// Environment holds the database environment.
type Environment struct {
environ *C.DB_ENV
}
// NewEnvironment creates a new database environment.
func NewEnvironment() (*Environment, error) {
var env *C.DB_ENV
err := C.db_env_create(&env, 0)
if err != 0 {
return nil, createError(err)
}
return &Environment{env}, nil
}
// Open a database in the environment.
func (env *Environment) Open(path string, flags C.u_int32_t, fileMode int) error {
mode := C.u_int32_t(fileMode)
err := C.go_env_open(env.environ, C.CString(path), flags, mode)
return createError(err)
}
// Close a database in the environment.
func (env *Environment) Close() error {
err := C.go_env_close(env.environ, 0)
return createError(err)
}