-
Notifications
You must be signed in to change notification settings - Fork 0
ClassORMLite
hp-sam edited this page Sep 3, 2014
·
4 revisions
local orm = require "framework.orm"local context = orm.new(, { ["tablename"] =
, ... })local db = sqlite3.open(sandbox:resolveFile("data:///testorm2.sqlite"))
local blob_model = {
-- ["id"] = "integer primary key", -- id is not required to define.
["path"] = "text",
["temppath"] = "text",
["name"] = "text",
["typeid"] = "integer",
["contenttype"] = "text",
["md5"] = "text",
["size"] = "integer",
["status"] = "integer default 0"
}
local block_model = {
["blobid"] = "integer",
["bg"] = "integer default 0",
["ed"] = "integer default 0",
["hash"] = "text",
["status"] = "integer"
}
local context = orm.new(db, {
["blob"] = blob_model,
["block"] = block_model
})local row = context.("new|insert", {modelmap})
local row = context.blob("new", {
path = "test",
size = 123
})row.path = nil
row.typeid = "2"
row:update()local results = context.("list|select", format, ...)
local results = context.blob("list", "id>? and typeid=?", 40, 2)
for k,v in ipairs(results) do
print(v.id)
endcontext.("delete", format, ...) or row:delete()
context.blob("delete", "id=? and typeid=?", 40, 2)