Skip to content

Latest commit

 

History

History
186 lines (140 loc) · 5.35 KB

README.ja.md

File metadata and controls

186 lines (140 loc) · 5.35 KB

Maven Central GitHub license Javadocs Build Status Coverage Status

uroboroSQL

uroboroSQL

uroboroSQLは、Java8対応の2Way-SQLが利用可能なシンプルなSQL実行ライブラリです。

uroboroSQLは主にSQL中心の設計コンセプトを採用しています。Javaを中心に考えてSQLを組み立てるという思想ではなく、SQLに足りないところをJavaで補うという思想です。

エンタープライズで培われたノウハウとして、区分値サポート、リトライ、フィルターによるカスタマイズなどの機能を充実させています。また、2Way-SQLに対して、カバレッジを取れるようにするという、品質視点での機能があるのも特徴です。

さらにSQLの開発生産性を格段に上げるREPL機能も搭載しています。

asciicast

Installation

for Maven

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

または

<dependency>
    <groupId>jp.co.future</groupId>
    <artifactId>uroborosql</artifactId>
    <version>1.0.0</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.0'
compile group: 'org.springframework', name: 'spring-expression', version: '5.3.20'

または

compile group: 'jp.co.future', name: 'uroborosql', version: '1.0.0'
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

開発で便利なSQL formatterも用意しています。

License

Released under the MIT License.