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

Support queries yielding heterogeneous results #108

Merged
merged 6 commits into from Oct 13, 2020
Merged

Conversation

alextwoods
Copy link
Contributor

Issue: #107

Description of changes:
Add #multi_model_filter to BuildableSearch which takes either a passed Proc/lambda or a block. Given the raw item data that model_filter returns the class (or nil to skip) to use for that item.

Example Usage

class Model_A
  include Aws::Record
  set_table_name(TABLE_NAME)

  string_attr :uuid, hash_key: true
  string_attr :class_name, range_key: true

  string_attr :attr_a
end

class Model_B
  include Aws::Record
  set_table_name(TABLE_NAME)

  string_attr :uuid, hash_key: true
  string_attr :class_name, range_key: true

  string_attr :attr_b
end

# use multi_model_filter to create a query on TABLE_NAME
items = Model_A.build_scan.multi_model_filter do |raw_item_attributes|
  case raw_item_attributes['class_name']
  when "A" then Model_A
  when "B" then Model_B
  else
    nil
  end
end.complete!

Of note:

  • This still requires calling complete! on the query which is a little strange. But allows you to pass a lambda/proc was a parameter to multi_model_filter and use it just like any other builder function. (One alternative is to call complete! when a block is passed, but treat a passed parameter as a builder function).
  • The item data is raw - which means keys are the raw strings from the db (rather than any translated, symbolized names).

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@alextwoods alextwoods linked an issue Sep 3, 2020 that may be closed by this pull request
Copy link
Member

@awood45 awood45 left a comment

Choose a reason for hiding this comment

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

At a glance this looks pretty good. May also want to consider writing integration tests for this.

@alextwoods
Copy link
Contributor Author

Was out last week - but will pick this back up this week and add integ tests.

@alextwoods alextwoods marked this pull request as ready for review September 14, 2020 23:37
@alextwoods
Copy link
Contributor Author

Have had to prioritize other work - but returning to this now. I will merge this tomorrow unless there are any other comments.

@alextwoods alextwoods merged commit 6061abc into master Oct 13, 2020
@alextwoods alextwoods deleted the model_filter branch October 13, 2020 19:46
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.

Query yielding heterogeneous results
4 participants