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

More criteria functions #1010

Merged
merged 6 commits into from
Mar 11, 2024
Merged

More criteria functions #1010

merged 6 commits into from
Mar 11, 2024

Conversation

jwoertink
Copy link
Member

I was having a little fun and decided to add just a few more I thought may be helpful.

This adds a few extra Criteria functions

  • LENGTH()
  • REVERSE()
  • ABS()
  • CEIL()
  • FLOOR()
# Find all users that have a username length of 6 characters
UserQuery.new.username.length.eq(6)

# Find all users where the secret in reverse is equal to "terces"
UserQuery.new.secret.reverse.eq("terces")

# Find all transactions where the abs amount is 400 (i.e. matches 400 and -400)
TransactionQuery.new.amount.abs.eq(400)

# Find all purchases where the amount rounded up is equal to 40.0
PurchaseQuery.new.amount.ceil.eq(40.0)

# Find all purchases where the amount rounded down is equal to 30.0
PurchaseQuery.new.amount.floor.eq(30.0)

Comment on lines +74 to +75
define_function_criteria(ceil, V)
define_function_criteria(floor, V)
Copy link
Member Author

Choose a reason for hiding this comment

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

Although in postgres the value looks like an integer when using these, the type is numeric which maps to Float64 in Crystal.

@jwoertink jwoertink merged commit d8909ef into main Mar 11, 2024
9 checks passed
@jwoertink jwoertink deleted the more_criteria_functions branch March 11, 2024 14:50
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.

1 participant