Data JDBC SQLite
Arconia Data JDBC SQLite adds SQLite support to Spring Data JDBC. It contributes an SQLite dialect and the SQLite JDBC driver, so you can use SQLite as the database backing your Spring Data JDBC repositories.
Dependencies
Arconia Data JDBC SQLite is designed to be used alongside the Spring Boot Starter for Spring Data JDBC. Add both dependencies to your project.
-
Gradle
-
Maven
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'io.arconia:arconia-data-jdbc-sqlite'
}
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>io.arconia</groupId>
<artifactId>arconia-data-jdbc-sqlite</artifactId>
</dependency>
The Arconia module brings in the org.xerial:sqlite-jdbc driver transitively, so no additional SQLite dependency is required.
Arconia publishes a BOM (Bill of Materials) that you can use to manage the version of the Arconia libraries. It is recommended to use the BOM to ensure that all dependencies are compatible.
-
Gradle
-
Maven
dependencyManagement {
imports {
mavenBom "io.arconia:arconia-bom:0.28.0"
}
}
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.arconia</groupId>
<artifactId>arconia-bom</artifactId>
<version>0.28.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Configuration
Configure the data source to point at an SQLite database. The SQLite JDBC driver supports both file-based and in-memory databases.
-
File-based
-
In-memory
spring:
datasource:
url: "jdbc:sqlite:./data/app.db"
spring:
datasource:
url: "jdbc:sqlite::memory:"
Spring Boot detects the JDBC URL and configures the data source automatically. Spring Data JDBC discovers the SQLite dialect contributed by this module via Spring’s spring.factories mechanism, so no further wiring is required.
Ahead-of-Time Processing
When using Spring Data JDBC with ahead-of-time processing (targeting either the JVM or a native image), the default dialect resolution requires a database connection at build time. To avoid that, declare a JdbcDialect bean for SQLite so the dialect is known statically.
import io.arconia.data.jdbc.sqlite.dialect.JdbcSqliteDialect;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration(proxyBeanMethods = false)
class JdbcConfiguration {
@Bean
JdbcSqliteDialect jdbcDialect() {
return JdbcSqliteDialect.INSTANCE;
}
}