Skip to content

Instantly share code, notes, and snippets.

@DHosseiny
Last active December 3, 2018 23:57
Show Gist options
  • Save DHosseiny/fbf807e80cf5669a7afd2ff65244d1dc to your computer and use it in GitHub Desktop.
Save DHosseiny/fbf807e80cf5669a7afd2ff65244d1dc to your computer and use it in GitHub Desktop.
Kotlin Extension Functions + Entity Dao
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()
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)
}
}
@DHosseiny
Copy link
Author

Using Kotlin Extension Functions with Entity Dao can provide readable code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment