mirror of
https://github.com/RaisFast/raisfast.git
synced 2026-09-30 08:03:20 +00:00
improve plugin sdk
This commit is contained in:
@@ -2,70 +2,70 @@ local M = {}
|
||||
M.SDK_VERSION = "1.0.0"
|
||||
|
||||
function M.dbQuery(sql, params)
|
||||
local paramsJson = params and Host.jsonEncode(params) or nil
|
||||
local result = Host.dbQuery(sql, paramsJson)
|
||||
local paramsJson = params and RaisFastHost.jsonEncode(params) or nil
|
||||
local result = RaisFastHost.dbQuery(sql, paramsJson)
|
||||
if not result then error("query returned no result") end
|
||||
if result:sub(1, 6) == "error:" then error(result:sub(7)) end
|
||||
return Host.jsonDecode(result)
|
||||
return RaisFastHost.jsonDecode(result)
|
||||
end
|
||||
|
||||
function M.dbExec(sql, params)
|
||||
local paramsJson = params and Host.jsonEncode(params) or nil
|
||||
local result = Host.dbExecute(sql, paramsJson)
|
||||
return Host.jsonDecode(result)
|
||||
local paramsJson = params and RaisFastHost.jsonEncode(params) or nil
|
||||
local result = RaisFastHost.dbExecute(sql, paramsJson)
|
||||
return RaisFastHost.jsonDecode(result)
|
||||
end
|
||||
|
||||
function M.dbBegin()
|
||||
local result = Host.jsonDecode(Host.dbBegin())
|
||||
local result = RaisFastHost.jsonDecode(RaisFastHost.dbBegin())
|
||||
if not result.ok then error("dbBegin failed") end
|
||||
return result
|
||||
end
|
||||
|
||||
function M.dbCommit()
|
||||
local result = Host.jsonDecode(Host.dbCommit())
|
||||
local result = RaisFastHost.jsonDecode(RaisFastHost.dbCommit())
|
||||
if not result.ok then error("dbCommit failed") end
|
||||
return result
|
||||
end
|
||||
|
||||
function M.dbRollback()
|
||||
return Host.jsonDecode(Host.dbRollback())
|
||||
return RaisFastHost.jsonDecode(RaisFastHost.dbRollback())
|
||||
end
|
||||
|
||||
function M.httpGet(url)
|
||||
return Host.httpGet(url)
|
||||
return RaisFastHost.httpGet(url)
|
||||
end
|
||||
|
||||
function M.httpGetJson(url)
|
||||
local result = Host.httpGet(url)
|
||||
local result = RaisFastHost.httpGet(url)
|
||||
if not result then return nil end
|
||||
local ok, decoded = pcall(Host.jsonDecode, result)
|
||||
local ok, decoded = pcall(RaisFastHost.jsonDecode, result)
|
||||
return ok and decoded or nil
|
||||
end
|
||||
|
||||
function M.httpPost(url, body)
|
||||
local jsonBody = type(body) == "string" and body or Host.jsonEncode(body)
|
||||
return Host.httpPost(url, jsonBody)
|
||||
local jsonBody = type(body) == "string" and body or RaisFastHost.jsonEncode(body)
|
||||
return RaisFastHost.httpPost(url, jsonBody)
|
||||
end
|
||||
|
||||
function M.httpPostJson(url, body)
|
||||
local jsonBody = type(body) == "string" and body or Host.jsonEncode(body)
|
||||
local result = Host.httpPost(url, jsonBody)
|
||||
local jsonBody = type(body) == "string" and body or RaisFastHost.jsonEncode(body)
|
||||
local result = RaisFastHost.httpPost(url, jsonBody)
|
||||
if not result then return nil end
|
||||
local ok, decoded = pcall(Host.jsonDecode, result)
|
||||
local ok, decoded = pcall(RaisFastHost.jsonDecode, result)
|
||||
return ok and decoded or nil
|
||||
end
|
||||
|
||||
function M.configGet(key) return Host.getConfig(key) end
|
||||
function M.configGet(key) return RaisFastHost.getConfig(key) end
|
||||
|
||||
function M.storeGet(key) return Host.getData(key) end
|
||||
function M.storeSet(key, value) return Host.setData(key, value) end
|
||||
function M.storeGet(key) return RaisFastHost.getData(key) end
|
||||
function M.storeSet(key, value) return RaisFastHost.setData(key, value) end
|
||||
|
||||
function M.vfsRead(path) return Host.fsRead(path) end
|
||||
function M.vfsWrite(path, content) return Host.fsWrite(path, content) end
|
||||
function M.vfsDelete(path) return Host.fsDelete(path) end
|
||||
function M.vfsExists(path) return Host.fsExists(path) end
|
||||
function M.vfsRead(path) return RaisFastHost.fsRead(path) end
|
||||
function M.vfsWrite(path, content) return RaisFastHost.fsWrite(path, content) end
|
||||
function M.vfsDelete(path) return RaisFastHost.fsDelete(path) end
|
||||
function M.vfsExists(path) return RaisFastHost.fsExists(path) end
|
||||
function M.vfsList(path)
|
||||
local result = Host.fsList(path)
|
||||
local result = RaisFastHost.fsList(path)
|
||||
if not result then return nil end
|
||||
local list = {}
|
||||
for part in result:gmatch("[^,]+") do
|
||||
@@ -86,7 +86,7 @@ function M.extractJson(input, field)
|
||||
local ok, result = pcall(function()
|
||||
local parsed = input
|
||||
if type(input) == "string" then
|
||||
parsed = Host.jsonDecode(input)
|
||||
parsed = RaisFastHost.jsonDecode(input)
|
||||
end
|
||||
if not field or field == "" then return parsed end
|
||||
local val = parsed
|
||||
@@ -95,7 +95,7 @@ function M.extractJson(input, field)
|
||||
val = val[part]
|
||||
end
|
||||
if type(val) == "string" then
|
||||
local decodeOk, decoded = pcall(Host.jsonDecode, val)
|
||||
local decodeOk, decoded = pcall(RaisFastHost.jsonDecode, val)
|
||||
if decodeOk then return decoded end
|
||||
return val
|
||||
end
|
||||
@@ -104,15 +104,15 @@ function M.extractJson(input, field)
|
||||
return ok and result or nil
|
||||
end
|
||||
|
||||
function M.logInfo(msg) Host.log("info", msg) end
|
||||
function M.logWarn(msg) Host.log("warn", msg) end
|
||||
function M.logError(msg) Host.log("error", msg) end
|
||||
function M.logInfo(msg) RaisFastHost.log("info", msg) end
|
||||
function M.logWarn(msg) RaisFastHost.log("warn", msg) end
|
||||
function M.logError(msg) RaisFastHost.log("error", msg) end
|
||||
|
||||
function M.newId() return Host.newId() end
|
||||
function M.newId() return RaisFastHost.newId() end
|
||||
|
||||
function M.eventEmit(eventType, data)
|
||||
local dataStr = type(data) == "string" and data or Host.jsonEncode(data)
|
||||
return Host.emitEvent(eventType, dataStr)
|
||||
local dataStr = type(data) == "string" and data or RaisFastHost.jsonEncode(data)
|
||||
return RaisFastHost.emitEvent(eventType, dataStr)
|
||||
end
|
||||
|
||||
_sdk_module = M
|
||||
|
||||
Reference in New Issue
Block a user