### GETS Multiple Subqueries Example Source: https://github.com/tencent/apijson/blob/master/README-extend.md Demonstrates multiple subqueries using the GETS method. This method executes a validation process. Ensure Access and Request are configured with authentication information. ```json { "sql@": { "@method": "GETS", "with": true, "from": "Sys_role", "Sys_role": { "@column": "id", "role_name": "超级管理员" } }, "sql_user@": { "@method": "GETS", "with": true, "from": "Sys_user", "Sys_user": { "@column": "id", "id": "4732209c-5785-4827-b532-5092f154fd94" } }, "Sys_user_role:sur[]": { "@method": "GETS", "Sys_user_role": { "role_id{}@": "sql", "user_id{}@": "sql_user" } }, "Sys_role_permission:srp[]": { "@method": "GETS", "Sys_role_permission": { "role_id{}@": "sql" } }, "@explain": true } ``` -------------------------------- ### Get a User Source: https://github.com/tencent/apijson/blob/master/Document.md This example demonstrates how to retrieve a single user object. It shows the request format and the expected JSON response. ```APIDOC ## GET /get/{"User":{}} ### Description Retrieves a single user object from the system. ### Method GET ### Endpoint /get/{"User":{}} ### Request Body ```json { "User":{ } } ``` ### Response #### Success Response (200) - **User** (object) - Contains user details like id, sex, name, certified, tag, phone, head, date, and pictureList. - **code** (integer) - The status code of the response. - **msg** (string) - A message indicating the success or failure of the request. #### Response Example ```json { "User":{ "id":38710, "sex":0, "name":"TommyLemon", "certified":true, "tag":"Android&Java", "phone":13000038710, "head":"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", "date":1485948110000, "pictureList":[ "http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", "http://common.cnblogs.com/images/icon_weibo_24.png" ] }, "code":200, "msg":"success" } ``` ``` -------------------------------- ### Get a Moment and its publisher Source: https://github.com/tencent/apijson/blob/master/Document.md This example illustrates fetching a 'Moment' object and its associated 'User' (publisher) by linking 'User.id' to 'Moment.userId'. ```APIDOC ## GET /get/{"Moment":{},"User":{"id@":"Moment/userId"}} ### Description Retrieves a 'Moment' object and its corresponding publisher ('User') by joining on the 'userId' field. ### Method GET ### Endpoint /get/{"Moment":{},"User":{"id@":"Moment/userId"}} ### Request Body ```json { "Moment":{}, "User":{ "id@":"Moment/userId" } } ``` ### Response #### Success Response (200) - **Moment** (object) - Contains details of the moment, such as id, userId, date, and content. - **User** (object) - Contains details of the user who published the moment, including id, sex, name, tag, head, contactIdList, and date. - **code** (integer) - The status code of the response. - **msg** (string) - A message indicating the success or failure of the request. #### Response Example ```json { "Moment":{ "id":12, "userId":70793, "date":"2017-02-08 16:06:11.0", "content":"1111534034" }, "User":{ "id":70793, "sex":0, "name":"Strong", "tag":"djdj", "head":"http://static.oschina.net/uploads/user/585/1170143_50.jpg?t=1390226446000", "contactIdList":[ 38710, 82002 ], "date":"2017-02-01 19:21:50.0" }, "code":200, "msg":"success" } ``` ``` -------------------------------- ### Get an array of Users Source: https://github.com/tencent/apijson/blob/master/Document.md This example shows how to retrieve a limited array of user objects, specifying which columns to include. It details the request and response structures. ```APIDOC ## GET /get/{"[]":{"count":3,"User":{"@column":"id,name"}}} ### Description Retrieves a specified number of user objects, fetching only the 'id' and 'name' fields. ### Method GET ### Endpoint /get/{"[]":{"count":3,"User":{"@column":"id,name"}}} ### Parameters #### Query Parameters - **count** (integer) - Optional - Specifies the maximum number of results to return. - **@column** (string) - Optional - A comma-separated list of fields to include in the response. ### Request Body ```json { "[]":{ "count":3, "User":{ "@column":"id,name" } } } ``` ### Response #### Success Response (200) - **[]** (array) - An array of user objects, each containing 'id' and 'name'. - **code** (integer) - The status code of the response. - **msg** (string) - A message indicating the success or failure of the request. #### Response Example ```json { "[]":[ { "User":{ "id":38710, "name":"TommyLemon" } }, { "User":{ "id":70793, "name":"Strong" } }, { "User":{ "id":82001, "name":"Android" } } ], "code":200, "msg":"success" } ``` ``` -------------------------------- ### Complete Commit Example Source: https://github.com/tencent/apijson/blob/master/CONTRIBUTING_COMMIT.md A comprehensive example demonstrating the use of 'feat' type, a detailed body with bullet points, and issue association. ```markdown feat: 添加了分享功能 给每篇文章添加了分享功能 - 添加分享到微信功能 - 添加分享到朋友圈功能 issue #1, #2 closes #1 ``` -------------------------------- ### GETS Single Subquery Example Source: https://github.com/tencent/apijson/blob/master/README-extend.md Demonstrates a single subquery using the GETS method. This method executes a validation process. Ensure Access and Request are configured with authentication information. ```json { "sql@": { "with": true, "from": "Sys_user_role", "Sys_user_role": { "@column": "role_id", "user_id": "4732209c-5785-4827-b532-5092f154fd94" } }, "Sys_role[]": { "Sys_role": { "id{}@": "sql" }, "page": 0, "count": 10, "query": 2 }, "tag":"Sys_role[]", "total@": "/Sys_role[]/total", "@explain": true } ``` -------------------------------- ### JSON Configuration for DELETE and GET Operations Source: https://github.com/tencent/apijson/blob/master/README-extend.md This JSON configuration demonstrates how to set up a GET request to retrieve role permissions and a DELETE request to remove them based on the retrieved SQL result. It utilizes 'sql@' for dynamic query building and '@method' to specify HTTP methods. ```json { "sql@": { "@method": "GET", "with": true, "from": "Sys_role_permission", "Sys_role_permission": { "@column": "id", "role_id": ["94f79f0b-331b-4cc5-bfc0-ebfc47d00f13"] } }, "Sys_role_permission": { "@method": "DELETE", "id@": "sql" }, "explan": true } ``` -------------------------------- ### Enable Query Profiling Source: https://github.com/tencent/apijson/blob/master/Document.md Enables query profiling for the 'Moment' table. Set '@explain' to true to get detailed performance information about the query. ```json ["@explain":true] ``` -------------------------------- ### APIJSON Self-Defined Keyword Example Source: https://github.com/tencent/apijson/blob/master/Document.md Shows how to use self-defined keywords, such as 'name@' in this example, to add custom fields to the response. This allows for flexible data structuring and inclusion of application-specific information. ```JSON {"User":{}, "[]":{ "name@":"User/name", "Moment":{} }} ``` -------------------------------- ### HEAD Multiple Subqueries Example Source: https://github.com/tencent/apijson/blob/master/README-extend.md Demonstrates multiple subqueries using the HEAD method for retrieving quantity. The GET/HEAD methods do not execute the validation process. ```json { "sql@": { "@method": "GET", "with": true, "from": "Sys_role", "Sys_role": { "@column": "id", "role_name": "超级管理员" } }, "sql_user@": { "@method": "GET", "with": true, "from": "Sys_user", "Sys_user": { "@column": "id", "id": "4732209c-5785-4827-b532-5092f154fd94" } }, "Sys_user_role": { "@method": "HEAD", "role_id{}@": "sql", "user_id{}@": "sql_user" }, "Sys_role_permission": { "@method": "HEAD", "role_id{}@": "sql" }, "@explain": true } ``` -------------------------------- ### Getting Data in a Range with '%' Source: https://github.com/tencent/apijson/blob/master/Document.md Retrieve data within a specified range using the '%' keyword followed by 'start,end'. This is applicable to Boolean, Number, or String data types and functions like SQL's BETWEEN. ```JSON "date%":"2017-10-01,2018-10-01" ``` -------------------------------- ### GETS Method Source: https://github.com/tencent/apijson/blob/master/Document.md Used to get data with high security and confidentiality, such as bank accounts or birth dates. Requires a 'tag' parameter. ```APIDOC ## GETS /gets/ ### Description Get data with high security and confidentiality. Eg. bank accounts, birth date. ### Method GET ### Endpoint base_url/gets/ ### Request Body Requires adding `"tag":tag` with the same level as the table name. Other conditions are the same as **GET**. ### Response Same as **GET**. ``` -------------------------------- ### Closing Issue Example Source: https://github.com/tencent/apijson/blob/master/CONTRIBUTING_COMMIT.md When committing to the default branch, use keywords like 'closes' followed by the issue number to automatically close the issue. ```markdown closes #1 ``` -------------------------------- ### Get a Moment and its Publisher Source: https://github.com/tencent/apijson/blob/master/Document.md Retrieve a 'Moment' object and its associated 'User' publisher by linking 'User.id' to 'Moment.userId'. ```json { "Moment":{ }, "User":{ "id@":"Moment/userId" } } ``` -------------------------------- ### Get Data in a Range Source: https://github.com/tencent/apijson/blob/master/Document.md Retrieve data within a specified range using the `"key%":["start,end"]` format, applicable to Boolean, Number, or String types. ```APIDOC ## Get Data in a Range ### Description Retrieve data within a specified range using the format `"key%":["start,end"]`. This is applicable to Boolean, Number, or String types and is useful for date or numerical ranges. ### Example ```json { "User[]": { "count": 3, "User": { "date%": "2017-01-01,2018-01-01" } } } ``` This example retrieves user data registered between '2017-01-01' and '2018-01-01'. ### URL Example `http://apijson.cn:8080/get/{"User[]":{"count":3,"User":{"date%2525":"2017-01-01,2018-01-01"}}}` ### SQL Equivalent `date BETWEEN '2017-01-01' AND '2018-01-01'` ``` -------------------------------- ### GET Method Source: https://github.com/tencent/apijson/blob/master/Document.md Used to retrieve data. Supports filtering and conditions within the request body. ```APIDOC ## GET /get/ ### Description A general way to get data. You can use dev tools to make edits in a web browser. ### Method GET ### Endpoint base_url/get/ ### Request Body ```json { "TableName":{ //Add conditions here. } } ``` **Example:** To get a Moment with `id = 235`: ```json { "Moment":{ "id":235 } } ``` ### Response #### Success Response (200) ```json { "TableName":{ "...": "..." }, "code":200, "msg":"success" } ``` **Example:** ```json { "Moment":{ "id":235, "userId":38710, "content":"APIJSON is the real-time coding-free, powerful and secure ORM" }, "code":200, "msg":"success" } ``` ``` -------------------------------- ### Commit Body Example Source: https://github.com/tencent/apijson/blob/master/CONTRIBUTING_COMMIT.md The Body provides a detailed explanation of the commit. It can span multiple lines and use bullet points for clarity. Explain the motivation for the change and contrast it with previous behavior. ```markdown More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. Further paragraphs come after blank lines. - Bullet points are okay, too - Use a hanging indent ``` -------------------------------- ### HEAD Single Subquery Example Source: https://github.com/tencent/apijson/blob/master/README-extend.md Demonstrates a single subquery using the HEAD method for retrieving quantity. The GET/HEAD methods do not execute the validation process. ```json { "sql@": { "@method": "GET", "with": true, "from": "Sys_user_role", "Sys_user_role": { "@column": "role_id", "user_id": "4732209c-5785-4827-b532-5092f154fd94" } }, "Sys_role": { "@method": "head", "id{}@": "sql" }, "@explain": true } ``` -------------------------------- ### DELETE with Referenced ID and Subquery (Success Case) Source: https://github.com/tencent/apijson/blob/master/README-extend.md This example shows a successful DELETE operation using a subquery to fetch IDs from 'Sys_user_role' and then using those IDs to delete from 'Sys_user'. This demonstrates the correct usage when 'id{}@' is combined with a subquery. ```json { "sql@": { "@method": "GET", "with": true, "from": "Sys_user_role", "Sys_user_role": { "@column": "user_id", "role_id{}@": ["0bb92d96-8ca6-469e-91e8-60308ce5b835"] } }, "Sys_user:aa": { "@method": "DELETE", "id{}@": "sql" }, "explan": true } ``` -------------------------------- ### GETS Single Subquery Alternative Syntax Source: https://github.com/tencent/apijson/blob/master/README-extend.md An alternative syntax for a single subquery using the GETS method, leveraging the '@gets' array for specifying subqueries. This method executes a validation process. Ensure Access and Request are configured with authentication information. ```json { "@gets": ["sql@","Sys_role[]"], "sql@": { "with": true, "from": "Sys_user_role", "Sys_user_role": { "@column": "role_id", "user_id": "4732209c-5785-4827-b532-5092f154fd94" } }, "Sys_role[]": { "Sys_role": { "id{}@": "sql" }, "page": 0, "count": 10, "query": 2 }, "tag":"Sys_role[]", "total@": "/Sys_role[]/total", "@explain": true } ``` -------------------------------- ### Query Multiple Range References Source: https://github.com/tencent/apijson/blob/master/README-extend.md Illustrates querying multiple range references simultaneously, allowing for complex data fetching across different tables based on specific criteria. This example uses two SQL 'WITH' clauses. ```json { "sql@": { "@method": "GET", "with": true, "from": "Sys_role", "Sys_role": { "@column": "id", "role_name": "角色1" } }, "sql_user@": { "@method": "GET", "with": true, "from": "Sys_user", "Sys_user": { "@column": "id", "id": "f0894db2-6940-4d89-a5b2-4405d0ad0c8f" } }, "Sys_user_role:sur[]": { "@method": "GET", "Sys_user_role": { "role_id{}@": "sql", "user_id{}@": "sql_user" } }, "Sys_role_permission:srp[]": { "@method": "GET", "Sys_role_permission": { "role_id{}@": "sql" } }, "@explain": true } ``` -------------------------------- ### Check Private Information with APIJSON Source: https://github.com/tencent/apijson/blob/master/Document.md Use the 'tag' keyword to specify the data structure to query. This example demonstrates fetching privacy information. ```json { "tag": "Privacy", "Privacy": { "id": 82001 } } ``` -------------------------------- ### HEADS Method Source: https://github.com/tencent/apijson/blob/master/Document.md Used to get counts of confidential data, like bank accounts. Requires a 'tag' parameter. ```APIDOC ## HEADS /heads/ ### Description Get counts of confidential data (eg. bank account). ### Method HEAD ### Endpoint base_url/heads/ ### Request Body Requires adding `"tag":tag` with the same level as the table name. Other conditions are the same as **HEAD**. ### Response Same as **HEAD**. ``` -------------------------------- ### HEAD Method Source: https://github.com/tencent/apijson/blob/master/Document.md Used to get counts of data. Supports filtering and conditions within the request body. ```APIDOC ## HEAD /head/ ### Description A general way to get counts. You can use dev tools to make edits in a web browser. ### Method HEAD ### Endpoint base_url/head/ ### Request Body ```json { "TableName":{ // ... conditions ... } } ``` **Example:** Get the number of Moments posted by the user with `id = 38710`: ```json { "Moment":{ "userId":38710 } } ``` ### Response #### Success Response (200) ```json { "TableName":{ "code":200, "msg":"success", "count":10 }, "code":200, "msg":"success" } ``` **Example:** ```json { "Moment":{ "code":200, "msg":"success", "count":10 }, "code":200, "msg":"success" } ``` ``` -------------------------------- ### HEADS Single Subquery Example Source: https://github.com/tencent/apijson/blob/master/README-extend.md Demonstrates a single subquery using the HEADS method for retrieving quantity. This method executes a validation process. Ensure Access and Request are configured with authentication information. ```json { "sql@": { "@method": "GET", "with": true, "from": "Sys_user_role", "Sys_user_role": { "@column": "role_id", "user_id": "4732209c-5785-4827-b532-5092f154fd94" } }, "Sys_role": { "@method": "heads", "id{}@": "sql" }, "@explain": true } ``` -------------------------------- ### Get a Single User Object Source: https://github.com/tencent/apijson/blob/master/Document.md Use this snippet to retrieve a single user object. The response includes all user details. ```json { "User":{ } } ``` -------------------------------- ### Get Data in Arrays using APIJSON Source: https://github.com/tencent/apijson/blob/master/Document.md Use the 'key[]' syntax to retrieve data as an array. The part after the colon is a JSONObject. 'key' is optional; if it matches the table name, the JSONObject can be simplified. ```json {"User[]":{"count":3,"User":{}}} ``` -------------------------------- ### Get an Array of Users with Specific Columns Source: https://github.com/tencent/apijson/blob/master/Document.md Retrieve a limited number of user records, fetching only the 'id' and 'name' columns. The 'count' parameter limits the results. ```json { "[]":{ "count":3, "User":{ "@column":"id,name" } } } ``` -------------------------------- ### Check Private Information using Version 1 APIJSON Source: https://github.com/tencent/apijson/blob/master/Document.md Specify the 'version' keyword to use a particular API version. This example fetches privacy information using version 1. ```json { "version": 1, "tag": "Privacy", "Privacy": { "id": 82001 } } ``` -------------------------------- ### Alternative DELETE with Subquery on Same Table Source: https://github.com/tencent/apijson/blob/master/README-extend.md An alternative syntax for performing a DELETE operation with a subquery on the same table. This method first retrieves the subquery results using '@get' and then applies them to the DELETE condition. ```json { "@get": ["sql@"], "sql@": { "with": true, "from": "User", "User": { "@column": "username", "username": "test4" } }, "User": { "username{}@": "sql" }, "explan": true } ``` -------------------------------- ### Group and Filter Moments with Custom Function Name Source: https://github.com/tencent/apijson/blob/master/Document.md Similar to the previous example, but renames the aggregated 'max(id)' column to 'maxId' for clarity in the results. ```json ["@column":"userId;max(id):maxId", "@group":"userId", "@having":"(maxId)>=100"] ``` -------------------------------- ### Format Moments Interface Response with APIJSON Source: https://github.com/tencent/apijson/blob/master/Document.md Utilize the 'format' keyword to control the casing of keys in the JSON response. This example formats the 'Moments' interface response to camelCase. ```json { "format": true, "[]": { "page": 0, "count": 3, "Moment": {}, "User": { "id@": "/Moment/userId" }, "Comment[]": { "count": 3, "Comment": { "momentId@": "[]/Moment/id" } } } } ``` -------------------------------- ### GET Request for Data Source: https://github.com/tencent/apijson/blob/master/Document.md Use this method to retrieve data. You can specify conditions within the JSON payload. The response includes the requested data along with a status code and message. ```json { "TableName":{ //Add contiditions here. } } Eg. To get a Moment with `id = 235`: { "Moment":{ "id":235 } } ``` ```json { "TableName":{ ... }, "code":200, "msg":"success" } Eg. { "Moment":{ "id":235, "userId":38710, "content":"APIJSON is the real-time coding-free, powerful and secure ORM" }, "code":200, "msg":"success" } ``` -------------------------------- ### Get Moment List with User and Comment Data Source: https://github.com/tencent/apijson/blob/master/Document.md This snippet shows how to retrieve a list of Moments, similar to Twitter tweets, along with associated User and Comment data. It includes pagination, content filtering, and referencing fields from related objects. ```json { "[]":{ "page":0, "count":2, "Moment":{ "content$":"%a%" }, "User":{ "id@":"/Moment/userId", "@column":"id,name,head" }, "Comment[]":{ "count":2, "Comment":{ "momentId@":"[]/Moment/id" } } } } ``` ```json { "[]":[ { "Moment":{ "id":15, "userId":70793, "date":1486541171000, "content":"APIJSON is a JSON Transmission Protocol…", "praiseUserIdList":[ 82055, 82002, 82001 ], "pictureList":[ "http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", "http://common.cnblogs.com/images/icon_weibo_24.png" ] }, "User":{ "id":70793, "name":"Strong", "head":"http://static.oschina.net/uploads/user/585/1170143_50.jpg?t=1390226446000" }, "Comment[]":[ { "id":176, "toId":166, "userId":38710, "momentId":15, "date":1490444883000, "content":"thank you" }, { "id":1490863469638, "toId":0, "userId":82002, "momentId":15, "date":1490863469000, "content":"Just do it" } ] }, { "Moment":{ "id":58, "userId":90814, "date":1485947671000, "content":"This is a Content...-435", "praiseUserIdList":[ 38710, 82003, 82005, 93793, 82006, 82044, 82001 ], "pictureList":[ "http://static.oschina.net/uploads/img/201604/22172507_aMmH.jpg" ] }, "User":{ "id":90814, "name":7, "head":"http://static.oschina.net/uploads/user/51/102723_50.jpg?t=1449212504000" }, "Comment[]":[ { "id":13, "toId":0, "userId":82005, "momentId":58, "date":1485948050000, "content":"This is a Content...-13" }, { "id":77, "toId":13, "userId":93793, "momentId":58, "date":1485948050000, "content":"This is a Content...-77" } ] } ], "code":200, "msg":"success" } ``` -------------------------------- ### Add JitPack Repository for Gradle Source: https://github.com/tencent/apijson/blob/master/APIJSONORM/README.md Append this to the repositories block in your root build.gradle file for Gradle projects. ```gradle allprojects { repositories { ... maven { url 'https://jitpack.io' } } } ``` -------------------------------- ### SQL Transformation with WITH Clause Source: https://github.com/tencent/apijson/blob/master/Roadmap.md Demonstrates the transformation of standard SQL queries into a format utilizing a WITH clause for improved readability and performance. This applies to both Moment and Comment tables. ```sql WITH (SELECT `id` FROM `sys`.`User` WHERE `id` IN($contactIdList)) AS `sql` SELECT * FROM `sys`.`Moment` WHERE ( (`userId` IN `sql` ) ) ORDER BY `date` DESC LIMIT 10 OFFSET 0 ``` ```sql WITH (SELECT `id` FROM `sys`.`User` WHERE `id` IN($contactIdList)) AS `sql` SELECT * FROM `sys`.`Comment` WHERE ( (`userId` IN `sql` ) ) ORDER BY `date` DESC LIMIT 10 OFFSET 0 ``` -------------------------------- ### GETS Request for Confidential Data Source: https://github.com/tencent/apijson/blob/master/Document.md This method retrieves confidential data with high security. It requires an additional 'tag' parameter in the request payload, similar to other GET requests. ```json You need to add "tag":tag with the same level of `Moment:{}`. Others are the same as **GET**. ``` -------------------------------- ### Issue Association Example Source: https://github.com/tencent/apijson/blob/master/CONTRIBUTING_COMMIT.md Associate a commit with an issue by referencing its number in the Footer. ```markdown issue #2 ``` -------------------------------- ### Map Stone Class to b_stone Table Source: https://github.com/tencent/apijson/blob/master/详细的说明文档.md Configuration within DemoSQLConfig to map the 'Stone' Java class to the 'b_stone' database table. This is necessary when the class and table names do not match. ```Java //表名映射,隐藏真实表名,对安全要求很高的表可以这么做 static { TABLE_KEY_MAP.put(User.class.getSimpleName(), "apijson_user"); TABLE_KEY_MAP.put(Privacy.class.getSimpleName(), "apijson_privacy"); TABLE_KEY_MAP.put(Stone.class.getSimpleName(), "b_stone"); // <--这一句 } ``` -------------------------------- ### Query Single Range Reference with SQL Source: https://github.com/tencent/apijson/blob/master/README-extend.md Demonstrates querying a single range reference using a SQL 'WITH' clause. This is useful for complex joins and conditional data retrieval. Two syntaxes are provided. ```json { "sql@": { "@method": "GET", "with": true, "from": "Sys_role", "Sys_role": { "@column": "id", "role_name": "角色1" } }, "Sys_user_role:sur[]": { "@method": "GET", "Sys_user_role": { "role_id{}@": "sql" } }, "Sys_role_permission:srp[]": { "@method": "GET", "Sys_role_permission": { "role_id{}@": "sql" } }, "@explain": true } ``` ```json { "@get": ["sql@","Sys_user_role:sur[]","Sys_role_permission:srp[]"], "sql@": { "with": true, "from": "Sys_role", "Sys_role": { "@column": "id", "role_name": "角色1" } }, "Sys_user_role:sur[]": { "Sys_user_role": { "role_id{}@": "sql" } }, "Sys_role_permission:srp[]": { "Sys_role_permission": { "role_id{}@": "sql" } }, "@explain": true } ``` -------------------------------- ### Support for Distributed Systems with @url Source: https://github.com/tencent/apijson/blob/master/Roadmap.md Enables forwarding requests to other servers for execution. A '~' prefix can be used to indicate asynchronous execution. ```JSON { "User": { "@url": "http://apijson.cn:8080/get" //转发给其它服务器执行 }, "[]": { "Comment": { "userId@": "User/id" } }, "@explain": true } ``` -------------------------------- ### GETS Multiple Subqueries Source: https://github.com/tencent/apijson/blob/master/README-extend.md Retrieves multiple records with subqueries. This operation performs a validation process and requires authentication. ```APIDOC ## GET /lowCodePlatform/forms/api/gets (Multiple Subqueries) ### Description Retrieves multiple records with subqueries. This operation performs a validation process and requires authentication. ### Method GET ### Endpoint /lowCodePlatform/forms/api/gets ### Request Body ```json { "sql@": { "@method": "GETS", "with": true, "from": "Sys_role", "Sys_role": { "@column": "id", "role_name": "超级管理员" } }, "sql_user@": { "@method": "GETS", "with": true, "from": "Sys_user", "Sys_user": { "@column": "id", "id": "4732209c-5785-4827-b532-5092f154fd94" } }, "Sys_user_role:sur[]": { "@method": "GETS", "Sys_user_role": { "role_id{}@": "sql", "user_id{}@": "sql_user" } }, "Sys_role_permission:srp[]": { "@method": "GETS", "Sys_role_permission": { "role_id{}@": "sql" } }, "@explain": true } ``` ### Response (Response details not provided in the source text) ### Error Handling (Error handling details not provided in the source text) ``` -------------------------------- ### 使用 '~' 进行模糊查询 Source: https://github.com/tencent/apijson/blob/master/详细的说明文档.md 使用 `content~` 语法代替 `content$:'%keyword%'` 来表示包含某字符串,提高查询便捷性。 ```JSON { "[]": { "Moment":{ "content~":"keyword", "@column":"id,date,content:text" } } } ``` -------------------------------- ### GETS Single Subquery Source: https://github.com/tencent/apijson/blob/master/README-extend.md Retrieves a single record with a subquery. This operation performs a validation process and requires authentication. ```APIDOC ## GET /lowCodePlatform/forms/api/gets (Single Subquery) ### Description Retrieves a single record with a subquery. This operation performs a validation process and requires authentication. ### Method GET ### Endpoint /lowCodePlatform/forms/api/gets ### Request Body ```json { "sql@": { "with": true, "from": "Sys_user_role", "Sys_user_role": { "@column": "role_id", "user_id": "4732209c-5785-4827-b532-5092f154fd94" } }, "Sys_role[]": { "Sys_role": { "id{}@": "sql" }, "page": 0, "count": 10, "query": 2 }, "tag":"Sys_role[]", "total@": "/Sys_role[]/total", "@explain": true } ``` ### Request Body (Alternative Syntax) ```json { "@gets": ["sql@","Sys_role[]"], "sql@": { "with": true, "from": "Sys_user_role", "Sys_user_role": { "@column": "role_id", "user_id": "4732209c-5785-4827-b532-5092f154fd94" } }, "Sys_role[]": { "Sys_role": { "id{}@": "sql" }, "page": 0, "count": 10, "query": 2 }, "tag":"Sys_role[]", "total@": "/Sys_role[]/total", "@explain": true } ``` ### Response (Response details not provided in the source text) ### Error Handling (Error handling details not provided in the source text) ``` -------------------------------- ### Add JitPack Repository for Maven Source: https://github.com/tencent/apijson/blob/master/APIJSONORM/README.md Include this repository in your pom.xml to allow Maven to fetch dependencies from JitPack. ```xml jitpack.io https://jitpack.io ``` -------------------------------- ### APIJSON Response for Delete Operation Source: https://github.com/tencent/apijson/blob/master/Document.md This is an example of a successful response after a delete operation, indicating the status and affected IDs. ```json { "TableName":{ "code":200, "msg":"success", "id[]":[100,110,120], "count":3 }, "code":200, "msg":"success" } ``` -------------------------------- ### Get Element from Array by Position Source: https://github.com/tencent/apijson/blob/master/Document.md Retrieves the first element from the 'pictureList' array using a self-defined '@position' keyword and a custom function 'getFromArray'. ```json ["@position":0, //self-defined keyword "firstPicture()":"getFromArray(pictureList,@position)"] ``` -------------------------------- ### Subquery Source: https://github.com/tencent/apijson/blob/master/Document.md Perform subqueries using the `"key@":{"range":"ALL/ANY","from":"Table","Table":{...}}` structure, similar to SQL subqueries. ```APIDOC ## Subquery ### Description Perform subqueries using the `"key@":{"range":"ALL/ANY","from":"Table","Table":{...}}` structure. This allows for complex queries similar to SQL subqueries. ### Example ```json { "User": { "id@": { "from": "Comment", "Comment": { "@column": "min(userId)" } } } } ``` This example retrieves the minimum `userId` from the `Comment` table and assigns it to the `User.id`. ### URL Example `http://apijson.cn:8080/get/{"User":{"id@":{"from":"Comment","Comment":{"@column":"min(userId)"}}}}` ### SQL Equivalent `WHERE id=(SELECT min(userId) FROM Comment)` ``` -------------------------------- ### 使用正则表达式匹配数据 Source: https://github.com/tencent/apijson/blob/master/详细的说明文档.md 使用 `content~` 语法配合正则表达式 `^[0-9]+$` 查询 `content` 列为纯数字的数据,并指定返回 `id,date,content` 列。 ```JSON { "[]": { "Moment":{ "content~":"^[0-9]+$", "@column":"id,date,content:text" } } } ``` -------------------------------- ### Clone Forked Repository Source: https://github.com/tencent/apijson/blob/master/CONTRIBUTING.md Clone the forked APIJSON repository to your local machine to begin making changes. ```bash git clone git@github.com:/APIJSON.git ``` -------------------------------- ### APIJSON Response Example for Comment Deletion Source: https://github.com/tencent/apijson/blob/master/Document.md This JSON structure represents a typical response after deleting comments, showing success status and details. ```json { "Comment":{ "code":200, "msg":"success", "id[]":[100,110,120], "count":3 }, "code":200, "msg":"success" } ``` -------------------------------- ### Fuzzy Matching with '$' Source: https://github.com/tencent/apijson/blob/master/Document.md Implement fuzzy matching using the '$' keyword followed by SQL search expressions. This allows for flexible searching based on patterns like '%key%' or 'key%'. ```JSON "name$":"%m%" ``` -------------------------------- ### POST Method Source: https://github.com/tencent/apijson/blob/master/Document.md Used to add new data. The 'id' is generated automatically. Requires a 'tag' parameter. ```APIDOC ## POST /post/ ### Description Add new data. ### Method POST ### Endpoint base_url/post/ ### Request Body ```json { "TableName":{ // ... fields ... }, "tag":tag } ``` The id in `{}` is generated automatically when the table is built and can’t be set by the user. **Example:** A user with `id = 38710` posts a new Moment: ```json { "Moment":{ "userId":38710, "content":"APIJSON is the real-time coding-free, powerful and secure ORM" }, "tag":"Moment" } ``` ### Response #### Success Response (200) ```json { "TableName":{ "code":200, "msg":"success", "id":38710 }, "code":200, "msg":"success" } ``` **Example:** ```json { "Moment":{ "code":200, "msg":"success", "id":120 }, "code":200, "msg":"success" } ``` ``` -------------------------------- ### Synchronize Local Repository with Upstream Source: https://github.com/tencent/apijson/blob/master/CONTRIBUTING.md Fetch changes from the upstream APIJSON repository and rebase your local branch onto the latest version. This ensures your contributions are based on the most recent code. ```bash git pull --rebase ``` ```bash git fetch git rebase / ``` -------------------------------- ### Specify Database for Table Access Source: https://github.com/tencent/apijson/blob/master/Document.md Queries the 'User' table from the 'POSTGRESQL' database. Use this to connect to different database systems. ```json ["@database":"POSTGRESQL"] ``` -------------------------------- ### Get Data with Specific IDs using APIJSON Source: https://github.com/tencent/apijson/blob/master/Document.md Retrieve data where the 'id' field matches any of the IDs provided in the array. This is equivalent to an SQL 'IN' clause. ```json {"User[]":{"count":3,"User":{"id{}":[38710,82001,70793]}}} ``` -------------------------------- ### 过滤包含特定 ID 的列表数据 Source: https://github.com/tencent/apijson/blob/master/详细的说明文档.md 使用 `praiseUserIdList<>` 语法过滤出 `praiseUserIdList` 数组中包含 `82001` 的数据,并指定返回 `id,date,content,praiseUserIdList` 列。 ```JSON { "[]": { "Moment":{ "praiseUserIdList<>":82001, "@column":"id,date,content,praiseUserIdList" } } } ``` -------------------------------- ### 模糊查询包含特定字符串的数据 Source: https://github.com/tencent/apijson/blob/master/详细的说明文档.md 使用 `content$` 语法进行模糊查询,筛选出 `content` 列包含 `%APIJSON%` 的数据,并指定返回 `id,date,content` 列。 ```JSON { "[]": { "Moment":{ "content$":"%APIJSON%", "@column":"id,date,content:text" } } } ``` -------------------------------- ### Get Data Containing an Element using APIJSON Source: https://github.com/tencent/apijson/blob/master/Document.md Find data where a JSON array field contains a specific element. The 'key<>' syntax is used for this containment check. ```json {"User[]":{"count":3,"User":{"contactIdList<>":38710}}} ``` -------------------------------- ### HEADS Request for Confidential Counts Source: https://github.com/tencent/apijson/blob/master/Document.md Use this method to get counts of confidential data. It requires an additional 'tag' parameter in the request payload, similar to other HEAD requests. ```json You need to add "tag":tag with the same level of `Moment:{}`. Others are the same as **HEAD**. ``` -------------------------------- ### HEAD Request for Counts Source: https://github.com/tencent/apijson/blob/master/Document.md Use this method to get the count of data entries matching specific conditions. The response includes the count along with a status code and message. ```json { "TableName":{ … } } {…} are conditions. Eg. Get the number of Moments posted by the user with `id = 38710`: { "Moment":{ "userId":38710 } } ``` ```json { "TableName":{ "code":200, "msg":"success", "count":10 }, "code":200, "msg":"success" } Eg. { "Moment":{ "code":200, "msg":"success", "count":10 }, "code":200, "msg":"success" } ``` -------------------------------- ### Add APIJSON Dependency for Gradle Source: https://github.com/tencent/apijson/blob/master/APIJSONORM/README.md Add this implementation dependency to your module's build.gradle file (e.g., app/build.gradle). ```gradle dependencies { implementation 'com.github.Tencent:APIJSON:8.1.8' } ``` -------------------------------- ### Fuzzy Matching Source: https://github.com/tencent/apijson/blob/master/Document.md Implement fuzzy matching using SQL search expressions with the `"key$":["SQL search expressions"]` format. ```APIDOC ## Fuzzy Matching ### Description Implement fuzzy matching using SQL search expressions with the format `"key$":["SQL search expressions"]`. Supports wildcards like `%` for flexible searching. ### Example ```json { "User[]": { "count": 3, "User": { "name$": "%m%" } } } ``` This example searches for users whose names contain 'm'. ### URL Example `http://apijson.cn:8080/get/{"User[]":{"count":3,"User":{"name$":"%2525m%2525"}}}` ### SQL Equivalent `name LIKE '%m%'` ``` -------------------------------- ### APIJSON ORM Content Validation Configuration Source: https://github.com/tencent/apijson/wiki/Home Configure content validation rules within the database configuration. This example shows how to validate the 'type' field to accept only specific integer values. ```json "VERIFY":{ "type{}":[0,1,2] } ``` -------------------------------- ### 组合多个条件进行数据筛选 Source: https://github.com/tencent/apijson/blob/master/详细的说明文档.md 组合使用 `id&{}` 和 `id!{}` 来筛选出 id 在 10 到 40 之间但不包含 12 的数据,并指定返回 `id,date,content` 列。 ```JSON { "[]": { "Moment":{ "id&{}":">=10,<=40", "id!{}":[12], "@column":"id,date,content:text" } } } ``` -------------------------------- ### Function Calls in Parameters Source: https://github.com/tencent/apijson/blob/master/Document.md Trigger backend functions by including them in URL parameters. The format `"key()":"function(key0,key1...)"` allows for dynamic data retrieval or testing. ```APIDOC ## Function Calls in Parameters ### Description Include functions in parameters to trigger backend processing. The format `"key()":"function(key0,key1...)"` allows the backend to execute a function with specified keys. ### Example ```json ["isPraised()":"isContain(praiseUserIdList,userId)"] ``` This example uses the `isPraised()` function to check if a user has praised a moment, utilizing the `isContain` function with `praiseUserIdList` and `userId`. ### URL Example `http://apijson.cn:8080/get/{"Moment":{"id":301,"isPraised()":"isContain(praiseUserIdList,userId)"}}` ### Response Returns a boolean indicating whether the condition is met (e.g., `"isPraised":true`). ``` -------------------------------- ### Get Data with Comparison Operations using APIJSON Source: https://github.com/tencent/apijson/blob/master/Document.md Filter data based on comparison operations like '<=', '>'. Use single quotes for non-numeric characters. This supports SQL-like 'OR' conditions for the same field. ```json {"User[]":{"count":3,"User":{"id{}":"<=80000,>90000"}}} ``` -------------------------------- ### Using Functions in URL Parameters Source: https://github.com/tencent/apijson/blob/master/Document.md Trigger backend functions for data retrieval or verification by including functions in parameters. The backend function signature is `function(JSONObject request, String key0, String key1...)`. ```JSON "key()":"function (key0,key1...)" ``` ```JSON "isPraised()":"isContain(praiseUserIdList,userId)" ```