예제 #1
0
func Open(path string, mode DBMode) (*DB, error) {
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	cmode := C.notmuch_database_mode_t(mode)

	db := &DB{}
	cdb := (**C.notmuch_database_t)(unsafe.Pointer(&db.cptr))

	cerr := C.notmuch_database_open(cpath, cmode, cdb)

	err := statusErr(cerr)
	return db, err
}
예제 #2
0
파일: db.go 프로젝트: gmuch/gmuch
// Open opens the database at the location path using mode. Caller is responsible
// for closing the database when done.
func Open(path string, mode DBMode) (*DB, error) {
	cpath := C.CString(path)
	defer C.free(unsafe.Pointer(cpath))

	cmode := C.notmuch_database_mode_t(mode)
	var cdb *C.notmuch_database_t
	cdbptr := (**C.notmuch_database_t)(&cdb)
	err := statusErr(C.notmuch_database_open(cpath, cmode, cdbptr))
	if err != nil {
		return nil, err
	}
	db := &DB{cptr: unsafe.Pointer(cdb)}
	setGcClose(db)
	return db, nil
}
예제 #3
0
/* Open an existing notmuch database located at 'path'.
 *
 * The database should have been created at some time in the past,
 * (not necessarily by this process), by calling
 * notmuch_database_create with 'path'. By default the database should be
 * opened for reading only. In order to write to the database you need to
 * pass the NOTMUCH_DATABASE_MODE_READ_WRITE mode.
 *
 * An existing notmuch database can be identified by the presence of a
 * directory named ".notmuch" below 'path'.
 *
 * The caller should call notmuch_database_destroy when finished with
 * this database.
 *
 * In case of any failure, this function returns NULL, (after printing
 * an error message on stderr).
 */
func OpenDatabase(path string, mode DatabaseMode) (*Database, Status) {

	var c_path *C.char = C.CString(path)
	defer C.free(unsafe.Pointer(c_path))

	if c_path == nil {
		return nil, STATUS_OUT_OF_MEMORY
	}

	self := &Database{db: nil}
	st := Status(C.notmuch_database_open(c_path, C.notmuch_database_mode_t(mode), &self.db))
	if st != STATUS_SUCCESS {
		return nil, st
	}
	return self, st
}