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.

Creating a Global Custom Table

Step 1: Access the Management Interface

Global Custom Table List

  1. Log in to the Edge Admin console
  2. Navigate to Global Configuration > Global Custom Table
  3. Click the Create Custom Table button

Step 2: Configure Basic Table Information

Custom Table Field Configuration

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:

AttributeDescriptionNotes
Column NameName of the columnOnly supports English letters, numbers, and underscores
Column TypeType of the columnSee supported column types below
Column DescriptionDescription of the column’s purposeOptional, helps understand column meaning
Default ValueDefault value for the columnDefault fill value when adding new data
Query KeyPrimary key used to query this row of data
Not NULLWhether the column value can be emptyCheck this option for required columns
SyncWhether to synchronize to edge nodesAffects data availability on Edge Nodes
UniqueWhether column values must be uniqueUsed to ensure data integrity

Supported Column Types

TypeDescriptionUse Cases
TextString typeUsername, title, description, etc.
NumberNumeric typeAge, count, price, etc.
BooleanTrue/false valueSwitch status, enabled/disabled, etc.
IP AddressIPv4/IPv6 addressNetwork configuration, access control, etc.
DomainDomain name formatWebsite address, service endpoint, etc.
ArrayString arrayTag list, categories, etc.
IP Address ArrayIP address listWhitelist, blacklist, etc.
Domain ArrayDomain name listMulti-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 New Custom 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

Insert 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

Lua Module Configuration

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

Edge Language Configuration

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