Create BitsyDatabase which extends Room and created Assets Entity and Assets Dao to use in the Room db
This commit is contained in:
parent
f04708bde1
commit
e7d2719a4d
3 changed files with 78 additions and 0 deletions
|
@ -0,0 +1,17 @@
|
|||
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.Asset
|
||||
|
||||
@Dao
|
||||
interface AssetDao {
|
||||
|
||||
@Query("SELECT * FROM assets")
|
||||
fun getAllAssets(): LiveData<List<Asset>>
|
||||
|
||||
@Insert
|
||||
fun insert(asset: Asset)
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package cy.agorise.bitsybitshareswallet.daos
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import cy.agorise.bitsybitshareswallet.models.Asset
|
||||
|
||||
@Database(entities = [Asset::class], version = 1, exportSchema = false)
|
||||
abstract class BitsyDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun assetDao(): AssetDao
|
||||
|
||||
companion object {
|
||||
|
||||
// To make sure there is always only one instance of the database open
|
||||
@Volatile
|
||||
private var INSTANCE: BitsyDatabase? = null
|
||||
|
||||
internal fun getDatabase(context: Context): BitsyDatabase? {
|
||||
if (INSTANCE == null) {
|
||||
synchronized(BitsyDatabase::class.java) {
|
||||
INSTANCE = Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
BitsyDatabase::class.java, "BiTSyWallet.db"
|
||||
)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
return INSTANCE
|
||||
}
|
||||
|
||||
fun destroyInstance() {
|
||||
INSTANCE = null
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "assets")
|
||||
data class Asset(
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "id") val id: String,
|
||||
@ColumnInfo(name = "symbol") val symbol: String,
|
||||
@ColumnInfo(name = "precision") val precision: Int,
|
||||
@ColumnInfo(name = "issuer") val issuer: String,
|
||||
@ColumnInfo(name = "description") val description: String,
|
||||
@ColumnInfo(name = "max_supply") val maxSupply: Long, // TODO verify type
|
||||
@ColumnInfo(name = "market_fee_percent") val marketFeePercent: Float, // TODO verify type
|
||||
@ColumnInfo(name = "max_market_fee") val maxMarketFee: Float, // TODO verify type
|
||||
@ColumnInfo(name = "issuer_permissions") val issuerPermissions: Int,
|
||||
@ColumnInfo(name = "flags") val flags: Int,
|
||||
@ColumnInfo(name = "asset_type") val assetType: Int,
|
||||
@ColumnInfo(name = "bit_asset_id") val bitAssetId: String,
|
||||
@ColumnInfo(name = "holders_count") val holdersCount: Int
|
||||
)
|
Loading…
Reference in a new issue