Beispiel #1
0
Datei: mdbm.go Projekt: tann/mdbm
// Dup duplicates an existing DB handle
func (db *MDBM) Dup() (dup *MDBM, err error) {
	db.mutex.Lock()
	defer db.mutex.Unlock()

	dup = &MDBM{
		flags: db.flags,
		perms: db.perms,
		psize: db.psize,
		dsize: db.dsize,
	}
	C.mdbm_iter_init(&dup.iter)

	dup.dbh, err = C.mdbm_dup_handle(db.dbh, 0)
	if err != nil {
		return nil, err
	}

	return dup, nil
}
Beispiel #2
0
Datei: mdbm.go Projekt: tann/mdbm
// Open opens an existing DB or creates a new DB. Options can be passed in
// using these setters:
//	mdbm.Flags (Default mdbm.ReadWrite | mdbm.Create)
//	mdbm.Perms (Default 0600)
//	mdbm.PageSize (Default 4KB)
//	mdbm.StartSize (Default 1MB)
func Open(dbfile string, options ...option) (db *MDBM, err error) {
	db = &MDBM{
		flags: ReadWrite | Create,
		perms: 0666,
		psize: 0,
		dsize: 0,
	}
	C.mdbm_iter_init(&db.iter)

	for _, opt := range options {
		opt(db)
	}

	fn := C.CString(dbfile)
	defer C.free(unsafe.Pointer(fn))

	db.dbh, err = C.mdbm_open(fn, C.int(db.flags), C.int(db.perms), C.int(db.psize), C.int(db.dsize))
	if err != nil {
		return nil, err
	}
	return db, nil
}
Beispiel #3
0
Datei: mdbm.go Projekt: tann/mdbm
// Restart resets DB iterator
func (db *MDBM) Restart() {
	C.mdbm_iter_init(&db.iter)
}