ObjectiveSQL 1.3.6バージョンがリリースされ、手続き型SQLプログラミングと同等の式

ObjectiveSQLの最初の公式バージョンは、コードを自動的に生成する機能を提供しました。これは、単純なSQLプログラミングのコーディング作業に取って代わり、複雑なSQLソリューションを開始しました。

ObjectiveSQLは、JavaオペレーターのSQLオペレーターへの直接マッピングを実現し、式の一貫性を実現できるJavaコンパイラーを変更することにより、オペレーターのオーバーロードを実装します。これにより、SQL手続き型プログラミングが実現され、複雑なSQLプログラミングが簡単になります。 、わかりやすいです。詳しくは公式資料をご覧ください。

公式アドレス:http//www.objsql.com

Github:https:  //github.com/braisdom/ObjectiveSql

Gitee:https://gitee.com/mirrors/ObjectiveSql 

IntelliJ IDEAプラグイン(バージョン1.2.7はまだオンラインではないため、インストールについてはドキュメントを参照してください):http//www.objsql.com/docs/basic/intellij

  1. 手続き型SQLプログラミング
// Calculating the member related order data 
Member.Table memberTable = Member.asTable();
Order.Table orderTable = Order.asTable();

Select select = new Select();

select.from(orderTable, memberTable);
select.where(orderTable.memberId.eq(memberTable.id));

select.project(memberTable.no, memberTable.name, memberTable.mobile);

select.project(countDistinct(orderTable.no).as("order_count"))
        .project(sum(orderTable.quantity).as("total_quantity"))
        .project(sum(orderTable.amount).as("total_amount"))
        .project(min(orderTable.salesAt).as("first_shopping"))
        .project(max(orderTable.salesAt).as("last_shopping"));

select.groupBy(memberTable.no, memberTable.name, memberTable.mobile);

上記のコードによって生成されたSQLは次のとおりです。

SELECT
	`T0`.`no` ,
	`T0`.`name` ,
	`T0`.`mobile` ,
	COUNT(DISTINCT `T1`.`no` ) AS `order_count`,
	SUM(`T1`.`quantity` ) AS `total_quantity`,
	SUM(`T1`.`amount` ) AS `total_amount`,
	MIN(`T1`.`sales_at` ) AS `first_shopping`,
	MAX(`T1`.`sales_at` ) AS `last_shopping`
FROM
	`orders` AS `T1`,
	`members` AS `T0`
WHERE
	(`T1`.`member_id` = `T0`.`id` )
GROUP BY
	`T0`.`no` ,
	`T0`.`name` ,
	`T0`.`mobile`

2.同等の式(Java計算式はSQLステートメント式にマップできます)

Order.Table orderTable = Order.asTable();
Select select = new Select();

select.project(sum(orderTable.amount) / sum(orderTable.quantity) * $(100) )
    .from(orderTable)
    .groupBy(orderTable.productId);

上記のコードによって生成されたSQLは次のとおりです。

SELECT SUM(order.amount) / SUM(order.quantity)  * 100
      FROM orders AS order GROUP BY order.produc_id

 

おすすめ

転載: www.oschina.net/news/119959/objectivesql-1-3-6-released