Implement updated rixxdb api interface

This commit is contained in:
Tobie Morgan Hitchcock 2017-11-16 17:16:54 +00:00
parent ce3b62ab4b
commit c0110b8af9
5 changed files with 62 additions and 25 deletions

View file

@ -24,7 +24,7 @@ type DBError struct {
// Error returns the string representation of the error.
func (e *DBError) Error() string {
return fmt.Sprintf("There was a problem writing to the database")
return fmt.Sprintf("Unable to write to the database")
}
// KVError is an error which occurs when there is a

View file

@ -19,5 +19,5 @@ type KV interface {
Exi() bool
Key() []byte
Val() []byte
Ver() int64
Ver() uint64
}

View file

@ -28,7 +28,7 @@ func init() {
var pntr *rixxdb.DB
path := strings.TrimLeft(opts.DB.Path, "rixxdb://")
path := strings.TrimPrefix(opts.DB.Path, "rixxdb://")
pntr, err = rixxdb.Open(path, &rixxdb.Config{
SyncPolicy: opts.DB.Time,

View file

@ -65,13 +65,45 @@ func (tx *TX) Commit() error {
return tx.pntr.Commit()
}
func (tx *TX) Get(ver int64, key []byte) (kvs.KV, error) {
all, err := tx.pntr.Get(ver, key)
func (tx *TX) Clr(key []byte) (kvs.KV, error) {
all, err := tx.pntr.Clr(key)
return one(all, err)
}
func (tx *TX) GetL(ver int64, key []byte) ([]kvs.KV, error) {
all, err := tx.pntr.GetL(ver, key)
func (tx *TX) ClrL(key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.ClrL(key, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
}
return many(out, err)
}
func (tx *TX) ClrP(key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.ClrP(key, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
}
return many(out, err)
}
func (tx *TX) ClrR(beg []byte, end []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.ClrR(beg, end, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
}
return many(out, err)
}
func (tx *TX) Get(ver int64, key []byte) (kvs.KV, error) {
all, err := tx.pntr.Get(uint64(ver), key)
return one(all, err)
}
func (tx *TX) GetL(ver int64, key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.GetL(uint64(ver), key, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
@ -80,7 +112,7 @@ func (tx *TX) GetL(ver int64, key []byte) ([]kvs.KV, error) {
}
func (tx *TX) GetP(ver int64, key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.GetP(ver, key, max)
all, err := tx.pntr.GetP(uint64(ver), key, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
@ -89,7 +121,7 @@ func (tx *TX) GetP(ver int64, key []byte, max uint64) ([]kvs.KV, error) {
}
func (tx *TX) GetR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.GetR(ver, beg, end, max)
all, err := tx.pntr.GetR(uint64(ver), beg, end, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
@ -98,16 +130,16 @@ func (tx *TX) GetR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, err
}
func (tx *TX) Del(ver int64, key []byte) (kvs.KV, error) {
all, err := tx.pntr.Del(ver, key)
all, err := tx.pntr.Del(uint64(ver), key)
return one(all, err)
}
func (tx *TX) DelC(ver int64, key []byte, exp []byte) (kvs.KV, error) {
return tx.pntr.DelC(ver, key, exp)
return tx.pntr.DelC(uint64(ver), key, exp)
}
func (tx *TX) DelL(ver int64, key []byte) ([]kvs.KV, error) {
all, err := tx.pntr.DelL(ver, key)
func (tx *TX) DelL(ver int64, key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.DelL(uint64(ver), key, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
@ -116,7 +148,7 @@ func (tx *TX) DelL(ver int64, key []byte) ([]kvs.KV, error) {
}
func (tx *TX) DelP(ver int64, key []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.DelP(ver, key, max)
all, err := tx.pntr.DelP(uint64(ver), key, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
@ -125,7 +157,7 @@ func (tx *TX) DelP(ver int64, key []byte, max uint64) ([]kvs.KV, error) {
}
func (tx *TX) DelR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.DelR(ver, beg, end, max)
all, err := tx.pntr.DelR(uint64(ver), beg, end, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
@ -134,17 +166,17 @@ func (tx *TX) DelR(ver int64, beg []byte, end []byte, max uint64) ([]kvs.KV, err
}
func (tx *TX) Put(ver int64, key []byte, val []byte) (kvs.KV, error) {
all, err := tx.pntr.Put(ver, key, val)
all, err := tx.pntr.Put(uint64(ver), key, val)
return one(all, err)
}
func (tx *TX) PutC(ver int64, key []byte, val []byte, exp []byte) (kvs.KV, error) {
all, err := tx.pntr.PutC(ver, key, val, exp)
all, err := tx.pntr.PutC(uint64(ver), key, val, exp)
return one(all, err)
}
func (tx *TX) PutL(ver int64, key []byte, val []byte) ([]kvs.KV, error) {
all, err := tx.pntr.PutL(ver, key, val)
func (tx *TX) PutL(ver int64, key []byte, val []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.PutL(uint64(ver), key, val, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
@ -153,7 +185,7 @@ func (tx *TX) PutL(ver int64, key []byte, val []byte) ([]kvs.KV, error) {
}
func (tx *TX) PutP(ver int64, key []byte, val []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.PutP(ver, key, val, max)
all, err := tx.pntr.PutP(uint64(ver), key, val, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v
@ -161,8 +193,8 @@ func (tx *TX) PutP(ver int64, key []byte, val []byte, max uint64) ([]kvs.KV, err
return many(out, err)
}
func (tx *TX) PutR(ver int64, key []byte, val []byte, exp []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.PutR(ver, key, val, exp, max)
func (tx *TX) PutR(ver int64, beg []byte, end []byte, val []byte, max uint64) ([]kvs.KV, error) {
all, err := tx.pntr.PutR(uint64(ver), beg, end, val, max)
out := make([]kvs.KV, len(all))
for i, v := range all {
out[i] = v

View file

@ -20,20 +20,25 @@ type TX interface {
Cancel() error
Commit() error
Clr([]byte) (KV, error)
ClrL([]byte, uint64) ([]KV, error)
ClrP([]byte, uint64) ([]KV, error)
ClrR([]byte, []byte, uint64) ([]KV, error)
Get(int64, []byte) (KV, error)
GetL(int64, []byte) ([]KV, error)
GetL(int64, []byte, uint64) ([]KV, error)
GetP(int64, []byte, uint64) ([]KV, error)
GetR(int64, []byte, []byte, uint64) ([]KV, error)
Del(int64, []byte) (KV, error)
DelC(int64, []byte, []byte) (KV, error)
DelL(int64, []byte) ([]KV, error)
DelL(int64, []byte, uint64) ([]KV, error)
DelP(int64, []byte, uint64) ([]KV, error)
DelR(int64, []byte, []byte, uint64) ([]KV, error)
Put(int64, []byte, []byte) (KV, error)
PutC(int64, []byte, []byte, []byte) (KV, error)
PutL(int64, []byte, []byte) ([]KV, error)
PutL(int64, []byte, []byte, uint64) ([]KV, error)
PutP(int64, []byte, []byte, uint64) ([]KV, error)
PutR(int64, []byte, []byte, []byte, uint64) ([]KV, error)
}