Documentation
¶
Overview ¶
Package dynamitedb provides an embedded singletable database engine running on s3.
Index ¶
- Variables
- func Add[T time.Time](operand time.Duration) *addUpdate[T]
- func After[T time.Time](operand T) *afterFilter[T]
- func Append[T any](items ...T) *appendUpdate[T]
- func Before[T time.Time](operand T) *beforeFilter[T]
- func Contains[T comparable](operands ...T) *containsFilter[T]
- func Create[T any](ctx context.Context, bucket *Bucket, model *T, opts ...Option) error
- func CustomFilter[T any](check func(databaseValue T) bool) *customFilter[T]
- func CustomUpdate[T any](update func(databaseValue T) (updatedValue T)) *customUpdate[T]
- func Delete[T any](ctx context.Context, bucket *Bucket, filter *T) error
- func Emplace[K comparable, V any](operand map[K]V) *emplaceUpdate[K, V]
- func Eq[T any](operand T) *eqFilter[T]
- func Get[T any](ctx context.Context, bucket *Bucket, filter *T) (*T, error)
- func GreaterOrEqThan[T int | float64 | time.Duration](operand T) *greaterOrEqThanFilter[T]
- func GreaterThan[T int | float64 | time.Duration](operand T) *greaterThanFilter[T]
- func Has[K, V comparable](key K, value V) *hasFilter[K, V]
- func In[T any](operands ...T) inFilter[T]
- func Includes[T string](operand string) *includesFilter[T]
- func Increment[T int | float64 | time.Duration](operand T) *incrementUpdate[T]
- func Key(id string) *key
- func KeyPrefix(prefix string) *beginsWithQuery
- func LessOrEqThan[T int | float64 | time.Duration](operand T) *lessOrEqThanFilter[T]
- func LessThan[T int | float64 | time.Duration](operand T) *lessThanFilter[T]
- func Multiply[T int | float64 | time.Duration](operand T) *multiplyUpdate[T]
- func NotEq[T any](operand T) *notEqFilter[T]
- func NotIn[T any](operands ...T) notInFilter[T]
- func Put[T any](ctx context.Context, bucket *Bucket, model *T, opts ...Option) error
- func Query[T any](ctx context.Context, bucket *Bucket, filter *T, opts ...Option) ([]*T, error)
- func Remove[T comparable](items ...T) *removeUpdate[T]
- func Set[T any](operand T) *setUpdate[T]
- func Toggle() *toggleUpdate[bool]
- func Update[T any](ctx context.Context, bucket *Bucket, update *T, opts ...Option) error
- func WithExpires(expires time.Time) func(*options)
- func WithLimit(limit int) func(*options)
- func WithStartAfter[T any](filter *T) func(*options)
- type Bucket
- type BucketOption
- type DataField
- type ETagField
- type KeyField
- type Option
Constants ¶
This section is empty.
Variables ¶
var ( // the specified object was not found ErrNotFound = errors.New("not found") // the specified object was found but the filter blocked it ErrFilterMismatch = errors.New("filter mismatch") // the object you want to insert does already exist ErrAlreadyExists = errors.New("already exists") // optimistic locking failure (operation aborted because another writer changed object mid transaction) ErrConcurrencyConflict = errors.New("optimistic lock failed") )
external error API to catch specific conditions.
Functions ¶
func After ¶
After checks if the database value is after the specified time. This is a filter operator.
func Append ¶
func Append[T any](items ...T) *appendUpdate[T]
Append appends the items to the previous slice. This is an update operator.
func Before ¶
Before checks if the database value is before the specified time. This is a filter operator.
func Contains ¶
func Contains[T comparable](operands ...T) *containsFilter[T]
Contains checks if the slice contains all of the operands. This is a filter operator.
func CustomFilter ¶
CustomFilter allows you to perform a custom filter check on the field. This is a filter operator.
func CustomUpdate ¶
func CustomUpdate[T any](update func(databaseValue T) (updatedValue T)) *customUpdate[T]
CustomUpdate allows you to perform a custom update action on the field. This is an update operator.
func Delete ¶ added in v0.1.0
Delete removes the specified object from database. If the object does not exist this becomes a noop returning nil.
func Emplace ¶
func Emplace[K comparable, V any](operand map[K]V) *emplaceUpdate[K, V]
Emplace updates the previous map with the provided new kv pairs. This is an update operator.
func Eq ¶
func Eq[T any](operand T) *eqFilter[T]
Eq checks for an exact match with the operand. For slices and map this enforces a deep equal state. This is a filter operator.
func Get ¶
Get fetches a single entry from database based on the filter. This operation performs no ListObject call and is more efficient but only works with exact key matches.
func GreaterOrEqThan ¶
GreaterOrEqThan compares exactly what it says. This is a filter operator.
func GreaterThan ¶
GreaterThan compares exactly what it says. This is a filter operator.
func Has ¶
func Has[K, V comparable](key K, value V) *hasFilter[K, V]
Has checks if the map contains the specified key value pair. This is a filter operator.
func In ¶
func In[T any](operands ...T) inFilter[T]
In checks if the database value is inside the provided list. Functionally equivalent to Eq but just with an operand for loop. This is a filter operator.
func Increment ¶
Increment increments the value with operand (can be positive or negative). This is an update operator.
func Key ¶
func Key(id string) *key
Key performs an exact match on the specified key id. Since keys are immutable this can be used for query and data fields.
func KeyPrefix ¶
func KeyPrefix(prefix string) *beginsWithQuery
KeyPrefix reads all entries with the specified prefix. Using KeyPrefix on PK and SK converts the PK to an exact match.
func LessOrEqThan ¶
LessOrEqThan compares exactly what it says. This is a filter operator.
func NotEq ¶
func NotEq[T any](operand T) *notEqFilter[T]
NotEq is just !Eq. This is a filter operator.
func NotIn ¶
func NotIn[T any](operands ...T) notInFilter[T]
NotIn is just !In. This is a filter operator.
func Query ¶
Query scans (by filter) and returns all database entries indexed by key prefix matches. Caution: if key prefixes are not properly organized a query can easily rawdog scan millions of entries.
func Remove ¶
func Remove[T comparable](items ...T) *removeUpdate[T]
Remove removes the provided items from the slice. This is an update operator.
func Set ¶
func Set[T any](operand T) *setUpdate[T]
Set simply overwrites the previous value. This is an update operator.
func Toggle ¶
func Toggle() *toggleUpdate[bool]
Toggle changes the value to !value. This is an update operator.
func Update ¶
Update changes the entry on the database (identified by PK / SK). For update operations see "Field" API on the schema. Update will modify v to represent the final state of the updated entry.
func WithExpires ¶
WithExpires can be specified to expire the updated or inserted item at a certain point in time. Notice that this relies on the S3 lifecycle and may not be immediately removed depending on implementation.
func WithLimit ¶
func WithLimit(limit int) func(*options)
WithLimit specifies the limit of elements to return. caution: even with a limit of 10 Query() will scan million of entries if it finds no filter matches.
func WithStartAfter ¶
func WithStartAfter[T any](filter *T) func(*options)
WithStartAfter specifies an item from where to start querying (useful for pagination). This parameter requires a filter object with an exact key match (other filter props are not checked).
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
type BucketOption ¶
func WithCredentials ¶
func WithCredentials(accessKey, secretKey string) BucketOption
WithCredentials specifies a static access and secret key. This disables the default AWS SDK credential process.
func WithRegion ¶
func WithRegion(region string) BucketOption
WithRegion specifies a static bucket region. This disables the default AWS SDK region process.
type DataField ¶
type DataField[T any] interface { // Value returns the raw data value. Value() T // contains filtered or unexported methods }
DataField defines a dynamite data field (initialize with dynamitedb.Data("blub")). Use Value() to retrieve the underlying value.
type ETagField ¶ added in v0.6.0
type ETagField *string
ETagField defines a dynamite OCC etag. Tag it with `etag:"true"` to mark for automatic insertion. Multiple etags are not allowed (dynamite will simply use the first in this situation).
type KeyField ¶
type KeyField interface {
// Value returns the raw key value.
Value() string
// contains filtered or unexported methods
}
KeyField defines a dynamite index key (initialize with dynamitedb.Key("123")). Tag it with `pk:"user"` to mark partition key or `sk:"order"` for sort key. Every model requires at least the partition key (sort key is optional). Multiple partition or sort keys are not allowed (dynamite will simply use the first in this situation).