各位,本次新版本做了比较大的优化,主要修复的问题如下:#79,#48,#67,#56
项目地址:https://github.com/braisdom/ObjectiveSql
重点特性介绍:
1)优化SQL 生成逻辑
Order.Table orderTable = Order.asTable();
Select select = new Select();
select.project((sum(orderTable.amount) / sum(orderTable.quantity) * 100).as("unit_amount"))
.from(orderTable)
.where(orderTable.quantity > 30 &&
orderTable.salesAt.between("2020-05-02 23:59:59", "2020-05-02 23:59:59"))
.groupBy(orderTable.memberId);
SELECT (SUM(`orders_t0`.`amount` ) / SUM(`orders_t0`.`quantity` ) * 100) AS unit_amount
FROM `orders` AS `orders_t0`
WHERE `orders_t0`.`quantity` > 30 AND `orders_t0`.`sales_at` BETWEEN '2020-05-01 00:00:00' AND '2020-05-02 23:59:59'
GROUP BY `orders_t0`.`member_id`
深度解析javac 构建AST 过程,对执行优先级和括号进行解析,生成完全符合Java 编码的SQL 语句
2)永真表达式(实现动态SQL 构建)
Order.Table orderTable = Order.asTable();
Select select = new Select();
LogicalExpression eternalExpression = new EternalExpression();
if(filteredNo.length > 0) {
eternalExpression = eternalExpression.and(orderTable.no.in(filteredNo));
}
if(filteredQuantity != 0) {
eternalExpression = eternalExpression.and(orderTable.quantity > filteredQuantity);
}
select.project((sum(orderTable.amount) / sum(orderTable.quantity) * 100).as("unit_amount"))
.from(orderTable)
.where(eternalExpression)
.groupBy(orderTable.memberId);