source'https://github.com/williamwen1986/LuakitPod.git'source'https://github.com/williamwen1986/curl.git'
pod 'curl', '~> 1.0.0'
pod 'LuakitPod', '~> 1.0.13'复制代码
-- Add the define table to dbData.lua-- Luakit provide 7 colum types-- IntegerField to sqlite integer -- RealField to sqlite real -- BlobField to sqlite blob -- CharField to sqlite varchar -- TextField to sqlite text -- BooleandField to sqlite bool-- DateTimeField to sqlite integer
user = {
__dbname__ = "test.db",
__tablename__ = "user",
username = {"CharField",{max_length = 100, unique = true, primary_key = true}},
password = {"CharField",{max_length = 50, unique = true}},
age = {"IntegerField",{null = true}},
job = {"CharField",{max_length = 50, null = true}},
des = {"TextField",{null = true}},
time_create = {"DateTimeField",{null = true}}
},
-- when you use, you can do just like belowlocal Table = require('orm.class.table')
local userTable = Table("user")
复制代码
插入数据
local userTable = Table("user")
local user = userTable({
username = "user1",
password = "abc",
time_create = os.time()
})
user:save()
复制代码
更新数据
local userTable = Table("user")
local user = userTable.get:primaryKey({"user1"}):first()
user.password = "efg"
user.time_create = os.time()
user:save()
复制代码
删除数据
local userTable = Table("user")
local user = userTable.get:primaryKey({"user1"}):first()
user:delete()
复制代码
批量更新数据
local userTable = Table("user")
userTable.get:where({age__gt = 40}):update({age = 45})
复制代码
批量删除数据
local userTable = Table("user")
userTable.get:where({age__gt = 40}):delete()
复制代码
select数据
local userTable = Table("user")
local users = userTable.get:all()
print("select all -----------")
local user = userTable.get:first()
print("select first -----------")
users = userTable.get:limit(3):offset(2):all()
print("select limit offset -----------")
users = userTable.get:order_by({desc('age'), asc('username')}):all()
print("select order_by -----------")
users = userTable.get:where({ age__lt = 30,
age__lte = 30,
age__gt = 10,
age__gte = 10,
username__in = {"first", "second", "creator"},
password__notin = {"testpasswd", "new", "hello"},
username__null = false
}):all()
print("select where -----------")
users = userTable.get:where({"scrt_tw",30},"password = ? AND age < ?"):all()
print("select where customs -----------")
users = userTable.get:primaryKey({"first","randomusername"}):all()
print("select primaryKey -----------")
复制代码
联表操作
local userTable = Table("user")
local newsTable = Table("news")
local user_group = newsTable.get:join(userTable):all()
print("join foreign_key")
user_group = newsTable.get:join(userTable,"news.create_user_id = user.username AND user.age < ?", {20}):all()
print("join where ")
user_group = newsTable.get:join(userTable,nil,nil,nil,{create_user_id = "username", title = "username"}):all()
print("join matchColumns ")
复制代码
local listener
lua_notification.createListener(function(l)
listener = l
listener:AddObserver(3,
function(data)print("lua Observer")
if data thenfor k,v inpairs(data) doprint("lua Observer"..k..v)
endendend
)
end);
复制代码
-- url , the request url-- isPost, boolean value represent post or get-- uploadContent, string value represent the post data-- uploadPath, string value represent the file path to post-- downloadPath, string value to tell where to save the response-- headers, tables to tell the http header-- socketWatcherTimeout, int value represent the socketTimeout-- onResponse, function value represent the response callback-- onProgress, function value represent the onProgress callback
lua_http.request({ url = "http://tj.nineton.cn/Heart/index/all?city=CHSH000000",
onResponse = function(response)end})
复制代码