BOOLEAN
Introduction
By adding the table field annotation @DataType=bool
, you can check whether the parameter value is 0 or 1.
Example
Data Dictionary
hrm.sys_tasks Human Resources System - System Task List
| Column name | Data type | Not empty | Increment | Key | Description | |-----------|-------------|----|----|----|------- -| | id | int(11) | yes | yes | primary key | - | | title | varchar(255) | Yes | - | - | Task title | | completed | tinyint(1) | - | - | - | Whether the task is completed |
-
Create hrm.sys_tasks task table
DROP TABLE IF EXISTS hrm.sys_tasks;
CREATE TABLE hrm.sys_tasks
(
id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
completed BOOLEAN COMMENT '0 not completed 1 completed @DataType=bool'
); -
Table comment
data_type=bool
means1
,0
is allowed
Parameter mapping and verification
Verification rules
- completed can only be a number 1 or 0
- title required
- id is optional, if id is passed, refer to the primary key constraint
ask
POST http://127.0.0.1:21000
Content-Type: application/json;charset=utf-8
{
"jsonrpc": "2.0",
"method": "hrm.sysTasks.add",
"params": {
"title": "testing boolean type",
"completed": 3
},
"id": "client-unique-request-id"
}
Response
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
{
"jsonrpc": "2.0",
"error": {
"code": -32602,
"message": "validating data type: completed: 3 does not validate as range(0|1)",
"data": {
"errorCode": "EU.Validator.DataTypeError",
"errorDetails": [
{
"field": "completed",
"fieldValue": 3,
"location": "hrm.sys_tasks",
"message": "completed: 3 does not validate as range(0|1)",
"validator": "range"
}
],
"errorMessage": "completed: 3 does not validate as range(0|1)"
}
},
"id": "client-unique-request-id"
}
Remarks: The above example was tested in Luwak 1.12.9.