MCPcopy Index your code
hub / github.com/braisdom/ObjectiveSql

github.com/braisdom/ObjectiveSql @1.4.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.4.6 ↗ · + Follow
2,175 symbols 6,841 edges 296 files 374 documented · 17%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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

<dependency>
    <groupId>com.github.braisdom</groupId>
    <artifactId>objective-sql</artifactId>
    <version>1.4.5</version>
</dependency>

<dependency>
  <groupId>com.github.braisdom</groupId>
  <artifactId>objsql-springboot</artifactId>
  <version>1.3.3</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

Extension points exported contracts — how you extend this code

ConnectionFactory (Interface)
A factory for creating the Connection of database, it is necessary for ObjectiveSql in runtime. Injecting t [7 implementers]
core/src/main/java/com/github/braisdom/objsql/ConnectionFactory.java
ORMFramework (Interface)
(no doc) [8 implementers]
benchmark/src/main/java/com/github/braisdom/objsql/benchmark/ORMFramework.java
Initializer (Interface)
(no doc) [4 implementers]
mangosdk/src/main/java/org/mangosdk/spi/processor/Initializer.java
LoggerFactory (Interface)
An abstract factory for creating Logger @see Logger [11 implementers]
core/src/main/java/com/github/braisdom/objsql/LoggerFactory.java
UserMapper (Interface)
(no doc)
benchmark/src/main/java/com/github/braisdom/objsql/benchmark/MyBatis.java
Logger (Interface)
(no doc) [2 implementers]
mangosdk/src/main/java/org/mangosdk/spi/processor/Logger.java
Sqlizable (Interface)
Indicates a node can become to SQL expression. [22 implementers]
core/src/main/java/com/github/braisdom/objsql/sql/Sqlizable.java
InterfaceTestClass (Interface)
(no doc)
mangosdk/src/test/resources/invalid/InterfaceTestClass.java

Core symbols most depended-on inside this repo

$
called by 259
core/src/main/java/com/github/braisdom/objsql/sql/Expressions.java
append
called by 230
core/src/main/java/com/github/braisdom/objsql/apt/StatementBuilder.java
toSql
called by 166
core/src/main/java/com/github/braisdom/objsql/sql/Sqlizable.java
size
called by 144
core/src/main/java/com/github/braisdom/objsql/pagination/PagedList.java
put
called by 142
core/src/main/java/com/github/braisdom/objsql/jdbc/BasicRowProcessor.java
get
called by 129
core/src/main/java/com/github/braisdom/objsql/pagination/PagedList.java
typeRef
called by 107
core/src/main/java/com/github/braisdom/objsql/apt/APTBuilder.java
valueOf
called by 106
mangosdk/src/main/java/org/mangosdk/spi/processor/CheckResult.java

Shape

Method 1,838
Class 290
Interface 43
Enum 4

Languages

Java100%

Modules by API surface

core/src/main/java/com/github/braisdom/objsql/jdbc/BaseResultSetHandler.java99 symbols
core/src/main/java/com/github/braisdom/objsql/sql/function/ClickHouse.java74 symbols
core/src/main/java/com/github/braisdom/objsql/sql/function/MySQL.java48 symbols
core/src/main/java/com/github/braisdom/objsql/jdbc/wrappers/SqlNullCheckedResultSet.java46 symbols
core/src/main/java/com/github/braisdom/objsql/sql/function/Ansi.java44 symbols
core/src/main/java/com/github/braisdom/objsql/Databases.java39 symbols
core/src/main/java/com/github/braisdom/objsql/BeanModelDescriptor.java36 symbols
core/src/main/java/com/github/braisdom/objsql/apt/DomainModelCodeGenerator.java34 symbols
core/src/main/java/com/github/braisdom/objsql/reflection/PropertyUtils.java33 symbols
core/src/main/java/com/github/braisdom/objsql/apt/APTBuilder.java31 symbols
core/src/main/java/com/github/braisdom/objsql/sql/Select.java30 symbols
core/src/main/java/com/github/braisdom/objsql/util/Inflector.java27 symbols

Datastores touched

(mysql)Database · 1 repos
objective_sqlDatabase · 1 repos
postgresDatabase · 1 repos

For agents

$ claude mcp add ObjectiveSql \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact