Skip to content

Instantly share code, notes, and snippets.

@JacquesSmuts
Last active April 25, 2019 18:17
Show Gist options
  • Save JacquesSmuts/b2419911d125845cdc701166491421e5 to your computer and use it in GitHub Desktop.
Save JacquesSmuts/b2419911d125845cdc701166491421e5 to your computer and use it in GitHub Desktop.
// In your shared domain/core module
data class User(
val id: String,
val name: String,
val surname: String,
val age: Int
)
// In your database module ONLY
@Entity(tableName = "UserTable")
internal data class UserEntity(
@PrimaryKey val id: String,
val name: String,
val surname: String,
val age: Int
) {
companion object {
fun from(user: User): UserEntity {
return UserEntity(user.id, user.name, user.surname, user.age)
}
}
fun toUser(): User {
return User(id, name, surname, age)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment