Skip to content

komamitsu/spring-data-sqlite

Repository files navigation

Spring Data JDBC integration for SQLite

This is a Spring Data JDBC integration for SQLite. The basic usage follows Spring Data JDBC - Reference Documentation.

Install

For Gradle

    implementation "org.komamitsu:spring-data-sqlite:1.2.0"

For Maven

<dependency>
    <groupId>org.komamitsu</groupId>
    <artifactId>spring-data-sqlite</artifactId>
    <version>1.2.0</version>
</dependency>

Configurations

spring.datasource.url

For instance,

spring.datasource.url=jdbc:sqlite:our-app.db

Annotations

@EnableSqliteRepositories annotation is needed on the JVM application to use this integration as follows

@SpringBootApplication
@EnableSqliteRepositories
public class MyApplication {
  @Autowired GroupRepository groupRepository;
  @Autowired UserRepository userRepository;

  :

Repository class

This library provides SqliteRepository that inherits PagingAndSortingRepository and has 2 new APIs insert() and update(). Spring Data JDBC basically requires users to use auto generated ID columns. If users want to use non auto generated ID column, there are some workarounds, but they're not perfect solutions. The 2 new APIs addresses the problem.

public interface CarRepository extends SqliteRepository<Car, Integer> {}
    Car car = new Car(assignedCarId, "my new car");
    carRepository.insert(car);
       :
    carRepository.update(modifiedCar);

Example application

Example application is a JVM application that uses this integration. It only serves as a reference and does not necessarily meet production code standards.