Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yusukeiwaki/realm-kotlin-helpers
https://github.com/yusukeiwaki/realm-kotlin-helpers
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/yusukeiwaki/realm-kotlin-helpers
- Owner: YusukeIwaki
- Created: 2018-01-06T16:48:25.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-08T08:35:33.000Z (about 7 years ago)
- Last Synced: 2024-10-18T08:18:22.247Z (3 months ago)
- Language: Kotlin
- Size: 126 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# realm-kotlin-helpers
[realm-java-helpers](https://github.com/YusukeIwaki/realm-java-helpers)のKotlin版。
非同期書き込みのところが、従来はBolts-TaskやRxJavaを使っていたが、このライブラリではKotlinのasync/awaitを利用している。## Setup
```
repositories {
maven { url "https://dl.bintray.com/yusukeiwaki/maven" }
}dependencies {
implementation 'io.github.yusukeiwaki.realm-kotlin-helpers:realm-kotlin-helper:0.0.2'
}
```## executeTransaction
```
launch {
KtRealmHelper.executeTransaction { realm ->
realm.createObject(User::class.java, 1)
}.await()KtRealmHelper.executeTransaction { realm ->
realm.createObject(User::class.java, 2)
}.await()
}
```## read/readList
```
// read a specific user
KtRealmHelper.read { realm ->
realm.where(User::class.java).equalTo("id", userId).findFirst()
}?.let {
Log.d("RealmHelperSample", "found: User[id=${it.id}]")
}// read all users
KtRealmHelper.readList { realm ->
realm.where(User::class.java).findAll()
}.forEach {
Log.d("RealmHelperSample", "list: User[id=${it.id}]")
}
```