diff --git a/conf/nginx.conf b/conf/nginx.conf index 17689ce..07d0c48 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -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 { diff --git a/src/test/testJsonSchem.lua b/src/test/testJsonSchema.lua similarity index 100% rename from src/test/testJsonSchem.lua rename to src/test/testJsonSchema.lua diff --git a/src/test/testOrm.lua b/src/test/testOrm.lua new file mode 100644 index 0000000..89f3993 --- /dev/null +++ b/src/test/testOrm.lua @@ -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