Skip to content
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

Observe query #1470

Merged
merged 35 commits into from
Sep 30, 2021
Merged

Observe query #1470

merged 35 commits into from
Sep 30, 2021

Conversation

poojamat
Copy link
Contributor

@poojamat poojamat commented Aug 30, 2021

Issue #, if available:

Description of changes:

  • Adding observe query api which
    • Return a stream that emits a snapshot with the initial data in the local DB, and subsequent snapshots containing data (items) synced from the cloud and isSynced status

    • Allow for processing updates in batches
      Sample Kotlin code:
      private fun observeQuery() {
      val tag = "ObserveQuery"
      val onQuerySnapshot: Consumer<DataStoreQuerySnapshot> =
      Consumer<DataStoreQuerySnapshot> { value: DataStoreQuerySnapshot ->
      Log.d(tag, "success on snapshot")
      Log.d(tag, "num records: " + value.items.size)
      Log.d(tag, "sync status: " + value.isSynced)
      }

      val observationStarted =
      Consumer { _: Cancelable ->
      Log.d(tag, "success on cancelable")
      }
      val onObservationError =
      Consumer { value: DataStoreException ->
      Log.d(tag, "error on snapshot$value")
      }
      val onObservationComplete = Action {
      Log.d(tag, "complete")
      }

      val predicate: QueryPredicate =
      NAME.contains("1").or(NAME.contains("2")).or(NAME.contains("3"))
      val QuerySortBy = QuerySortBy("car", "name", QuerySortOrder.ASCENDING)

      val options = ObserveQueryOptions(predicate, listOf(QuerySortBy))
      Amplify.DataStore.observeQuery(
      Blog::class.java,
      options,
      observationStarted,
      onQuerySnapshot,
      onObservationError,
      onObservationComplete
      )
      }
      By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@poojamat poojamat requested a review from a team August 30, 2021 17:28
@poojamat poojamat marked this pull request as draft August 30, 2021 17:28
@poojamat poojamat marked this pull request as ready for review September 10, 2021 21:06
Copy link
Contributor

@rjuliano rjuliano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple of comments, but it LGTM!

# Conflicts:
#	aws-datastore/src/androidTest/java/com/amplifyframework/datastore/storage/sqlite/ModelUpgradeSQLiteInstrumentedTest.java
#	aws-datastore/src/main/java/com/amplifyframework/datastore/storage/sqlite/SQLiteStorageAdapter.java
#	settings.gradle
@poojamat poojamat changed the base branch from observe-query-main to main September 29, 2021 18:36
@poojamat poojamat merged commit 4532bc6 into main Sep 30, 2021
@poojamat poojamat deleted the observe-query branch September 30, 2021 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants