/mbsql

MbSQL, an eDSL compiler plugin and library for SQL in Java

Primary LanguageJavaMIT LicenseMIT

MbSQL

MbSQL (embedded SQL), a simple toy to practice writing custom Java annotation processing. As a Java 9+ compiler plugin, it transforms the @MbSql-annotated String-typed variables into SQL commands in compile-time, hence it is unable to do name-binding in runtime, leaving ?s as placeholders in the output.

Motivating examples

From:

import io.anqur.mbsql.MbSql;
import static io.anqur.mbsql.Keyword.*;

public class Main {
    public static void main(String[] args) {
        @MbSql String command =
            SELECT + ALL +
            FROM + "t_student" +
            WHERE + EQ("c_name", $) +
            AND + EQ("c_age", 18);
    }
}

Into:

import io.anqur.mbsql.MbSql;
import static io.anqur.mbsql.Keyword.*;

public class Main {
    public static void main(String[] args) {
        @MbSql String command =
            "SELECT * FROM t_student WHERE c_name=? AND c_age=18;";
    }
}

Via:

$ javac -cp /path/to/mbsql.jar -Xplugin:MbSql Main.java
$ java -cp /path/to/mbsql.jar:. Main

License

MIT