Add missing DAOs (Data Access Object) to use with the Room database.

This commit is contained in:
Severiano Jaramillo 2018-11-01 14:57:23 -06:00
parent eed3407b7d
commit 73afded9bd
10 changed files with 59 additions and 13 deletions

View file

@ -8,7 +8,6 @@ import cy.agorise.bitsybitshareswallet.models.Asset
@Dao
interface AssetDao {
@Insert
fun insert(asset: Asset)

View file

@ -8,7 +8,6 @@ import cy.agorise.bitsybitshareswallet.models.Authority
@Dao
interface AuthorityDao {
@Insert
fun insert(authority: Authority)

View file

@ -8,7 +8,6 @@ import cy.agorise.bitsybitshareswallet.models.Balance
@Dao
interface BalanceDao {
@Insert
fun insert(balance: Balance)

View file

@ -8,23 +8,26 @@ import cy.agorise.bitsybitshareswallet.models.*
@Database(entities = [
Asset::class,
Balance::class,
UserAccount::class,
Authority::class,
UserAccountAuthority::class,
Balance::class,
BrainKey::class,
EquivalentValue::class,
Operation::class,
Transfer::class
Transfer::class,
UserAccount::class,
UserAccountAuthority::class
], version = 1, exportSchema = false)
abstract class BitsyDatabase : RoomDatabase() {
abstract fun assetDao(): AssetDao
abstract fun balanceDao(): BalanceDao
abstract fun userAccountDao(): UserAccountDao
abstract fun authorityDao(): AuthorityDao
abstract fun userAccountAuthorityDao(): UserAccountAuthorityDao
abstract fun balanceDao(): BalanceDao
abstract fun brainKeyDao(): BrainKeyDao
abstract fun equivalentValueDao(): EquivalentValueDao
abstract fun operationDao(): OperationDao
abstract fun transferDao(): TransferDao
abstract fun userAccountDao(): UserAccountDao
abstract fun userAccountAuthorityDao(): UserAccountAuthorityDao
companion object {

View file

@ -0,0 +1,16 @@
package cy.agorise.bitsybitshareswallet.daos
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import cy.agorise.bitsybitshareswallet.models.EquivalentValue
@Dao
interface EquivalentValueDao {
@Insert
fun insert(equivalentValue: EquivalentValue)
@Query("SELECT * FROM equivalent_values")
fun getAllEquivalentValues(): LiveData<List<EquivalentValue>>
}

View file

@ -0,0 +1,16 @@
package cy.agorise.bitsybitshareswallet.daos
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import cy.agorise.bitsybitshareswallet.models.Operation
@Dao
interface OperationDao {
@Insert
fun insert(operation: Operation)
@Query("SELECT * FROM operations")
fun getAllOperations(): LiveData<List<Operation>>
}

View file

@ -0,0 +1,16 @@
package cy.agorise.bitsybitshareswallet.daos
import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Query
import cy.agorise.bitsybitshareswallet.models.Transfer
@Dao
interface TransferDao {
@Insert
fun insert(transfer: Transfer)
@Query("SELECT * FROM transfers")
fun getAllTransfers(): LiveData<List<Transfer>>
}

View file

@ -8,7 +8,6 @@ import cy.agorise.bitsybitshareswallet.models.Authority
@Dao
interface UserAccountAuthorityDao {
@Insert
fun insert(userAccountAuthorityDao: UserAccountAuthorityDao)

View file

@ -8,7 +8,6 @@ import cy.agorise.bitsybitshareswallet.models.UserAccount
@Dao
interface UserAccountDao {
@Insert
fun insert(userAccount: UserAccount)

View file

@ -4,7 +4,7 @@ import androidx.room.ColumnInfo
import androidx.room.Entity
@Entity(tableName = "balances", primaryKeys = ["user_account_id", "asset_id"])
// TODO verify if we can add user_account_id as primary key
// TODO make userAccountId and assetId be ForeignKeys
data class Balance(
@ColumnInfo(name = "user_account_id") val userAccountId: String,
@ColumnInfo(name = "asset_id") val assetId: String,