sebelga / gstore-node

Google Datastore Entities Modeling for Node.js
Apache License 2.0
292 stars 53 forks source link

query filter on nested property value. #222

Open jeffj6123 opened 4 years ago

jeffj6123 commented 4 years ago

Is there a proper way to query on a nested property like this example below.

` interface KeyValue { key: string; value: string; }

interface KeyValueContainer { container: KeyValue[]; }

// Pass it on Schema creation const schema = new Schema({ container: { type: Array, optional: false }, });

const Kvc = gstore.model('KVC', schema);

Kvc.query().filter("container.key", "=", "test"); ` At the last line I get Argument of type '"container.key"' is not assignable to parameter of type '"container"'.ts(2345)

it looks like the filter only accepts the top level properties. Is there a way to handle this query in gstore-node or do I need to drop down to the base google cloud library?

Like I can drop <any> in front of the "container.key" string to remove the error but that feels like a weak solution.

sebelga commented 4 years ago

Hi @jeffj6123, sorry for the late answer!

Do you have an example on the Google doc (https://googleapis.dev/nodejs/datastore/latest/index.html) where it filters by an Array item and then property of the object? So I can understand better what you are trying to do. Cheers! 👍

jeffj6123 commented 4 years ago

Hey, @sebelga I am trying exactly where they mention it in their docs, but here is a reference to other people talking about it https://stackoverflow.com/questions/37290722/filter-entities-on-a-sub-entity-property-in-google-datastore-query . I have originally gotten familiar with it by using the python NDB where it allows for that.

jeffj6123 commented 3 years ago

Hey I wondered if there are any updates here?

sebelga commented 3 years ago

Hello, sorry for the late answer. I don't have the bandwidth to work currently on the project but there is a new maintainer who will be taking the lead shortly. I am going to label this issue as feature request and hopefully, we will be able to look into this.

In the short term, if by adding any you manage to make the query work, that's an acceptable solution 😊

dmk1111 commented 2 years ago

Hey, @jeffj6123 You can pass options with filter on nested properties: Знімок екрана 2021-11-18 о 12 26 43