Use varargs with @Insert
or @Insert
annotation.
interface ItemDao<T> { @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(entity: Item) : Long @Insert(onConflict = OnConflictStrategy.REPLACE) fun insertAll(vararg entity: Item) @Update fun update(entity: Item) @Update fun updateAll(vararg entity: Item) }
Insert multiple objects
// insert multiple itemsitemDao.insertAll(item1, item2, item3)
Convert List to varargs
// insert list of itemsval items = listOf<Item>(item1, item2, item3)itemDao.insertAll(*items.toTypedArray())
Convert Array to varargs
// insert array of itemsval items = arrayOf(item1, item2, item3)itemDao.insertAll(*items)