|
| 1 | +--- |
| 2 | +title: Kotlin API Reference |
| 3 | +--- |
| 4 | + |
| 5 | +# Kotlin API Reference |
| 6 | + |
| 7 | +Storm's Kotlin API is organized into a set of focused modules. Each module has a specific role, from the core ORM engine with coroutine support to Spring Boot auto-configuration and validation. This page provides an overview of the module structure and links to detailed documentation for each concept. |
| 8 | + |
| 9 | +## Module Overview |
| 10 | + |
| 11 | +### storm-kotlin |
| 12 | + |
| 13 | +The main Kotlin API module. It provides the `ORMTemplate` interface, extension functions (`DataSource.orm`, `Connection.orm`), repository interfaces, coroutine support, and the type-safe query DSL. This is the primary dependency for Kotlin applications. |
| 14 | + |
| 15 | +```kotlin |
| 16 | +// Gradle (Kotlin DSL) |
| 17 | +implementation("st.orm:storm-kotlin:@@STORM_VERSION@@") |
| 18 | +``` |
| 19 | + |
| 20 | +```xml |
| 21 | +<!-- Maven --> |
| 22 | +<dependency> |
| 23 | + <groupId>st.orm</groupId> |
| 24 | + <artifactId>storm-kotlin</artifactId> |
| 25 | + <version>@@STORM_VERSION@@</version> |
| 26 | +</dependency> |
| 27 | +``` |
| 28 | + |
| 29 | +The Kotlin API does not depend on any preview features. All APIs are stable and production-ready. |
| 30 | + |
| 31 | +### storm-kotlin-spring |
| 32 | + |
| 33 | +Spring Framework integration for Kotlin. Provides `RepositoryBeanFactoryPostProcessor` for repository auto-discovery and injection, `@EnableTransactionIntegration` for bridging Storm's programmatic transactions with Spring's `@Transactional`, and transaction-aware coroutine support. Add this module when you use Spring Framework without Spring Boot. |
| 34 | + |
| 35 | +```kotlin |
| 36 | +implementation("st.orm:storm-kotlin-spring:@@STORM_VERSION@@") |
| 37 | +``` |
| 38 | + |
| 39 | +See [Spring Integration](spring-integration.md) for configuration details. |
| 40 | + |
| 41 | +### storm-kotlin-spring-boot-starter |
| 42 | + |
| 43 | +Spring Boot auto-configuration for Kotlin. Automatically creates an `ORMTemplate` bean from the `DataSource`, discovers repositories, enables transaction integration, and binds `storm.*` properties from `application.yml`. This is the recommended dependency for Spring Boot applications. |
| 44 | + |
| 45 | +```kotlin |
| 46 | +implementation("st.orm:storm-kotlin-spring-boot-starter:@@STORM_VERSION@@") |
| 47 | +``` |
| 48 | + |
| 49 | +See [Spring Integration: Spring Boot Starter](spring-integration.md#spring-boot-starter) for what the starter provides and how to override its defaults. |
| 50 | + |
| 51 | +## Key Classes and Functions |
| 52 | + |
| 53 | +| Class/Function | Description | Guide | |
| 54 | +|----------------|-------------|-------| |
| 55 | +| `ORMTemplate` | The central entry point. Create with `dataSource.orm` or `ORMTemplate.of(dataSource)`. Provides access to entity/projection repositories and the SQL template query engine. | [Getting Started](getting-started.md) | |
| 56 | +| `EntityRepository<E, ID>` | Type-safe repository interface for CRUD operations on entities. Extend this interface and add custom query methods with default method bodies. | [Repositories](repositories.md) | |
| 57 | +| `ProjectionRepository<P, ID>` | Read-only repository for projections (subset of entity columns). | [Projections](projections.md) | |
| 58 | +| `Entity<ID>` | Marker interface for entity data classes. Implement this on your Kotlin data classes to enable repository operations. | [Entities](entities.md) | |
| 59 | +| `Projection<ID>` | Marker interface for projection data classes. | [Projections](projections.md) | |
| 60 | +| `DataSource.orm` | Extension property that creates an `ORMTemplate` from a `DataSource`. | [Getting Started](getting-started.md) | |
| 61 | +| `transaction { }` | Coroutine-aware programmatic transaction block. | [Transactions](transactions.md) | |
| 62 | +| `transactionBlocking { }` | Blocking variant of the programmatic transaction block. | [Transactions](transactions.md) | |
| 63 | +| `StormConfig` | Immutable configuration holder. Pass to `dataSource.orm(config)` to override defaults. | [Configuration](configuration.md) | |
| 64 | + |
| 65 | +## Coroutine Support |
| 66 | + |
| 67 | +Storm's Kotlin API provides first-class coroutine support. Query results can be consumed as `Flow<T>` for streaming, and the `transaction { }` block is a suspending function that integrates with structured concurrency. Storm leverages JVM virtual threads under the hood, so database operations do not block platform threads even when using JDBC (which is inherently synchronous). |
| 68 | + |
| 69 | +```kotlin |
| 70 | +// Streaming with Flow |
| 71 | +val users: Flow<User> = orm.entity(User::class).selectAll() |
| 72 | +users.collect { processUser(it) } |
| 73 | + |
| 74 | +// Suspending transaction |
| 75 | +transaction { |
| 76 | + orm insert User(name = "Alice") |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## Metamodel Generation |
| 81 | + |
| 82 | +The metamodel generates type-safe companion classes (e.g., `User_`) at compile time. These classes provide static references to entity fields for use in the query DSL, enabling compile-time checked queries. |
| 83 | + |
| 84 | +There are two ways to configure metamodel generation for Kotlin projects, depending on your build tool: |
| 85 | + |
| 86 | +- **Gradle with KSP:** Use `storm-metamodel-ksp`, which is a Kotlin Symbol Processing plugin. |
| 87 | +- **Maven with kapt:** Use `storm-metamodel-processor`, which is a standard Java annotation processor invoked through kapt. |
| 88 | + |
| 89 | +Both generate the same metamodel classes; they are different build tool integrations. |
| 90 | + |
| 91 | +**Gradle (Kotlin DSL) with KSP:** |
| 92 | + |
| 93 | +```kotlin |
| 94 | +plugins { |
| 95 | + id("com.google.devtools.ksp") version "2.0.21-1.0.28" |
| 96 | +} |
| 97 | + |
| 98 | +dependencies { |
| 99 | + ksp("st.orm:storm-metamodel-ksp:@@STORM_VERSION@@") |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +**Maven with kapt:** |
| 104 | + |
| 105 | +```xml |
| 106 | +<plugin> |
| 107 | + <groupId>org.jetbrains.kotlin</groupId> |
| 108 | + <artifactId>kotlin-maven-plugin</artifactId> |
| 109 | + <executions> |
| 110 | + <execution> |
| 111 | + <id>kapt</id> |
| 112 | + <goals><goal>kapt</goal></goals> |
| 113 | + <configuration> |
| 114 | + <annotationProcessorPaths> |
| 115 | + <path> |
| 116 | + <groupId>st.orm</groupId> |
| 117 | + <artifactId>storm-metamodel-processor</artifactId> |
| 118 | + <version>@@STORM_VERSION@@</version> |
| 119 | + </path> |
| 120 | + </annotationProcessorPaths> |
| 121 | + </configuration> |
| 122 | + </execution> |
| 123 | + </executions> |
| 124 | +</plugin> |
| 125 | +``` |
| 126 | + |
| 127 | +See [Metamodel](metamodel.md) for setup and usage. |
| 128 | + |
| 129 | +## KDoc |
| 130 | + |
| 131 | +KDoc is generated per module using Dokka. Select a module below to browse its API documentation. |
| 132 | + |
| 133 | +| Module | Description | |
| 134 | +|--------|-------------| |
| 135 | +| [storm-kotlin](../api/kotlin/storm-kotlin/index.html) | Kotlin API with coroutine support | |
| 136 | +| [storm-kotlin-spring](../api/kotlin/storm-kotlin-spring/index.html) | Spring Framework integration for Kotlin | |
| 137 | +| [storm-kotlin-spring-boot-starter](../api/kotlin/storm-kotlin-spring-boot-starter/index.html) | Spring Boot auto-configuration for Kotlin | |
| 138 | +| [storm-metamodel-ksp](../api/kotlin/storm-metamodel-ksp/index.html) | Kotlin Symbol Processing for metamodel generation | |
| 139 | +| [storm-kotlinx-serialization](../api/kotlin/storm-kotlinx-serialization/index.html) | Kotlinx Serialization support | |
0 commit comments