Answers for "how to get last inserted row id in room database android"

0

room insert and return id

class StudentRepository private constructor(private val studentDao: StudentDao)
    {

        fun getStudents() = studentDao.getStudents()

        fun insertStudent(student: Student): Single<Long>? {
            return Single.fromCallable(
                Callable<Long> { studentDao.insertStudent(student) }
            )
        }

 companion object {

        // For Singleton instantiation
        @Volatile private var instance: StudentRepository? = null

        fun getInstance(studentDao: StudentDao) =
                instance ?: synchronized(this) {
                    instance ?: StudentRepository(studentDao).also { instance = it }
                }
    }
}
Posted by: Guest on May-09-2020

Code answers related to "how to get last inserted row id in room database android"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language