Add options for Database/Table (#1516)
* Add options for Database/Table * fix opts
This commit is contained in:
parent
0a27a08184
commit
53549b6b30
@ -54,6 +54,7 @@ func WithContext(c context.Context) Option {
|
|||||||
|
|
||||||
// ReadOptions configures an individual Read operation
|
// ReadOptions configures an individual Read operation
|
||||||
type ReadOptions struct {
|
type ReadOptions struct {
|
||||||
|
Database, Table string
|
||||||
// Prefix returns all records that are prefixed with key
|
// Prefix returns all records that are prefixed with key
|
||||||
Prefix bool
|
Prefix bool
|
||||||
// Suffix returns all records that have the suffix key
|
// Suffix returns all records that have the suffix key
|
||||||
@ -67,6 +68,14 @@ type ReadOptions struct {
|
|||||||
// ReadOption sets values in ReadOptions
|
// ReadOption sets values in ReadOptions
|
||||||
type ReadOption func(r *ReadOptions)
|
type ReadOption func(r *ReadOptions)
|
||||||
|
|
||||||
|
// ReadFrom the database and table
|
||||||
|
func ReadFrom(database, table string) ReadOption {
|
||||||
|
return func(r *ReadOptions) {
|
||||||
|
r.Database = database
|
||||||
|
r.Table = table
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ReadPrefix returns all records that are prefixed with key
|
// ReadPrefix returns all records that are prefixed with key
|
||||||
func ReadPrefix() ReadOption {
|
func ReadPrefix() ReadOption {
|
||||||
return func(r *ReadOptions) {
|
return func(r *ReadOptions) {
|
||||||
@ -98,6 +107,7 @@ func ReadOffset(o uint) ReadOption {
|
|||||||
// WriteOptions configures an individual Write operation
|
// WriteOptions configures an individual Write operation
|
||||||
// If Expiry and TTL are set TTL takes precedence
|
// If Expiry and TTL are set TTL takes precedence
|
||||||
type WriteOptions struct {
|
type WriteOptions struct {
|
||||||
|
Database, Table string
|
||||||
// Expiry is the time the record expires
|
// Expiry is the time the record expires
|
||||||
Expiry time.Time
|
Expiry time.Time
|
||||||
// TTL is the time until the record expires
|
// TTL is the time until the record expires
|
||||||
@ -107,6 +117,14 @@ type WriteOptions struct {
|
|||||||
// WriteOption sets values in WriteOptions
|
// WriteOption sets values in WriteOptions
|
||||||
type WriteOption func(w *WriteOptions)
|
type WriteOption func(w *WriteOptions)
|
||||||
|
|
||||||
|
// WriteTo the database and table
|
||||||
|
func WriteTo(database, table string) WriteOption {
|
||||||
|
return func(w *WriteOptions) {
|
||||||
|
w.Database = database
|
||||||
|
w.Table = table
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// WriteExpiry is the time the record expires
|
// WriteExpiry is the time the record expires
|
||||||
func WriteExpiry(t time.Time) WriteOption {
|
func WriteExpiry(t time.Time) WriteOption {
|
||||||
return func(w *WriteOptions) {
|
return func(w *WriteOptions) {
|
||||||
@ -122,13 +140,25 @@ func WriteTTL(d time.Duration) WriteOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// DeleteOptions configures an individual Delete operation
|
// DeleteOptions configures an individual Delete operation
|
||||||
type DeleteOptions struct{}
|
type DeleteOptions struct {
|
||||||
|
Database, Table string
|
||||||
|
}
|
||||||
|
|
||||||
// DeleteOption sets values in DeleteOptions
|
// DeleteOption sets values in DeleteOptions
|
||||||
type DeleteOption func(d *DeleteOptions)
|
type DeleteOption func(d *DeleteOptions)
|
||||||
|
|
||||||
|
// DeleteFrom the database and table
|
||||||
|
func DeleteFrom(database, table string) DeleteOption {
|
||||||
|
return func(d *DeleteOptions) {
|
||||||
|
d.Database = database
|
||||||
|
d.Table = table
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ListOptions configures an individual List operation
|
// ListOptions configures an individual List operation
|
||||||
type ListOptions struct {
|
type ListOptions struct {
|
||||||
|
// List from the following
|
||||||
|
Database, Table string
|
||||||
// Prefix returns all keys that are prefixed with key
|
// Prefix returns all keys that are prefixed with key
|
||||||
Prefix string
|
Prefix string
|
||||||
// Suffix returns all keys that end with key
|
// Suffix returns all keys that end with key
|
||||||
@ -142,6 +172,14 @@ type ListOptions struct {
|
|||||||
// ListOption sets values in ListOptions
|
// ListOption sets values in ListOptions
|
||||||
type ListOption func(l *ListOptions)
|
type ListOption func(l *ListOptions)
|
||||||
|
|
||||||
|
// ListFrom the database and table
|
||||||
|
func ListFrom(database, table string) ListOption {
|
||||||
|
return func(l *ListOptions) {
|
||||||
|
l.Database = database
|
||||||
|
l.Table = table
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ListPrefix returns all keys that are prefixed with key
|
// ListPrefix returns all keys that are prefixed with key
|
||||||
func ListPrefix(p string) ListOption {
|
func ListPrefix(p string) ListOption {
|
||||||
return func(l *ListOptions) {
|
return func(l *ListOptions) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user