Wednesday, December 7, 2016

Grails 3.x + SQLite

Grails 3.x does not provide support SQLite out of the box. But with little effort, we can get something working fairly quickly as shown in the steps I've outlined below:

SQLite JDBC


Add the following lines to build.gradle to add the dependency for SQLite JDBC:

build.gradle
 compile 'org.xerial:sqlite-jdbc:3.15.1'  

You can find other versions of the JDBC library from the maven repo here:

https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc


SQLite Dialect

Clone and build the Github project to add the supporting classes for the SQLite Dialect from here:



Using maven to build, run the following command:

 mvn -DskipTests install  

Then take the resulting JAR file, sqlite-dialect-0.1.0.jar, under the /target folder and copy it to the lib folder in your Grails project.

In Grails 3.x, the lib folder no longer exists by default. Create a new folder in the root of your project

 mkdir $PROJECT_HOME/lib  

Copy the JAR file to the lib folder just created. For example:
 cp sqlite-dialect-0.1.0.jar /home/philip/agha/VariantStorage/lib  

Finally add the dependency of the JAR file in the build.gradle file:
 compile files('lib/sqlite-dialect-0.1.0.jar')  

Tying it together

Datasources are configured in application.yml:

 dataSource:  
   dbCreate: "update"  
   url: "jdbc:sqlite:/home/philip/ga4gh-server-env/registry.db"  
   logSql: "true"  
   dialect: "org.hibernate.dialect.SQLiteDialect"  
   driverClassName: "org.sqlite.JDBC"  



References:

http://stackoverflow.com/questions/19691940/grails-and-sqlite

http://stackoverflow.com/questions/32339950/how-to-add-a-non-mavenized-jar-dependency-to-a-grails-project-grails-3-x


No comments:

Post a Comment