Skip to content

Various enhancements#41

Open
heythisisnate wants to merge 5 commits intorubyonjets:masterfrom
konnected-io:master
Open

Various enhancements#41
heythisisnate wants to merge 5 commits intorubyonjets:masterfrom
konnected-io:master

Conversation

@heythisisnate
Copy link
Collaborator

@heythisisnate heythisisnate commented May 6, 2025

I've been using Jets with Dynomite for my company's cloud platform for years and going through an upgrade to Jets v5 and Dynomite v2. This PR includes various fixes/tweaks needed to Dynomite as I upgrade a fairly large application and work through the test suite.

Use expression_attribute_names when checking for uniqueness on create

When creating a new record, put_item is called with condition_expression: "attribute_not_exists(primary_key)" to validate uniqueness and raise if a record already exists. In the case where primary_key is a Reserved Word in DynamoDb this will fail with an Invalid ConditionExpression error.

This change utilizes the Expression attribute names to alias the primary key attribute name so that it will generate a valid condition expression even if it is a reserved word.

Use a key condition on tables with composite key if at least partition key is present

If a table is defined with a composite key (partition key and sort key), Dynomite reverts to doing a scan operation if you try to query with just the partition key. It is possible to use a key condition when only the partition key is present, and it avoids an expensive scan operation.

nil is a Falsey value in Typecaster

When casting a boolean field, nil is now considered a Falsey value.

Comments/questions

@tongueroo are the tests working in this repo? How to setup and run a test environment? I get errors when running bundle exec rspec spec and the examples don't even run. I will add tests if I can get them running.

@tongueroo
Copy link
Collaborator

Off the top of my head. I think when I run rspec I either use:

Hope that helps for now. You can merge whenever you feel good about it though

@heythisisnate
Copy link
Collaborator Author

@tongueroo I have dynamodb local, that's not the problem. I just don't see any test db schema or connection info in the repo. Is there a manual setup to set up the test db for the first time? I get these weird errors when running rspec:

An error occurred while loading ./spec/dynomite/item/callbacks_spec.rb.
Failure/Error: before_initialize :initialize_hook

NoMethodError:
  undefined method `before_initialize' for CallbacksTester:Class
# ./spec/dynomite/item/callbacks_spec.rb:4:in `<class:CallbacksTester>'
# ./spec/dynomite/item/callbacks_spec.rb:1:in `<top (required)>'

An error occurred while loading ./spec/dynomite/migration/dsl/global_secondary_index_spec.rb.
Failure/Error: GSI = Dynomite::Migration::Dsl::GlobalSecondaryIndex

NameError:
  uninitialized constant Dynomite::Migration::Dsl::GlobalSecondaryIndex
# ./spec/dynomite/migration/dsl/global_secondary_index_spec.rb:1:in `<top (required)>'

An error occurred while loading ./spec/dynomite/migration/dsl/local_secondary_index_spec.rb.
Failure/Error: LSI = Dynomite::Migration::Dsl::LocalSecondaryIndex

NameError:
  uninitialized constant Dynomite::Migration::Dsl::LocalSecondaryIndex
# ./spec/dynomite/migration/dsl/local_secondary_index_spec.rb:1:in `<top (required)>'

Finished in 0.00003 seconds (files took 0.55144 seconds to load)
0 examples, 0 failures, 3 errors occurred outside of examples

thanks for the push access!

@heythisisnate heythisisnate changed the title Use expression_attribute_names when checking for uniqueness on create Various enhancements May 14, 2025
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.

2 participants