Last active
April 25, 2019 18:17
-
-
Save JacquesSmuts/b2419911d125845cdc701166491421e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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