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

how to achieve nested filters query? #141

Closed
anjnaharsora opened this issue May 15, 2017 · 11 comments
Closed

how to achieve nested filters query? #141

anjnaharsora opened this issue May 15, 2017 · 11 comments

Comments

@anjnaharsora
Copy link

anjnaharsora commented May 15, 2017

Friends.scan({
or: [
{and: [{userRef: {eq: {id: param.user}}, friend: {eq: {id: param.friend}}}]},
{and:[{userRef: {eq: {id: param.friend}}, friend: {eq: {id: param.user}}}]}
]
}
Example.

@anjnaharsora anjnaharsora changed the title how to achieve nested filters queries? how to achieve nested filters query? May 15, 2017
@brandongoode
Copy link
Contributor

Currently, this isn't supported in Dynamooose. While DynamoDB does support this logic, it requires the use of a FilterExpression:

http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html#DDB-Scan-request-FilterExpression

Dynamoose uses the legacy ScanFilter which doesn't support nesting:

http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Scan.html#DDB-Scan-request-ScanFilter

This is something I would like to implement int he future, but haven't had the time to do.

See #65

@anjnaharsora
Copy link
Author

thanks @brandongoode

@lrcry
Copy link
Contributor

lrcry commented May 24, 2017

Hi all

I think it would be a nice idea for now that dynamoose allows raw filter in scan i.e. Model.scan(filter, options, callback) where a new option useRawAwsFilter could be added, so that we could use what is currently supported in aws-sdk.

const filter = {
  TableName: 'TestTable',
  FilterExpression: 'test.title = :title',
  ExpressionAttributeValues: {
    ':title': 'dynamotest'
  }
};
TestTable.scan(filter,{ 'useRawAwsFilter': true }).exec().then(...).catch(...)

I would like to try to fork one to see how it goes.

Regards

Hans

@lrcry lrcry mentioned this issue May 25, 2017
@brandongoode
Copy link
Contributor

@lrcry That great. I was thinking about this some over the past week and wanted to share my thoughts.

I don't think the useRawAwsFilter flag is needed. We could just assume if the filterExpression option is present then it should take priority. We need to make sure to account for attribute names. Also, in addition to passing in a filter option, I think having the scan building function too would be great.

Something like this:

GameResults
  .scan()
  .filterExpression('#s > :score')
  .expressionAttributeValues({ score : 100 })
  .expressionAttributeNames({ s : 'score'})

or

GameResults
  .scan({
    filterExpression: '#s > :score',
    expressionAttributeValues: { score : 100 },
    expressionAttributeNames: { s : 'score'}
  })

@lrcry
Copy link
Contributor

lrcry commented May 25, 2017

@brandongoode This syntax you suggested seems similar to this. BTW I got the one I raised implemented just now.

Just wondering if it is enough for now as I can see that quite a few people need the nested scan.

@brandongoode
Copy link
Contributor

Yes, it is very similar. A few minor differences around name and value definition. My goal is to have it align the current implementation of conditions (really just filter expressions) in .save - https://dynamoosejs.com/api#modelputoptions-callback--modelsaveoptions-callback.

I try to make sure all query and scans can be build using and object or the helper function.

Please go ahead and submit the PR for review. The functions can be added later.

@jderose9
Copy link

@lrcry I'm looking forward to this... thanks for the effort!

@brandongoode
Copy link
Contributor

@lrcry Do you know when you plan to have this PR ready. I'm planning to release 0.8 sometime over the next week. I would like to include this in that release if you think it will be ready.

@brandongoode brandongoode added this to the v0.8.0 milestone Jun 2, 2017
@brandongoode brandongoode mentioned this issue Jun 2, 2017
4 tasks
@lrcry
Copy link
Contributor

lrcry commented Jun 4, 2017

@brandongoode @jderose9 I'm still tackling with some problem over there. Trying to get it in v0.8. Thanks

@lrcry
Copy link
Contributor

lrcry commented Jun 4, 2017

#158

I've opened a PR here. Please feel free to tell me your thoughts.

Cheers ;)

@brandongoode
Copy link
Contributor

Closes by #158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants