所以我有这个问题 https://stackoverflow.com/questions/72058075/go-boltdb-query-using-bolthold之前,我在问题下面有一个有效的答案,但我刚刚意识到我提出的查询没有按计划工作。
基本上现在如果它像这样工作
(if the roleskey contains any of the roles in slice) and (if the tenantID is an empty string) or (if tenantIDKey is equal to tenantID)
但我需要的是
(if the roleskey contains any of the roles in slice) AND (if the tenantID is an empty string OR if tenantIDKey is equal to tenantID)
这是我当前的查询:
query := bolthold.Where(roleskey).ContainsAny(bolthold.Slice(roles)...).And(tenantIDKey).Eq("").Or(bolthold.Where(tenantIDKey).Eq(tenantID))
有谁知道如何解决这个问题?
Try:
query := bolthold.
Where(tenantIDKey).Eq("").
Or(
bolthold.
Where(tenantIDKey).
Eq(tenantID)
).
And(roleskey).
ContainsAny(bolthold.Slice(roles)...)
Or
query := bolthold.
Where(tenantIDKey).ContainsAny("", tenantID).
And(roleskey).
ContainsAny(bolthold.Slice(roles)...)
Or
query := bolthold.
Where(tenantIDKey).In("", tenantID).
And(roleskey).
ContainsAny(bolthold.Slice(roles)...)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)