Revert "Added Wrapper Functions To Support Transition From GKVLite"
This reverts commit 7530795d42
.
This commit is contained in:
parent
7530795d42
commit
15bf48b162
2 changed files with 0 additions and 88 deletions
|
@ -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 ...
|
||||
|
|
83
wrappers.go
83
wrappers.go
|
@ -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
|
||||
}
|
Loading…
Reference in a new issue