Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gmazzo/gradle-sqlite-plugin

A Gradle plugin to allow manipulating SQLite databases in the buildScript
https://github.com/gmazzo/gradle-sqlite-plugin

gradle gradle-plugin sqlite sqlite-database

Last synced: 27 days ago
JSON representation

A Gradle plugin to allow manipulating SQLite databases in the buildScript

Awesome Lists containing this project

README

        

# gradle-sqlite-plugin
A Gradle plugin to allow manipulating SQLite databases in the buildScript
> Credits to [tim-yates](https://stackoverflow.com/users/6509/tim-yates) for the working code
https://stackoverflow.com/a/33904851/1007772

## Usage
On your `build.gradle` add:
```groovy
plugins {
id 'com.github.gmazzo.sqlite'
}
```
Visit [Gradle plugins](https://plugins.gradle.org/plugin/com.github.gmazzo.sqlite) for further details on how to apply it

After applying, the standard `groovy.sql.Sql` can be used to open or create any SQLite database with:
```groovy
import groovy.sql.Sql

Sql.newInstance('jdbc:sqlite:' + databaseFile, 'org.sqlite.JDBC')
```
Or you can use this shortcut function:
```groovy
openSQLiteDatabase(databaseFile)
```

### Example
```groovy
plugins {
id 'com.github.gmazzo.sqlite'
}

task createSampleDatabase {
def databaseFile = file("$buildDir/sample.db")

outputs.file databaseFile

doLast {
def db = openSQLiteDatabase(databaseFile)
db.execute 'CREATE TABLE sample (name TEXT NOT NULL, value INTEGER NOT NULL)'
db.execute 'INSERT INTO sample VALUES (\'AAA\', 0)'
db.execute 'INSERT INTO sample VALUES (\'BBB\', 1)'
}
}
```

## Configuration
By default, this plugins relies in the `org.xerial:sqlite-jdbc:3.20.0` SQLite driver.
If you want to change it or update its version, add:
```groovy
sqlite {
driverDependency 'org.xerial:sqlite-jdbc:'
}
```