Implement produce service

This commit is contained in:
2021-06-20 18:16:33 -04:00
parent c7cbd7df57
commit 0136e616fb
14 changed files with 537 additions and 37 deletions
+11 -11
View File
@@ -3,7 +3,7 @@ package ramdb
import "github.com/google/btree"
// Get validates that the table and index for the given column exists and searches for the given key in the tree.
func (t *table) Get(column, key string) (r *record, err error) {
func (t *table) Get(column, key string) (r *Record, err error) {
if !t.exists {
return nil, ErrNoTable
}
@@ -16,18 +16,18 @@ func (t *table) Get(column, key string) (r *record, err error) {
}
// keyLookup tries to find the given key in the tree. It returns ErrNoRecord if not found.
func (t *table) keyLookup(key string, index *index) (r *record, err error) {
item := &record{id: keyHash(key)}
func (t *table) keyLookup(key string, index *index) (r *Record, err error) {
item := &Record{id: keyHash(key)}
result := index.tree.Get(item)
if result == nil {
return nil, ErrNoRecord
}
return result.(*record), nil
return result.(*Record), nil
}
// Select returns all of the records in the database sorted in ascending order by id.
func (t *table) Select(column string) (rr []*record, err error) {
// Select returns all of the Records in the database sorted in ascending order by id.
func (t *table) Select(column string) (rr []*Record, err error) {
if !t.exists {
return nil, ErrNoTable
}
@@ -37,7 +37,7 @@ func (t *table) Select(column string) (rr []*record, err error) {
}
t.indexes[column].tree.Ascend(func(item btree.Item) bool {
r := item.(*record)
r := item.(*Record)
rr = append(rr, r)
return true
})
@@ -45,8 +45,8 @@ func (t *table) Select(column string) (rr []*record, err error) {
return
}
// Insert adds the record to the database. It returns ErrRecordExists if the record already exists. Insert is thread safe.
func (t *table) Insert(r *record) error {
// Insert adds the Record to the database. It returns ErrRecordExists if the Record already exists. Insert is thread safe.
func (t *table) Insert(r *Record) error {
if !t.exists {
return ErrNoTable
}
@@ -69,8 +69,8 @@ func (t *table) Insert(r *record) error {
}
// Delete removes the item from the database. It returns ErrNoRecord if the record does not exist and ErrNotDeleted if the removal fails. Delete is thread safe.
func (t *table) Delete(r *record) error {
// Delete removes the item from the database. It returns ErrNoRecord if the Record does not exist and ErrNotDeleted if the removal fails. Delete is thread safe.
func (t *table) Delete(r *Record) error {
if !t.exists {
return ErrNoTable
}