com.github.braisdom:objective-sql

It makes domain models have the capabilities of commonly query and persistence, and solve complex query with programmable logic design at the same time

GroupId

GroupId

com.github.braisdom
ArtifactId

ArtifactId

objective-sql
Last Version

Last Version

1.4.6
Release Date

Release Date

Type

Type

jar
Description

Description

It makes domain models have the capabilities of commonly query and persistence, and solve complex query with programmable logic design at the same time
Project Organization

Project Organization

com.github.braisdom
Source Code Management

Source Code Management

https://github.com/braisdom/ObjectiveSql

Download objective-sql

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.braisdom/objective-sql/ -->
<dependency>
    <groupId>com.github.braisdom</groupId>
    <artifactId>objective-sql</artifactId>
    <version>1.4.6</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.braisdom/objective-sql/
implementation 'com.github.braisdom:objective-sql:1.4.6'
// https://jarcasting.com/artifacts/com.github.braisdom/objective-sql/
implementation ("com.github.braisdom:objective-sql:1.4.6")
'com.github.braisdom:objective-sql:jar:1.4.6'
<dependency org="com.github.braisdom" name="objective-sql" rev="1.4.6">
  <artifact name="objective-sql" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.braisdom', module='objective-sql', version='1.4.6')
)
libraryDependencies += "com.github.braisdom" % "objective-sql" % "1.4.6"
[com.github.braisdom/objective-sql "1.4.6"]

Dependencies

compile (5)

Group / Artifact Type Version
org.hibernate : hibernate-validator jar 6.1.5.Final
org.glassfish : javax.el jar 3.0.0
com.github.braisdom : mangosdk-spi jar 1.1.1
commons-beanutils : commons-beanutils jar 1.9.4
com.github.jsqlparser : jsqlparser jar 3.2

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
org.mockito : mockito-all jar 1.10.19

system (1)

Group / Artifact Type Version
com.sun » tools Optional jar 1.0

Project Modules

There are no modules declared in this project.

ObjectiveSQL is an ORM framework in Java based on ActiveRecord pattern, which encourages rapid development and clean, codes with the least, and convention over configuration.

Features

  • With one annotation your Class has fully featured capabilities of SQL programming
  • Easy to relational(has_one, has_many and belongs_to) query and paged query
  • Writing SQL expressions(arithmetic, comparison and logical) using Java syntax

Why to choose

  • If your project focuses on data analysis based on relation database, and a lot of arithmetic expressions in SQL statement. ObjectiveSQL will help you write expressions conveniently and safely using Java syntax
  • If you don’t want to write Java codes of database access and various configuration files, ObjectiveSQL's dynamic code generation will help you access the database without coding

Performance(Oracle JMH)

query_perf

Installation

IntelliJ IDEA plugin installation

Preferences/Settings -> Plugins -> Search with "ObjectiveSql" in market -> Install

Maven dependencies
<!-- 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>

Refer to the pom.xml for more configuration

Examples

ObjectiveSQL provides full example for various databases below, You can open it directly with IntelliJ IDEA as a standalone project. In fact, they are not just examples, but also unit tests of ObjectiveSQL in various databases.

If you want to run without configuration, you can try: SQLite

Others: MySQL, Oracle, MS SQL Server, PostgreSQL, Spring Boot

Simple SQL programming without coding

You define just a JavaBean with one annotation

@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;
}
Persistence
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");
Counting and querying
Member.countAll();
Member.count("id > ?", 1);
Member.queryByPrimaryKey(1);
Member.queryFirst("id = ?", 1);
Member.query("id > ?", 1);
Member.queryAll();
Paged querying
Page page = Page.create(0, 10);
PagedList<Member> members = Member.pagedQueryAll(page, Member.HAS_MANY_ORDERS);
Relation querying
Member.queryAll(Member.HAS_MANY_ORDERS);
Member.queryByPrimary(1, Member.HAS_MANY_ORDERS);
Member.queryByName("demo", Member.HAS_MANY_ORDERS);
...

Complex SQL programming

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`

Reference documentation

com.github.braisdom

Braisdom

It encourages rapid development and clean, codes with the least and convention over configuration.

Versions

Version
1.4.6
1.4.5
1.4.4
1.4.3
1.4.2
1.4.0
1.3.9
1.3.8
1.3.7
1.3.6
1.3.5
1.3.4
1.3.2
1.3.1
1.3
1.2
1.1
1.0