You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@adrxn Hi. That looks like a really nice idea.
Thank you for pointing out that the current implementation is not capable of handling such nested expressions. Do you have an idea how we could further improve on that idea and make it easier for the user? We could have a representation of the expression that looks like this in SleekDB internally, but forcing the user to handle nested arrays like that is not such I good idea I think.
Indeed maybe you have to get used to the JSON-like annotation of queries.
But the user has the freedom to make their clauses as complex as they want.
I mean, it is still possible to use something simple like : ["age", ">=", 16]
or use multiple where-clauses ...
For multiple compares (like your examples, and can be more than 2) you need to define if they should be or-ed or and-ed like:
{ "and" : [["age", ">=", 16], ["age", "<", 20]] }
The second 'and' is similar:
{ "and" : [["age", ">=", 24], ["age", "<", 28]] }
These two can be or-ed like :
{ "or" : [ { "and" : [["age", ">=", 16], ["age", "<", 20]] }, { "and" : [["age", ">=", 24], ["age", "<", 28]] }] }
And so on ...
The only other way I can think of to make complex expressions more readable for the user is to make your own expression parser to allow things like:
$store->where("(name like 'a%' or name like 'b%') and ((age >= 16 and age < 20) or (age >= 24 and age < 28))")
Activity
adrxn commentedon Jan 20, 2021
To be able to create more complex clauses with unlimited random use of 'and' and 'or' maybe the following idea.
E.g. to convert and expression like:
(name like 'a%' or name like 'b%') and ((age >= 16 and age < 20) or (age >= 24 and age < 28))
I'd like to propose the follwing JSON clause:
{
"and" : [
{
"or" : [
[ "name", "like", "a%" ],
[ "name", "like", "b%" ]
]
},
{
"or" : [
{
"and" : [
[ "age", ">=", 16 ],
[ "age", "<", 20 ]
]
},
{
"and" : [
[ "age", ">=", 24 ],
[ "age", "<", 28 ]
]
}
]
}
]
}
It will need recursive parsing.
I implemented something like that in C# once to create linq expressions dynamically.
Timu57 commentedon Jan 20, 2021
@adrxn Hi. That looks like a really nice idea.
Thank you for pointing out that the current implementation is not capable of handling such nested expressions. Do you have an idea how we could further improve on that idea and make it easier for the user? We could have a representation of the expression that looks like this in SleekDB internally, but forcing the user to handle nested arrays like that is not such I good idea I think.
adrxn commentedon Jan 20, 2021
Indeed maybe you have to get used to the JSON-like annotation of queries.
But the user has the freedom to make their clauses as complex as they want.
I mean, it is still possible to use something simple like : ["age", ">=", 16]
or use multiple where-clauses ...
For multiple compares (like your examples, and can be more than 2) you need to define if they should be or-ed or and-ed like:
{ "and" : [["age", ">=", 16], ["age", "<", 20]] }
The second 'and' is similar:
{ "and" : [["age", ">=", 24], ["age", "<", 28]] }
These two can be or-ed like :
{ "or" : [ { "and" : [["age", ">=", 16], ["age", "<", 20]] }, { "and" : [["age", ">=", 24], ["age", "<", 28]] }] }
And so on ...
The only other way I can think of to make complex expressions more readable for the user is to make your own expression parser to allow things like:
$store->where("(name like 'a%' or name like 'b%') and ((age >= 16 and age < 20) or (age >= 24 and age < 28))")
... but that will be harder for you to do ...