From 4c18c0bdac2d7d9499c989f8cf8b2eae0d55f319 Mon Sep 17 00:00:00 2001 From: wanglei <34475144@qq.com> Date: Tue, 14 Oct 2025 15:50:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=B5=8B=E8=AF=95orm=E6=B5=8B=E8=AF=95=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/nginx.conf | 5 +- .../{testJsonSchem.lua => testJsonSchema.lua} | 0 src/test/testOrm.lua | 51 +++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) rename src/test/{testJsonSchem.lua => testJsonSchema.lua} (100%) create mode 100644 src/test/testOrm.lua 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