From 083d381acb7623db7be0c75f5f42a660cebadae6 Mon Sep 17 00:00:00 2001 From: Dan Goldsmith Date: Thu, 6 Feb 2014 10:22:52 +0000 Subject: [PATCH 1/3] Update unqlite.go Trying to get it to compile with UNQLITE_ENABLE_THREADS=1 on Windows GCC --- unqlite.go | 1 + 1 file changed, 1 insertion(+) diff --git a/unqlite.go b/unqlite.go index 5deac94..f2783ac 100644 --- a/unqlite.go +++ b/unqlite.go @@ -3,6 +3,7 @@ package unqlitego /* #cgo linux CFLAGS: -DUNQLITE_ENABLE_THREADS=1 -Wno-unused-but-set-variable #cgo darwin CFLAGS: -DUNQLITE_ENABLE_THREADS=1 +#cgo windows CFLAGS: -DUNQLITE_ENABLE_THREADS=1 #include "./unqlite.h" #include */ From 7530795d42249399e756fdb70c2493bf6c377f13 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 10 Feb 2014 13:08:35 +0000 Subject: [PATCH 2/3] Added Wrapper Functions To Support Transition From GKVLite --- unqlite.go | 5 ++++ wrappers.go | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 wrappers.go diff --git a/unqlite.go b/unqlite.go index f2783ac..aba77dc 100644 --- a/unqlite.go +++ b/unqlite.go @@ -38,6 +38,11 @@ var errString = map[UnQLiteError]string{ // Database ... type Database struct { handle *C.unqlite + + // By Providing Marshaller and Unmarshaller Functions we can marshal to BSON + // Rather then JSON without being dependant on BSON. + marshal MarshalFunction + unmarshal UnmarshalFunction } // Cursor ... diff --git a/wrappers.go b/wrappers.go new file mode 100644 index 0000000..cc7ac0b --- /dev/null +++ b/wrappers.go @@ -0,0 +1,83 @@ +package unqlitego + +/* + * Additional Database Functions to Aid Transaciotn From GKVLite + */ +import ( + "encoding/json" +) + +type MarshalFunction func(interface{}) ([]byte, error) +type UnmarshalFunction func([]byte, interface{}) error + +func (t *Database) Marshal() MarshalFunction { + if t.marshal != nil { + return t.marshal + } else { + return json.Marshal + } +} + +func (t *Database) SetMarshal(override MarshalFunction) { + t.marshal = override +} + +func (t *Database) Unmarshal() UnmarshalFunction { + if t.unmarshal != nil { + return t.unmarshal + } else { + return json.Unmarshal + } +} + +func (t *Database) SetUnmarshal(override UnmarshalFunction) { + t.unmarshal = override +} + +func (t *Database) SetObject(key string, object interface{}) error { + byteObject, err := t.Marshal()(object) + + if err != nil { + return err + } + + err = t.Begin() + if err != nil { + return err + } + + err = t.Store([]byte(key), byteObject) + if err != nil { + t.Rollback() + return err + } + + err = t.Commit() + if err != nil { + t.Rollback() + return err + } + + return nil +} + +func (t *Database) GetObject(key string, object interface{}) error { + + byteObject, err := t.Fetch([]byte(key)) + if err != nil { + if err == UnQLiteError(-6) { + //Not Found is not an error in my world... + return nil + } + return err + } + + if byteObject != nil { + err = t.Unmarshal()(byteObject, &object) + if err != nil { + return err + } + } + + return nil +} From 15bf48b1629aefc2e95650fedb9342d121cae234 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 11 Feb 2014 10:48:31 +0000 Subject: [PATCH 3/3] Revert "Added Wrapper Functions To Support Transition From GKVLite" This reverts commit 7530795d42249399e756fdb70c2493bf6c377f13. --- unqlite.go | 5 ---- wrappers.go | 83 ----------------------------------------------------- 2 files changed, 88 deletions(-) delete mode 100644 wrappers.go diff --git a/unqlite.go b/unqlite.go index aba77dc..f2783ac 100644 --- a/unqlite.go +++ b/unqlite.go @@ -38,11 +38,6 @@ var errString = map[UnQLiteError]string{ // Database ... type Database struct { handle *C.unqlite - - // By Providing Marshaller and Unmarshaller Functions we can marshal to BSON - // Rather then JSON without being dependant on BSON. - marshal MarshalFunction - unmarshal UnmarshalFunction } // Cursor ... diff --git a/wrappers.go b/wrappers.go deleted file mode 100644 index cc7ac0b..0000000 --- a/wrappers.go +++ /dev/null @@ -1,83 +0,0 @@ -package unqlitego - -/* - * Additional Database Functions to Aid Transaciotn From GKVLite - */ -import ( - "encoding/json" -) - -type MarshalFunction func(interface{}) ([]byte, error) -type UnmarshalFunction func([]byte, interface{}) error - -func (t *Database) Marshal() MarshalFunction { - if t.marshal != nil { - return t.marshal - } else { - return json.Marshal - } -} - -func (t *Database) SetMarshal(override MarshalFunction) { - t.marshal = override -} - -func (t *Database) Unmarshal() UnmarshalFunction { - if t.unmarshal != nil { - return t.unmarshal - } else { - return json.Unmarshal - } -} - -func (t *Database) SetUnmarshal(override UnmarshalFunction) { - t.unmarshal = override -} - -func (t *Database) SetObject(key string, object interface{}) error { - byteObject, err := t.Marshal()(object) - - if err != nil { - return err - } - - err = t.Begin() - if err != nil { - return err - } - - err = t.Store([]byte(key), byteObject) - if err != nil { - t.Rollback() - return err - } - - err = t.Commit() - if err != nil { - t.Rollback() - return err - } - - return nil -} - -func (t *Database) GetObject(key string, object interface{}) error { - - byteObject, err := t.Fetch([]byte(key)) - if err != nil { - if err == UnQLiteError(-6) { - //Not Found is not an error in my world... - return nil - } - return err - } - - if byteObject != nil { - err = t.Unmarshal()(byteObject, &object) - if err != nil { - return err - } - } - - return nil -}