Last active
December 3, 2018 23:57
-
-
Save DHosseiny/fbf807e80cf5669a7afd2ff65244d1dc to your computer and use it in GitHub Desktop.
Kotlin Extension Functions + Entity Dao
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
import com.example.db.ConversationDao.Properties.Mid | |
import com.example.db.UserDao.Properties.Username | |
fun UserDao.getByUsername(username: String): User = | |
queryBuilder().where(Username.eq(username)).unique() | |
fun MessageDao.getMessage(mid: Long): Message = | |
queryBuilder().where(Mid.eq(mid)).unique() |
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
import com.example.db.getByUsername | |
import com.example.db.getMessage | |
/** | |
* Created by Davud. | |
*/ | |
class MainActivity : Activity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
var user = DatabaseManager.userDao.getByUsername("David") | |
var message = DatabaseManager.messageDao.getMessage(3) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using Kotlin Extension Functions with Entity Dao can provide readable code.