Documentation
¶
Overview ¶
Package rlist is a database-backed list repository. It provides methods to interact with lists in the database.
Index ¶
- type DB
- func (d *DB) Delete(key string, elem any) (int, error)
- func (d *DB) DeleteBack(key string, elem any, count int) (int, error)
- func (d *DB) DeleteFront(key string, elem any, count int) (int, error)
- func (d *DB) Get(key string, idx int) (core.Value, error)
- func (d *DB) InsertAfter(key string, pivot, elem any) (int, error)
- func (d *DB) InsertBefore(key string, pivot, elem any) (int, error)
- func (d *DB) Len(key string) (int, error)
- func (d *DB) PopBack(key string) (core.Value, error)
- func (d *DB) PopBackPushFront(src, dest string) (core.Value, error)
- func (d *DB) PopFront(key string) (core.Value, error)
- func (d *DB) PushBack(key string, elem any) (int, error)
- func (d *DB) PushFront(key string, elem any) (int, error)
- func (d *DB) Range(key string, start, stop int) ([]core.Value, error)
- func (d *DB) Set(key string, idx int, elem any) error
- func (d *DB) Trim(key string, start, stop int) (int, error)
- type Tx
- func (tx *Tx) Delete(key string, elem any) (int, error)
- func (tx *Tx) DeleteBack(key string, elem any, count int) (int, error)
- func (tx *Tx) DeleteFront(key string, elem any, count int) (int, error)
- func (tx *Tx) Get(key string, idx int) (core.Value, error)
- func (tx *Tx) InsertAfter(key string, pivot, elem any) (int, error)
- func (tx *Tx) InsertBefore(key string, pivot, elem any) (int, error)
- func (tx *Tx) Len(key string) (int, error)
- func (tx *Tx) PopBack(key string) (core.Value, error)
- func (tx *Tx) PopBackPushFront(src, dest string) (core.Value, error)
- func (tx *Tx) PopFront(key string) (core.Value, error)
- func (tx *Tx) PushBack(key string, elem any) (int, error)
- func (tx *Tx) PushFront(key string, elem any) (int, error)
- func (tx *Tx) Range(key string, start, stop int) ([]core.Value, error)
- func (tx *Tx) Set(key string, idx int, elem any) error
- func (tx *Tx) Trim(key string, start, stop int) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB is a database-backed list repository. A list is a sequence of strings ordered by insertion order. Use the list repository to work with lists and their elements.
func (*DB) Delete ¶
Delete deletes all occurrences of an element from a list. Returns the number of elements deleted. Does nothing if the key does not exist or is not a list.
func (*DB) DeleteBack ¶
DeleteBack deletes the first count occurrences of an element from a list, starting from the back. Count must be positive. Returns the number of elements deleted. Does nothing if the key does not exist or is not a list.
func (*DB) DeleteFront ¶
DeleteFront deletes the first count occurrences of an element from a list, starting from the front. Count must be positive. Returns the number of elements deleted. Does nothing if the key does not exist or is not a list.
func (*DB) Get ¶
Get returns an element from a list by index (0-based). Negative index count from the end of the list (-1 is the last element, -2 is the second last, etc.) If the index is out of bounds, returns ErrNotFound. If the key does not exist or is not a list, returns ErrNotFound.
func (*DB) InsertAfter ¶
InsertAfter inserts an element after another element (pivot). Returns the length of the list after the operation. If the pivot does not exist, returns (-1, ErrNotFound). If the key does not exist or is not a list, returns (0, ErrNotFound).
func (*DB) InsertBefore ¶
InsertBefore inserts an element before another element (pivot). Returns the length of the list after the operation. If the pivot does not exist, returns (-1, ErrNotFound). If the key does not exist or is not a list, returns (0, ErrNotFound).
func (*DB) Len ¶
Len returns the number of elements in a list. If the key does not exist or is not a list, returns 0.
func (*DB) PopBack ¶
PopBack removes and returns the last element of a list. If the key does not exist or is not a list, returns ErrNotFound.
func (*DB) PopBackPushFront ¶
PopBackPushFront removes the last element of a list and prepends it to another list (or the same list). If the source key does not exist or is not a list, returns ErrNotFound.
func (*DB) PopFront ¶
PopFront removes and returns the first element of a list. If the key does not exist or is not a list, returns ErrNotFound.
func (*DB) PushBack ¶
PushBack appends an element to a list. Returns the length of the list after the operation. If the key does not exist, creates it. If the key exists but is not a list, returns ErrKeyType.
func (*DB) PushFront ¶
PushFront prepends an element to a list. Returns the length of the list after the operation. If the key does not exist, creates it. If the key exists but is not a list, returns ErrKeyType.
func (*DB) Range ¶
Range returns a range of elements from a list. Both start and stop are zero-based, inclusive. Negative indexes count from the end of the list (-1 is the last element, -2 is the second last, etc.) If the key does not exist or is not a list, returns an empty slice.
func (*DB) Set ¶
Set sets an element in a list by index (0-based). Negative index count from the end of the list (-1 is the last element, -2 is the second last, etc.) If the index is out of bounds, returns ErrNotFound. If the key does not exist or is not a list, returns ErrNotFound.
func (*DB) Trim ¶
Trim removes elements from both ends of a list so that only the elements between start and stop indexes remain. Returns the number of elements removed.
Both start and stop are zero-based, inclusive. Negative indexes count from the end of the list (-1 is the last element, -2 is the second last, etc.)
Does nothing if the key does not exist or is not a list.
type Tx ¶
type Tx struct {
// contains filtered or unexported fields
}
Tx is a list repository transaction.
func (*Tx) Delete ¶
Delete deletes all occurrences of an element from a list. Returns the number of elements deleted. Does nothing if the key does not exist or is not a list.
func (*Tx) DeleteBack ¶
DeleteBack deletes the first count occurrences of an element from a list, starting from the back. Count must be positive. Returns the number of elements deleted. Does nothing if the key does not exist or is not a list.
func (*Tx) DeleteFront ¶
DeleteFront deletes the first count occurrences of an element from a list, starting from the front. Count must be positive. Returns the number of elements deleted. Does nothing if the key does not exist or is not a list.
func (*Tx) Get ¶
Get returns an element from a list by index (0-based). Negative index count from the end of the list (-1 is the last element, -2 is the second last, etc.) If the index is out of bounds, returns ErrNotFound. If the key does not exist or is not a list, returns ErrNotFound.
func (*Tx) InsertAfter ¶
InsertAfter inserts an element after another element (pivot). Returns the length of the list after the operation. If the pivot does not exist, returns (-1, ErrNotFound). If the key does not exist or is not a list, returns (0, ErrNotFound).
func (*Tx) InsertBefore ¶
InsertBefore inserts an element before another element (pivot). Returns the length of the list after the operation. If the pivot does not exist, returns (-1, ErrNotFound). If the key does not exist or is not a list, returns (0, ErrNotFound).
func (*Tx) Len ¶
Len returns the number of elements in a list. If the key does not exist or is not a list, returns 0.
func (*Tx) PopBack ¶
PopBack removes and returns the last element of a list. If the key does not exist or is not a list, returns ErrNotFound.
func (*Tx) PopBackPushFront ¶
PopBackPushFront removes the last element of a list and prepends it to another list (or the same list). If the source key does not exist or is not a list, returns ErrNotFound.
func (*Tx) PopFront ¶
PopFront removes and returns the first element of a list. If the key does not exist or is not a list, returns ErrNotFound.
func (*Tx) PushBack ¶
PushBack appends an element to a list. Returns the length of the list after the operation. If the key does not exist, creates it. If the key exists but is not a list, returns ErrKeyType.
func (*Tx) PushFront ¶
PushFront prepends an element to a list. Returns the length of the list after the operation. If the key does not exist, creates it. If the key exists but is not a list, returns ErrKeyType.
func (*Tx) Range ¶
Range returns a range of elements from a list. Both start and stop are zero-based, inclusive. Negative indexes count from the end of the list (-1 is the last element, -2 is the second last, etc.) If the key does not exist or is not a list, returns an empty slice.
func (*Tx) Set ¶
Set sets an element in a list by index (0-based). Negative index count from the end of the list (-1 is the last element, -2 is the second last, etc.) If the index is out of bounds, returns ErrNotFound. If the key does not exist or is not a list, returns ErrNotFound.
func (*Tx) Trim ¶
Trim removes elements from both ends of a list so that only the elements between start and stop indexes remain. Returns the number of elements removed.
Both start and stop are zero-based, inclusive. Negative indexes count from the end of the list (-1 is the last element, -2 is the second last, etc.)
Does nothing if the key does not exist or is not a list.