Comments (3)
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.
from sleekdb.
@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.
from sleekdb.
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 ...
from sleekdb.
Related Issues (20)
- Math & Logic operations HOT 2
- nested column select and distinct return empty array HOT 3
- simple join approach
- SleekDB Extension of builtin "named functions" by users
- Allow to use UUIDs as primary keys HOT 2
- How to Run SleekDB HOT 4
- JSON Wildcard Notation HOT 2
- Incorrect escaping of characters?
- Select with alias at join HOT 5
- Class 'SleekDB\Store' not found HOT 2
- how we do search with join HOT 6
- Searching for value in array. HOT 2
- [Feature Request] Simple key-value lookup HOT 1
- [Feature Request] Searching from multiple stores HOT 1
- [SUGGESTION] please set config:timeout default to false HOT 2
- How to set special chars? HOT 7
- Use SleekDB as a readonly store HOT 2
- updateById method undefined HOT 3
- Group by Date
- replace file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sleekdb.