1
0
mirror of https://github.com/lxsang/antd-web-apps synced 2024-11-20 02:18:20 +01:00
antd-web-apps/apps/silk/BaseModel.lua
2018-08-22 19:38:36 +02:00

46 lines
963 B
Lua

-- create class
BaseModel = BaseObject:extends{class="BaseModel",registry = {}}
function BaseModel:initialize()
self.db = self.registry.db
if self.db and self.name and self.name ~= "" and self.fields and not self.db:available(self.name) then
self.db:createTable(self.name, self.fields)
end
end
function BaseModel:create(m)
if self.db and m then
return self.db:insert(self.name,m)
end
return false
end
function BaseModel:update(m)
if self.db and m then
return self.db:update(self.name,m)
end
return false
end
function BaseModel:delete(cond)
if self.db and m then
return self.db:delete(self.name,cond)
end
return false
end
function BaseModel:find(cond)
if self.db and m then
return self.db:find(self.name, cond)
end
return false
end
function BaseModel:findAll()
if self.db and m then
return self.db:getAll(self.name)
end
return false
end