项目地址: https://github.com/braisdom/ObjectiveSql
> ObjectiveSQL 是我构想了很长时间,到底是让 Java 像 SQL 一样编程,还是让 SQL 让 Java 一样编程,纠结了很久,还是让 Java 更像 SQL,Java 的语法表现力不够,只能扩展 Javac,实现了算法运算,比较运算,逻辑运算符重载,并封装了常用数据的的函数,抽象了 Expression,使的 Java 非常接的 SQL,同时也实现了简单 SQL 编程的代码生成,基本不需要写代码,也不需要配置就能实现简单 SQL 的编程,话不多说,先看示例,有兴趣可以到 github 上看。
```
Order.Table orderTable = Order.asTable();
Select select = new Select();
select.project(sum(orderTable.amount) / sum(orderTable.quantity) * 100)
.from(orderTable)
.groupBy(orderTable.productId);
Member.Table member = Member.asTable();
Order.Table order = Order.asTable();
Select select = new Select();
select.from(order, member)
.where(order.memberId.eq(member.id));
select.project(member.no,
member.name,
member.mobile,
countDistinct(order.no).as("order_count"),
sum(order.quantity).as("total_quantity"),
sum(order.amount).as("total_amount"),
min(order.salesAt).as("first_shopping"),
max(order.salesAt).as("last_shopping"));
select.groupBy(member.no, member.name, member.mobile);
```
ObjectiveSQL is an ORM framework in Java base on ActiveRecord pattern, which encourages rapid development and clean, codes with the least, and convention over configuration.
Features
Dynamic code generation with JSR 269 for Java API of database access
Full Java API of database access without coding
Dynamically SQL programming with Java syntax, and very close to SQL syntax