Skip to content

Commit d744419

Browse files
authored
Feature/storm 109 (#110)
Add Ktor integration support. (#109)
1 parent 7394b55 commit d744419

File tree

66 files changed

+3753
-155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3753
-155
lines changed

docs/ai.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,18 @@ For each selected tool, Storm installs two types of AI context:
5656

5757
| Skill | Purpose |
5858
|-------|---------|
59+
| storm-setup | Configure dependencies (detects Spring Boot, Ktor, or standalone) |
5960
| storm-docs | Load full Storm documentation |
6061
| storm-entity-kotlin | Create Kotlin entities |
6162
| storm-entity-java | Create Java entities |
62-
| storm-repository-kotlin | Write Kotlin repositories |
63+
| storm-repository-kotlin | Write Kotlin repositories (framework-aware: Spring Boot, Ktor, standalone) |
6364
| storm-repository-java | Write Java repositories |
6465
| storm-query-kotlin | Kotlin QueryBuilder queries |
6566
| storm-query-java | Java QueryBuilder queries |
6667
| storm-sql-kotlin | Kotlin SQL Templates |
6768
| storm-sql-java | Java SQL Templates |
6869
| storm-json-kotlin / storm-json-java | JSON columns and JSON aggregation |
69-
| storm-serialization-kotlin / storm-serialization-java | Entity serialization for REST APIs (Ref handling) |
70+
| storm-serialization-kotlin / storm-serialization-java | Entity serialization for REST APIs (framework-aware content negotiation) |
7071
| storm-migration | Write Flyway/Liquibase migration SQL |
7172

7273
### 3. Database connection (optional)

docs/configuration.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import TabItem from '@theme/TabItem';
33

44
# Configuration
55

6-
Storm can be configured through `StormConfig`, system properties, or Spring Boot's `application.yml`. These properties control runtime behavior for features like dirty checking and entity caching. All properties have sensible defaults, so **configuration is optional**. Storm works out of the box without any configuration.
6+
Storm can be configured through `StormConfig`, system properties, Spring Boot's `application.yml`, or Ktor's `application.conf`. These properties control runtime behavior for features like dirty checking and entity caching. All properties have sensible defaults, so **configuration is optional**. Storm works out of the box without any configuration.
77

88
---
99

@@ -17,7 +17,7 @@ Storm can be configured through `StormConfig`, system properties, or Spring Boot
1717
| `storm.entity_cache.retention` | `default` | Cache retention mode: `default` or `light` |
1818
| `storm.template_cache.size` | `2048` | Maximum number of compiled templates to cache |
1919
| `storm.validation.record_mode` | `fail` | Record validation mode: `fail`, `warn`, or `none` |
20-
| `storm.validation.schema_mode` | `none` | Schema validation mode: `none`, `warn`, or `fail` (Spring Boot only) |
20+
| `storm.validation.schema_mode` | `none` | Schema validation mode: `none`, `warn`, or `fail` (Spring Boot and Ktor) |
2121
| `storm.validation.strict` | `false` | Treat schema validation warnings as errors |
2222
| `storm.validation.interpolation_mode` | `warn` | Interpolation safety mode: `warn`, `fail`, or `none` (see [Interpolation Safety](#interpolation-safety)) |
2323
| `st.orm.scrollable.maxSize` | `1000` | Maximum window size allowed in a serialized cursor (system property only) |
@@ -44,9 +44,9 @@ java -Dstorm.update.default_mode=FIELD \
4444

4545
```kotlin
4646
val config = StormConfig.of(mapOf(
47-
"storm.update.default_mode" to "FIELD",
48-
"storm.entity_cache.retention" to "light",
49-
"storm.template_cache.size" to "4096"
47+
UPDATE_DEFAULT_MODE to "FIELD",
48+
ENTITY_CACHE_RETENTION to "light",
49+
TEMPLATE_CACHE_SIZE to "4096"
5050
))
5151

5252
val orm = ORMTemplate.of(dataSource, config)
@@ -60,9 +60,9 @@ val orm = dataSource.orm(config)
6060

6161
```java
6262
var config = StormConfig.of(Map.of(
63-
"storm.update.default_mode", "FIELD",
64-
"storm.entity_cache.retention", "light",
65-
"storm.template_cache.size", "4096"
63+
UPDATE_DEFAULT_MODE, "FIELD",
64+
ENTITY_CACHE_RETENTION, "light",
65+
TEMPLATE_CACHE_SIZE, "4096"
6666
));
6767

6868
var orm = ORMTemplate.of(dataSource, config);
@@ -94,6 +94,32 @@ storm:
9494
9595
The Spring Boot Starter binds these properties and builds a `StormConfig` that is passed to the `ORMTemplate` factory. Values not set in YAML fall back to system properties and then to built-in defaults. See [Spring Integration](spring-integration.md#configuration-via-applicationyml) for details.
9696

97+
**In Ktor's `application.conf`** (requires `storm-ktor`):
98+
99+
```hocon
100+
storm {
101+
ansiEscaping = false
102+
update {
103+
defaultMode = "ENTITY"
104+
dirtyCheck = "INSTANCE"
105+
maxShapes = 5
106+
}
107+
entityCache {
108+
retention = "default"
109+
}
110+
templateCache {
111+
size = 2048
112+
}
113+
validation {
114+
recordMode = "fail"
115+
schemaMode = "none"
116+
strict = false
117+
}
118+
}
119+
```
120+
121+
The Storm Ktor plugin reads these properties and builds a `StormConfig` that is passed to the `ORMTemplate` factory. HOCON supports environment variable substitution with `${?VAR_NAME}` syntax. See [Ktor Integration](ktor-integration.md#configuration) for details.
122+
97123
---
98124

99125
## ORMTemplate Factory Overloads

docs/dirty-checking.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ data class User(
402402
Globally via `StormConfig` or system property:
403403

404404
```kotlin
405-
val config = StormConfig.of(mapOf("storm.update.dirty_check" to "VALUE"))
405+
val config = StormConfig.of(mapOf(UPDATE_DIRTY_CHECK to "VALUE"))
406406
```
407407

408408
```bash
@@ -453,7 +453,7 @@ Storm enforces a **maximum number of UPDATE shapes per entity**. Once this limit
453453
**Configure via `StormConfig` or system property:**
454454

455455
```kotlin
456-
val config = StormConfig.of(mapOf("storm.update.max_shapes" to "10"))
456+
val config = StormConfig.of(mapOf(UPDATE_MAX_SHAPES to "10"))
457457
```
458458

459459
```bash
@@ -491,9 +491,9 @@ For cache retention settings, see [Entity Cache Configuration](entity-cache.md#c
491491
```kotlin
492492
// Via StormConfig
493493
val config = StormConfig.of(mapOf(
494-
"storm.update.default_mode" to "FIELD",
495-
"storm.update.dirty_check" to "VALUE",
496-
"storm.update.max_shapes" to "10"
494+
UPDATE_DEFAULT_MODE to "FIELD",
495+
UPDATE_DIRTY_CHECK to "VALUE",
496+
UPDATE_MAX_SHAPES to "10"
497497
))
498498
val orm = ORMTemplate.of(dataSource, config)
499499
```

docs/entity-cache.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ The `default` mode retains entities for the duration of the transaction, which p
213213
Configure retention behavior via `StormConfig` or system property:
214214

215215
```kotlin
216-
val config = StormConfig.of(mapOf("storm.entity_cache.retention" to "light"))
216+
val config = StormConfig.of(mapOf(ENTITY_CACHE_RETENTION to "light"))
217217
val orm = ORMTemplate.of(dataSource, config)
218218
```
219219

docs/first-entity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ The `insertAndFetch` method sends an INSERT statement, retrieves the auto-genera
158158

159159
```kotlin
160160
// Find by ID
161-
val user: User? = orm.entity(User::class).findById(userId)
161+
val user: User? = orm.entity<User>().findById(userId)
162162

163163
// Find by field value using the metamodel (requires storm-metamodel-processor)
164164
val user: User? = orm.find { User_.email eq "alice@example.com" }

docs/getting-started.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Once `storm init` has configured your tool, you can ask it to add the right depe
4646

4747
For example:
4848
- "Add Storm to this project with Spring Boot and PostgreSQL"
49+
- "Set up Storm with Ktor and PostgreSQL"
4950
- "Create entities for the users and orders tables"
5051
- "Write a repository method that finds orders by status with pagination"
5152

docs/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ If you are a tech lead or architect evaluating Storm for a production system, th
221221

222222
1. [Storm vs Other Frameworks](comparison.md) -- feature-level comparison across frameworks
223223
2. [Spring Integration](spring-integration.md) -- Spring Boot auto-configuration, repository scanning, DI
224-
3. [Batch Processing and Streaming](batch-streaming.md) -- bulk operations and large dataset handling
224+
3. [Ktor Integration](ktor-integration.md) -- Ktor plugin, HOCON configuration, coroutine-native transactions
225+
4. [Batch Processing and Streaming](batch-streaming.md) -- bulk operations and large dataset handling
225226
4. [Testing](testing.md) -- JUnit 5 integration, statement capture, and test isolation
226227
5. [Configuration](configuration.md) -- runtime tuning, dirty checking modes, cache retention
227228
6. [Database Dialects](dialects.md) -- database-specific optimizations
@@ -230,7 +231,7 @@ If you are a tech lead or architect evaluating Storm for a production system, th
230231

231232
Storm is focused on being a great ORM and SQL template engine. It intentionally does not include:
232233

233-
- **Schema migration or DDL generation.** Storm does not create, alter, or drop tables. Use [Flyway](https://flywaydb.org/) or [Liquibase](https://www.liquibase.com/) for schema versioning and migrations.
234+
- **Schema migration or DDL generation.** Storm does not automatically create, alter, or drop tables at runtime. With Storm's [AI integration](/ai), your coding assistant can read your database schema and generate Flyway or Liquibase migration scripts on demand. For schema versioning, use [Flyway](https://flywaydb.org/) or [Liquibase](https://www.liquibase.com/).
234235
- **Second-level cache.** Storm's entity cache is transaction-scoped and cleared on commit. For cross-transaction caching, use Spring's `@Cacheable` or a dedicated cache layer like Caffeine or Redis.
235236
- **Lazy loading proxies.** Entities are plain records with no proxies. Related entities are loaded eagerly in a single query via JOINs. For deferred loading, use [Refs](refs.md) to explicitly control when related data is fetched.
236237

docs/installation.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ implementation("st.orm:storm-kotlin-spring-boot-starter")
193193
</TabItem>
194194
</Tabs>
195195

196+
### Ktor Integration
197+
198+
For Ktor applications, add the Ktor plugin module. It provides a `Storm` plugin that manages the DataSource lifecycle, reads HOCON configuration, and exposes the `ORMTemplate` through extension properties on `Application`, `ApplicationCall`, and `RoutingContext`. See [Ktor Integration](ktor-integration.md) for full setup details.
199+
200+
```kotlin
201+
implementation("st.orm:storm-ktor")
202+
```
203+
204+
For testing:
205+
206+
```kotlin
207+
testImplementation("st.orm:storm-ktor-test")
208+
```
209+
196210
### JSON Support
197211

198212
Storm supports storing and reading JSON-typed columns. Pick the module that matches your serialization library:
@@ -214,6 +228,8 @@ storm-foundation (base interfaces)
214228
└── storm-kotlin / storm-java21 (your primary dependency)
215229
├── storm-kotlin-spring / storm-spring (Spring Framework)
216230
│ └── storm-kotlin-spring-boot-starter / storm-spring-boot-starter
231+
├── storm-ktor (Ktor)
232+
│ └── storm-ktor-test (testing support)
217233
├── dialect modules (postgresql, mysql, mariadb, oracle, mssqlserver, sqlite, h2)
218234
└── JSON modules (jackson2, jackson3, kotlinx-serialization)
219235
```

0 commit comments

Comments
 (0)