Giter Site home page Giter Site logo

Comments (3)

adrxn avatar adrxn commented on May 18, 2024 1

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.

Timu57 avatar Timu57 commented on May 18, 2024

@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.

adrxn avatar adrxn commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.