Assignment
Set global variables
Global variables can have values that can be set to values in the current session
- UserID = session.user_id
- CreatedBy = session.user_id
- LastModifiedBy = session.user_id
- ShopID = session.shop_id
- OrgID = session.org_id
Reference global variable assignment
Populated by Luwak with the following values
- user_id = @@UserID
- create_user_id = @@CreatedBy
- last_modified_user_id = @@LastModifiedBy
- @@Reference global variables
Example
SESSION
Simulate session data
{
"user_id": 1001,
"username": "luwak",
"shop_id": 168
}
Simulate session_id = F4C4690FA1EAA6D011A5127457951B3D Execute the following command to add to Redis
SELECT 1
HMSET F4C4690FA1EAA6D011A5127457951B3D user_id 1001 username luwak shop_id 168
EXPIRE F4C4690FA1EAA6D011A5127457951B3D 28800
Define global variables
- CreatedBy = session.user_id
- LastModifiedBy = session.user_id
Data model
Note the two column comments referencing global variable assignments
- create_user_id = @@CreatedBy
- last_modified_user_id = @@LastModifiedBy
DROP DATABASE IF EXISTS students;
CREATE DATABASE IF NOT EXISTS students;
USE students;
-- Class table: stores class information
CREATE TABLE class
(
id INT NOT NULL AUTO_INCREMENT COMMENT 'Class ID, primary key',
name VARCHAR(50) NOT NULL COMMENT 'Class name',
create_user_id INT COMMENT 'create_user_id = @@CreatedBy',
last_modified_user_id INT COMMENT 'last_modified_user_id = @@LastModifiedBy',
PRIMARY KEY (id)
) COMMENT ='Class Table';
request
POST http://127.0.0.1:21000
Content-Type: application/json;charset=utf-8
{
"jsonrpc": "2.0",
"method": "students.class.add",
"params": {
"data": {
"name": "Grade 1, Class 1"
},
"token": "F4C4690FA1EAA6D011A5127457951B3D"
},
"id": "client-unique-request-id"
}
Response
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"jsonrpc": "2.0",
"result": {
"id": 1
},
"id": "client-unique-request-id"
}
Actual stored data
mysql> select * from class;
+----+------------------+----------------+-------- ---------------+
| id | name | create_user_id | last_modified_user_id |
+----+------------------+----------------+-------- ---------------+
| 1 | Grade 1, Class 1 | 1001 | 1001 |
+----+------------------+----------------+-------- ---------------+
1 row in set (0.00 sec)