← Back to Stormify Documentation

Stormify

open class Stormify(val dataSource: DataSource, registrars: EntityRegistrar)

The main ORM controller. Entry point for all database operations.

Parameters

dataSource

the data source for all database operations

registrars

optional entity registrars to register at construction time

Constructors

Link copied to clipboard
constructor(dataSource: DataSource, vararg registrars: EntityRegistrar)

Types

Link copied to clipboard
object Companion

Holds the library-wide defaultInstance used when no instance is explicitly attached.

Properties

Link copied to clipboard
val dataSource: DataSource
Link copied to clipboard

When enabled, throws on field/column mismatches; when disabled, logs warnings.

Link copied to clipboard
var logger: Logger

The logger used by this Stormify instance. Defaults to a logger named "Stormify".

Link copied to clipboard

The naming policy used to convert Kotlin property names to database column names. Default is NamingPolicy.LOWER_CASE_WITH_UNDERSCORES (snake_case). Changing this only affects entities resolved after the change.

Link copied to clipboard

The SQL dialect used by this Stormify instance. Auto-detected from the data source on first access. Can be set manually for proxy scenarios where auto-detection fails.

Functions

Link copied to clipboard

Excludes a field name from all entity mappings (e.g. inherited fields that have no database column).

Link copied to clipboard

Sets this instance as defaultInstance and returns it.

fun <R> asDefault(block: (Stormify) -> R): R

Runs block with this instance as the default, restoring the previous default when the block exits. Use for scoped overrides such as per-request tenants.

Link copied to clipboard
fun <T : StormifyAware> attach(target: T): T

Attaches this Stormify instance to target so the target can use it for database operations without receiving it as an explicit parameter.

Link copied to clipboard
fun <T : Any> create(item: T): T

Inserts a new entity into the database and returns it with generated values populated.

fun <T : Any> create(items: Collection<T>): List<T>

Inserts multiple entities in a batch and returns them. Generated keys are only populated for single-item batches.

Link copied to clipboard
fun <T : Any> delete(deletedItem: T)

Deletes an entity from the database based on its primary key.

fun <T : Any> delete(items: Collection<T>)

Deletes multiple entities from the database based on their primary keys.

Link copied to clipboard
fun executeUpdate(query: String, vararg params: Any?): Int

Executes an SQL UPDATE/INSERT/DELETE and returns the number of affected rows.

Link copied to clipboard
inline fun <T : Any> findAll(whereClause: String = "", vararg arguments: Any?): List<T>

Finds all entities, optionally filtered by a WHERE clause.

Link copied to clipboard
inline fun <T : Any> findById(id: Any): T?

Finds a single entity by its primary key value (single PK only).

Link copied to clipboard
inline fun <D : Any> getDetails(parent: Any, propertyName: String? = null): List<D>

Retrieves all detail (child) entities related to a parent entity through a foreign key.

inline fun <D : Any> getDetails(parent: Any, referenceField: ReferencePath): List<D>

Type-safe variant of getDetails that accepts an annotation-processor-generated reference path (e.g. Paths.AuditEntry_.createdBy) instead of a string. The compiler guarantees the referenced property exists on the child type, so typos and renames surface at build time rather than on first query.

Link copied to clipboard
fun <T : Any> getTableInfo(kclass: KClass<T>): TableInfo<T>

Returns the TableInfo metadata for the given entity class, resolving and caching it if necessary.

Link copied to clipboard
fun <T : Any> populate(entity: T): T

Refreshes an entity with fresh data from the database based on its primary key.

Link copied to clipboard
fun procedure(name: String, vararg args: Any?)

Executes a stored procedure with IN / OUT / INOUT parameters.

Link copied to clipboard
inline fun <T : Any> read(query: String, vararg params: Any?): List<T>

Executes a SELECT query and returns all results as a list.

Link copied to clipboard
inline fun <T : Any> readCursor(query: String, vararg params: Any?, noinline consumer: (T) -> Unit): Int

Executes a SELECT query and processes results row-by-row via consumer. Returns row count.

Link copied to clipboard
inline fun <T : Any> readOne(query: String, vararg params: Any?): T?

Executes a SELECT query and returns exactly one result, or null if none found.

Link copied to clipboard
fun registerPrimaryKeyResolver(priority: Int, resolver: (String, String) -> Boolean)

Registers a primary key resolver used when no @Id or @DbField(primaryKey=true) annotation is present. The resolver receives the table name and field name and returns true if the field is a primary key. Lower priority values are evaluated first.

Link copied to clipboard

Removes a previously blacklisted field name, allowing it to be mapped again.

Link copied to clipboard
fun Stormify.suspending(config: PoolConfig = PoolConfig()): SuspendStormify

Wraps this Stormify instance with a coroutine-aware transaction API backed by a DefaultSuspendConnectionPool configured with config. Safe to call multiple times with different configs; each returned SuspendStormify is independent.

Link copied to clipboard

Executes a block within a database transaction with automatic commit/rollback.

Link copied to clipboard
fun <T : Any> update(updatedItem: T): T

Updates an existing entity in the database based on its primary key.

fun <T : Any> update(items: Collection<T>): List<T>

Updates multiple entities in a batch based on their primary keys.