$ show JetBrains/Exposed
Exposed is a Kotlin SQL ORM library by JetBrains that provides a type-safe DSL for database operations, an optional DAO/entity layer, schema migration tooling, and multi-database support. The architecture is modular: a core module (exposed-core) defines the SQL DSL, column types, expression trees, and vendor dialects; separate modules implement synchronous JDBC (exposed-jdbc) and reactive R2DBC (exposed-r2dbc) backends; the DAO layer (exposed-dao, exposed-dao-r2dbc) adds entity management with caching, relationships, and lifecycle hooks; additional modules provide encryption, JSON, money types, Spring Boot auto-configuration, and Gradle/Maven plugins for migration generation. The library supports H2, MySQL, MariaDB, PostgreSQL, Oracle, SQL Server, SQLite, and Amazon Redshift, with extensive dialect-specific SQL generation and type mapping. Key entry points include Database.connect() for JDBC and R2dbcDatabase.connect() for R2DBC, transaction scopes (transaction {} / suspendTransaction {}), table/column definitions via DSL functions, and entity classes (IntEntity, UuidEntity, etc.) for the DAO pattern. Data flows through a query builder that constructs parameterized SQL statements, which are then executed by backend-specific executables (BlockingExecutable for JDBC, SuspendExecutable for R2DBC). The library also provides statement interceptors for logging and monitoring, and a migration utility that can generate Flyway-compatible scripts from table definitions. External dependencies include JDBC drivers for each supported database, R2DBC drivers, Spring Framework (for the Spring Boot starters and transaction integration), and optional libraries for encryption (AES, BCrypt, Argon2). The build system is Gradle with Kotlin DSL, and the project publishes multiple artifacts to Maven Central. The codebase demonstrates strong engineering practices with extensive cross-database test suites, parameterized tests, and continuous integration across multiple database containers.
The LLM identified 6 files worth highlighting for reuse:
A generic, type-safe entity identifier that wraps a value and associates it with a specific table. It implements equality based on both the table and the value, supports lazy loading via EntityIDFactory, and provides a clean separation between the identity concept and the entity itself. This pattern is reusable in any Kotlin project needing typed, table-scoped IDs without coupling to the full ORM.
A set of interfaces (StatementInterceptor, GlobalStatementInterceptor) that define hooks for before/after statement execution, commit, and rollback. The pattern allows composing multiple interceptors via CompositeSqlLogger and supports both JDBC and R2DBC backends. This is a clean, isolated plugin architecture that can be extracted for any system needing lifecycle instrumentation around database operations.
An extensible type mapping system for R2DBC that uses a TypeMapper interface with priority-based resolution and dialect/column-type filtering. Mappers are registered via ServiceLoader, with fallback to a DefaultTypeMapper. This pattern cleanly separates value conversion logic from the core framework and can be reused in any project needing pluggable, database-specific type conversions.
A sealed class hierarchy representing database-specific FOR UPDATE / FOR SHARE locking options. Each subclass encapsulates the SQL suffix generation for a particular dialect (MySQL, PostgreSQL, Oracle, MariaDB), including wait/skip-locked modes. This pattern demonstrates clean separation of vendor-specific SQL generation into a type-safe, extensible hierarchy that can be adapted for any feature with dialect-specific syntax.
A lazy-loading iterable abstraction that separates the size/count of a result set from its actual iteration. SizedIterable and LazySizedIterable provide a consistent interface for pagination and result handling without forcing eager loading. This pattern is reusable in any Kotlin project that needs to represent deferred query results with known or unknown cardinality.
An enumeration defining migration version naming formats (TIMESTAMP, MAJOR_MINOR, etc.) with regex-based parsing and fallback. It encapsulates the logic for generating and matching Flyway-compatible migration file names. This is a self-contained, testable component that can be extracted for any project needing configurable, pattern-based file naming conventions.