Global Custom Table
Overview
Global Custom Table is a powerful feature provided by Edge Admin that allows administrators to create and manage custom data tables for storing and organizing specific business data. This feature provides flexible data structure definition and management capabilities, supporting multiple data types and query methods.
Note
Data distributed by this feature will occupy space in the LMDB database on Edge Nodes. The default size is 8GB, shared by all configurations. Therefore, storing large amounts of data is not recommended. Please plan data volume reasonably to avoid impacting system performance.Creating a Global Custom Table
Step 1: Access the Management Interface
- Log in to the Edge Admin console
- Navigate to Global Configuration > Global Custom Table
- Click the Create Custom Table button
Step 2: Configure Basic Table Information
Basic Configuration
- Table Name: Enter the table name (only supports English letters, numbers, and underscores, used for internal system identification)
- Description: Add a description of the table’s purpose for easier management and maintenance
- Send Events: Whether to send corresponding event notifications to related systems when table data changes. This typically needs to be used in conjunction with Edge Admin’s Lua plugins.
Column Configuration
Columns are the core structure for storing business data. Each column contains the following attributes:
Attribute | Description | Notes |
---|---|---|
Column Name | Name of the column | Only supports English letters, numbers, and underscores |
Column Type | Type of the column | See supported column types below |
Column Description | Description of the column’s purpose | Optional, helps understand column meaning |
Default Value | Default value for the column | Default fill value when adding new data |
Query Key | Primary key used to query this row of data | |
Not NULL | Whether the column value can be empty | Check this option for required columns |
Sync | Whether to synchronize to edge nodes | Affects data availability on Edge Nodes |
Unique | Whether column values must be unique | Used to ensure data integrity |
Supported Column Types
Type | Description | Use Cases |
---|---|---|
Text | String type | Username, title, description, etc. |
Number | Numeric type | Age, count, price, etc. |
Boolean | True/false value | Switch status, enabled/disabled, etc. |
IP Address | IPv4/IPv6 address | Network configuration, access control, etc. |
Domain | Domain name format | Website address, service endpoint, etc. |
Array | String array | Tag list, categories, etc. |
IP Address Array | IP address list | Whitelist, blacklist, etc. |
Domain Array | Domain name list | Multi-domain configuration, etc. |
Usage Example
The following demonstrates the usage of Global Custom Table through a complete user information management example.
1. Create User Information Table
Create a user information table named example_users
with the following fields:
username
: Username (text type, query key, unique)age
: Age (number type)enable
: Whether enabled (boolean type)ip
: IP address (IP address type)domain
: Domain name (domain type)array
: Tag array (array type)ip_array
: IP address list (IP address array type)domain_array
: Domain name list (domain array type)
2. Add Test Data
Add a test user data entry:
- Username:
oredge
- Age:
10
- Enabled status:
true
- IP address:
1.2.3.4
- Domain:
openresty.com
- Tags:
["openresty", "edge"]
- IP list:
["1.2.3.4", "2.3.4.5"]
- Domain list:
["openresty.com", "doc.openresty.com"]
3. Create Lua Query Module
Create a Lua module named check_user
for querying user information:
local ct = require("custom_table")
local cjson_encode = require("cjson.safe").encode
local get_uri_args = ngx.req.get_uri_args
local ngx_say = ngx.say
local _M = {}
function _M.go()
-- Get username from URI parameters
local uri_args = get_uri_args()
local username = uri_args.username
if not username then
ngx_say("Error: username parameter is required")
return
end
-- Query user information
local res, err = ct.get("example_users", { username = username })
if not res then
ngx_say("Error: ", err or "User Not Found")
return
end
-- Return user information
ngx_say("Hello ", res.username, ", your info: ", cjson_encode(res))
end
return _M
In the Lua module, use the custom_table
module to retrieve custom data:
local ct = require("custom_table")
local res, err = ct.get("table_name", { field = "value" })
4. Reference Lua Module in Application
Call the Lua module in the application’s Edge Language rules:
true =>
foreign-call(module: "check_user", func: "go");
5. Testing and Verification
After the configuration is published, perform functional testing:
Test 1: Query existing user
$ curl --resolve oredge-example.com:80:127.0.0.1 'http://oredge-example.com/?username=oredge'
Hello oredge, your info: {"enable":true,"domain_array":["openresty.com","doc.openresty.com"],"ip_array":["1.2.3.4","2.3.4.5"],"username":"oredge","domain":"openresty.com","ip":"1.2.3.4","age":10,"array":["openresty","edge"]}
Test 2: Query non-existent user
$ curl --resolve oredge-example.com:80:127.0.0.1 'http://oredge-example.com/?username=notfound'
Error: User Not Found