Restream / reindexer

Embeddable, in-memory, document-oriented database with a high-level Query builder interface.

Home Page:https://reindexer.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How Query.Or() works?

yaxinr opened this issue · comments

This do not work how i assume

 _, found := db.Query("goal").
 WhereInt64("id", reindexer.SET, root.Nodes...).
 WhereInt64("parent_updated_at", reindexer.GT, root.UpdatedAt).
 Or().
 WhereInt64("parent", reindexer.SET, root.Nodes...).
 WhereInt64("parent_updated_at", reindexer.GT, root.UpdatedAt).
 Get()

This work

 _, found := db.Query("goal").
   WhereInt64("id", reindexer.SET, root.Nodes...).
   WhereInt64("parent_updated_at", reindexer.GT, root.UpdatedAt).
   Get()
_, found2 := db.Query("goal").
   WhereInt64("parent", reindexer.SET, root.Nodes...).
   WhereInt64("parent_updated_at", reindexer.GT, root.UpdatedAt).
   Get()

if found || found2 {
}

In your case it can be:

_, found := db.Query("goal").
 WhereInt64("id", reindexer.SET, root.Nodes...).Or().WhereInt64("parent", reindexer.SET, root.Nodes...).
 WhereInt64("parent_updated_at", reindexer.GT, root.UpdatedAt).
 Get()

At the moment there is no parentheses implementation like in SQL foo="1" AND (foo="2" OR bar="3"), so the Or()/Not() operator only affects the next operator as far as I understand.

Hi.
In version 2.1.0 there are query brackets functional has been implemented.
So, now it is possible to write this query:

OpenBracket().
WhereInt64("id", reindexer.SET, root.Nodes...).
 WhereInt64("parent_updated_at", reindexer.GT, root.UpdatedAt).
CloseBracket().
 Or().
OpenBracket().
 WhereInt64("parent", reindexer.SET, root.Nodes...).
 WhereInt64("parent_updated_at", reindexer.GT, root.UpdatedAt).
CloseBracket()