From the course: Android Development Essential Training: Manage Data with Kotlin

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Define SQL operations in a DAO interface

Define SQL operations in a DAO interface

From the course: Android Development Essential Training: Manage Data with Kotlin

Start my 1-month free trial

Define SQL operations in a DAO interface

- [Instructor] After defining a database entity that is a database table, the next step is to create a DAO, or a Data Access Object interface. Typically you'll have one DAO for each entity but you can really design it however you like. The purpose of a DAO interface is to define database operations, queries, insert, update and delete operations and so on. I'll create my new interface in the data package and I'll name it Monster DAO. I'll set the kind as interface and click okay. Above the interface declaration, I'll add the DAO annotation from the Room library and now the rest of the job is simply to define each of the operations you want to support. If you want to select data from a database, you can use the query annotation and within the parenthesis, you pass in the string that you want to execute. For me that'll be a string of select astrisk from monsters. Now notice as I start typing the name of the table, it appears automatically and that's because Android Studio has been…

Contents