box.once('schema', function() box.schema.create_space('db') box.space.db:create_index('primary', { type = 'hash', parts = {1, 'string'} }) end)
local function save(req) local id = req:stash('id') box.space.db:upsert({ id, 1 }, {{ '=', 2, req.body }}) return req:render{ json = box.space.db:select(id) } end
local function load(req) local id = req:stash('id') return req:render{ json = box.space.db:select(id) } end
local httpd = require('http.server') local server = httpd.new('0', 8000) server:route({ path = '/:id', method = 'POST' }, save) server:route({ path = '/:id', method = 'GET' }, load) server:start()
Подскажите, в чем я ошибся? Как правильно получить и сохранить тело запроса?
Vladimir Lebedev
unread,
Jan 11, 2018, 10:24:55 AM1/11/18
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to tarantool-ru
Привет!
Проблема, на самом деле в том, как вы сохраняете запрос. Вместо box.space.db:upsert({ id, 1 }, {{ '=', 2, req.body }}) надо использовать box.space.db:upsert({ id, req.body }, {{ '=', 2, req.body }}).
Иначе при первом POST в вашем варианте во второе поле в тапле всегда записывалась единица, а не тело запроса. Почитайте еще документацию на box.space:upsert().
Володя
Eugene Prokopiev
unread,
Jan 11, 2018, 1:19:11 PM1/11/18
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to tarant...@googlegroups.com
И еще :read() вместо .body
Спасибо!
11 января 2018 г., 18:24 пользователь Vladimir Lebedev
<vale...@gmail.com> написал: