Emulating the OR condition in the data warehouse

I am using Google App Engine with Python (Django). How to emulate "SELECT * FROM bla WHERE touser = common.userstats("key") OR fromuser = common.userstats("key") ORDER BY date ASC"

?

I was thinking of something similar, but I cannot get it in the order I want.

    recievedlist = models.P1.all()
    recievedlist.filter("touser =", common.userstats("key"))
    plus1list = recievedlist.fetch(50)

    sendlist = models.P1.all()
    sendlist.filter("fromuser =", common.userstats("key"))
    plus1list += sendlist.fetch(50)

    # order plus1list

      

+2


a source to share


1 answer


You can add ListProperty

to your model which contains both touser

and fromuser

. Then you can run one query to retrieve the entities you are interested in sorted by date. This removes the datastore query and in-memory sorting, but costs you an extra index and a little more storage space on your model.

(pseudo) Example:

class bla(db.Model):
    ...
    toandfromuser = db.ListProperty(...)

      



Then you can make a query like this (since the object will match if the ANY list item toandfromuser

matches the value you want):

SELECT * FROM bla WHERE toandfromuser = common.userstats("key") ORDER BY date ASC

      

+2


a source







All Articles