Introduction to Exposed: A Kotlin ORM Framework
Overview
Exposed is an ORM framework specifically crafted for the Kotlin programming language. It acts as a lightweight SQL library atop JDBC drivers, offering a seamless interaction with databases. The project provides two primary methods for accessing databases: a typesafe SQL DSL and lightweight Data Access Objects (DAO). Inspired by its mascot, the mimicry-savvy cuttlefish, Exposed is renowned for its adaptability across various database engines. This adaptability ensures developers can construct applications that remain independent of any specific database engine, allowing swift transitions between them with minimal code modifications.
Supported Databases
Exposed supports a diverse range of databases:
- H2 (version 2.x)
- MariaDB
- MySQL
- Oracle
- PostgreSQL (using both standard and pgjdbc-ng drivers)
- Microsoft SQL Server
- SQLite
This broad compatibility ensures that developers can work with their preferred databases without compatibility concerns.
Dependencies and Configuration
For developers aiming to incorporate Exposed into their projects, the library is readily available in the Maven Central repository. Users can integrate Exposed with their projects using build systems like Gradle or Maven. It's important to set the Kotlin JVM target to 8, or 17 for Spring projects, in order to ensure compatibility.
Exposed Modules
Exposed comprises several modules, each catering to specific requirements:
exposed-core
: The fundamental module offering DSL API and mapping capabilities.exposed-crypt
: Adds encrypted data storage and client-side encoding/decoding functionalities.exposed-dao
: Provides the DAO API.exposed-java-time
andexposed-jodatime
: Offer date-time extensions using Java8 Time API and JodaTime, respectively.exposed-jdbc
: Implements transport level operations using the Java JDBC API.exposed-json
: Enables JSON and JSONB data type operations.exposed-kotlin-datetime
: Date-time extensions based on kotlinx-datetime.exposed-money
: Supports MonetaryAmount operations via the "javax.money:money-api".exposed-spring-boot-starter
: Integrates Exposed with Spring Boot, offering an alternative to Hibernate.
Examples and Sample Code
Exposed provides numerous examples, showcasing its SQL DSL and DAO capabilities:
-
SQL DSL: This feature allows developers to define and manipulate database schemas directly within Kotlin code, offering operations like insertions, updates, deletions, and complex queries using Kotlin's standard syntax.
-
DAO: The DAO approach provides a more object-oriented method of handling database operations, automatically mapping database tables to Kotlin classes.
For hands-on learners, the provided sample code demonstrates how Exposed operates within a project, guiding them through the process of executing database schema operations and managing records seamlessly.
Community and Contribution
The Exposed community is vibrant and welcoming, offering various platforms for interaction, such as the #exposed channel on Kotlin’s Slack. Those interested in contributing to the project are encouraged to follow the project's contribution guidelines and submit pull requests linked to existing issues for an organized development process.
Additional Resources
For developers seeking more information, several resources are available:
- Documentation: Offers comprehensive guides with examples to help users get started.
- Migration Guide: Assists developers in transitioning between Exposed versions.
- Issue Tracker: Allows users to log unwanted behaviors or request new features.
By participating in the Exposed project, contributors agree to the Apache License, Version 2.0, ensuring that all contributions are open and accessible to the community.