-
Notifications
You must be signed in to change notification settings - Fork 46
Executing stored procedures with List type input #162
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
Comments
In short: I'll give a bit background soon. |
Ok, thank you this worked. I passed the arguments as tuple, when given as a list input it worked like you said. Appreciate the answer. |
Sorry for the long read. It is for ones who will confused by the same API details and will want to understand what is going on. Let's define a function to use in the example below (very similar to your one): function log_tuples(tuples)
for _, t in ipairs(tuples) do
require('log').info('tuple: ' .. require('json').encode(t))
end
end (Note: It is written for ease experimenting: it is not good style for an application or a library code. Please, avoid global functions and requires inside a function where possible.) First, let's look as the tuples = {}
table.insert(tuples, {1, 2, 3})
table.insert(tuples, {4, 5, 6})
table.insert(tuples, {7, 8, 9})
connection:call('log_tuples', {tuples}) Result:
Why we need to wrap the argument into the list? Because one may want to pass several arguments to a function, say: function log_tuples(tuples, prefix)
local prefix = prefix or ''
for _, t in ipairs(tuples) do
require('log').info(prefix .. 'tuple: ' .. require('json').encode(t))
end
end Check: tuples = {}
table.insert(tuples, {1, 2, 3})
table.insert(tuples, {4, 5, 6})
table.insert(tuples, {7, 8, 9})
connection:call('log_tuples', {tuples, 'my_app | '}) Result:
Back to Python. Everything is very same as for import tarantool
t = tarantool.connect('localhost', 3301)
tuples = []
tuples.append((1, 2, 3))
tuples.append((4, 5, 6))
tuples.append((7, 8, 9))
t.call('log_tuples', [tuples]) The result is the same as for the first net.box call. However there is strange peculiar in the tarantool-python API (the code below is part of the tarantool-python/tarantool/connection.py Lines 375 to 377 in bd37703
So if several arguments are passed to the t.call('log_tuples', [tuples, 'my_app | '])
t.call('log_tuples', tuples, 'my_app | ') Why? Who knows... I guess somebody in the past had the thought that it is convenient to have such autoguessing. |
BTW, there is the Telegram channel, where tarantool developers and power users answer questions interactively. Questions are usually answered faster in the chat.
The is the documentation (the link is in the header of README) with the following relevant pages:
I would not say that the documentation is satisfying. The documentation is generated from the We're not always very responsible (shame on me), so expect a delay between sending PR and review / merge. I think this issue is resolved and should be closed, but if you have a clear plan around the documentation, let's file another one about it. |
Thank you for all the detailed explanation and the code samples and for sharing the telegram channel info, I will look into it for further questions/discussions. |
Hi,
I am trying to call a function on tarantool which inserts given list input into a space. Function looks like below, it gets list, loop over records and inserts into a space named tester.
When I call the function within tarantool like the following, it works as expected and inserts records into the space.
tarantool> lst = {{1,'Test',1}, {2, 'Test2', 2}}
tarantool> batch_insert_tester(lst)
When I try to call the function through the library, it fails with the following error.
This is the code I have been using, as an input I am sending list of value tuples (tester space has 3 fields). How can I call a function with a list input like this?
Here is the function defined on tarantool:
The text was updated successfully, but these errors were encountered: