Skip to content

Latest commit

 

History

History
188 lines (141 loc) · 5.32 KB

README.md

File metadata and controls

188 lines (141 loc) · 5.32 KB

Maven Central GitHub license Javadocs Build Status Coverage Status

uroboroSQL

uroboroSQL

UroboroSQL is a simple SQL execution library that can utilize 2-way-SQL compatible with Java 8.

UroboroSQL mainly adopts a SQL-centered design concept. The concept does not focus on Java to assemble SQL, but is based on an idea of making up for weaknesses of SQL with Java.

From the knowhow acquired through our business, we have enhanced UroboroSQL with functions like partition value support, retrying, filtering customization, and so on. Also, for quality assurance purposes, it features a coverage analysis function available for 2-way-SQL.

There is also REPL which dramatically increases SQL development productivity.

asciicast

for Japanese, see README.ja.md

Installation

for Maven

<dependency>
    <groupId>jp.co.future</groupId>
    <artifactId>uroborosql</artifactId>
    <version>1.0.1</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>5.3.20</version>
</dependency>

or

<dependency>
    <groupId>jp.co.future</groupId>
    <artifactId>uroborosql</artifactId>
    <version>1.0.1</version>
</dependency>
<dependency>
    <groupId>ognl</groupId>
    <artifactId>ognl</artifactId>
    <version>3.1.23</version>
</dependency>

for Gradle

compile group: 'jp.co.future', name: 'uroborosql', version: '1.0.1'
compile group: 'org.springframework', name: 'spring-expression', version: '5.3.20'

or

compile group: 'jp.co.future', name: 'uroborosql', version: '1.0.1'
compile group: 'ognl', name: 'ognl', version: '3.1.23'

Documentation

https://future-architect.github.io/uroborosql-doc/

Requirement

  • Java 11 or later.

Quick start

2Way-SQL

/* department/select_department.sql */

SELECT /* _SQL_ID_ */
  DEPT.DEPT_NO AS DEPT_NO
, DEPT.DEPT_NAME AS DEPT_NAME
FROM
  DEPARTMENT DEPT
WHERE
  1    = 1
/*IF SF.isNotEmpty(dept_no)*/
AND DEPT.DEPT_NO = /*dept_no*/1
/*END*/
/*IF SF.isNotEmpty(dept_name)*/
AND DEPT.DEPT_NAME = /*dept_name*/'sample'
/*END*/
/* department/insert_department.sql */

INSERT
/* _SQL_ID_ */
INTO
  DEPARTMENT
(
  DEPT_NO
, DEPT_NAME
) VALUES (
  /*dept_no*/1
, /*dept_name*/'sample'
)
SqlConfig config = UroboroSQL.builder("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "")
    .build();

try (SqlAgent agent = config.agent()) {
  // SELECT
  List<Map<String, Object>> departments = agent.query("department/select_department")
      .param("dept_no", 1001)
      .collect();

  // INSERT
  int count = agent.update("department/insert_department")
      .param("dept_no", 1001)
      .param("dept_name", "sales")
      .count();
}

DAO Interface

SqlConfig config = UroboroSQL.builder("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", "sa", "")
    .build();

try (SqlAgent agent = config.agent()) {
  // select
  Department dept = agent.find(Department.class, 1001)
      .orElse(null);

  // insert
  Department hrDept = new Department();
  hrDept.setDeptNo(1002);
  hrDept.setDeptName("HR");
  agent.insert(hrDept);

  // update
  hrDept.setDeptName("Human Resources");
  agent.update(hrDept);

  // delete
  agent.delete(hrDept);
}

Sample application

Automated code generation

SQL Formatter

uroboroSQL

We also prepare a SQL formatter useful for development.

License

Released under the MIT License.