Skip to content

Commit 9ce325c

Browse files
crud: support schema opts
Follows #336
1 parent 9a58dc8 commit 9ce325c

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
2323
- Support `IPROTO_WATCH_ONCE` request type for Tarantool
2424
version >= 3.0.0-alpha1 (#337)
2525
- Support `yield_every` option for crud select requests (#350)
26+
- Support `crud.schema` request options (#351)
2627

2728
### Changed
2829

crud/options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
batchSizeOptName = "batch_size"
2424
fetchLatestMetadataOptName = "fetch_latest_metadata"
2525
noreturnOptName = "noreturn"
26+
cachedOptName = "cached"
2627
)
2728

2829
// OptUint is an optional uint.

crud/schema.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,39 @@ func msgpackIsMap(code byte) bool {
1414
return code == msgpcode.Map16 || code == msgpcode.Map32 || msgpcode.IsFixedMap(code)
1515
}
1616

17+
// SchemaOpts describes options for `crud.schema` method.
18+
type SchemaOpts struct {
19+
// Timeout is a `vshard.call` timeout and vshard
20+
// master discovery timeout (in seconds).
21+
Timeout OptFloat64
22+
// VshardRouter is cartridge vshard group name or
23+
// vshard router instance.
24+
VshardRouter OptString
25+
// Cached defines whether router should reload storage schema on call.
26+
Cached OptBool
27+
}
28+
29+
// EncodeMsgpack provides custom msgpack encoder.
30+
func (opts SchemaOpts) EncodeMsgpack(enc *msgpack.Encoder) error {
31+
const optsCnt = 3
32+
33+
names := [optsCnt]string{timeoutOptName, vshardRouterOptName,
34+
cachedOptName}
35+
values := [optsCnt]interface{}{}
36+
exists := [optsCnt]bool{}
37+
values[0], exists[0] = opts.Timeout.Get()
38+
values[1], exists[1] = opts.VshardRouter.Get()
39+
values[2], exists[2] = opts.Cached.Get()
40+
41+
return encodeOptions(enc, names[:], values[:], exists[:])
42+
}
43+
1744
// SchemaRequest helps you to create request object to call `crud.schema`
1845
// for execution by a Connection.
1946
type SchemaRequest struct {
2047
baseRequest
2148
space OptString
49+
opts SchemaOpts
2250
}
2351

2452
// MakeSchemaRequest returns a new empty SchemaRequest.
@@ -35,6 +63,13 @@ func (req SchemaRequest) Space(space string) SchemaRequest {
3563
return req
3664
}
3765

66+
// Opts sets the options for the SelectRequest request.
67+
// Note: default value is nil.
68+
func (req SchemaRequest) Opts(opts SchemaOpts) SchemaRequest {
69+
req.opts = opts
70+
return req
71+
}
72+
3873
// Body fills an encoder with the call request body.
3974
func (req SchemaRequest) Body(res tarantool.SchemaResolver, enc *msgpack.Encoder) error {
4075
if value, ok := req.space.Get(); ok {

crud/tarantool_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ var opObjManyOpts = crud.OperationObjectManyOpts{
8787
Timeout: crud.MakeOptFloat64(timeout),
8888
}
8989

90+
var schemaOpts = crud.SchemaOpts{
91+
Timeout: crud.MakeOptFloat64(timeout),
92+
Cached: crud.MakeOptBool(false),
93+
}
94+
9095
var conditions = []crud.Condition{
9196
{
9297
Operator: crud.Lt,
@@ -216,6 +221,11 @@ var testProcessDataCases = []struct {
216221
1,
217222
crud.MakeStorageInfoRequest().Opts(baseOpts),
218223
},
224+
{
225+
"Schema",
226+
1,
227+
crud.MakeSchemaRequest().Opts(schemaOpts),
228+
},
219229
}
220230

221231
var testResultWithErrCases = []struct {

0 commit comments

Comments
 (0)