Connect with us

Code

Exposed – Kotlin SQL Framework

Exposed is a lightweight SQL library on top of JDBC driver for Kotlin language. Exposed has two flavors of database access: typesafe SQL wrapping DSL and lightweight Data Access Objects (DAO).

With Exposed, you have two ways for database access: wrapping DSL and a lightweight DAO. Our official mascot is the cuttlefish, which is well-known for its outstanding mimicry ability that enables it to blend seamlessly into any environment. Similar to our mascot, Exposed can be used to mimic a variety of database engines and help you build applications without dependencies on any specific database engine and switch between them with very little or no changes.

Dependencies

Maven Central configuration

Releases of Exposed are available in the Maven Central repository. You can declare this repository in your build script as follows:

Maven

<!-- Versions after 0.30.1 -->
<!-- Versions before 0.30.1 is unavailable for now-->
<repositories>
    <repository>
        <id>mavenCentral</id>
        <name>mavenCentral</name>
        <url>https://repo1.maven.org/maven2/</url>
    </repository>
</repositories>

Gradle Groovy and Kotlin DSL

Warning: You might need to set your Kotlin JVM target to 8 and when using Spring to 17 in order for it to work properly

repositories {
    // Versions after 0.30.1
    // Versions before 0.30.1 is unavailable for now
    mavenCentral()
}

Exposed modules

Exposed consists of the following modules:

  • exposed-core – base module, which contains both DSL api along with mapping
  • exposed-crypt – provides additional column types to store encrypted data in DB and encode/decode it on client-side
  • exposed-dao – DAO api
  • exposed-java-time – date-time extensions based on Java8 Time API
  • exposed-jdbc – transport level implementation based on Java JDBC API
  • exposed-jodatime – date-time extensions based on JodaTime library
  • exposed-json – JSON and JSONB data type extensions
  • exposed-kotlin-datetime – date-time extensions based on kotlinx-datetime
  • exposed-money – extensions to support MonetaryAmount from “javax.money:money-api”
  • exposed-spring-boot-starter – a starter for Spring Boot to utilize Exposed as the ORM instead of Hibernate
<dependencies>
    <dependency>
        <groupId>org.jetbrains.exposed</groupId>
        <artifactId>exposed-core</artifactId>
        <version>0.44.1</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.exposed</groupId>
        <artifactId>exposed-crypt</artifactId>
        <version>0.44.1</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.exposed</groupId>
        <artifactId>exposed-dao</artifactId>
        <version>0.44.1</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.exposed</groupId>
        <artifactId>exposed-java-time</artifactId>
        <version>0.44.1</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.exposed</groupId>
        <artifactId>exposed-jdbc</artifactId>
        <version>0.44.1</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.exposed</groupId>
        <artifactId>exposed-jodatime</artifactId>
        <version>0.44.1</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.exposed</groupId>
        <artifactId>exposed-json</artifactId>
        <version>0.44.1</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.exposed</groupId>
        <artifactId>exposed-kotlin-datetime</artifactId>
        <version>0.44.1</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.exposed</groupId>
        <artifactId>exposed-money</artifactId>
        <version>0.44.1</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.exposed</groupId>
        <artifactId>exposed-spring-boot-starter</artifactId>
        <version>0.44.1</version>
    </dependency>
</dependencies>

Gradle Groovy

dependencies {
    implementation 'org.jetbrains.exposed:exposed-core:0.44.1'
    implementation 'org.jetbrains.exposed:exposed-crypt:0.44.1'
    implementation 'org.jetbrains.exposed:exposed-dao:0.44.1'
    implementation 'org.jetbrains.exposed:exposed-jdbc:0.44.1'
    
    implementation 'org.jetbrains.exposed:exposed-jodatime:0.44.1'
    // or
    implementation 'org.jetbrains.exposed:exposed-java-time:0.44.1'
    // or
    implementation 'org.jetbrains.exposed:exposed-kotlin-datetime:0.44.1'
    
    implementation 'org.jetbrains.exposed:exposed-json:0.44.1'
    implementation 'org.jetbrains.exposed:exposed-money:0.44.1'
    implementation 'org.jetbrains.exposed:exposed-spring-boot-starter:0.44.1'
}

Gradle Kotlin DSL

In build.gradle.kts:

val exposedVersion: String by project
dependencies {
    implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
    implementation("org.jetbrains.exposed:exposed-crypt:$exposedVersion")
    implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
    implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
    
    implementation("org.jetbrains.exposed:exposed-jodatime:$exposedVersion")
    // or
    implementation("org.jetbrains.exposed:exposed-java-time:$exposedVersion")
    // or
    implementation("org.jetbrains.exposed:exposed-kotlin-datetime:$exposedVersion")
    
    implementation("org.jetbrains.exposed:exposed-json:$exposedVersion")
    implementation("org.jetbrains.exposed:exposed-money:$exposedVersion")
    implementation("org.jetbrains.exposed:exposed-spring-boot-starter:$exposedVersion")
}

and in gradle.properties

exposedVersion=0.44.1

Samples

Check out the samples for a quick start.

Links

Currently, Exposed is available for maven/gradle builds. Check the Maven Central and read (Getting started) to get an insight on setting up Exposed.

For more information visit the links below:

Filing issues

Please note that we are moving away from GitHub Issues for reporting of bugs and features. Please log any new requests on YouTrack. You must be logged in to view and log issues, otherwise you will be met with a 404.

Community

Do you have questions? Feel free to request an invitation for the kotlinlang slack and join the project conversation at our #exposed channel.

Exposed on GitHub: https://github.com/JetBrains/Exposed
Platform: Android
⭐️: 7.6K
Advertisement

Trending