← Back to Stormify Documentation

db

class db<T>(defaultValue: T) : ReadWriteProperty<Any?, T>

Property delegate that triggers auto-population from the database on first access. Use with AutoTable entities: properties delegated to db will lazily load the entity's data when read or written for the first time.

class User : AutoTable() {
var name: String by db("")
}

Constructors

Link copied to clipboard
constructor(defaultValue: T)

Functions

Link copied to clipboard
open operator override fun getValue(thisRef: Any?, property: KProperty<*>): T

Delegate read: triggers lazy-load from the database on first access when the entity is a AutoTable stub (i.e. only its primary key is set and no db field has been written yet). Otherwise returns the in-memory value.

Link copied to clipboard
open operator override fun setValue(thisRef: Any?, property: KProperty<*>, value: T)

Delegate write: marks the owning AutoTable as user-touched so it is no longer considered a stub (which prevents a subsequent read from triggering lazy-load), then stores the new value in memory. No immediate database write.