ObjectiveSql
1.0.0
ObjectiveSQL是一個基於ActiveRecord模式的Java ORM框架,它鼓勵快速開發和清潔,最少的程式碼,以及約定優於配置。
Class
就擁有 SQL 程式設計的全功能has_one
, has_many
和belongs_to
)查詢和分頁查詢arithmetic
、 comparison
和logical
)Preferences/Settings
-> Plugins
-> Search with "ObjectiveSql" in market
-> Install
<!-- In standalone -->
< dependency >
< groupId >com.github.braisdom</ groupId >
< artifactId >objective-sql</ artifactId >
< version >1.4.6</ version >
</ dependency >
<!-- In Spring Boot -->
< dependency >
< groupId >com.github.braisdom</ groupId >
< artifactId >objsql-springboot</ artifactId >
< version >1.3.4</ version >
</ dependency >
更多配置參考pom.xml
ObjectiveSQL 在下面提供了各種資料庫的完整範例,您可以直接使用 IntelliJ IDEA 將其作為獨立專案開啟。事實上,它們不僅僅是範例,也是 ObjectiveSQL 在各種資料庫中的單元測試。
如果你想不配置運行,可以嘗試:SQLite
其他:MySQL、Oracle、MS SQL Server、PostgreSQL、Spring Boot
您只需定義一個帶有註解的 JavaBean
@ DomainModel
public class Member {
private String no ;
@ Queryable
private String name ;
private Integer gender ;
private String mobile ;
private String otherInfo ;
@ Relation ( relationType = RelationType . HAS_MANY )
private List < Order > orders ;
}
Member . create ( newMember );
Member . create ( new Member []{ newMember1 , newMember2 , newMember3 }, false );
Member . update ( 1L , newMember , true );
Member . update ( "name = 'Smith => Jackson'" , "name = ?" , "Alice" );
Member . destroy ( 1L );
Member . destroy ( "name = ?" , "Mary" );
Member . countAll ();
Member . count ( "id > ?" , 1 );
Member . queryByPrimaryKey ( 1 );
Member . queryFirst ( "id = ?" , 1 );
Member . query ( "id > ?" , 1 );
Member . queryAll ();
Page page = Page . create ( 0 , 10 );
PagedList < Member > members = Member . pagedQueryAll ( page , Member . HAS_MANY_ORDERS );
Member . queryAll ( Member . HAS_MANY_ORDERS );
Member . queryByPrimary ( 1 , Member . HAS_MANY_ORDERS );
Member . queryByName ( "demo" , Member . HAS_MANY_ORDERS );
...
Order . Table orderTable = Order . asTable ();
Select select = new Select ();
// In ObjectiveSQL, Java operator can be overloaded
select . project ( sum ( orderTable . amount ) / sum ( orderTable . quantity ) * 100 )
. from ( orderTable )
. where ( orderTable . quantity > 30 &&
orderTable . salesAt . between ( "2020-10-10 00:00:00" , "2020-10-30 23:59:59" ))
. groupBy ( orderTable . productId );
SELECT SUM ( ` T0 ` . ` amount ` ) / SUM ( ` T0 ` . ` quantity ` ) * 100
FROM ` orders ` AS ` T0 `
WHERE ` T0 ` . ` quantity ` > 30 AND
` T0 ` . ` sales_at ` BETWEEN ' 2020-10-10 00:00:00 ' AND ' 2020-10-30 23:59:59 ' )
GROUP BY ` T0 ` . ` product_id `