mirage-sql.github.io

Mirage-SQL

Mirage-SQL is an easy and powerful SQL centric database access library for Java (or JVM based languages) which provides dynamic SQL templates in plain SQL files.

Using

You can get Mirage-SQL from the Maven Central Repository. Add the following fragment into your pom.xml.

<dependency>
    <groupId>com.miragesql</groupId>
    <artifactId>miragesql</artifactId>
    <version>2.0.0</version>
</dependency>

or in a Gradle based project add to your build.gradle the following line:

compile 'com.miragesql:miragesql:2.0.0'

If you are updating your application from a previous Mirage-SQL version, see the Migration Guide.

Example

This is a simple example of a SQL template:

SELECT * FROM BOOK
/*BEGIN*/
  WHERE
  /*IF author != null */
        AUTHOR = /*author*/'Naoki Takezoe'
  /*END*/
  /*IF minPrice != null */
    AND PRICE >= /*minPrice*/20
  /*END*/
  /*IF maxPrice != null */
    AND PRICE <= /*maxPrice*/100
  /*END*/
/*END*/
ORDER BY BOOK_ID ASC

In Mirage-SQL, you can embed variables or conditions using special SQL comments, so it’s a plain SQL that can be run with any SQL client tool directly. This feature used in the Mirage’s SQL template it’s called 2Way SQL.