1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 18:28:22 +01:00
antd-web-apps/blog/models/BlogModel.lua
DanyLE a76942f2f3
All checks were successful
gitea-sync/antd-web-apps/pipeline/head This commit looks good
WIP: make code compatible with new SILK API
2023-04-26 18:51:03 +02:00

51 lines
1.1 KiB
Lua

BaseModel:subclass("BlogModel",{
registry = {},
name = "blogs",
fields = {
tags = "TEXT",
content = "TEXT",
utime = "NUMERIC",
rendered = "TEXT",
title = "TEXT",
utimestr = "TEXT",
ctime = "NUMERIC",
ctimestr = "TEXT",
publish = "INTEGER DEFAULT 0"
}
})
function BlogModel:fetch(cnd, limit, order)
local filter = {
order = { "ctime$desc" },
fields = {
"id", "title", "utime", "ctime", "utimestr", "content", "ctimestr", "rendered", "tags"
}
}
if limit then
filter.limit = limit
end
if order then
filter.order = order
end
filter.where = {}
if cnd then
filter.where = cnd
end
filter.where.publish = 1
return self:find(filter)
end
function BlogModel:minid()
local cond = { fields = { "MIN(id)" } }
local data = self:find(cond)
return data[1]["MIN(id)"]
end
function BlogModel:maxid()
local cond = { fields = { "MAX(id)" } }
local data = self:find(cond)
return data[1]["MAX(id)"]
end