|
| 1 | +package crud |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/tarantool/go-tarantool" |
| 7 | +) |
| 8 | + |
| 9 | +type CountOpts struct { |
| 10 | + Timeout OptUint `crud:"timeout"` |
| 11 | + VshardRouter OptString `crud:"vshard_router"` |
| 12 | + Mode OptString `crud:"mode"` |
| 13 | + PreferReplica OptBool `crud:"prefer_replica"` |
| 14 | + Balance OptBool `crud:"balance"` |
| 15 | + YieldEvery OptUint `crud:"yield_every"` |
| 16 | + BucketId OptUint `crud:"bucket_id"` |
| 17 | + ForceMapCall OptBool `crud:"force_map_call"` |
| 18 | + Fullscan OptBool `crud:"fullscan"` |
| 19 | +} |
| 20 | + |
| 21 | +// CountRequest helps you to create request object to call `crud.count` |
| 22 | +// for execution by a Connection. |
| 23 | +type CountRequest struct { |
| 24 | + spaceRequest |
| 25 | + conditions []Condition |
| 26 | + opts CountOpts |
| 27 | +} |
| 28 | + |
| 29 | +// NewCountRequest returns a new empty CountRequest. |
| 30 | +func NewCountRequest(space interface{}) *CountRequest { |
| 31 | + req := new(CountRequest) |
| 32 | + req.initImpl("crud.count") |
| 33 | + req.setSpace(space) |
| 34 | + req.conditions = []Condition{} |
| 35 | + req.opts = CountOpts{} |
| 36 | + return req |
| 37 | +} |
| 38 | + |
| 39 | +// Conditions sets the conditions for the CountRequest request. |
| 40 | +// Note: default value is nil. |
| 41 | +func (req *CountRequest) Conditions(conditions []Condition) *CountRequest { |
| 42 | + req.conditions = conditions |
| 43 | + return req |
| 44 | +} |
| 45 | + |
| 46 | +// Opts sets the options for the CountRequest request. |
| 47 | +// Note: default value is nil. |
| 48 | +func (req *CountRequest) Opts(opts CountOpts) *CountRequest { |
| 49 | + req.opts = opts |
| 50 | + return req |
| 51 | +} |
| 52 | + |
| 53 | +// Body fills an encoder with the call request body. |
| 54 | +func (req *CountRequest) Body(res tarantool.SchemaResolver, enc *encoder) error { |
| 55 | + req.impl.Args([]interface{}{req.space, req.conditions, convertToMap(req.opts)}) |
| 56 | + return req.impl.Body(res, enc) |
| 57 | +} |
| 58 | + |
| 59 | +// Context sets a passed context to CRUD request. |
| 60 | +func (req *CountRequest) Context(ctx context.Context) *CountRequest { |
| 61 | + req.impl = req.impl.Context(ctx) |
| 62 | + |
| 63 | + return req |
| 64 | +} |
0 commit comments