Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DaoGenerator code template for IntelliJ/AS
package ${PACKAGE_NAME}
#parse("File Header.java")
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Update
import androidx.room.Query
@Dao
interface ${NAME} {
@Insert
suspend fun insert(${tableName}s: List<${tableClass}>)
@Insert
suspend fun insert($tableName: ${tableClass})
@Query("SELECT * FROM $tableName")
suspend fun getAll(): List<${tableClass}>
@Query("SELECT * FROM $tableName WHERE ${idFieldName} = :id")
suspend fun get(id: ${idFieldType}): ${tableClass}
@Update
suspend fun update(${tableName}: ${tableClass})
@Query("DELETE from ${tableName}")
suspend fun deleteAll()
@Query("DELETE FROM $tableName WHERE ${idFieldName} = :id")
suspend fun delete(id: ${idFieldType}): ${tableClass}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment