From 4c6b4dbf1f00391d79af0c8579ffaf9a13ded3d4 Mon Sep 17 00:00:00 2001 From: nobonobo Date: Tue, 26 Nov 2013 23:32:24 +0900 Subject: [PATCH] lib func implemented. --- README.md | 2 +- unqlite.go | 53 +++++++++++++++++++++++++++++++++++------------------ 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 5eeba08..b6cc619 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Install --------- ```sh -go get github.com/nobonobo/unqlitego +go get -d github.com/nobonobo/unqlitego cd $GOPATH/src/github.com/nobonobo/unqlitego git submodule init git submodule update diff --git a/unqlite.go b/unqlite.go index 5a28f0e..f2f86ef 100644 --- a/unqlite.go +++ b/unqlite.go @@ -47,7 +47,7 @@ type Cursor struct { func init() { C.unqlite_lib_init() - if C.unqlite_lib_is_threadsafe() != 1 { + if !IsThreadSafe() { panic("unqlite library was not compiled for thread-safe option UNQLITE_ENABLE_THREADS=1") } } @@ -79,12 +79,6 @@ func (db *Database) Close() (err error) { return } -// Config ... -func (db *Database) Config(operate int, args ...interface{}) (err error) { - err = errors.New("not implemented") - return -} - // Store ... func (db *Database) Store(key, value []byte) (err error) { res := C.unqlite_kv_store(db.handle, @@ -300,14 +294,46 @@ func (curs *Cursor) Value() (value []byte, err error) { return } +// Shutdown ... +func Shutdown() (err error) { + res := C.unqlite_lib_shutdown() + if res != C.UNQLITE_OK { + err = UnQLiteError(res) + return + } +} + +// IsThreadSafe ... +func IsThreadSafe() bool { + return C.unqlite_lib_is_threadsafe() == 1 +} + +// Version ... +func Version() string { + return C.GoString(C.unqlite_lib_version()) +} + +// Signature ... +func Signature() string { + return C.GoString(C.unqlite_lib_signature()) +} + +// Ident ... +func Ident() string { + return C.GoString(C.unqlite_lib_ident()) +} + +// Copyright ... +func Copyright() string { + return C.GoString(C.unqlite_lib_copyright()) +} + /* TODO: implement // Database Engine Handle int unqlite_config(unqlite *pDb,int nOp,...); // Key/Value (KV) Store Interfaces -int unqlite_kv_store_fmt(unqlite *pDb,const void *pKey,int nKeyLen,const char *zFormat,...); -int unqlite_kv_append_fmt(unqlite *pDb,const void *pKey,int nKeyLen,const char *zFormat,...); int unqlite_kv_fetch_callback(unqlite *pDb,const void *pKey, int nKeyLen,int (*xConsumer)(const void *,unsigned int,void *),void *pUserData); int unqlite_kv_config(unqlite *pDb,int iOp,...); @@ -319,16 +345,7 @@ int unqlite_kv_cursor_data_callback(unqlite_kv_cursor *pCursor,int (*xConsumer)( // Utility interfaces int unqlite_util_load_mmaped_file(const char *zFile,void **ppMap,unqlite_int64 *pFileSize); int unqlite_util_release_mmaped_file(void *pMap,unqlite_int64 iFileSize); -int unqlite_util_random_string(unqlite *pDb,char *zBuf,unsigned int buf_size); -unsigned int unqlite_util_random_num(unqlite *pDb); // Global Library Management Interfaces int unqlite_lib_config(int nConfigOp,...); -int unqlite_lib_init(void); -int unqlite_lib_shutdown(void); -int unqlite_lib_is_threadsafe(void); -const char * unqlite_lib_version(void); -const char * unqlite_lib_signature(void); -const char * unqlite_lib_ident(void); -const char * unqlite_lib_copyright(void); */