[Hasor framework] Dataway codeless interface tool DataQL aggregation query engine uses Mybatis to implement paging query example and problem analysis (for GreenPlum database)

This article has participated in the "Newcomer Creation Ceremony" event to start the road of gold creation together.

For the use of Hasor framework Dataway, please refer to the SpringBoot integration Hasor [Dataway codeless interface tool] configuration and problem solving that I shared earlier . Here is a record of the problems encountered with DataQL.

1. Examples and explanations

The DataQL of the interface is as follows: Questions and explanations 1: [The dialect of GreenPlum database should use postgresql] The previous sharing of DataQL aggregation query engine executor error analysis and solution explains why, you can take a look if you are interested.

// SQL 执行器切换为分页模式及首页页面设置
hint FRAGMENT_SQL_QUERY_BY_PAGE = true
hint FRAGMENT_SQL_QUERY_BY_PAGE_NUMBER_OFFSET = 1
hint FRAGMENT_SQL_PAGE_DIALECT = "postgresql"

// 统一转驼峰
// 问题及说明2:通过下边的查询SQL测试得出结论,转驼峰的规则是,全部字母小写下划线后的字母大写,特别要注意的是【这里的驼峰只针对数据查询的字段,分页字段默认是驼峰的,下面附上测试】。
// default、upper、lower、hump
hint FRAGMENT_SQL_COLUMN_CASE = "hump" 

// 定义查询SQL
// 问题及说明3:对mybatis的支持并不完善,支持的标签有<select> <insert> <delete> <update> <if> 和<foreach>相关,<where>标签测试是不支持的。
// 问题及说明4:Date类型数据的查询,需要使用 TO_CHAR 函数,否则是毫秒值。
var dataSetFun = @@mybatis(keyword,futurestartdate) <%
    <select>
        SELECT
	        firstrecommendfield AS first_recommend_field,
	        secondrecommendfield AS second_REcommend_Field,
            TO_CHAR(futurestartdate, 'yyyy-MM-dd') AS future_start_date
        FROM
	        yz_test_match
        WHERE futurestartdate is not null
        <if test="keyword != null and keyword != ''">
           AND firstrecommendfield like concat('%','${keyword}','%') 
        </if>    
        <if test="futurestartdate != null and futurestartdate != ''">
           AND futurestartdate = '${futurestartdate}'
        </if>  
        ORDER BY futurestartdate
    </select>
%>
 
// 创建分页查询对象
// 问题及说明5:参数的传递规则,顺序很重要,从左到右是SQL内的参数顺序。
var pageQuery =  dataSetFun(${keyword},${futurestartdate},${pageSize},${pageNumber});
// 设置分页信息
run pageQuery.setPageInfo({
    "pageSize"    : #{pageSize}, 
    "currentPage" : #{pageNumber}
});
// 执行分页查询
var pageData = pageQuery.data();
// 查询分页信息
var pageInfo = pageQuery.pageInfo();
// 返回结果封装
// 问题及说明6:结果会封装到之前的value内。
return {
  "pageData" : pageData,
  "pageInfo" : pageInfo
};
复制代码

The parameters are as follows: The parameters here do not need to pay attention to the order.

{
  "keyword": "",
  "futurestartdate": "2021-04-18",
  "pageSize": 1,
  "pageNumber": 1
}
复制代码

Results of the:

{
  "success": true,
  "message": "OK",
  "location": null,
  "code": 0,
  "lifeCycleTime": 220,
  "executionTime": 214,
  "value": {
    "pageData": [
      {
        "firstRecommendField": "豫A5VT98",
        "secondRecommendField": "460020603684395",
        "futureStartDate": "2021-04-18"
      }
    ],
    "pageInfo": {
      "enable": true,
      "pageSize": 1,
      "totalCount": 5175,
      "totalPage": 5175,
      "currentPage": 1,
      "recordPosition": 0
    }
  }
}
复制代码

2. Test the FRAGMENT_SQL_COLUMN_CASE setting

Only post the changed settings:

hint FRAGMENT_SQL_COLUMN_CASE = "upper" 
复制代码

Result: We can see that the fields of pageData are all capitalized, and the fields of pageInfo are still in camel case.

{
  "success": true,
  "message": "OK",
  "location": null,
  "code": 0,
  "lifeCycleTime": 206,
  "executionTime": 199,
  "value": {
    "pageData": {
      "FIRST_RECOMMEND_FIELD": "豫A5VT98",
      "SECOND_RECOMMEND_FIELD": "460020603684395",
      "FUTURE_START_DATE": "2021-04-18"
    },
    "pageInfo": {
      "enable": true,
      "pageSize": 1,
      "totalCount": 5175,
      "totalPage": 5175,
      "currentPage": 1,
      "recordPosition": 0
    }
  }
}
复制代码

Guess you like

Origin juejin.im/post/7085355968661291045