1
0
mirror of https://github.com/lxsang/antd-lua-plugin synced 2024-12-29 10:48:21 +01:00
antd-lua-plugin/example-app/os/db/delete.lua
2018-09-19 15:08:49 +02:00

29 lines
838 B
Lua

auth_or_die("User unauthorized. Please login")
local rq = (JSON.decodeString(REQUEST.query.json))
if(rq ~= nil and rq.table ~= nil) then
local model = require("db.model").get(SESSION.iotos_user, rq.table, nil)
local ret
if model == nil then
fail("Cannot get table metadata:"..rq.table)
else
if(rq.id == nil ) then
if(rq.cond) then
ret = model:delete(rq.cond)
model:close()
else
model:close()
return fail("Unknow element to delete")
end
else
ret = model:deleteByID(rq.id)
model:close()
end
if ret then
result(ret)
else
fail("Querry error or database is locked")
end
end
else
fail("Unknown database request")
end