Skip to content

Instantly share code, notes, and snippets.

@pjagielski
Last active February 11, 2019 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjagielski/8db8be309a10ec90fc7cea6d7f413223 to your computer and use it in GitHub Desktop.
Save pjagielski/8db8be309a10ec90fc7cea6d7f413223 to your computer and use it in GitHub Desktop.
sealed class UserId : RefId<Long>() {
object New : UserId() {
override val value: Long by IdNotPersistedDelegate<Long>()
}
data class Persisted(override val value: Long) : UserId() {
override fun toString() = "UserId(value=$value)"
}
}
data class User(
val id: UserId = UserId.New,
//...
)
fun Table.userId(name: String) = longWrapper<UserId>(name, UserId::Persisted, UserId::value)
object UserTable : Table("users") {
val id = userId("id").primaryKey().autoIncrement()
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment