Version v1.0-RC1 of the documentation is no longer actively maintained. The site that you are currently viewing is an archived snapshot. For up-to-date documentation, see the latest version.
Examples
Overview
We provide several sample applications including JDBC access, R2DBC access, Spring Boot integration, Ktor integration.
Requirements
These are requirements for running the sample applications:
- JDK 11 or later version
- Docker (used by some applications)
Get the repository
Clone the komapper/komapper-examples repository.
$ git clone https://github.com/komapper/komapper-examples.git
$ cd komapper-examples
The repository has a multi-project configuration of Gradle. Each subproject is implemented as a sample application.
Sample applications
console-jdbc
This project is a console application that uses JDBC to access the database. To run it, execute the following command:
$ ./gradlew :console-jdbc:run
console-r2dbc
This project is a console application that uses R2DBC to access the database. To run it, execute the following command:
$ ./gradlew :console-r2dbc:run
quarkus-jdbc
This project is a Quarkus web application that uses JDBC to access PostgreSQL database.
SeeREADME for more details.
spring-boot-jdbc
This project is a Spring Boot web application that uses JDBC to access the database. To run it, execute the following command:
$ ./gradlew :spring-boot-jdbc:bootRun
Once the application is running, open http://localhost:8080
in your browser.
The message returned from the database will be displayed in your browser.
To add a message to the database, pass it as a query parameter, like http://localhost:8080/?text=Hi
.
If you open http://localhost:8080
again, you will see the list with the added data.
spring-boot-r2dbc
This project is a Spring Boot web application that uses R2DBC to access the database. To run it, execute the following command:
$ ./gradlew :spring-boot-r2dbc:bootRun
Once the application is running, open http://localhost:8080
in your browser.
The message returned from the database will be displayed in your browser.
To add a message to the database, pass it as a query parameter, like http://localhost:8080/?text=Hi
.
If you open http://localhost:8080
again, you will see the list with the added data.
spring-native-jdbc
This project is a Spring Boot web application that supports Spring Native and uses JDBC to access the database.
You can build the native application with the following command:
$ ./gradlew :spring-native-jdbc:bootBuildImage
To run the application, start Docker as follows:
$ docker run --rm -p 8080:8080 docker.io/library/spring-native-jdbc:0.0.1
Once the application is running, open http://localhost:8080
in your browser.
The message returned from the database will be displayed in your browser.
To add a message to the database, pass it as a query parameter, like http://localhost:8080/?text=Hi
.
If you open http://localhost:8080
again, you will see the list with the added data.
spring-native-r2dbc
This project is a Spring Boot web application that supports Spring Native and uses R2DBC to access the database.
In the current version, there is a limitation regarding Kotlin coroutines.
repository-pattern-jdbc
This project contains an example implementation of the repository pattern.
To run a test that invokes the repository, execute the following command:
$ ./gradlew :repository-pattern-jdbc:check
codegen
This project uses the Gradle plugin. to generate the source code for entity classes from database metadata.
Note
Since this project uses Testcontainers, Docker is required.The configuration of the Komapper Gradle plugin is described in the komapper
block in the build.gradle.kts file.
In this example, we will generate code from MySQL and PostgreSQL.
To generate code from MySQL, run the following command:
$ ./gradlew :codegen:komapperMysqlGenerator
To generate code from PostgreSQL, issue the following command:
$ ./gradlew :codegen:komapperPostgresqlGenerator
To generate code from both MySQL and PostgreSQL at onece, execute the following command:
$ ./gradlew :codegen:komapperGenerator
The generated code will be output under codgen/src/main/kotlin
.
comparison-with-exposed
This project is based on the JetBrains Exposed sample code. and rewritten for Komapper.
To run it, execute the following command:
$ ./gradlew :comparison-with-exposed:run
jpetstore
This project is a Spring Boot web application that uses JDBC to access the database.
The application is based on jpetstore-6, which was created by the MyBatis team.
To run it, execute the following command:
$ ./gradlew :jpetstore:bootRun
Once the application is running, open http://localhost:8080
in your browser.
Where you are prompted to sign in, you can use the following username and password.
- username: jpetstore
- password: jpetstore
kweet
This project is a Spring Boot web application that uses R2DBC to access the database.
The application is based on Kweet, which was created by the Ktor team.
To run it, execute the following command:
$ ./gradlew :kweet:run
Once the application is running, open http://localhost:8080
in your browser.