Skip to content

mirage-sql/mirage

Repository files navigation

Mirage-SQL Build Maven Central Join the chat at https://gitter.im/mirage-sql/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.1.2</version>
</dependency>

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

compile 'com.miragesql:miragesql:2.1.2'

or just download it from the Release Page.

Other Mirage-SQL Modules:

Module Description Gradle
Mirage-SQL Test The testing functionality. testCompile 'com.miragesql:miragesql-test:2.1.2'
Mirage-SQL Tools The development tools. testCompile 'com.miragesql:miragesql-tools:2.1.2'
Mirage-SQL Integration The integration with Spring, Guice and Seasar2.. compile 'com.miragesql:miragesql-integration:2.1.2'

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

With 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.

Links: