Skip to content

Commit 107e780

Browse files
committed
update example
1 parent 738d7a8 commit 107e780

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

examples/echo.lua

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,37 @@
1-
json=require('json');
2-
3-
function echo(a)
4-
if type(a) == 'table' then
5-
return {{a}}
6-
end
7-
return {a}
8-
end
9-
101
box.cfg {
112
log_level = 5;
123
listen = 9999;
134
}
145

15-
if not box.space.tester then
6+
box.once('grant', function()
167
box.schema.user.grant('guest', 'read,write,execute', 'universe')
178
box.schema.create_space('tester')
9+
end)
10+
11+
-- Table
12+
local users = box.schema.space.create('users', {if_not_exists=true})
13+
-- Indexes
14+
users:create_index('user_id', {if_not_exists=true})
15+
16+
-- $ wget 127.0.0.1:8081/tnt --post-data='{"method":"add_user","params": ["Vasa","Soshnikov"]}'
17+
function add_user(user_first_name, user_last_name)
18+
print(user_last_name, user_first_name)
19+
return users:auto_increment{user_first_name, user_last_name}
20+
end
21+
22+
-- $ wget 127.0.0.1:8081/tnt --post-data='{"method":"get_user_by_id","params", [1]}'
23+
function get_user_by_id(user_id)
24+
return users.index.user_id:get{user_id}
25+
end
26+
27+
-- $ wget 127.0.0.1:8081/tnt --post-data='{"method":"get_users"}'
28+
function get_users()
29+
return users:select{}
30+
end
31+
32+
function echo(a)
33+
if type(a) == 'table' then
34+
return {{a}}
35+
end
36+
return {a}
1837
end

0 commit comments

Comments
 (0)