-
Notifications
You must be signed in to change notification settings - Fork 608
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(core): migrate from dbflow to room for client #2300
base: kmp-impl
Are you sure you want to change the base?
Changes from all commits
8c972ad
8d10daa
4b24e68
987119e
a4299e0
4e1ecdb
2f3b52b
1fedc46
054d4f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2025 Mifos Initiative | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.room.dao | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import androidx.room.Transaction | ||
import androidx.room.Update | ||
import com.mifos.core.model.objects.clients.Page | ||
import com.mifos.room.entities.accounts.ClientAccounts | ||
import com.mifos.room.entities.accounts.loans.LoanAccount | ||
import com.mifos.room.entities.accounts.savings.SavingsAccount | ||
import com.mifos.room.entities.client.Client | ||
import com.mifos.room.entities.client.ClientPayload | ||
import com.mifos.room.entities.group.GroupWithAssociations | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface ClientDao { | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun saveClient(client: Client) | ||
|
||
@Query("SELECT * FROM Client") | ||
fun readAllClients(): Flow<Page<Client>> | ||
|
||
@Query("SELECT * FROM GroupTable WHERE id = :groupId") | ||
fun getGroupAssociateClients(groupId: Int): Flow<GroupWithAssociations> | ||
|
||
@Query("SELECT * FROM Client WHERE id = :clientId LIMIT 1") | ||
fun getClient(clientId: Int): Flow<Client> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
fun saveClientAccounts( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Save, delete and update should be a suspend function always There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does your statement hold true even when the function returns a flow? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
clientAccounts: ClientAccounts, | ||
clientId: Int, | ||
): Flow<ClientAccounts> | ||
|
||
@Query("SELECT * FROM LoanAccount WHERE clientId = :clientId") | ||
fun getLoanAccounts(clientId: Long): Flow<List<LoanAccount>> | ||
|
||
@Query("SELECT * FROM SavingsAccount WHERE clientId = :clientId") | ||
fun getSavingsAccounts(clientId: Long): Flow<List<SavingsAccount>> | ||
|
||
// TODO add readClientAccounts, use combine | ||
|
||
// TODO saveClientTemplate | ||
|
||
// TODO readClientTemplate | ||
|
||
// TODO saveClientPayloadToDB | ||
|
||
// TODO readClientPayloadFromDB | ||
|
||
// TODO deleteClientPayload | ||
|
||
@Query("DELETE FROM ClientPayload WHERE id = :id") | ||
fun deleteClientPayloadById(id: Int) | ||
|
||
@Query("DELETE FROM DataTablePayload WHERE clientCreationTime = :clientCreationTime") | ||
fun deleteDataTablePayloadByTime(clientCreationTime: Long) | ||
|
||
@Transaction | ||
fun deleteClientPayload(id: Int, clientCreationTime: Long): Flow<List<ClientPayload>> | ||
|
||
@Update | ||
suspend fun updateDatabaseClientPayload(clientPayload: ClientPayload): Flow<ClientPayload> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove Flow from here. Don't use Flow in dao unless we are retrieving list. Check the entire DAO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@biplab1 my apologies. Ignore the previous comment.
Check if we need a single item. If yes add 'LIMIT 1`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In DatabaseHelperClient.kt, this function was returning
Observable<GroupWithAssociations>
, so it was changed toFlow<GroupWithAssociations>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@biplab1 This is the function right?
it should be this instead