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

Query support #5

Closed
jeremydaly opened this issue Dec 1, 2019 · 5 comments
Closed

Query support #5

jeremydaly opened this issue Dec 1, 2019 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jeremydaly
Copy link
Owner

Someone mentioned this to me, but I’m not sure of the correct abstraction level. If the models and types can aid in building queries, then I think this would be useful, but I don’t want to cross into ORM territory.

There are a limited set of sortKey operations, so some simple abstraction could work, but the library probably shouldn’t be parsing queries. There would likely need to be a different way to input it, and I don’t think chaining makes sense in this case (e.g. .field(‘somevalue‘).gt().value(someValue)).

This needs more feedback.

@jeremydaly jeremydaly added enhancement New feature or request help wanted Extra attention is needed labels Dec 1, 2019
This was referenced Dec 1, 2019
@tomaswisten
Copy link

Yes, querying seems to be the missing piece for my use cases as well. Thanks for a promising project!

@sreimer15
Copy link

So I've been playing around with nosql-workbench from aws and they have a concept of a "facet".

Which is the "The access patterns of the application that will interact with the table."
In that GUI
You can define a name for your facet
an alias for the partion key
and an alias for your sort key
as well as "other attributes" to include

So perhaps in your domain object you can define a "facet" with its own primary and secondary key compositions as well as aliases. That way you're encouraging the end user to think about their access patterns before hand.

Screen Shot 2020-01-02 at 8 56 53 PM

const item = { 
   globalSortKeyAlias,
   primaryKeyAlias
}

User.query("facetName", item)

Perhaps other attribute projection is not part of the MVP

What do you think? I really like what you've done and I appreciate the care you've put in to encourage best practices and single table design with dynamo db. Thank you!

@jeremydaly
Copy link
Owner Author

Thanks for the feedback and kind words @sreimer15! The access pattern/facet thing was something I was thinking about in issue #8, but that's an interesting thought to tie the two together.

I think there still needs to be a low-level querying capability, but definitely something to think of.

@DaKaZ
Copy link

DaKaZ commented Feb 16, 2020

@jeremydaly what do you think about this syntax for building the query params:

Model.query({
  pk: 'hashKey', // you would use your Model's pk definition or alias here
  index: 'gsiName', // optional, only if using a GSI with query
  limit: 10, // optional limit
  sortKey: {  // optional, if omitted the query would just be on the partition key
    operator: '=', // =, >, >=, <, <=, between, begins_with
    value: '',
    secondaryValue: '', // only used with between
    consistentRead: true, // optional, default false
  },
  filter: { // filter is optional
    key: 'keyName',
    operator: '=', // =, >, >=, <, <=, between, begins_with
    value: '',
    secondaryValue: '' // only used with between
  }
})

It seems like we could build all the syntax needed with that and it would similar syntax/methods as the get/put functionality in the library already. So a minimal example would look like:

const queryParams = MyModel.query({ pk: '123abc' })

And a more complete example:

const queryParams = MyModel.query({ 
  pk: '123abc',
  limit: 10,
  sortKey: {
    operator: 'begins_with'
    value: 'meta' // the first part of a compounded key
  }
})

DaKaZ added a commit to DaKaZ/dynamodb-toolbox that referenced this issue Feb 27, 2020
@jeremydaly
Copy link
Owner Author

Added in the v0.2 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants