Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to validate tuple against space format in Lua #9979

Open
locker opened this issue Apr 26, 2024 · 0 comments
Open

Add function to validate tuple against space format in Lua #9979

locker opened this issue Apr 26, 2024 · 0 comments
Labels
app feature A new functionality

Comments

@locker
Copy link
Member

locker commented Apr 26, 2024

The only way to validate a tuple against a space format without inserting it into the space is using box.tuple.new with the format option:

tarantool> box.tuple.new({'a', 1}, {format = box.space._schema:format()})
---
- ['a', 1]
...

tarantool> box.tuple.new({1, 2}, {format = box.space._schema:format()})
---
- error: 'Tuple field 1 (key) type does not match one required by operation: expected
    string, got unsigned'
...

It'd be nice if a tuple format object had the validate method so that we wouldn't have to create a new tuple in this case:

local format = box.tuple.format.new({{'key', 'string'}, {'value', 'any'}})
format:validate({'a', 1}) -- ok
format:validate(box.tuple.new({'a', 1})) -- ok
format:validate({1, 2}) -- error
format:validate(box.tuple.new({1, 2})) -- error

Similarly to index.parts, it should be possible to use validate with space.format:

box.space._schema.format -- returns format object
box.space._schema.format:validate({'a', 1}) -- ok
box.space._schema.format:validate(box.tuple.new({'a', 1})) -- ok
box.space._schema.format:validate({1, 2}) -- error
box.space._schema.format:validate(box.tuple.new({1, 2})) -- error

Similar tickets for key_def and index.parts:

@locker locker added feature A new functionality app labels Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app feature A new functionality
Projects
None yet
Development

No branches or pull requests

1 participant