1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-12-29 02:38:22 +01:00
antd-web-apps/blog/models/BlogModel.lua

51 lines
1.1 KiB
Lua
Raw Normal View History

2018-09-05 16:56:04 +02:00
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" },
2018-09-05 16:56:04 +02:00
fields = {
2021-02-17 12:59:42 +01:00
"id", "title", "utime", "ctime", "utimestr", "content", "ctimestr", "rendered", "tags"
}
2018-09-05 16:56:04 +02:00
}
2018-09-05 16:56:04 +02:00
if limit then
filter.limit = limit
2018-09-05 16:56:04 +02:00
end
if order then
filter.order = order
2018-09-05 16:56:04 +02:00
end
filter.where = {}
if cnd then
filter.where = cnd
end
filter.where.publish = 1
return self:find(filter)
2018-09-05 16:56:04 +02:00
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