Skip to content

Commit

Permalink
Apply review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cbullinger committed Aug 9, 2023
1 parent 86b8226 commit 24dce60
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import io.realm.kotlin.ext.query
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.ext.realmSetOf
import io.realm.kotlin.internal.platform.runBlocking
import io.realm.kotlin.mongodb.App
import io.realm.kotlin.mongodb.Credentials
import io.realm.kotlin.mongodb.sync.SyncConfiguration
import io.realm.kotlin.query.RealmResults
import io.realm.kotlin.types.*
import io.realm.kotlin.types.annotations.Ignore
Expand Down Expand Up @@ -309,5 +312,49 @@ class SchemaTest: RealmTest() {
Realm.deleteRealm(config)
}
}
@Test
fun test() {
class ShoppingCart: EmbeddedRealmObject {
var _id : String =""
var active: Boolean = false
var brand: String = ""
var created : RealmInstant = RealmInstant.from(0,0)
var updated : RealmInstant = RealmInstant.from(0,0)
var name : String = ""
//var positions : RealmList<Position> = realmListOf()
}
class Blegh: RealmObject {
@PrimaryKey
var _id: String = ""
var _class: String = ""

var created: RealmInstant = RealmInstant.from(0,0)
var updated: RealmInstant = RealmInstant.from(0,0)

var shoppingCart : RealmList<ShoppingCart> = realmListOf<ShoppingCart>()
}

val app = App.create(FLEXIBLE_APP_ID)
// use constants for query names, so you can edit or remove them later
val NAME_QUERY = "First query"
print(NAME_QUERY)
runBlocking {
val user = app.login(Credentials.anonymous(reuseExisting = false))
val config = SyncConfiguration.Builder(user, setOf(Blegh::class))
.initialSubscriptions { realm ->
add(
//realm.query<User>("_id.@type == 'string'"),
realm.query<Blegh>(""),
"All subscriptions"
)
}
.build()
val realm = Realm.open(config)
print("Successfully opened realm: ${realm.configuration.name}")
realm.close()
}
}


}
// :replace-end:
7 changes: 4 additions & 3 deletions source/sdk/kotlin/sync/background-sync.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ logic as a standalone connection to your backend. As a result, you'll
need to:

#. Get the Realm sync configuration for your app
#. Authenticate a user to open the realm. You can use a user's cached
credentials if the user recently used the app.
#. :ref:`Authenticate a user <kotlin-authenticate-users>` to open the realm.
You can use a user's cached credentials for a logged-in user whose
refresh token has not expired.
#. Open the realm, then use
`SyncSession.downloadAllServerChanges() <{+kotlin-sync-prefix+}io.realm.kotlin.mongodb.sync/-sync-session/download-all-server-changes.html>`__
and `SyncSession.uploadAllLocalChanges() <{+kotlin-sync-prefix+}io.realm.kotlin.mongodb.sync/-sync-session/upload-all-local-changes.html>`__
Expand Down Expand Up @@ -120,7 +121,7 @@ To create a worker that periodically performs background sync:
- If the realm frequently updates throughout the day, consider setting a repeat
interval of 1-3 hours.
- If the realm only updates a small number of times each day, it's best to
set a higher repeat interval and only background sync once or twice a day.
set a less frequent repeat interval and only background sync once or twice a day.

3. Enqueue your worker with the Android OS. Assign it a unique identifier
so that you can update the job in the future.
Expand Down

0 comments on commit 24dce60

Please sign in to comment.