store: create options helpers
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
9fc0b5f88b
commit
a13cb01005
@ -86,6 +86,15 @@ func Table(t string) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewReadOptions fills ReadOptions struct with opts slice
|
||||||
|
func NewReadOptions(opts ...ReadOption) ReadOptions {
|
||||||
|
options := ReadOptions{}
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&options)
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
// ReadOptions configures an individual Read operation
|
// ReadOptions configures an individual Read operation
|
||||||
type ReadOptions struct {
|
type ReadOptions struct {
|
||||||
Database string
|
Database string
|
||||||
@ -103,14 +112,19 @@ func ReadFrom(database, table string) ReadOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewWriteOptions fills WriteOptions struct with opts slice
|
||||||
|
func NewWriteOptions(opts ...WriteOption) WriteOptions {
|
||||||
|
options := WriteOptions{}
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&options)
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
// WriteOptions configures an individual Write operation
|
// WriteOptions configures an individual Write operation
|
||||||
// If Expiry and TTL are set TTL takes precedence
|
|
||||||
type WriteOptions struct {
|
type WriteOptions struct {
|
||||||
Database string
|
Database string
|
||||||
Table string
|
Table string
|
||||||
// Expiry is the time the record expires
|
|
||||||
Expiry time.Time
|
|
||||||
// TTL is the time until the record expires
|
|
||||||
TTL time.Duration
|
TTL time.Duration
|
||||||
Metadata metadata.Metadata
|
Metadata metadata.Metadata
|
||||||
}
|
}
|
||||||
@ -126,13 +140,6 @@ func WriteTo(database, table string) WriteOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteExpiry is the time the record expires
|
|
||||||
func WriteExpiry(t time.Time) WriteOption {
|
|
||||||
return func(w *WriteOptions) {
|
|
||||||
w.Expiry = t
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// WriteTTL is the time the record expires
|
// WriteTTL is the time the record expires
|
||||||
func WriteTTL(d time.Duration) WriteOption {
|
func WriteTTL(d time.Duration) WriteOption {
|
||||||
return func(w *WriteOptions) {
|
return func(w *WriteOptions) {
|
||||||
@ -147,6 +154,15 @@ func WriteMetadata(md metadata.Metadata) WriteOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDeleteOptions fills DeleteOptions struct with opts slice
|
||||||
|
func NewDeleteOptions(opts ...DeleteOption) DeleteOptions {
|
||||||
|
options := DeleteOptions{}
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&options)
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteOptions configures an individual Delete operation
|
// DeleteOptions configures an individual Delete operation
|
||||||
type DeleteOptions struct {
|
type DeleteOptions struct {
|
||||||
Database, Table string
|
Database, Table string
|
||||||
@ -163,6 +179,15 @@ func DeleteFrom(database, table string) DeleteOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewListOptions fills ListOptions struct with opts slice
|
||||||
|
func NewListOptions(opts ...ListOption) ListOptions {
|
||||||
|
options := ListOptions{}
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&options)
|
||||||
|
}
|
||||||
|
return options
|
||||||
|
}
|
||||||
|
|
||||||
// ListOptions configures an individual List operation
|
// ListOptions configures an individual List operation
|
||||||
type ListOptions struct {
|
type ListOptions struct {
|
||||||
// List from the following
|
// List from the following
|
||||||
|
Loading…
Reference in New Issue
Block a user