package Ġcom . ben jamin wan . ocr . nc nn Ċ Ċ import Ġandroid . icu . text . Alphabet ic Index Ċ import Ġandroidx . annotation . Worker Thread Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . as LiveData Ċ import Ġcom . ben jamin wan . ocr . nc nn . dao . Records Dao Ċ import Ġcom . ben jamin wan . ocr . nc nn . models . Records Ċ import Ġkotlinx . coroutines . flow . Flow Ċ Ċ // ĠDe cla res Ġthe ĠDAO Ġas Ġa Ġprivate Ġproperty Ġin Ġthe Ġconstructor . ĠPass Ġin Ġthe ĠDAO Ċ // Ġinstead Ġof Ġthe Ġwhole Ġdatabase , Ġbecause Ġyou Ġonly Ġneed Ġaccess Ġto Ġthe ĠDAO Ċ class ĠRecords Repository ( private Ġval ĠRecords Dao : ĠRecords Dao ) Ġ{ ĊĊĠĠĠ Ġ// ĠRoom Ġexecutes Ġall Ġqueries Ġon Ġa Ġseparate Ġthread . ĊĠĠĠ Ġ// ĠOb served ĠFlow Ġwill Ġnotify Ġthe Ġobserver Ġwhen Ġthe Ġdata Ġhas Ġchanged . ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġall Records : ĠFlow < List < Records >> ĊĊĠĠĠ Ġ// ĠBy Ġdefault ĠRoom Ġruns Ġsuspend Ġqueries Ġoff Ġthe Ġmain Ġthread , Ġtherefore , Ġwe Ġdon 't Ġneed Ġto ĊĠĠĠ Ġ// Ġimplement Ġanything Ġelse Ġto Ġensure Ġwe 're Ġnot Ġdoing Ġlong Ġrunning Ġdatabase Ġwork ĊĠĠĠ Ġ// Ġoff Ġthe Ġmain Ġthread . ĊĠĠĠ Ġ@ Suppress (" Red undant Suspend Modifier ") ĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġsuspend Ġfun Ġinsert ( Records : ĠRecords ) Ġ{ ĊĠĠĠĠĠĠĠ ĠRecords Dao . insert ( Records ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġ@ Suppress (" Red undant Suspend Modifier ") ĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġsuspend Ġfun Ġupdate ( Records : ĠRecords ) Ġ{ ĊĠĠĠĠĠĠĠ ĠRecords Dao . update ( Records ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġ@ Suppress (" Red undant Suspend Modifier ") ĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġsuspend Ġfun Ġdelete ( Records : ĠRecords ) Ġ{ ĊĠĠĠĠĠĠĠ ĠRecords Dao . delete ( Records ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suppress (" Red undant Suspend Modifier ") ĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġfun Ġselect All (): ĠFlow < List < Records >> Ġ{ ĊĠĠĠĠĠĠĠ Ġall Records Ġ= ĠRecords Dao . getAll () ĊĠĠĠĠĠĠĠ Ġreturn Ġall Records ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suppress (" Red undant Suspend Modifier ") ĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġfun Ġsearch By Address ( address : ĠString ) Ġ: ĠFlow < List < Records >> Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠRecords Dao . findBy Address ( address ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġ@ Suppress (" Red undant Suspend Modifier ") ĊĠĠĠ Ġ@ Worker Thread ĊĠĠĠ Ġfun Ġsearch By Status ( status : ĠString ) Ġ: ĠFlow < List < Records >> { ĊĠĠĠĠĠĠĠ Ġreturn ĠRecords Dao . findBy Status ( status ) ĊĠĠĠ Ġ} Ċ }