修改配置增加测试orm测试文件
This commit is contained in:
parent
938da21250
commit
4c18c0bdac
|
|
@ -50,7 +50,10 @@ http {
|
|||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testWsdl.lua';
|
||||
}
|
||||
location /jsonSchema {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testJsonSchem.lua';
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testJsonSchema.lua';
|
||||
}
|
||||
location /testOrm {
|
||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testOrm.lua';
|
||||
}
|
||||
location /checkip {
|
||||
content_by_lua_block {
|
||||
|
|
|
|||
51
src/test/testOrm.lua
Normal file
51
src/test/testOrm.lua
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
----------------------------- ORM SETTINGS --------------------------------
|
||||
DB = {
|
||||
DEBUG = true,
|
||||
new = true,
|
||||
backtrace = true,
|
||||
name = "AuthDB",
|
||||
type = "postgresql",
|
||||
username = "postgresql",
|
||||
password = "Admin123",
|
||||
host = "127.0.0.1",
|
||||
port = 5432
|
||||
}
|
||||
|
||||
----------------------------- REQUIRE --------------------------------
|
||||
|
||||
local Table = require("orm.model")
|
||||
local fields = require("orm.tools.fields")
|
||||
|
||||
----------------------------- CREATE TABLE --------------------------------
|
||||
|
||||
local User = Table({
|
||||
__tablename__ = "user",
|
||||
username = fields.CharField({max_length = 100, unique = true}),
|
||||
password = fields.CharField({max_length = 50, unique = true}),
|
||||
age = fields.IntegerField({max_length = 2, null = true}),
|
||||
job = fields.CharField({max_length = 50, null = true}),
|
||||
time_create = fields.DateTimeField({null = true})
|
||||
})
|
||||
|
||||
----------------------------- CREATE DATA --------------------------------
|
||||
|
||||
local user = User({
|
||||
username = "zhangsan",
|
||||
password = "123456",
|
||||
time_create = os.time()
|
||||
})
|
||||
|
||||
user:save()
|
||||
print("User " .. user.username .. " has id " .. user.id)
|
||||
-- User Bob Smith has id 1
|
||||
|
||||
----------------------------- GET DATA --------------------------------
|
||||
|
||||
local first_user = User.get:first()
|
||||
print("First user name is: " .. first_user.username)
|
||||
-- First user name is: First user
|
||||
|
||||
local users = User.get:all()
|
||||
print("We get " .. users:count() .. " users")
|
||||
-- We get 5 users
|
||||
Loading…
Reference in New Issue
Block a user