mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
Reviewed By: dlvhdr Differential Revision: D17112173 fbshipit-source-id: df0e89212dcfa593868300fdea26b0958b0d0c95
81 lines
1.1 KiB
Markdown
Executable File
81 lines
1.1 KiB
Markdown
Executable File
---
|
|
id: predicates
|
|
title: Predicates
|
|
---
|
|
|
|
## Field Predicates
|
|
|
|
- **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 Predicates
|
|
|
|
- **HasEdge**. For example, for edge named `owner` of type `Pet`, use:
|
|
|
|
```go
|
|
client.Pet.
|
|
Query().
|
|
Where(user.HasOwner()).
|
|
All(ctx)
|
|
```
|
|
|
|
- **HasEdgeWith**. Add list of predicates for edge predicate.
|
|
|
|
```go
|
|
client.Pet.
|
|
Query().
|
|
Where(user.HasOwnerWith(user.Name("a8m"))).
|
|
All(ctx)
|
|
```
|
|
|
|
|
|
## Negation (NOT)
|
|
|
|
```go
|
|
client.Pet.
|
|
Query().
|
|
Where(user.Not(user.NameHasPrefix("Ari"))).
|
|
All(ctx)
|
|
```
|
|
|
|
## Disjunction (OR)
|
|
|
|
```go
|
|
client.Pet.
|
|
Query().
|
|
Where(
|
|
user.Or(
|
|
user.HasOwner(),
|
|
user.Not(user.HasFriends()),
|
|
)
|
|
).
|
|
All(ctx)
|
|
```
|
|
|
|
## Conjunction (AND)
|
|
|
|
```go
|
|
client.Pet.
|
|
Query().
|
|
Where(
|
|
user.And(
|
|
user.HasOwner(),
|
|
user.Not(user.HasFriends()),
|
|
)
|
|
).
|
|
All(ctx)
|
|
```
|