mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
Query policy (#411)
* entc/gen: drop xerrors package usage * all: bump dependencies version * entc/gen: adding query privacy policy support
This commit is contained in:
@@ -327,7 +327,6 @@ func (cq *CarQuery) prepareQuery(ctx context.Context) error {
|
||||
}
|
||||
cq.sql = prev
|
||||
}
|
||||
// Privacy and query checks go here.
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -15,7 +16,6 @@ import (
|
||||
"github.com/facebookincubator/ent/dialect"
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
|
||||
"golang.org/x/xerrors"
|
||||
)
|
||||
|
||||
// ent aliases to avoid import conflict in user's code.
|
||||
@@ -24,6 +24,7 @@ type (
|
||||
Hook = ent.Hook
|
||||
Value = ent.Value
|
||||
Query = ent.Query
|
||||
Policy = ent.Policy
|
||||
Mutator = ent.Mutator
|
||||
Mutation = ent.Mutation
|
||||
MutateFunc = ent.MutateFunc
|
||||
@@ -116,7 +117,7 @@ func IsNotFound(err error) bool {
|
||||
return false
|
||||
}
|
||||
var e *NotFoundError
|
||||
return xerrors.As(err, &e)
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// MaskNotFound masks nor found error.
|
||||
@@ -143,7 +144,7 @@ func IsNotSingular(err error) bool {
|
||||
return false
|
||||
}
|
||||
var e *NotSingularError
|
||||
return xerrors.As(err, &e)
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||
@@ -162,7 +163,7 @@ func IsNotLoaded(err error) bool {
|
||||
return false
|
||||
}
|
||||
var e *NotLoadedError
|
||||
return xerrors.As(err, &e)
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
// ConstraintError returns when trying to create/update one or more entities and
|
||||
@@ -189,7 +190,7 @@ func IsConstraintError(err error) bool {
|
||||
return false
|
||||
}
|
||||
var e *ConstraintError
|
||||
return xerrors.As(err, &e)
|
||||
return errors.As(err, &e)
|
||||
}
|
||||
|
||||
func isSQLConstraintError(err error) (*ConstraintError, bool) {
|
||||
|
||||
@@ -327,7 +327,6 @@ func (gq *GroupQuery) prepareQuery(ctx context.Context) error {
|
||||
}
|
||||
gq.sql = prev
|
||||
}
|
||||
// Privacy and query checks go here.
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -358,7 +358,6 @@ func (uq *UserQuery) prepareQuery(ctx context.Context) error {
|
||||
}
|
||||
uq.sql = prev
|
||||
}
|
||||
// Privacy and query checks go here.
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user