mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
@@ -55,14 +55,14 @@ func (cc *CardCreate) Mutation() *CardMutation {
|
||||
|
||||
// Save creates the Card in the database.
|
||||
func (cc *CardCreate) Save(ctx context.Context) (*Card, error) {
|
||||
if err := cc.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
err error
|
||||
node *Card
|
||||
)
|
||||
if len(cc.hooks) == 0 {
|
||||
if err = cc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = cc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
@@ -70,6 +70,9 @@ func (cc *CardCreate) Save(ctx context.Context) (*Card, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = cc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cc.mutation = mutation
|
||||
node, err = cc.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
@@ -94,7 +97,8 @@ func (cc *CardCreate) SaveX(ctx context.Context) *Card {
|
||||
return v
|
||||
}
|
||||
|
||||
func (cc *CardCreate) preSave() error {
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cc *CardCreate) check() error {
|
||||
if _, ok := cc.mutation.Expired(); !ok {
|
||||
return &ValidationError{Name: "expired", err: errors.New("ent: missing required field \"expired\"")}
|
||||
}
|
||||
@@ -184,13 +188,13 @@ func (ccb *CardCreateBulk) Save(ctx context.Context) ([]*Card, error) {
|
||||
func(i int, root context.Context) {
|
||||
builder := ccb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
if err := builder.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation, ok := m.(*CardMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
|
||||
@@ -70,15 +70,14 @@ func (cu *CardUpdate) ClearOwner() *CardUpdate {
|
||||
|
||||
// Save executes the query and returns the number of rows/vertices matched by this operation.
|
||||
func (cu *CardUpdate) Save(ctx context.Context) (int, error) {
|
||||
|
||||
if _, ok := cu.mutation.OwnerID(); cu.mutation.OwnerCleared() && !ok {
|
||||
return 0, errors.New("ent: clearing a unique edge \"owner\"")
|
||||
}
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
)
|
||||
if len(cu.hooks) == 0 {
|
||||
if err = cu.check(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
affected, err = cu.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
@@ -86,6 +85,9 @@ func (cu *CardUpdate) Save(ctx context.Context) (int, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = cu.check(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
cu.mutation = mutation
|
||||
affected, err = cu.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
@@ -123,6 +125,14 @@ func (cu *CardUpdate) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cu *CardUpdate) check() error {
|
||||
if _, ok := cu.mutation.OwnerID(); cu.mutation.OwnerCleared() && !ok {
|
||||
return errors.New("ent: clearing a required unique edge \"owner\"")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
@@ -244,15 +254,14 @@ func (cuo *CardUpdateOne) ClearOwner() *CardUpdateOne {
|
||||
|
||||
// Save executes the query and returns the updated entity.
|
||||
func (cuo *CardUpdateOne) Save(ctx context.Context) (*Card, error) {
|
||||
|
||||
if _, ok := cuo.mutation.OwnerID(); cuo.mutation.OwnerCleared() && !ok {
|
||||
return nil, errors.New("ent: clearing a unique edge \"owner\"")
|
||||
}
|
||||
var (
|
||||
err error
|
||||
node *Card
|
||||
)
|
||||
if len(cuo.hooks) == 0 {
|
||||
if err = cuo.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = cuo.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
@@ -260,6 +269,9 @@ func (cuo *CardUpdateOne) Save(ctx context.Context) (*Card, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = cuo.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cuo.mutation = mutation
|
||||
node, err = cuo.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
@@ -297,6 +309,14 @@ func (cuo *CardUpdateOne) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (cuo *CardUpdateOne) check() error {
|
||||
if _, ok := cuo.mutation.OwnerID(); cuo.mutation.OwnerCleared() && !ok {
|
||||
return errors.New("ent: clearing a required unique edge \"owner\"")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (c *Card, err error) {
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
|
||||
@@ -62,14 +62,14 @@ func (uc *UserCreate) Mutation() *UserMutation {
|
||||
|
||||
// Save creates the User in the database.
|
||||
func (uc *UserCreate) Save(ctx context.Context) (*User, error) {
|
||||
if err := uc.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
err error
|
||||
node *User
|
||||
)
|
||||
if len(uc.hooks) == 0 {
|
||||
if err = uc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
node, err = uc.sqlSave(ctx)
|
||||
} else {
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
@@ -77,6 +77,9 @@ func (uc *UserCreate) Save(ctx context.Context) (*User, error) {
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err = uc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
uc.mutation = mutation
|
||||
node, err = uc.sqlSave(ctx)
|
||||
mutation.done = true
|
||||
@@ -101,7 +104,8 @@ func (uc *UserCreate) SaveX(ctx context.Context) *User {
|
||||
return v
|
||||
}
|
||||
|
||||
func (uc *UserCreate) preSave() error {
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (uc *UserCreate) check() error {
|
||||
if _, ok := uc.mutation.Age(); !ok {
|
||||
return &ValidationError{Name: "age", err: errors.New("ent: missing required field \"age\"")}
|
||||
}
|
||||
@@ -188,13 +192,13 @@ func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
|
||||
func(i int, root context.Context) {
|
||||
builder := ucb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
if err := builder.preSave(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation, ok := m.(*UserMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
var err error
|
||||
|
||||
@@ -83,7 +83,6 @@ func (uu *UserUpdate) ClearCard() *UserUpdate {
|
||||
|
||||
// Save executes the query and returns the number of rows/vertices matched by this operation.
|
||||
func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
|
||||
|
||||
var (
|
||||
err error
|
||||
affected int
|
||||
@@ -276,7 +275,6 @@ func (uuo *UserUpdateOne) ClearCard() *UserUpdateOne {
|
||||
|
||||
// Save executes the query and returns the updated entity.
|
||||
func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
||||
|
||||
var (
|
||||
err error
|
||||
node *User
|
||||
|
||||
Reference in New Issue
Block a user