title: Do I have to use LiveData to read Query from Room DataBase in Android - Kotlin
body: <p>I develop a simple grocery list App using MVVM model.</p>
  
  <p>I have those files:</p>
  
  <ul>
  <li><code>Database</code> (2 Tables: Shopping Item and Reference Item) + <code>DAO</code> (unique)</li>
  <li><code>Repository</code> (Unique)</li>
  <li><code>ViewModel</code> (Unique)</li>
  <li><code>Fragment</code>/<code>Activity</code></li>
  </ul>
  
  <p>In the <code>DAO</code>, I define all my queries. Currently, all my <code>//Custom</code> queries return a <code>LiveData&lt;&gt;</code> type like this:</p>
  
  <pre><code>@Dao
  interface ShoppingDao {
  
      // Shopping Items
      @Insert(onConflict = OnConflictStrategy.REPLACE)
      suspend fun insertShoppingItem(item: ShoppingItem)
  
      @Delete
      suspend fun deleteShoppingItem(item: ShoppingItem)
  
      @Update
      suspend fun updateShoppingItem(item: ShoppingItem)
  
      @Query(value = "DELETE FROM shopping_items")
      suspend fun deleteAllShoppingItems()
  
      @Query(value = "SELECT * FROM shopping_items")
      fun getAllShoppingItem(): LiveData&lt;List&lt;ShoppingItem&gt;&gt;
  
      // Custom
      @Query(value = "SELECT COALESCE(SUM(item_amount),0) FROM shopping_items")
      fun getAllShoppingCount(): LiveData&lt;Int&gt;
  
      @Query(value = "SELECT COALESCE(SUM(item_total_price), 0.0) FROM shopping_items")
      fun getAllShoppingTotal(): LiveData&lt;Float&gt;
  </code></pre>
  
  <p>Then in the repository none of them use <code>suspend fun</code> to be called. Thus, in the ViewModel they also don't use a <code>suspend fun</code> to be called.</p>
  
  <p>I would like to use <code>getAllShoppingCount()</code> for example without using a <code>LiveData</code> with an <code>Observer</code>.</p>
  
  <p>Is it possible ?</p>
  
  <p>Is it a best practice ?</p>
  
  <p>Without the LiveData, I will have to use <code>suspend fun</code> to do my <code>Query</code>, but when I use:</p>
  
  <pre><code>fun updateShoppingItem(item: ShoppingItem) = CoroutineScope(Dispatchers.Main).launch {
      repository.updateShoppingItem(item)
  }
  </code></pre>
  
  <p>It returns a <code>Job</code> not the type the <code>Query</code> should return. How can I change that if I can use something else than <code>LiveData</code>.</p>