ent 基本使用十八 查询谓词

ent 生成的代码包含了比较完整的查询谓词

字段谓词

  • Bool:
    • =, !=
  • Numeric:
    • =, !=, >, <, >=, <=,
    • IN, NOT IN
  • Time:
    • =, !=, >, <, >=, <=
    • IN, NOT IN
  • String:
    • =, !=, >, <, >=, <=
    • IN, NOT IN
    • Contains, HasPrefix, HasSuffix
    • ContainsFold, EqualFold (SQL specific)
  • Optional fields:
    • IsNil, NotNil

edge 谓词

  • HasEdge
 client.Pet.
      Query().
      Where(user.HasOwner()).
      All(ctx)
 
  • HasEdgeWith
 client.Pet.
      Query().
      Where(user.HasOwnerWith(user.Name("a8m"))).
      All(ctx)

Not

client.Pet.
    Query().
    Where(user.Not(user.NameHasPrefix("Ari"))).
    All(ctx)

OR

client.Pet.
    Query().
    Where(
        user.Or(
            user.HasOwner(),
            user.Not(user.HasFriends()),
        )
    ).
    All(ctx)

AND

client.Pet.
    Query().
    Where(
        user.And(
            user.HasOwner(),
            user.Not(user.HasFriends()),
        )
    ).
    All(ctx)

参考资料

https://entgo.io/docs/predicates/

posted on 2019-10-15 13:50  荣锋亮  阅读(486)  评论(0编辑  收藏  举报

导航