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

filter operators #32

Closed
wants to merge 11 commits into from
Closed

Conversation

Evertt
Copy link
Contributor

@Evertt Evertt commented May 13, 2016

Now you can make a filter like so:

let formatter = NSDateFormatter()
formatter.dateFormat = "dd-MM-yyyy"
let birthday = formatter.dateFromString("03-11-1990")!

let filter: Filter = ("name" == "Evert" && "age" > 18) || ("id" =~ 1...5 && "birthday" < birthday)

print(filter)

Which would print ((name = Evert and age > 18) or (id in [1, 2, 3, 4, 5] and birthday < 1990-11-03))

This is just to show you a work in progress. I didn't update any of the other code to work with this change. So in its current form Fluent would not compile.

I just wanted to ask you guys how you like it so far. So er.. how do you like it so far? ^_^

If you guys approve then I would like to continue to change the Query class so you can just do something like:

let users: [User] = Query().filter("age" > 18 && "subscribed" == true).orderBy("name", .asc).all()

Now you can make a filter like so:

    let filter: Filter = "name" == "Evert" && id ~= 1…5

Which would print as:

    (name = Evert and id in [1, 2, 3, 4, 5])
@Evertt Evertt added the enhancement New feature or request label May 13, 2016
@Evertt Evertt mentioned this pull request May 13, 2016
@Evertt Evertt mentioned this pull request May 16, 2016
@tanner0101 tanner0101 changed the title Pretty filter building filter operators May 18, 2016
@tanner0101
Copy link
Member

I really like this addition. I'm close to merging a refactor to Fluent and we can add this to it afterward.

@Evertt
Copy link
Contributor Author

Evertt commented May 18, 2016

Cool, happy to hear this work was not for nothing. @Joannis also suggested on Slack to add 3 more filters, namely .all([Filter]), .any([Filter]), and .none([Filter]). Because with .and and .either you can only add 2 filters at a time. And I agree, it's a nice addition. Of course there are no overloadable operators for those filters, but as was said in another thread, not everyone will be using the operators anyway.

@Evertt
Copy link
Contributor Author

Evertt commented May 26, 2016

Or what we could also do is not add .all, .any and .none to Filter, but do add them as functions to Query, where Query would then translate them to filter using the .not, .both and .either cases.

@tanner0101
Copy link
Member

Let's revisit #33. The query model has changed significantly since May.

@tanner0101 tanner0101 closed this Aug 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants