Skip to content

Instantly share code, notes, and snippets.

@NsAveek
Created October 12, 2018 04:41
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 NsAveek/9a618eb4354400e043609bfa051210de to your computer and use it in GitHub Desktop.
Save NsAveek/9a618eb4354400e043609bfa051210de to your computer and use it in GitHub Desktop.
The Database class with Repository pattern
class DatabaseRepository : IStoreRepository {
private var realm: Realm = Realm.getDefaultInstance()
override fun saveStudentData(student: Student): Boolean {
try {
realm.executeTransaction {
realm.insertOrUpdate(student)
}
} catch (e: Exception) {
return false
} finally {
if (realm!=null) realm.close()
}
return true
}
override fun updateStudentData(student: Student): Int {
return 1
}
override fun deleteStudentData(student: Student): Boolean {
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment