Getting Started with Exposed
Adding Dependencies
Before starting using Exposed, you need to add the dependencies to your project.
Getting Started
Starting a transaction
Every database access using Exposed is started by obtaining a connection and creating a transaction.
To get a connection:
It is also possible to provide javax.sql.DataSource
for advanced behaviors such as connection pooling:
More details on Database and DataSource.
After obtaining a connection, all SQL statements should be placed inside a transaction:
To see the actual DB calls, add a logger:
To log DB calls when using Exposed with a Spring Boot application, add the following property to the application.properties
file:
The exposed-spring-boot-starter
README covers the necessary steps to configure Exposed to use this and any other properties.
Alternatively, the SpringTransactionManager
class has the parameter showSql
, which can be set to true
if a transaction manager bean is defined manually.
DSL & DAO
Exposed comes in two flavors: DSL (Domain-Specific Language) and DAO (Data Access Object).
On a high level, DSL means type-safe syntax that is similar to SQL, whereas DAO means doing CRUD operations on entities.
Observe the below examples and head on to the specific section of each API for more details.
Your first Exposed DSL
More on DSL API
Your first Exposed DAO
More on DAO API