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

Fix comparisons to nil in queries & make such queries explicit #46

Merged

Conversation

hibachrach
Copy link
Contributor

Continuation/migration of luckyframework/lucky_record#289. See there for details.

Closes #38.

Will now throw an error at compile-time if one writes something like:
```
UserQuery::BaseQuery.nickname.is(nil)
```

The methods `is?`/`is_not?` exist for comparing to possibly `nil`
values.
`IS NULL`/`IS NOT NULL` is kind of a special case, so this makes a bit
more sense.
@hibachrach
Copy link
Contributor Author

@paulcsmith Continuing on some questions from the previous PR:

And actually I'm wondering if we even need is_not since we have .not.eq and .not.nilable_eq.

I think you're totally right here. Let's get rid of them. Do we want to eliminate not(value) as well?

The question mark already indicates "returns Bool" or "can return Nil",
so it makes sense not to overload it with a third additional meaning

This also eliminates `is_not`/`is_not?` as they are redundant--one can
simply use `.not.eq`/`.not.nillable_eq` instead.
@paulcsmith
Copy link
Member

Hmm great question. I kind of like the shorthand “not” method. But at the same time I like the explicitness of “not.eq”

I think we should try removing it and we can add it back later if we get sick of typing “not.eq”. Does that sound good?

@hibachrach
Copy link
Contributor Author

Sounds grrrrreaaat!

image

This was simply a shortcut for `Avram::Criteria#not.eq(T)`, which is not
significantly longer and is a bit clearer.
Copy link
Member

@paulcsmith paulcsmith left a comment

Choose a reason for hiding this comment

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

Just one tiny comment. This looks awesome! Could you also add something to the change log for Lucky? https://github.com/luckyframework/lucky/blob/master/CHANGELOG.md#in-master-but-no-released-since-v012

Something like:

is in queries has been renamed to eq. For example: UserQuery.new.name.not.is("Emily") should now be UserQuery.new.name.not.eq("Emily")

def not(value) : T
is_not(value)
def nilable_eq(value)
add_clause(Avram::Where::Equal.new(column, V::Lucky.to_db!(value)))
Copy link
Member

Choose a reason for hiding this comment

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

I think this might make more sense with the method body swapped with eq. So this method body would replace eq and this method (nilable_eq(value)) would call eq(value). Does that make sense?

It makes sense to have `eq` have the primary business logic here
@hibachrach
Copy link
Contributor Author

@paulcsmith Should I open up a separate pull request for that?

@paulcsmith
Copy link
Member

@HarrisonB Yes that'd be great! It would be on the Lucky repo and not Avram. I'm trying to keep all Lucky framework relevant changes there so people using master now what changed and so when I make upgrade notes I don't forget anything :P

@paulcsmith paulcsmith merged commit 048a16a into luckyframework:master Feb 6, 2019
@paulcsmith
Copy link
Member

Thanks for tackling this 🎉 :D

@hibachrach hibachrach deleted the hib-make-nil-queries-explicit branch February 6, 2019 17:43
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