英文:
Google appengine datastore filter with OR like sql (golang)
问题
我有一个结构体:
type Test struct{
Name string
Creation time.Time
User *datastore.Key
Membres []*datastore.Key
}
我想在Datastore查询中找到与此SQL查询等效的结果:
SELECT * FROM Test WHERE User=myOwnUser OR myOwnUser in(Membres)
谢谢。
英文:
I have a struct
type Test struct{
Name string
Creation time.Time
User *datastore.Key
Membres []*datastore.Key
}
I want equivalent of this sql query in datastore query
SELECT * FROM Test WHERE User=myOwnUser OR myOwnUser in(Membres)
Thank's
答案1
得分: 1
GQL提供了许多类似SQL的功能,但OR不是其中之一(参见GQL参考文档)。您可以执行两个查询并对结果进行集合交集操作。或者,您可以进行一些去规范化的操作,添加一个包含两者的UserAndMembers属性,然后只需使用一个IN查询。
英文:
GQL provides many SQL-like features, but OR isn't one of them (see GQL reference). You could do two queries and a set intersection on the results. Alternatively you could denormalize a bit and add a UserAndMembers property which contained both and then just use an IN query.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论