ScopeNotes.kt (876B) - raw


      1 package me.rhunk.snapenhance.storage
      2 
      3 import androidx.core.database.getStringOrNull
      4 
      5 fun AppDatabase.getScopeNotes(id: String): String? {
      6     return database.rawQuery("SELECT content FROM notes WHERE id = ?", arrayOf(id)).use {
      7         if (it.moveToNext()) {
      8             it.getStringOrNull(0)
      9         } else {
     10             null
     11         }
     12     }
     13 }
     14 
     15 fun AppDatabase.setScopeNotes(id: String, content: String?) {
     16     if (content == null || content.isEmpty() == true) {
     17         executeAsync {
     18             database.execSQL("DELETE FROM notes WHERE id = ?", arrayOf(id))
     19         }
     20         return
     21     }
     22 
     23     executeAsync {
     24         database.execSQL("INSERT OR REPLACE INTO notes (id, content) VALUES (?, ?)", arrayOf(id, content))
     25     }
     26 }
     27 
     28 fun AppDatabase.deleteScopeNotes(id: String) {
     29     executeAsync {
     30         database.execSQL("DELETE FROM notes WHERE id = ?", arrayOf(id))
     31     }
     32 }