github.com/ronaksoft/rony@v0.16.26-0.20230807065236-1743dbfe6959/store/call_options.go (about)

     1  package store
     2  
     3  /*
     4     Creation Time: 2021 - Jan - 27
     5     Created by:  (ehsan)
     6     Maintainers:
     7        1.  Ehsan N. Moosa (E2)
     8     Auditor: Ehsan N. Moosa (E2)
     9     Copyright Ronak Software Group 2020
    10  */
    11  
    12  type ListOption struct {
    13  	skip    int32
    14  	limit   int32
    15  	reverse bool
    16  }
    17  
    18  func NewListOption() *ListOption {
    19  	return &ListOption{
    20  		skip:    0,
    21  		limit:   100,
    22  		reverse: false,
    23  	}
    24  }
    25  
    26  func (o *ListOption) SetSkip(skip int32) *ListOption {
    27  	o.skip = skip
    28  
    29  	return o
    30  }
    31  
    32  func (o *ListOption) Skip() int32 {
    33  	return o.skip
    34  }
    35  
    36  func (o *ListOption) SetLimit(limit int32) *ListOption {
    37  	if limit > 0 && limit < 1000 {
    38  		o.limit = limit
    39  	}
    40  
    41  	return o
    42  }
    43  
    44  func (o *ListOption) Limit() int32 {
    45  	return o.limit
    46  }
    47  
    48  func (o *ListOption) SetForward() *ListOption {
    49  	o.reverse = false
    50  
    51  	return o
    52  }
    53  
    54  func (o *ListOption) SetBackward() *ListOption {
    55  	o.reverse = true
    56  
    57  	return o
    58  }
    59  
    60  func (o *ListOption) Backward() bool {
    61  	return o.reverse
    62  }
    63  
    64  type IterOption struct {
    65  	reverse   bool
    66  	offsetKey []byte
    67  	onClose   func(key []byte)
    68  }
    69  
    70  func NewIterOption() *IterOption {
    71  	return &IterOption{}
    72  }
    73  
    74  func (o *IterOption) SetOffsetKey(offset []byte) *IterOption {
    75  	o.offsetKey = offset
    76  
    77  	return o
    78  }
    79  
    80  func (o *IterOption) SetForward() *IterOption {
    81  	o.reverse = false
    82  
    83  	return o
    84  }
    85  
    86  func (o *IterOption) SetBackward() *IterOption {
    87  	o.reverse = true
    88  
    89  	return o
    90  }
    91  
    92  func (o *IterOption) SetOnClose(f func(key []byte)) *IterOption {
    93  	o.onClose = f
    94  
    95  	return o
    96  }
    97  
    98  func (o *IterOption) Backward() bool {
    99  	return o.reverse
   100  }
   101  
   102  func (o *IterOption) OffsetKey() []byte {
   103  	return o.offsetKey
   104  }
   105  
   106  func (o *IterOption) OnClose(key []byte) {
   107  	if o.onClose == nil {
   108  		return
   109  	}
   110  	o.onClose(key)
   111  }