aws-amplify / amplify-swift

A declarative library for application development using cloud services.
Apache License 2.0
458 stars 198 forks source link

Add ability to write a predicate based on properties of an embedded collection. #2984

Open sscheetz opened 1 year ago

sscheetz commented 1 year ago

Is your feature request related to a problem? Please describe.

I have a model that looks like

public struct Queue: Model {
   public let id: String
   public var customerId: String
   public var queueSeeds: [QueueSeed]?

where queueSeeds is an EmbeddedCollection.

I would like to be able to delete rows in the cloud datastore based on if any of the queueSeeds have a certain property set to true, but it isn't possible to write a predicate for that.

I think there is a workaround of querying all Queues for the customer, filtering queueIds in memory, then deleting the correct queueIds but I don't want to fill up the local database with queues that aren't being deleted.

Describe the solution you'd like

I would like a way to build a predicate based on the EmbeddedCollection. I believe dynamo would support this query naturally.

Describe alternatives you've considered

Querying all Queues, filtering locally, deleting correct queueIds, but I don't want to fill the local cache with data that will never be deleted.

Is the feature request related to any of the existing Amplify categories?

DataStore

Additional context

No response

github-actions[bot] commented 1 year ago

This has been identified as a feature request. If this feature is important to you, we strongly encourage you to give a 👍 reaction on the request. This helps us prioritize new features most important to you. Thank you!

lawmicha commented 1 year ago

Hi @sscheetz, I believe the Amplify.DataStore.delete(ModelType, condition) operation queries the local database given the condition, finds all rows that are to be deleted, queues them up as Mutation Events to the AppSync, and removes them locally. Your workaround would work in that it will pull the Queues into memory, and the local database will already have the Queues.

I can see that the problem here is that you can't specify a condition based on the queueSeeds property, can you confirm that this is the feature request you're looking for?

Amplify.DataStore.delete(Queue.self, condition: Queue.keys.queueSeeds.someProperty.eqs(true))
diogoAntunes commented 11 months ago

Yeah this would be great, having the ability to query based on a condition of a embedded collection

Amplify.DataStore.delete(Queue.self, condition: Queue.keys.queueSeeds.someProperty.eqs(true))