A MySQL to H2 SQL conversion library written in Java.
Parse a MySQL dump and convert it to H2 statements either as an embedded library or as a standalone tool.
Next steps can include:
- clean up the interface to avoid Iterators
- implement other statements (SELECT, UPDATE...)
- provide samples for an on-the-fly conversion with datasource-proxy http://code.google.com/p/datasource-proxy/
Other ideas:
- look at jOOQ http://www.jooq.org/ to see if it can be used to model the DML statements and Liquibase http://www.liquibase.org/ for the DDL part
mvn clean package
will generate the SQL parser and build an executable JAR.
Extend the parser to support more statements, see BasicTest and ConverterTest diff for details.
Since last commit of andrewparmet/mysql2h2-converter is 2018, change this library's pom to a new group and new version, and you can use the new one from JitPack.
Gradle example:
Step 1. Add the JitPack repository to your build file:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency:
dependencies {
implementation 'com.github.alphahinex:mysql2h2-converter:0.3.1'
}
As a library:
private static void convertAndCreate(Statement stmt, String sqlDump) throws SQLException, ParseException {
List<SQLStatement> stmts = SQLUtils.parseStatements(sqlDump, DbType.mysql, SQLParserFeature.MySQLSupportStandardComment);
stmt.execute(SQLUtils.toSQLString(stmts, DbType.h2));
}
On the command line, after mvn package
of course:
$ java -jar target/mysql2h2-converter-tool-0.3.1.jar demos/disconf-mysql.sql > disconf-h2.sql
This code is provided under the MIT license.