diff --git a/entc/gen/template/builder/mutation.tmpl b/entc/gen/template/builder/mutation.tmpl index ecb813110..8f2f6fd24 100644 --- a/entc/gen/template/builder/mutation.tmpl +++ b/entc/gen/template/builder/mutation.tmpl @@ -411,6 +411,11 @@ func (m *{{ $mutation }}) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *{{ $mutation }}) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation ({{ $n.Name }}). func (m *{{ $mutation }}) Type() string { return m.typ @@ -479,7 +484,7 @@ func (m *{{ $mutation }}) SetField(name string, value ent.Value) error { if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.Set{{ $f.StructField }}(v) + m.{{ $f.MutationSet }}(v) return nil {{- end }} } diff --git a/entc/gen/template/builder/setter.tmpl b/entc/gen/template/builder/setter.tmpl index 62cf72ec2..13907e83a 100644 --- a/entc/gen/template/builder/setter.tmpl +++ b/entc/gen/template/builder/setter.tmpl @@ -26,9 +26,9 @@ in the LICENSE file in the root directory of this source tree. func ({{ $receiver }} *{{ $builder }}) {{ $func }}({{ $p }} {{ $f.Type }}) *{{ $builder }} { {{- /* setting numeric type override previous calls to Add. */}} {{- if and $updater $f.SupportsMutationAdd }} - {{ $receiver }}.mutation.{{ print "Reset" $f.StructField }}() + {{ $receiver }}.mutation.{{ $f.MutationReset }}() {{- end }} - {{ $receiver }}.mutation.{{ $func }}({{ $p }}) + {{ $receiver }}.mutation.{{ $f.MutationSet }}({{ $p }}) return {{ $receiver }} } diff --git a/entc/gen/template/client.tmpl b/entc/gen/template/client.tmpl index b82700e86..8f05e4871 100644 --- a/entc/gen/template/client.tmpl +++ b/entc/gen/template/client.tmpl @@ -143,6 +143,19 @@ func (c *Client) Use(hooks ...Hook) { {{- end }} {{- end }} + +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + {{- range $n := $.Nodes }} + case *{{ $n.MutationName }}: + return c.{{ $n.Name }}.mutate(ctx, m) + {{- end }} + default: + return nil, fmt.Errorf("{{ $pkg }}: unknown mutation type %T", m) + } +} + {{ range $n := $.Nodes }} {{ $client := print $n.Name "Client" }} // {{ $client }} is a client for the {{ $n.Name }} schema. @@ -285,6 +298,20 @@ func (c *{{ $client }}) Hooks() []Hook { {{- end }} } +func (c *{{ $client }}) mutate(ctx context.Context, m *{{ $n.MutationName }}) (Value, error) { + switch m.Op() { + case OpCreate: + return (&{{ $n.CreateName }}{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&{{ $n.UpdateName }}{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&{{ $n.UpdateOneName }}{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&{{ $n.DeleteName }}{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("{{ $pkg }}: unknown {{ $n.Name }} mutation op: %q", m.Op()) + } +} {{ end }} {{ end }} diff --git a/entc/gen/type.go b/entc/gen/type.go index 0e1785b75..57ff3e827 100644 --- a/entc/gen/type.go +++ b/entc/gen/type.go @@ -1044,7 +1044,7 @@ func (f Field) EntSQL() *entsql.Annotation { // mutMethods returns the method names of mutation interface. var mutMethods = func() map[string]bool { - names := map[string]bool{"Client": true, "Tx": true, "Where": true} + names := map[string]bool{"Client": true, "Tx": true, "Where": true, "SetOp": true} t := reflect.TypeOf(new(ent.Mutation)).Elem() for i := 0; i < t.NumMethod(); i++ { names[t.Method(i).Name] = true diff --git a/entc/integration/cascadelete/ent/client.go b/entc/integration/cascadelete/ent/client.go index c1f0ab397..64221f1e5 100644 --- a/entc/integration/cascadelete/ent/client.go +++ b/entc/integration/cascadelete/ent/client.go @@ -141,6 +141,20 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CommentMutation: + return c.Comment.mutate(ctx, m) + case *PostMutation: + return c.Post.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // CommentClient is a client for the Comment schema. type CommentClient struct { config @@ -247,6 +261,21 @@ func (c *CommentClient) Hooks() []Hook { return c.hooks.Comment } +func (c *CommentClient) mutate(ctx context.Context, m *CommentMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CommentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CommentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CommentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CommentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Comment mutation op: %q", m.Op()) + } +} + // PostClient is a client for the Post schema. type PostClient struct { config @@ -369,6 +398,21 @@ func (c *PostClient) Hooks() []Hook { return c.hooks.Post } +func (c *PostClient) mutate(ctx context.Context, m *PostMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PostCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PostUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PostDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Post mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -474,3 +518,18 @@ func (c *UserClient) QueryPosts(u *User) *PostQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/cascadelete/ent/mutation.go b/entc/integration/cascadelete/ent/mutation.go index fe4aacefa..8442d4649 100644 --- a/entc/integration/cascadelete/ent/mutation.go +++ b/entc/integration/cascadelete/ent/mutation.go @@ -255,6 +255,11 @@ func (m *CommentMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CommentMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Comment). func (m *CommentMutation) Type() string { return m.typ @@ -746,6 +751,11 @@ func (m *PostMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PostMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Post). func (m *PostMutation) Type() string { return m.typ @@ -1197,6 +1207,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/config/ent/client.go b/entc/integration/config/ent/client.go index 7a72877d6..efe27468d 100644 --- a/entc/integration/config/ent/client.go +++ b/entc/integration/config/ent/client.go @@ -126,6 +126,16 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -215,3 +225,18 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/config/ent/mutation.go b/entc/integration/config/ent/mutation.go index caf315529..84e4a3e2b 100644 --- a/entc/integration/config/ent/mutation.go +++ b/entc/integration/config/ent/mutation.go @@ -256,6 +256,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/customid/ent/client.go b/entc/integration/customid/ent/client.go index a992624d8..11d20bb4a 100644 --- a/entc/integration/customid/ent/client.go +++ b/entc/integration/customid/ent/client.go @@ -243,6 +243,48 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *AccountMutation: + return c.Account.mutate(ctx, m) + case *BlobMutation: + return c.Blob.mutate(ctx, m) + case *BlobLinkMutation: + return c.BlobLink.mutate(ctx, m) + case *CarMutation: + return c.Car.mutate(ctx, m) + case *DeviceMutation: + return c.Device.mutate(ctx, m) + case *DocMutation: + return c.Doc.mutate(ctx, m) + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *IntSIDMutation: + return c.IntSID.mutate(ctx, m) + case *LinkMutation: + return c.Link.mutate(ctx, m) + case *MixinIDMutation: + return c.MixinID.mutate(ctx, m) + case *NoteMutation: + return c.Note.mutate(ctx, m) + case *OtherMutation: + return c.Other.mutate(ctx, m) + case *PetMutation: + return c.Pet.mutate(ctx, m) + case *RevisionMutation: + return c.Revision.mutate(ctx, m) + case *SessionMutation: + return c.Session.mutate(ctx, m) + case *TokenMutation: + return c.Token.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // AccountClient is a client for the Account schema. type AccountClient struct { config @@ -349,6 +391,21 @@ func (c *AccountClient) Hooks() []Hook { return c.hooks.Account } +func (c *AccountClient) mutate(ctx context.Context, m *AccountMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AccountCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AccountUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AccountUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AccountDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Account mutation op: %q", m.Op()) + } +} + // BlobClient is a client for the Blob schema. type BlobClient struct { config @@ -487,6 +544,21 @@ func (c *BlobClient) Hooks() []Hook { return c.hooks.Blob } +func (c *BlobClient) mutate(ctx context.Context, m *BlobMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&BlobCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&BlobUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&BlobUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&BlobDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Blob mutation op: %q", m.Op()) + } +} + // BlobLinkClient is a client for the BlobLink schema. type BlobLinkClient struct { config @@ -560,6 +632,21 @@ func (c *BlobLinkClient) Hooks() []Hook { return c.hooks.BlobLink } +func (c *BlobLinkClient) mutate(ctx context.Context, m *BlobLinkMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&BlobLinkCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&BlobLinkUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&BlobLinkUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&BlobLinkDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown BlobLink mutation op: %q", m.Op()) + } +} + // CarClient is a client for the Car schema. type CarClient struct { config @@ -666,6 +753,21 @@ func (c *CarClient) Hooks() []Hook { return c.hooks.Car } +func (c *CarClient) mutate(ctx context.Context, m *CarMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CarCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CarUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CarDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Car mutation op: %q", m.Op()) + } +} + // DeviceClient is a client for the Device schema. type DeviceClient struct { config @@ -788,6 +890,21 @@ func (c *DeviceClient) Hooks() []Hook { return c.hooks.Device } +func (c *DeviceClient) mutate(ctx context.Context, m *DeviceMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&DeviceCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&DeviceUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&DeviceUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&DeviceDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Device mutation op: %q", m.Op()) + } +} + // DocClient is a client for the Doc schema. type DocClient struct { config @@ -926,6 +1043,21 @@ func (c *DocClient) Hooks() []Hook { return c.hooks.Doc } +func (c *DocClient) mutate(ctx context.Context, m *DocMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&DocCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&DocUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&DocUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&DocDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Doc mutation op: %q", m.Op()) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -1032,6 +1164,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // IntSIDClient is a client for the IntSID schema. type IntSIDClient struct { config @@ -1154,6 +1301,21 @@ func (c *IntSIDClient) Hooks() []Hook { return c.hooks.IntSID } +func (c *IntSIDClient) mutate(ctx context.Context, m *IntSIDMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&IntSIDCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&IntSIDUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&IntSIDUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&IntSIDDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown IntSID mutation op: %q", m.Op()) + } +} + // LinkClient is a client for the Link schema. type LinkClient struct { config @@ -1244,6 +1406,21 @@ func (c *LinkClient) Hooks() []Hook { return c.hooks.Link } +func (c *LinkClient) mutate(ctx context.Context, m *LinkMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&LinkCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&LinkUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&LinkUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&LinkDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Link mutation op: %q", m.Op()) + } +} + // MixinIDClient is a client for the MixinID schema. type MixinIDClient struct { config @@ -1334,6 +1511,21 @@ func (c *MixinIDClient) Hooks() []Hook { return c.hooks.MixinID } +func (c *MixinIDClient) mutate(ctx context.Context, m *MixinIDMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&MixinIDCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&MixinIDUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&MixinIDUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&MixinIDDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown MixinID mutation op: %q", m.Op()) + } +} + // NoteClient is a client for the Note schema. type NoteClient struct { config @@ -1456,6 +1648,21 @@ func (c *NoteClient) Hooks() []Hook { return c.hooks.Note } +func (c *NoteClient) mutate(ctx context.Context, m *NoteMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&NoteCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&NoteUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&NoteUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&NoteDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Note mutation op: %q", m.Op()) + } +} + // OtherClient is a client for the Other schema. type OtherClient struct { config @@ -1546,6 +1753,21 @@ func (c *OtherClient) Hooks() []Hook { return c.hooks.Other } +func (c *OtherClient) mutate(ctx context.Context, m *OtherMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&OtherCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&OtherUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&OtherUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&OtherDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Other mutation op: %q", m.Op()) + } +} + // PetClient is a client for the Pet schema. type PetClient struct { config @@ -1700,6 +1922,21 @@ func (c *PetClient) Hooks() []Hook { return c.hooks.Pet } +func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Pet mutation op: %q", m.Op()) + } +} + // RevisionClient is a client for the Revision schema. type RevisionClient struct { config @@ -1790,6 +2027,21 @@ func (c *RevisionClient) Hooks() []Hook { return c.hooks.Revision } +func (c *RevisionClient) mutate(ctx context.Context, m *RevisionMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&RevisionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&RevisionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&RevisionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&RevisionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Revision mutation op: %q", m.Op()) + } +} + // SessionClient is a client for the Session schema. type SessionClient struct { config @@ -1896,6 +2148,21 @@ func (c *SessionClient) Hooks() []Hook { return c.hooks.Session } +func (c *SessionClient) mutate(ctx context.Context, m *SessionMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SessionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SessionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SessionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Session mutation op: %q", m.Op()) + } +} + // TokenClient is a client for the Token schema. type TokenClient struct { config @@ -2002,6 +2269,21 @@ func (c *TokenClient) Hooks() []Hook { return c.hooks.Token } +func (c *TokenClient) mutate(ctx context.Context, m *TokenMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TokenCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TokenUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TokenDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Token mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -2155,3 +2437,18 @@ func (c *UserClient) QueryPets(u *User) *PetQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/customid/ent/mutation.go b/entc/integration/customid/ent/mutation.go index 50c453f02..5422ec7b4 100644 --- a/entc/integration/customid/ent/mutation.go +++ b/entc/integration/customid/ent/mutation.go @@ -285,6 +285,11 @@ func (m *AccountMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *AccountMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Account). func (m *AccountMutation) Type() string { return m.typ @@ -794,6 +799,11 @@ func (m *BlobMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *BlobMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Blob). func (m *BlobMutation) Type() string { return m.typ @@ -1207,6 +1217,11 @@ func (m *BlobLinkMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *BlobLinkMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (BlobLink). func (m *BlobLinkMutation) Type() string { return m.typ @@ -1779,6 +1794,11 @@ func (m *CarMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CarMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Car). func (m *CarMutation) Type() string { return m.typ @@ -2259,6 +2279,11 @@ func (m *DeviceMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *DeviceMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Device). func (m *DeviceMutation) Type() string { return m.typ @@ -2773,6 +2798,11 @@ func (m *DocMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *DocMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Doc). func (m *DocMutation) Type() string { return m.typ @@ -3199,6 +3229,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -3588,6 +3623,11 @@ func (m *IntSIDMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *IntSIDMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (IntSID). func (m *IntSIDMutation) Type() string { return m.typ @@ -3934,6 +3974,11 @@ func (m *LinkMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *LinkMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Link). func (m *LinkMutation) Type() string { return m.typ @@ -4288,6 +4333,11 @@ func (m *MixinIDMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *MixinIDMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (MixinID). func (m *MixinIDMutation) Type() string { return m.typ @@ -4733,6 +4783,11 @@ func (m *NoteMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *NoteMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Note). func (m *NoteMutation) Type() string { return m.typ @@ -5076,6 +5131,11 @@ func (m *OtherMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *OtherMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Other). func (m *OtherMutation) Type() string { return m.typ @@ -5527,6 +5587,11 @@ func (m *PetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Pet). func (m *PetMutation) Type() string { return m.typ @@ -5880,6 +5945,11 @@ func (m *RevisionMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *RevisionMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Revision). func (m *RevisionMutation) Type() string { return m.typ @@ -6176,6 +6246,11 @@ func (m *SessionMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *SessionMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Session). func (m *SessionMutation) Type() string { return m.typ @@ -6535,6 +6610,11 @@ func (m *TokenMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TokenMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Token). func (m *TokenMutation) Type() string { return m.typ @@ -7053,6 +7133,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/edgefield/ent/client.go b/entc/integration/edgefield/ent/client.go index 862b01163..a94544813 100644 --- a/entc/integration/edgefield/ent/client.go +++ b/entc/integration/edgefield/ent/client.go @@ -184,6 +184,32 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CarMutation: + return c.Car.mutate(ctx, m) + case *CardMutation: + return c.Card.mutate(ctx, m) + case *InfoMutation: + return c.Info.mutate(ctx, m) + case *MetadataMutation: + return c.Metadata.mutate(ctx, m) + case *NodeMutation: + return c.Node.mutate(ctx, m) + case *PetMutation: + return c.Pet.mutate(ctx, m) + case *PostMutation: + return c.Post.mutate(ctx, m) + case *RentalMutation: + return c.Rental.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // CarClient is a client for the Car schema. type CarClient struct { config @@ -290,6 +316,21 @@ func (c *CarClient) Hooks() []Hook { return c.hooks.Car } +func (c *CarClient) mutate(ctx context.Context, m *CarMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CarCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CarUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CarDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Car mutation op: %q", m.Op()) + } +} + // CardClient is a client for the Card schema. type CardClient struct { config @@ -396,6 +437,21 @@ func (c *CardClient) Hooks() []Hook { return c.hooks.Card } +func (c *CardClient) mutate(ctx context.Context, m *CardMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CardCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CardUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CardUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CardDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Card mutation op: %q", m.Op()) + } +} + // InfoClient is a client for the Info schema. type InfoClient struct { config @@ -502,6 +558,21 @@ func (c *InfoClient) Hooks() []Hook { return c.hooks.Info } +func (c *InfoClient) mutate(ctx context.Context, m *InfoMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&InfoCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&InfoUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&InfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&InfoDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Info mutation op: %q", m.Op()) + } +} + // MetadataClient is a client for the Metadata schema. type MetadataClient struct { config @@ -640,6 +711,21 @@ func (c *MetadataClient) Hooks() []Hook { return c.hooks.Metadata } +func (c *MetadataClient) mutate(ctx context.Context, m *MetadataMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&MetadataCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&MetadataUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&MetadataUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&MetadataDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Metadata mutation op: %q", m.Op()) + } +} + // NodeClient is a client for the Node schema. type NodeClient struct { config @@ -762,6 +848,21 @@ func (c *NodeClient) Hooks() []Hook { return c.hooks.Node } +func (c *NodeClient) mutate(ctx context.Context, m *NodeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&NodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&NodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&NodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&NodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Node mutation op: %q", m.Op()) + } +} + // PetClient is a client for the Pet schema. type PetClient struct { config @@ -868,6 +969,21 @@ func (c *PetClient) Hooks() []Hook { return c.hooks.Pet } +func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Pet mutation op: %q", m.Op()) + } +} + // PostClient is a client for the Post schema. type PostClient struct { config @@ -974,6 +1090,21 @@ func (c *PostClient) Hooks() []Hook { return c.hooks.Post } +func (c *PostClient) mutate(ctx context.Context, m *PostMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PostCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PostUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PostDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Post mutation op: %q", m.Op()) + } +} + // RentalClient is a client for the Rental schema. type RentalClient struct { config @@ -1096,6 +1227,21 @@ func (c *RentalClient) Hooks() []Hook { return c.hooks.Rental } +func (c *RentalClient) mutate(ctx context.Context, m *RentalMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&RentalCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&RentalUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&RentalUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&RentalDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Rental mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -1313,3 +1459,18 @@ func (c *UserClient) QueryRentals(u *User) *RentalQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/edgefield/ent/mutation.go b/entc/integration/edgefield/ent/mutation.go index 67c23de1a..b5c20b0d1 100644 --- a/entc/integration/edgefield/ent/mutation.go +++ b/entc/integration/edgefield/ent/mutation.go @@ -282,6 +282,11 @@ func (m *CarMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CarMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Car). func (m *CarMutation) Type() string { return m.typ @@ -728,6 +733,11 @@ func (m *CardMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CardMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Card). func (m *CardMutation) Type() string { return m.typ @@ -1163,6 +1173,11 @@ func (m *InfoMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *InfoMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Info). func (m *InfoMutation) Type() string { return m.typ @@ -1702,6 +1717,11 @@ func (m *MetadataMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *MetadataMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Metadata). func (m *MetadataMutation) Type() string { return m.typ @@ -2265,6 +2285,11 @@ func (m *NodeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *NodeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Node). func (m *NodeMutation) Type() string { return m.typ @@ -2701,6 +2726,11 @@ func (m *PetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Pet). func (m *PetMutation) Type() string { return m.typ @@ -3127,6 +3157,11 @@ func (m *PostMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PostMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Post). func (m *PostMutation) Type() string { return m.typ @@ -3621,6 +3656,11 @@ func (m *RentalMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *RentalMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Rental). func (m *RentalMutation) Type() string { return m.typ @@ -4446,6 +4486,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/edgeschema/ent/client.go b/entc/integration/edgeschema/ent/client.go index f0592dab2..d56c2c2e4 100644 --- a/entc/integration/edgeschema/ent/client.go +++ b/entc/integration/edgeschema/ent/client.go @@ -219,6 +219,42 @@ func (c *Client) Use(hooks ...Hook) { c.UserTweet.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *FriendshipMutation: + return c.Friendship.mutate(ctx, m) + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *GroupTagMutation: + return c.GroupTag.mutate(ctx, m) + case *RelationshipMutation: + return c.Relationship.mutate(ctx, m) + case *RelationshipInfoMutation: + return c.RelationshipInfo.mutate(ctx, m) + case *RoleMutation: + return c.Role.mutate(ctx, m) + case *RoleUserMutation: + return c.RoleUser.mutate(ctx, m) + case *TagMutation: + return c.Tag.mutate(ctx, m) + case *TweetMutation: + return c.Tweet.mutate(ctx, m) + case *TweetLikeMutation: + return c.TweetLike.mutate(ctx, m) + case *TweetTagMutation: + return c.TweetTag.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + case *UserGroupMutation: + return c.UserGroup.mutate(ctx, m) + case *UserTweetMutation: + return c.UserTweet.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // FriendshipClient is a client for the Friendship schema. type FriendshipClient struct { config @@ -341,6 +377,21 @@ func (c *FriendshipClient) Hooks() []Hook { return c.hooks.Friendship } +func (c *FriendshipClient) mutate(ctx context.Context, m *FriendshipMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FriendshipCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FriendshipUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FriendshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FriendshipDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Friendship mutation op: %q", m.Op()) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -495,6 +546,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // GroupTagClient is a client for the GroupTag schema. type GroupTagClient struct { config @@ -617,6 +683,21 @@ func (c *GroupTagClient) Hooks() []Hook { return c.hooks.GroupTag } +func (c *GroupTagClient) mutate(ctx context.Context, m *GroupTagMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupTagCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupTagUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupTagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupTagDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown GroupTag mutation op: %q", m.Op()) + } +} + // RelationshipClient is a client for the Relationship schema. type RelationshipClient struct { config @@ -698,6 +779,21 @@ func (c *RelationshipClient) Hooks() []Hook { return append(hooks[:len(hooks):len(hooks)], relationship.Hooks[:]...) } +func (c *RelationshipClient) mutate(ctx context.Context, m *RelationshipMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&RelationshipCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&RelationshipUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&RelationshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&RelationshipDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Relationship mutation op: %q", m.Op()) + } +} + // RelationshipInfoClient is a client for the RelationshipInfo schema. type RelationshipInfoClient struct { config @@ -788,6 +884,21 @@ func (c *RelationshipInfoClient) Hooks() []Hook { return c.hooks.RelationshipInfo } +func (c *RelationshipInfoClient) mutate(ctx context.Context, m *RelationshipInfoMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&RelationshipInfoCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&RelationshipInfoUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&RelationshipInfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&RelationshipInfoDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown RelationshipInfo mutation op: %q", m.Op()) + } +} + // RoleClient is a client for the Role schema. type RoleClient struct { config @@ -910,6 +1021,21 @@ func (c *RoleClient) Hooks() []Hook { return c.hooks.Role } +func (c *RoleClient) mutate(ctx context.Context, m *RoleMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&RoleCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&RoleUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&RoleUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&RoleDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Role mutation op: %q", m.Op()) + } +} + // RoleUserClient is a client for the RoleUser schema. type RoleUserClient struct { config @@ -983,6 +1109,21 @@ func (c *RoleUserClient) Hooks() []Hook { return c.hooks.RoleUser } +func (c *RoleUserClient) mutate(ctx context.Context, m *RoleUserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&RoleUserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&RoleUserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&RoleUserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&RoleUserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown RoleUser mutation op: %q", m.Op()) + } +} + // TagClient is a client for the Tag schema. type TagClient struct { config @@ -1137,6 +1278,21 @@ func (c *TagClient) Hooks() []Hook { return c.hooks.Tag } +func (c *TagClient) mutate(ctx context.Context, m *TagMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TagCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TagUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TagDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Tag mutation op: %q", m.Op()) + } +} + // TweetClient is a client for the Tweet schema. type TweetClient struct { config @@ -1323,6 +1479,21 @@ func (c *TweetClient) Hooks() []Hook { return c.hooks.Tweet } +func (c *TweetClient) mutate(ctx context.Context, m *TweetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TweetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TweetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TweetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TweetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Tweet mutation op: %q", m.Op()) + } +} + // TweetLikeClient is a client for the TweetLike schema. type TweetLikeClient struct { config @@ -1397,6 +1568,21 @@ func (c *TweetLikeClient) Hooks() []Hook { return append(hooks[:len(hooks):len(hooks)], tweetlike.Hooks[:]...) } +func (c *TweetLikeClient) mutate(ctx context.Context, m *TweetLikeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TweetLikeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TweetLikeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TweetLikeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TweetLikeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown TweetLike mutation op: %q", m.Op()) + } +} + // TweetTagClient is a client for the TweetTag schema. type TweetTagClient struct { config @@ -1519,6 +1705,21 @@ func (c *TweetTagClient) Hooks() []Hook { return c.hooks.TweetTag } +func (c *TweetTagClient) mutate(ctx context.Context, m *TweetTagMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TweetTagCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TweetTagUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TweetTagUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TweetTagDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown TweetTag mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -1802,6 +2003,21 @@ func (c *UserClient) Hooks() []Hook { return append(hooks[:len(hooks):len(hooks)], user.Hooks[:]...) } +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} + // UserGroupClient is a client for the UserGroup schema. type UserGroupClient struct { config @@ -1924,6 +2140,21 @@ func (c *UserGroupClient) Hooks() []Hook { return c.hooks.UserGroup } +func (c *UserGroupClient) mutate(ctx context.Context, m *UserGroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserGroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserGroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserGroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserGroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown UserGroup mutation op: %q", m.Op()) + } +} + // UserTweetClient is a client for the UserTweet schema. type UserTweetClient struct { config @@ -2045,3 +2276,18 @@ func (c *UserTweetClient) QueryTweet(ut *UserTweet) *TweetQuery { func (c *UserTweetClient) Hooks() []Hook { return c.hooks.UserTweet } + +func (c *UserTweetClient) mutate(ctx context.Context, m *UserTweetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserTweetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserTweetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserTweetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserTweetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown UserTweet mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/edgeschema/ent/mutation.go b/entc/integration/edgeschema/ent/mutation.go index 96883edac..b0fb1defc 100644 --- a/entc/integration/edgeschema/ent/mutation.go +++ b/entc/integration/edgeschema/ent/mutation.go @@ -401,6 +401,11 @@ func (m *FriendshipMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *FriendshipMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Friendship). func (m *FriendshipMutation) Type() string { return m.typ @@ -1050,6 +1055,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -1566,6 +1576,11 @@ func (m *GroupTagMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupTagMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (GroupTag). func (m *GroupTagMutation) Type() string { return m.typ @@ -2038,6 +2053,11 @@ func (m *RelationshipMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *RelationshipMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Relationship). func (m *RelationshipMutation) Type() string { return m.typ @@ -2476,6 +2496,11 @@ func (m *RelationshipInfoMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *RelationshipInfoMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (RelationshipInfo). func (m *RelationshipInfoMutation) Type() string { return m.typ @@ -2881,6 +2906,11 @@ func (m *RoleMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *RoleMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Role). func (m *RoleMutation) Type() string { return m.typ @@ -3261,6 +3291,11 @@ func (m *RoleUserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *RoleUserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (RoleUser). func (m *RoleUserMutation) Type() string { return m.typ @@ -3873,6 +3908,11 @@ func (m *TagMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TagMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Tag). func (m *TagMutation) Type() string { return m.typ @@ -4583,6 +4623,11 @@ func (m *TweetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TweetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Tweet). func (m *TweetMutation) Type() string { return m.typ @@ -5050,6 +5095,11 @@ func (m *TweetLikeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TweetLikeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (TweetLike). func (m *TweetLikeMutation) Type() string { return m.typ @@ -5568,6 +5618,11 @@ func (m *TweetTagMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TweetTagMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (TweetTag). func (m *TweetTagMutation) Type() string { return m.typ @@ -6473,6 +6528,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ @@ -7156,6 +7216,11 @@ func (m *UserGroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserGroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (UserGroup). func (m *UserGroupMutation) Type() string { return m.typ @@ -7676,6 +7741,11 @@ func (m *UserTweetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserTweetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (UserTweet). func (m *UserTweetMutation) Type() string { return m.typ diff --git a/entc/integration/ent/client.go b/entc/integration/ent/client.go index a1858e388..9c90f3fc3 100644 --- a/entc/integration/ent/client.go +++ b/entc/integration/ent/client.go @@ -236,6 +236,44 @@ func (c *Client) Driver() dialect.Driver { return c.driver } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CardMutation: + return c.Card.mutate(ctx, m) + case *CommentMutation: + return c.Comment.mutate(ctx, m) + case *FieldTypeMutation: + return c.FieldType.mutate(ctx, m) + case *FileMutation: + return c.File.mutate(ctx, m) + case *FileTypeMutation: + return c.FileType.mutate(ctx, m) + case *GoodsMutation: + return c.Goods.mutate(ctx, m) + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *GroupInfoMutation: + return c.GroupInfo.mutate(ctx, m) + case *ItemMutation: + return c.Item.mutate(ctx, m) + case *LicenseMutation: + return c.License.mutate(ctx, m) + case *NodeMutation: + return c.Node.mutate(ctx, m) + case *PetMutation: + return c.Pet.mutate(ctx, m) + case *SpecMutation: + return c.Spec.mutate(ctx, m) + case *TaskMutation: + return c.Task.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // CardClient is a client for the Card schema. type CardClient struct { config @@ -358,6 +396,21 @@ func (c *CardClient) Hooks() []Hook { return c.hooks.Card } +func (c *CardClient) mutate(ctx context.Context, m *CardMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CardCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CardUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CardUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CardDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Card mutation op: %q", m.Op()) + } +} + // CommentClient is a client for the Comment schema. type CommentClient struct { config @@ -448,6 +501,21 @@ func (c *CommentClient) Hooks() []Hook { return c.hooks.Comment } +func (c *CommentClient) mutate(ctx context.Context, m *CommentMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CommentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CommentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CommentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CommentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Comment mutation op: %q", m.Op()) + } +} + // FieldTypeClient is a client for the FieldType schema. type FieldTypeClient struct { config @@ -538,6 +606,21 @@ func (c *FieldTypeClient) Hooks() []Hook { return c.hooks.FieldType } +func (c *FieldTypeClient) mutate(ctx context.Context, m *FieldTypeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FieldTypeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FieldTypeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FieldTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FieldTypeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown FieldType mutation op: %q", m.Op()) + } +} + // FileClient is a client for the File schema. type FileClient struct { config @@ -676,6 +759,21 @@ func (c *FileClient) Hooks() []Hook { return c.hooks.File } +func (c *FileClient) mutate(ctx context.Context, m *FileMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FileCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FileUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FileDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown File mutation op: %q", m.Op()) + } +} + // FileTypeClient is a client for the FileType schema. type FileTypeClient struct { config @@ -782,6 +880,21 @@ func (c *FileTypeClient) Hooks() []Hook { return c.hooks.FileType } +func (c *FileTypeClient) mutate(ctx context.Context, m *FileTypeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FileTypeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FileTypeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FileTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FileTypeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown FileType mutation op: %q", m.Op()) + } +} + // GoodsClient is a client for the Goods schema. type GoodsClient struct { config @@ -872,6 +985,21 @@ func (c *GoodsClient) Hooks() []Hook { return c.hooks.Goods } +func (c *GoodsClient) mutate(ctx context.Context, m *GoodsMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GoodsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GoodsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GoodsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GoodsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Goods mutation op: %q", m.Op()) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -1026,6 +1154,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // GroupInfoClient is a client for the GroupInfo schema. type GroupInfoClient struct { config @@ -1132,6 +1275,21 @@ func (c *GroupInfoClient) Hooks() []Hook { return c.hooks.GroupInfo } +func (c *GroupInfoClient) mutate(ctx context.Context, m *GroupInfoMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupInfoCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupInfoUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupInfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupInfoDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown GroupInfo mutation op: %q", m.Op()) + } +} + // ItemClient is a client for the Item schema. type ItemClient struct { config @@ -1222,6 +1380,21 @@ func (c *ItemClient) Hooks() []Hook { return c.hooks.Item } +func (c *ItemClient) mutate(ctx context.Context, m *ItemMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ItemCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ItemUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ItemDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Item mutation op: %q", m.Op()) + } +} + // LicenseClient is a client for the License schema. type LicenseClient struct { config @@ -1312,6 +1485,21 @@ func (c *LicenseClient) Hooks() []Hook { return c.hooks.License } +func (c *LicenseClient) mutate(ctx context.Context, m *LicenseMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&LicenseCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&LicenseUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&LicenseUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&LicenseDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown License mutation op: %q", m.Op()) + } +} + // NodeClient is a client for the Node schema. type NodeClient struct { config @@ -1434,6 +1622,21 @@ func (c *NodeClient) Hooks() []Hook { return c.hooks.Node } +func (c *NodeClient) mutate(ctx context.Context, m *NodeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&NodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&NodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&NodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&NodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Node mutation op: %q", m.Op()) + } +} + // PetClient is a client for the Pet schema. type PetClient struct { config @@ -1556,6 +1759,21 @@ func (c *PetClient) Hooks() []Hook { return c.hooks.Pet } +func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Pet mutation op: %q", m.Op()) + } +} + // SpecClient is a client for the Spec schema. type SpecClient struct { config @@ -1662,6 +1880,21 @@ func (c *SpecClient) Hooks() []Hook { return c.hooks.Spec } +func (c *SpecClient) mutate(ctx context.Context, m *SpecMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SpecCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SpecUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SpecUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SpecDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Spec mutation op: %q", m.Op()) + } +} + // TaskClient is a client for the Task schema. type TaskClient struct { config @@ -1752,6 +1985,21 @@ func (c *TaskClient) Hooks() []Hook { return c.hooks.Task } +func (c *TaskClient) mutate(ctx context.Context, m *TaskMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Task mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -2017,3 +2265,18 @@ func (c *UserClient) QueryParent(u *User) *UserQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/ent/file_create.go b/entc/integration/ent/file_create.go index 3da3bd866..f6b020538 100644 --- a/entc/integration/ent/file_create.go +++ b/entc/integration/ent/file_create.go @@ -78,7 +78,7 @@ func (fc *FileCreate) SetNillableGroup(s *string) *FileCreate { // SetOp sets the "op" field. func (fc *FileCreate) SetOp(b bool) *FileCreate { - fc.mutation.SetOp(b) + fc.mutation.SetOpField(b) return fc } diff --git a/entc/integration/ent/file_update.go b/entc/integration/ent/file_update.go index 994c1e71a..0323da4ed 100644 --- a/entc/integration/ent/file_update.go +++ b/entc/integration/ent/file_update.go @@ -104,7 +104,7 @@ func (fu *FileUpdate) ClearGroup() *FileUpdate { // SetOp sets the "op" field. func (fu *FileUpdate) SetOp(b bool) *FileUpdate { - fu.mutation.SetOp(b) + fu.mutation.SetOpField(b) return fu } @@ -584,7 +584,7 @@ func (fuo *FileUpdateOne) ClearGroup() *FileUpdateOne { // SetOp sets the "op" field. func (fuo *FileUpdateOne) SetOp(b bool) *FileUpdateOne { - fuo.mutation.SetOp(b) + fuo.mutation.SetOpField(b) return fuo } diff --git a/entc/integration/ent/mutation.go b/entc/integration/ent/mutation.go index 988d98dab..56ab92355 100644 --- a/entc/integration/ent/mutation.go +++ b/entc/integration/ent/mutation.go @@ -503,6 +503,11 @@ func (m *CardMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CardMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Card). func (m *CardMutation) Type() string { return m.typ @@ -1261,6 +1266,11 @@ func (m *CommentMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CommentMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Comment). func (m *CommentMutation) Type() string { return m.typ @@ -5500,6 +5510,11 @@ func (m *FieldTypeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *FieldTypeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (FieldType). func (m *FieldTypeMutation) Type() string { return m.typ @@ -7765,8 +7780,8 @@ func (m *FileMutation) ResetGroup() { delete(m.clearedFields, file.FieldGroup) } -// SetOp sets the "op" field. -func (m *FileMutation) SetOp(b bool) { +// SetOpField sets the "op" field. +func (m *FileMutation) SetOpField(b bool) { m._op = &b } @@ -8026,6 +8041,11 @@ func (m *FileMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *FileMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (File). func (m *FileMutation) Type() string { return m.typ @@ -8137,7 +8157,7 @@ func (m *FileMutation) SetField(name string, value ent.Value) error { if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetOp(v) + m.SetOpField(v) return nil case file.FieldFieldID: v, ok := value.(int) @@ -8679,6 +8699,11 @@ func (m *FileTypeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *FileTypeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (FileType). func (m *FileTypeMutation) Type() string { return m.typ @@ -9023,6 +9048,11 @@ func (m *GoodsMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GoodsMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Goods). func (m *GoodsMutation) Type() string { return m.typ @@ -9717,6 +9747,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -10347,6 +10382,11 @@ func (m *GroupInfoMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupInfoMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (GroupInfo). func (m *GroupInfoMutation) Type() string { return m.typ @@ -10745,6 +10785,11 @@ func (m *ItemMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *ItemMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Item). func (m *ItemMutation) Type() string { return m.typ @@ -11108,6 +11153,11 @@ func (m *LicenseMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *LicenseMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (License). func (m *LicenseMutation) Type() string { return m.typ @@ -11553,6 +11603,11 @@ func (m *NodeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *NodeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Node). func (m *NodeMutation) Type() string { return m.typ @@ -12209,6 +12264,11 @@ func (m *PetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Pet). func (m *PetMutation) Type() string { return m.typ @@ -12682,6 +12742,11 @@ func (m *SpecMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *SpecMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Spec). func (m *SpecMutation) Type() string { return m.typ @@ -13112,6 +13177,11 @@ func (m *TaskMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TaskMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Task). func (m *TaskMutation) Type() string { return m.typ @@ -14535,6 +14605,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/gremlin/ent/client.go b/entc/integration/gremlin/ent/client.go index c568b384d..7422b62b1 100644 --- a/entc/integration/gremlin/ent/client.go +++ b/entc/integration/gremlin/ent/client.go @@ -208,6 +208,44 @@ func (c *Client) Driver() dialect.Driver { return c.driver } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CardMutation: + return c.Card.mutate(ctx, m) + case *CommentMutation: + return c.Comment.mutate(ctx, m) + case *FieldTypeMutation: + return c.FieldType.mutate(ctx, m) + case *FileMutation: + return c.File.mutate(ctx, m) + case *FileTypeMutation: + return c.FileType.mutate(ctx, m) + case *GoodsMutation: + return c.Goods.mutate(ctx, m) + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *GroupInfoMutation: + return c.GroupInfo.mutate(ctx, m) + case *ItemMutation: + return c.Item.mutate(ctx, m) + case *LicenseMutation: + return c.License.mutate(ctx, m) + case *NodeMutation: + return c.Node.mutate(ctx, m) + case *PetMutation: + return c.Pet.mutate(ctx, m) + case *SpecMutation: + return c.Spec.mutate(ctx, m) + case *TaskMutation: + return c.Task.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // CardClient is a client for the Card schema. type CardClient struct { config @@ -320,6 +358,21 @@ func (c *CardClient) Hooks() []Hook { return c.hooks.Card } +func (c *CardClient) mutate(ctx context.Context, m *CardMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CardCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CardUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CardUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CardDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Card mutation op: %q", m.Op()) + } +} + // CommentClient is a client for the Comment schema. type CommentClient struct { config @@ -410,6 +463,21 @@ func (c *CommentClient) Hooks() []Hook { return c.hooks.Comment } +func (c *CommentClient) mutate(ctx context.Context, m *CommentMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CommentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CommentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CommentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CommentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Comment mutation op: %q", m.Op()) + } +} + // FieldTypeClient is a client for the FieldType schema. type FieldTypeClient struct { config @@ -500,6 +568,21 @@ func (c *FieldTypeClient) Hooks() []Hook { return c.hooks.FieldType } +func (c *FieldTypeClient) mutate(ctx context.Context, m *FieldTypeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FieldTypeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FieldTypeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FieldTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FieldTypeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown FieldType mutation op: %q", m.Op()) + } +} + // FileClient is a client for the File schema. type FileClient struct { config @@ -623,6 +706,21 @@ func (c *FileClient) Hooks() []Hook { return c.hooks.File } +func (c *FileClient) mutate(ctx context.Context, m *FileMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FileCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FileUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FileDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown File mutation op: %q", m.Op()) + } +} + // FileTypeClient is a client for the FileType schema. type FileTypeClient struct { config @@ -724,6 +822,21 @@ func (c *FileTypeClient) Hooks() []Hook { return c.hooks.FileType } +func (c *FileTypeClient) mutate(ctx context.Context, m *FileTypeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FileTypeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FileTypeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FileTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FileTypeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown FileType mutation op: %q", m.Op()) + } +} + // GoodsClient is a client for the Goods schema. type GoodsClient struct { config @@ -814,6 +927,21 @@ func (c *GoodsClient) Hooks() []Hook { return c.hooks.Goods } +func (c *GoodsClient) mutate(ctx context.Context, m *GoodsMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GoodsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GoodsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GoodsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GoodsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Goods mutation op: %q", m.Op()) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -948,6 +1076,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // GroupInfoClient is a client for the GroupInfo schema. type GroupInfoClient struct { config @@ -1049,6 +1192,21 @@ func (c *GroupInfoClient) Hooks() []Hook { return c.hooks.GroupInfo } +func (c *GroupInfoClient) mutate(ctx context.Context, m *GroupInfoMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupInfoCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupInfoUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupInfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupInfoDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown GroupInfo mutation op: %q", m.Op()) + } +} + // ItemClient is a client for the Item schema. type ItemClient struct { config @@ -1139,6 +1297,21 @@ func (c *ItemClient) Hooks() []Hook { return c.hooks.Item } +func (c *ItemClient) mutate(ctx context.Context, m *ItemMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ItemCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ItemUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ItemUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ItemDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Item mutation op: %q", m.Op()) + } +} + // LicenseClient is a client for the License schema. type LicenseClient struct { config @@ -1229,6 +1402,21 @@ func (c *LicenseClient) Hooks() []Hook { return c.hooks.License } +func (c *LicenseClient) mutate(ctx context.Context, m *LicenseMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&LicenseCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&LicenseUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&LicenseUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&LicenseDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown License mutation op: %q", m.Op()) + } +} + // NodeClient is a client for the Node schema. type NodeClient struct { config @@ -1341,6 +1529,21 @@ func (c *NodeClient) Hooks() []Hook { return c.hooks.Node } +func (c *NodeClient) mutate(ctx context.Context, m *NodeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&NodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&NodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&NodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&NodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Node mutation op: %q", m.Op()) + } +} + // PetClient is a client for the Pet schema. type PetClient struct { config @@ -1453,6 +1656,21 @@ func (c *PetClient) Hooks() []Hook { return c.hooks.Pet } +func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Pet mutation op: %q", m.Op()) + } +} + // SpecClient is a client for the Spec schema. type SpecClient struct { config @@ -1554,6 +1772,21 @@ func (c *SpecClient) Hooks() []Hook { return c.hooks.Spec } +func (c *SpecClient) mutate(ctx context.Context, m *SpecMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&SpecCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&SpecUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&SpecUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&SpecDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Spec mutation op: %q", m.Op()) + } +} + // TaskClient is a client for the Task schema. type TaskClient struct { config @@ -1644,6 +1877,21 @@ func (c *TaskClient) Hooks() []Hook { return c.hooks.Task } +func (c *TaskClient) mutate(ctx context.Context, m *TaskMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Task mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -1854,3 +2102,18 @@ func (c *UserClient) QueryParent(u *User) *UserQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/gremlin/ent/file_create.go b/entc/integration/gremlin/ent/file_create.go index 49dcb6d99..ffba3cf6e 100644 --- a/entc/integration/gremlin/ent/file_create.go +++ b/entc/integration/gremlin/ent/file_create.go @@ -78,7 +78,7 @@ func (fc *FileCreate) SetNillableGroup(s *string) *FileCreate { // SetOp sets the "op" field. func (fc *FileCreate) SetOp(b bool) *FileCreate { - fc.mutation.SetOp(b) + fc.mutation.SetOpField(b) return fc } diff --git a/entc/integration/gremlin/ent/file_update.go b/entc/integration/gremlin/ent/file_update.go index a703f9f3c..7e441cd99 100644 --- a/entc/integration/gremlin/ent/file_update.go +++ b/entc/integration/gremlin/ent/file_update.go @@ -104,7 +104,7 @@ func (fu *FileUpdate) ClearGroup() *FileUpdate { // SetOp sets the "op" field. func (fu *FileUpdate) SetOp(b bool) *FileUpdate { - fu.mutation.SetOp(b) + fu.mutation.SetOpField(b) return fu } @@ -495,7 +495,7 @@ func (fuo *FileUpdateOne) ClearGroup() *FileUpdateOne { // SetOp sets the "op" field. func (fuo *FileUpdateOne) SetOp(b bool) *FileUpdateOne { - fuo.mutation.SetOp(b) + fuo.mutation.SetOpField(b) return fuo } diff --git a/entc/integration/gremlin/ent/mutation.go b/entc/integration/gremlin/ent/mutation.go index 5c07152e4..02a6ba12e 100644 --- a/entc/integration/gremlin/ent/mutation.go +++ b/entc/integration/gremlin/ent/mutation.go @@ -503,6 +503,11 @@ func (m *CardMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CardMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Card). func (m *CardMutation) Type() string { return m.typ @@ -1261,6 +1266,11 @@ func (m *CommentMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CommentMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Comment). func (m *CommentMutation) Type() string { return m.typ @@ -5500,6 +5510,11 @@ func (m *FieldTypeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *FieldTypeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (FieldType). func (m *FieldTypeMutation) Type() string { return m.typ @@ -7765,8 +7780,8 @@ func (m *FileMutation) ResetGroup() { delete(m.clearedFields, file.FieldGroup) } -// SetOp sets the "op" field. -func (m *FileMutation) SetOp(b bool) { +// SetOpField sets the "op" field. +func (m *FileMutation) SetOpField(b bool) { m._op = &b } @@ -8026,6 +8041,11 @@ func (m *FileMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *FileMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (File). func (m *FileMutation) Type() string { return m.typ @@ -8137,7 +8157,7 @@ func (m *FileMutation) SetField(name string, value ent.Value) error { if !ok { return fmt.Errorf("unexpected type %T for field %s", value, name) } - m.SetOp(v) + m.SetOpField(v) return nil case file.FieldFieldID: v, ok := value.(int) @@ -8679,6 +8699,11 @@ func (m *FileTypeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *FileTypeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (FileType). func (m *FileTypeMutation) Type() string { return m.typ @@ -9023,6 +9048,11 @@ func (m *GoodsMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GoodsMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Goods). func (m *GoodsMutation) Type() string { return m.typ @@ -9717,6 +9747,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -10347,6 +10382,11 @@ func (m *GroupInfoMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupInfoMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (GroupInfo). func (m *GroupInfoMutation) Type() string { return m.typ @@ -10745,6 +10785,11 @@ func (m *ItemMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *ItemMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Item). func (m *ItemMutation) Type() string { return m.typ @@ -11108,6 +11153,11 @@ func (m *LicenseMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *LicenseMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (License). func (m *LicenseMutation) Type() string { return m.typ @@ -11553,6 +11603,11 @@ func (m *NodeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *NodeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Node). func (m *NodeMutation) Type() string { return m.typ @@ -12209,6 +12264,11 @@ func (m *PetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Pet). func (m *PetMutation) Type() string { return m.typ @@ -12682,6 +12742,11 @@ func (m *SpecMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *SpecMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Spec). func (m *SpecMutation) Type() string { return m.typ @@ -13112,6 +13177,11 @@ func (m *TaskMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TaskMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Task). func (m *TaskMutation) Type() string { return m.typ @@ -14535,6 +14605,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/hooks/ent/card.go b/entc/integration/hooks/ent/card.go index 9a8cba85d..1cd69188b 100644 --- a/entc/integration/hooks/ent/card.go +++ b/entc/integration/hooks/ent/card.go @@ -29,6 +29,8 @@ type Card struct { CreatedAt time.Time `json:"created_at,omitempty"` // InHook is a mandatory field that is set by the hook. InHook string `json:"in_hook,omitempty"` + // ExpiredAt holds the value of the "expired_at" field. + ExpiredAt time.Time `json:"expired_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the CardQuery when eager-loading is set. Edges CardEdges `json:"edges"` @@ -66,7 +68,7 @@ func (*Card) scanValues(columns []string) ([]any, error) { values[i] = new(sql.NullInt64) case card.FieldNumber, card.FieldName, card.FieldInHook: values[i] = new(sql.NullString) - case card.FieldCreatedAt: + case card.FieldCreatedAt, card.FieldExpiredAt: values[i] = new(sql.NullTime) case card.ForeignKeys[0]: // user_cards values[i] = new(sql.NullInt64) @@ -115,6 +117,12 @@ func (c *Card) assignValues(columns []string, values []any) error { } else if value.Valid { c.InHook = value.String } + case card.FieldExpiredAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field expired_at", values[i]) + } else if value.Valid { + c.ExpiredAt = value.Time + } case card.ForeignKeys[0]: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for edge-field user_cards", value) @@ -166,6 +174,9 @@ func (c *Card) String() string { builder.WriteString(", ") builder.WriteString("in_hook=") builder.WriteString(c.InHook) + builder.WriteString(", ") + builder.WriteString("expired_at=") + builder.WriteString(c.ExpiredAt.Format(time.ANSIC)) builder.WriteByte(')') return builder.String() } diff --git a/entc/integration/hooks/ent/card/card.go b/entc/integration/hooks/ent/card/card.go index 5d8699c5b..383268330 100644 --- a/entc/integration/hooks/ent/card/card.go +++ b/entc/integration/hooks/ent/card/card.go @@ -25,6 +25,8 @@ const ( FieldCreatedAt = "created_at" // FieldInHook holds the string denoting the in_hook field in the database. FieldInHook = "in_hook" + // FieldExpiredAt holds the string denoting the expired_at field in the database. + FieldExpiredAt = "expired_at" // EdgeOwner holds the string denoting the owner edge name in mutations. EdgeOwner = "owner" // Table holds the table name of the card in the database. @@ -45,6 +47,7 @@ var Columns = []string{ FieldName, FieldCreatedAt, FieldInHook, + FieldExpiredAt, } // ForeignKeys holds the SQL foreign-keys that are owned by the "cards" diff --git a/entc/integration/hooks/ent/card/where.go b/entc/integration/hooks/ent/card/where.go index 9061acb3f..15f14aced 100644 --- a/entc/integration/hooks/ent/card/where.go +++ b/entc/integration/hooks/ent/card/where.go @@ -113,6 +113,13 @@ func InHook(v string) predicate.Card { }) } +// ExpiredAt applies equality check predicate on the "expired_at" field. It's identical to ExpiredAtEQ. +func ExpiredAt(v time.Time) predicate.Card { + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldExpiredAt), v)) + }) +} + // NumberEQ applies the EQ predicate on the "number" field. func NumberEQ(v string) predicate.Card { return predicate.Card(func(s *sql.Selector) { @@ -488,6 +495,84 @@ func InHookContainsFold(v string) predicate.Card { }) } +// ExpiredAtEQ applies the EQ predicate on the "expired_at" field. +func ExpiredAtEQ(v time.Time) predicate.Card { + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldExpiredAt), v)) + }) +} + +// ExpiredAtNEQ applies the NEQ predicate on the "expired_at" field. +func ExpiredAtNEQ(v time.Time) predicate.Card { + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldExpiredAt), v)) + }) +} + +// ExpiredAtIn applies the In predicate on the "expired_at" field. +func ExpiredAtIn(vs ...time.Time) predicate.Card { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.In(s.C(FieldExpiredAt), v...)) + }) +} + +// ExpiredAtNotIn applies the NotIn predicate on the "expired_at" field. +func ExpiredAtNotIn(vs ...time.Time) predicate.Card { + v := make([]any, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.NotIn(s.C(FieldExpiredAt), v...)) + }) +} + +// ExpiredAtGT applies the GT predicate on the "expired_at" field. +func ExpiredAtGT(v time.Time) predicate.Card { + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldExpiredAt), v)) + }) +} + +// ExpiredAtGTE applies the GTE predicate on the "expired_at" field. +func ExpiredAtGTE(v time.Time) predicate.Card { + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldExpiredAt), v)) + }) +} + +// ExpiredAtLT applies the LT predicate on the "expired_at" field. +func ExpiredAtLT(v time.Time) predicate.Card { + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldExpiredAt), v)) + }) +} + +// ExpiredAtLTE applies the LTE predicate on the "expired_at" field. +func ExpiredAtLTE(v time.Time) predicate.Card { + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldExpiredAt), v)) + }) +} + +// ExpiredAtIsNil applies the IsNil predicate on the "expired_at" field. +func ExpiredAtIsNil() predicate.Card { + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldExpiredAt))) + }) +} + +// ExpiredAtNotNil applies the NotNil predicate on the "expired_at" field. +func ExpiredAtNotNil() predicate.Card { + return predicate.Card(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldExpiredAt))) + }) +} + // HasOwner applies the HasEdge predicate on the "owner" edge. func HasOwner() predicate.Card { return predicate.Card(func(s *sql.Selector) { diff --git a/entc/integration/hooks/ent/card_create.go b/entc/integration/hooks/ent/card_create.go index 594a5ee91..ef6af5b30 100644 --- a/entc/integration/hooks/ent/card_create.go +++ b/entc/integration/hooks/ent/card_create.go @@ -73,6 +73,20 @@ func (cc *CardCreate) SetInHook(s string) *CardCreate { return cc } +// SetExpiredAt sets the "expired_at" field. +func (cc *CardCreate) SetExpiredAt(t time.Time) *CardCreate { + cc.mutation.SetExpiredAt(t) + return cc +} + +// SetNillableExpiredAt sets the "expired_at" field if the given value is not nil. +func (cc *CardCreate) SetNillableExpiredAt(t *time.Time) *CardCreate { + if t != nil { + cc.SetExpiredAt(*t) + } + return cc +} + // SetOwnerID sets the "owner" edge to the User entity by ID. func (cc *CardCreate) SetOwnerID(id int) *CardCreate { cc.mutation.SetOwnerID(id) @@ -244,6 +258,10 @@ func (cc *CardCreate) createSpec() (*Card, *sqlgraph.CreateSpec) { _spec.SetField(card.FieldInHook, field.TypeString, value) _node.InHook = value } + if value, ok := cc.mutation.ExpiredAt(); ok { + _spec.SetField(card.FieldExpiredAt, field.TypeTime, value) + _node.ExpiredAt = value + } if nodes := cc.mutation.OwnerIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entc/integration/hooks/ent/card_update.go b/entc/integration/hooks/ent/card_update.go index 4f94ed813..1ad9c7f10 100644 --- a/entc/integration/hooks/ent/card_update.go +++ b/entc/integration/hooks/ent/card_update.go @@ -73,6 +73,26 @@ func (cu *CardUpdate) SetInHook(s string) *CardUpdate { return cu } +// SetExpiredAt sets the "expired_at" field. +func (cu *CardUpdate) SetExpiredAt(t time.Time) *CardUpdate { + cu.mutation.SetExpiredAt(t) + return cu +} + +// SetNillableExpiredAt sets the "expired_at" field if the given value is not nil. +func (cu *CardUpdate) SetNillableExpiredAt(t *time.Time) *CardUpdate { + if t != nil { + cu.SetExpiredAt(*t) + } + return cu +} + +// ClearExpiredAt clears the value of the "expired_at" field. +func (cu *CardUpdate) ClearExpiredAt() *CardUpdate { + cu.mutation.ClearExpiredAt() + return cu +} + // SetOwnerID sets the "owner" edge to the User entity by ID. func (cu *CardUpdate) SetOwnerID(id int) *CardUpdate { cu.mutation.SetOwnerID(id) @@ -187,6 +207,12 @@ func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := cu.mutation.InHook(); ok { _spec.SetField(card.FieldInHook, field.TypeString, value) } + if value, ok := cu.mutation.ExpiredAt(); ok { + _spec.SetField(card.FieldExpiredAt, field.TypeTime, value) + } + if cu.mutation.ExpiredAtCleared() { + _spec.ClearField(card.FieldExpiredAt, field.TypeTime) + } if cu.mutation.OwnerCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -281,6 +307,26 @@ func (cuo *CardUpdateOne) SetInHook(s string) *CardUpdateOne { return cuo } +// SetExpiredAt sets the "expired_at" field. +func (cuo *CardUpdateOne) SetExpiredAt(t time.Time) *CardUpdateOne { + cuo.mutation.SetExpiredAt(t) + return cuo +} + +// SetNillableExpiredAt sets the "expired_at" field if the given value is not nil. +func (cuo *CardUpdateOne) SetNillableExpiredAt(t *time.Time) *CardUpdateOne { + if t != nil { + cuo.SetExpiredAt(*t) + } + return cuo +} + +// ClearExpiredAt clears the value of the "expired_at" field. +func (cuo *CardUpdateOne) ClearExpiredAt() *CardUpdateOne { + cuo.mutation.ClearExpiredAt() + return cuo +} + // SetOwnerID sets the "owner" edge to the User entity by ID. func (cuo *CardUpdateOne) SetOwnerID(id int) *CardUpdateOne { cuo.mutation.SetOwnerID(id) @@ -425,6 +471,12 @@ func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (_node *Card, err error) if value, ok := cuo.mutation.InHook(); ok { _spec.SetField(card.FieldInHook, field.TypeString, value) } + if value, ok := cuo.mutation.ExpiredAt(); ok { + _spec.SetField(card.FieldExpiredAt, field.TypeTime, value) + } + if cuo.mutation.ExpiredAtCleared() { + _spec.ClearField(card.FieldExpiredAt, field.TypeTime) + } if cuo.mutation.OwnerCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entc/integration/hooks/ent/client.go b/entc/integration/hooks/ent/client.go index 8a609beef..0f717af92 100644 --- a/entc/integration/hooks/ent/client.go +++ b/entc/integration/hooks/ent/client.go @@ -134,6 +134,18 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CardMutation: + return c.Card.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // CardClient is a client for the Card schema. type CardClient struct { config @@ -241,6 +253,21 @@ func (c *CardClient) Hooks() []Hook { return append(hooks[:len(hooks):len(hooks)], card.Hooks[:]...) } +func (c *CardClient) mutate(ctx context.Context, m *CardMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CardCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CardUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CardUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CardDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Card mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -379,3 +406,18 @@ func (c *UserClient) Hooks() []Hook { hooks := c.hooks.User return append(hooks[:len(hooks):len(hooks)], user.Hooks[:]...) } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/hooks/ent/internal/schema.go b/entc/integration/hooks/ent/internal/schema.go index dfd968ff2..f053c7266 100644 --- a/entc/integration/hooks/ent/internal/schema.go +++ b/entc/integration/hooks/ent/internal/schema.go @@ -10,4 +10,4 @@ // Package internal holds a loadable version of the latest schema. package internal -const Schema = `{"Schema":"entgo.io/ent/entc/integration/hooks/ent/schema","Package":"entgo.io/ent/entc/integration/hooks/ent","Schemas":[{"name":"Card","config":{"Table":""},"edges":[{"name":"owner","type":"User","ref_name":"cards","unique":true,"inverse":true}],"fields":[{"name":"number","type":{"Type":7,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"default":true,"default_value":"unknown","default_kind":24,"immutable":true,"validators":1,"position":{"Index":0,"MixedIn":false,"MixinIndex":0}},{"name":"name","type":{"Type":7,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":1,"MixedIn":false,"MixinIndex":0},"comment":"Exact name written on card"},{"name":"created_at","type":{"Type":2,"Ident":"","PkgPath":"time","PkgName":"","Nillable":false,"RType":null},"default":true,"default_kind":19,"position":{"Index":2,"MixedIn":false,"MixinIndex":0}},{"name":"in_hook","type":{"Type":7,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"position":{"Index":3,"MixedIn":false,"MixinIndex":0},"comment":"InHook is a mandatory field that is set by the hook."}],"hooks":[{"Index":0,"MixedIn":true,"MixinIndex":0},{"Index":0,"MixedIn":false,"MixinIndex":0},{"Index":1,"MixedIn":false,"MixinIndex":0}]},{"name":"User","config":{"Table":""},"edges":[{"name":"cards","type":"Card"},{"name":"friends","type":"User"},{"name":"best_friend","type":"User","unique":true}],"fields":[{"name":"version","type":{"Type":12,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"default":true,"default_value":0,"default_kind":2,"position":{"Index":0,"MixedIn":true,"MixinIndex":0}},{"name":"name","type":{"Type":7,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"position":{"Index":0,"MixedIn":false,"MixinIndex":0}},{"name":"worth","type":{"Type":17,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":1,"MixedIn":false,"MixinIndex":0}},{"name":"password","type":{"Type":7,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":2,"MixedIn":false,"MixinIndex":0},"sensitive":true}],"hooks":[{"Index":0,"MixedIn":true,"MixinIndex":0},{"Index":0,"MixedIn":false,"MixinIndex":0}]}],"Features":["schema/snapshot"]}` +const Schema = `{"Schema":"entgo.io/ent/entc/integration/hooks/ent/schema","Package":"entgo.io/ent/entc/integration/hooks/ent","Schemas":[{"name":"Card","config":{"Table":""},"edges":[{"name":"owner","type":"User","ref_name":"cards","unique":true,"inverse":true}],"fields":[{"name":"number","type":{"Type":7,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"default":true,"default_value":"unknown","default_kind":24,"immutable":true,"validators":1,"position":{"Index":0,"MixedIn":false,"MixinIndex":0}},{"name":"name","type":{"Type":7,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":1,"MixedIn":false,"MixinIndex":0},"comment":"Exact name written on card"},{"name":"created_at","type":{"Type":2,"Ident":"","PkgPath":"time","PkgName":"","Nillable":false,"RType":null},"default":true,"default_kind":19,"position":{"Index":2,"MixedIn":false,"MixinIndex":0}},{"name":"in_hook","type":{"Type":7,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"position":{"Index":3,"MixedIn":false,"MixinIndex":0},"comment":"InHook is a mandatory field that is set by the hook."},{"name":"expired_at","type":{"Type":2,"Ident":"","PkgPath":"time","PkgName":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":4,"MixedIn":false,"MixinIndex":0}}],"hooks":[{"Index":0,"MixedIn":true,"MixinIndex":0},{"Index":0,"MixedIn":false,"MixinIndex":0},{"Index":1,"MixedIn":false,"MixinIndex":0}]},{"name":"User","config":{"Table":""},"edges":[{"name":"cards","type":"Card"},{"name":"friends","type":"User"},{"name":"best_friend","type":"User","unique":true}],"fields":[{"name":"version","type":{"Type":12,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"default":true,"default_value":0,"default_kind":2,"position":{"Index":0,"MixedIn":true,"MixinIndex":0}},{"name":"name","type":{"Type":7,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"position":{"Index":0,"MixedIn":false,"MixinIndex":0}},{"name":"worth","type":{"Type":17,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":1,"MixedIn":false,"MixinIndex":0}},{"name":"password","type":{"Type":7,"Ident":"","PkgPath":"","PkgName":"","Nillable":false,"RType":null},"optional":true,"position":{"Index":2,"MixedIn":false,"MixinIndex":0},"sensitive":true}],"hooks":[{"Index":0,"MixedIn":true,"MixinIndex":0},{"Index":0,"MixedIn":false,"MixinIndex":0}]}],"Features":["schema/snapshot"]}` diff --git a/entc/integration/hooks/ent/migrate/schema.go b/entc/integration/hooks/ent/migrate/schema.go index e31d4d372..1abfc302f 100644 --- a/entc/integration/hooks/ent/migrate/schema.go +++ b/entc/integration/hooks/ent/migrate/schema.go @@ -19,6 +19,7 @@ var ( {Name: "name", Type: field.TypeString, Nullable: true}, {Name: "created_at", Type: field.TypeTime}, {Name: "in_hook", Type: field.TypeString}, + {Name: "expired_at", Type: field.TypeTime, Nullable: true}, {Name: "user_cards", Type: field.TypeInt, Nullable: true}, } // CardsTable holds the schema information for the "cards" table. @@ -29,7 +30,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "cards_users_cards", - Columns: []*schema.Column{CardsColumns[5]}, + Columns: []*schema.Column{CardsColumns[6]}, RefColumns: []*schema.Column{UsersColumns[0]}, OnDelete: schema.SetNull, }, diff --git a/entc/integration/hooks/ent/mutation.go b/entc/integration/hooks/ent/mutation.go index 1ca4ab1d4..09b6cf862 100644 --- a/entc/integration/hooks/ent/mutation.go +++ b/entc/integration/hooks/ent/mutation.go @@ -43,6 +43,7 @@ type CardMutation struct { name *string created_at *time.Time in_hook *string + expired_at *time.Time clearedFields map[string]struct{} owner *int clearedowner bool @@ -306,6 +307,55 @@ func (m *CardMutation) ResetInHook() { m.in_hook = nil } +// SetExpiredAt sets the "expired_at" field. +func (m *CardMutation) SetExpiredAt(t time.Time) { + m.expired_at = &t +} + +// ExpiredAt returns the value of the "expired_at" field in the mutation. +func (m *CardMutation) ExpiredAt() (r time.Time, exists bool) { + v := m.expired_at + if v == nil { + return + } + return *v, true +} + +// OldExpiredAt returns the old "expired_at" field's value of the Card entity. +// If the Card object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *CardMutation) OldExpiredAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldExpiredAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldExpiredAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldExpiredAt: %w", err) + } + return oldValue.ExpiredAt, nil +} + +// ClearExpiredAt clears the value of the "expired_at" field. +func (m *CardMutation) ClearExpiredAt() { + m.expired_at = nil + m.clearedFields[card.FieldExpiredAt] = struct{}{} +} + +// ExpiredAtCleared returns if the "expired_at" field was cleared in this mutation. +func (m *CardMutation) ExpiredAtCleared() bool { + _, ok := m.clearedFields[card.FieldExpiredAt] + return ok +} + +// ResetExpiredAt resets all changes to the "expired_at" field. +func (m *CardMutation) ResetExpiredAt() { + m.expired_at = nil + delete(m.clearedFields, card.FieldExpiredAt) +} + // SetOwnerID sets the "owner" edge to the User entity by id. func (m *CardMutation) SetOwnerID(id int) { m.owner = &id @@ -355,6 +405,11 @@ func (m *CardMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CardMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Card). func (m *CardMutation) Type() string { return m.typ @@ -364,7 +419,7 @@ func (m *CardMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *CardMutation) Fields() []string { - fields := make([]string, 0, 4) + fields := make([]string, 0, 5) if m.number != nil { fields = append(fields, card.FieldNumber) } @@ -377,6 +432,9 @@ func (m *CardMutation) Fields() []string { if m.in_hook != nil { fields = append(fields, card.FieldInHook) } + if m.expired_at != nil { + fields = append(fields, card.FieldExpiredAt) + } return fields } @@ -393,6 +451,8 @@ func (m *CardMutation) Field(name string) (ent.Value, bool) { return m.CreatedAt() case card.FieldInHook: return m.InHook() + case card.FieldExpiredAt: + return m.ExpiredAt() } return nil, false } @@ -410,6 +470,8 @@ func (m *CardMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldCreatedAt(ctx) case card.FieldInHook: return m.OldInHook(ctx) + case card.FieldExpiredAt: + return m.OldExpiredAt(ctx) } return nil, fmt.Errorf("unknown Card field %s", name) } @@ -447,6 +509,13 @@ func (m *CardMutation) SetField(name string, value ent.Value) error { } m.SetInHook(v) return nil + case card.FieldExpiredAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetExpiredAt(v) + return nil } return fmt.Errorf("unknown Card field %s", name) } @@ -480,6 +549,9 @@ func (m *CardMutation) ClearedFields() []string { if m.FieldCleared(card.FieldName) { fields = append(fields, card.FieldName) } + if m.FieldCleared(card.FieldExpiredAt) { + fields = append(fields, card.FieldExpiredAt) + } return fields } @@ -497,6 +569,9 @@ func (m *CardMutation) ClearField(name string) error { case card.FieldName: m.ClearName() return nil + case card.FieldExpiredAt: + m.ClearExpiredAt() + return nil } return fmt.Errorf("unknown Card nullable field %s", name) } @@ -517,6 +592,9 @@ func (m *CardMutation) ResetField(name string) error { case card.FieldInHook: m.ResetInHook() return nil + case card.FieldExpiredAt: + m.ResetExpiredAt() + return nil } return fmt.Errorf("unknown Card field %s", name) } @@ -1087,6 +1165,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/hooks/ent/schema/card.go b/entc/integration/hooks/ent/schema/card.go index 552d525e4..6a5477d84 100644 --- a/entc/integration/hooks/ent/schema/card.go +++ b/entc/integration/hooks/ent/schema/card.go @@ -18,7 +18,7 @@ import ( "entgo.io/ent/schema/mixin" ) -// RejectUpdate rejects all update operations +// RejectUpdate rejects ~all update operations // that are not on a specific entity. type RejectUpdate struct { mixin.Schema @@ -26,7 +26,11 @@ type RejectUpdate struct { func (RejectUpdate) Hooks() []ent.Hook { return []ent.Hook{ - hook.Reject(ent.OpUpdate), + hook.If( + hook.Reject(ent.OpUpdate), + // Accept only updates that contains the "expired_at" field. + hook.Not(hook.HasFields(card.FieldExpiredAt)), + ), } } @@ -84,6 +88,8 @@ func (Card) Fields() []ent.Field { Default(time.Now), field.String("in_hook"). Comment("InHook is a mandatory field that is set by the hook."), + field.Time("expired_at"). + Optional(), } } diff --git a/entc/integration/hooks/hooks_test.go b/entc/integration/hooks/hooks_test.go index d4bf813ec..d1d035bbc 100644 --- a/entc/integration/hooks/hooks_test.go +++ b/entc/integration/hooks/hooks_test.go @@ -9,6 +9,7 @@ import ( "fmt" "sort" "testing" + "time" "entgo.io/ent/entc/integration/hooks/ent" "entgo.io/ent/entc/integration/hooks/ent/card" @@ -105,6 +106,48 @@ func TestMutationClient(t *testing.T) { require.Equal(t, a8m.Name, crd.Name) } +func TestMutatorClient(t *testing.T) { + ctx := context.Background() + client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1") + defer client.Close() + client.Use( + hook.On( + func(next ent.Mutator) ent.Mutator { + return hook.CardFunc(func(ctx context.Context, m *ent.CardMutation) (ent.Value, error) { + op := ent.OpUpdate + if _, exists := m.ID(); exists && m.Op().Is(ent.OpDeleteOne) { + op = ent.OpUpdateOne + } + // Change the operation to update. + m.SetOp(op) + // Record when card was expired. + m.SetExpiredAt(time.Now()) + // Ensure card was not expired before. + m.Where(card.ExpiredAtIsNil()) + return m.Client().Mutate(ctx, m) + }) + }, + ent.OpDelete|ent.OpDeleteOne, + ), + ) + c1 := client.Card.Create().SetNumber("1234").SaveX(ctx) + client.Card.DeleteOne(c1).ExecX(ctx) + expired := client.Card.Query().OnlyX(ctx) + require.False(t, expired.ExpiredAt.IsZero()) + + client.Card.Create().SetNumber("4567").ExecX(ctx) + client.Card.Create().SetNumber("7890").ExecX(ctx) + client.Card.Delete().Where(card.Number("4567")).ExecX(ctx) + cards := client.Card.Query().Order(ent.Asc(card.FieldNumber)).AllX(ctx) + require.Len(t, cards, 3) + require.True(t, cards[0].ExpiredAt.Equal(expired.ExpiredAt), "expired field should not be updated") + require.False(t, cards[1].ExpiredAt.IsZero()) + require.True(t, cards[2].ExpiredAt.IsZero()) + + client.Card.Delete().ExecX(ctx) + require.False(t, client.Card.Query().Where(card.ExpiredAtIsNil()).ExistX(ctx)) +} + func TestMutationTx(t *testing.T) { ctx := context.Background() client := enttest.Open(t, "sqlite3", "file:ent?mode=memory&cache=shared&_fk=1", enttest.WithMigrateOptions(migrate.WithGlobalUniqueID(true))) diff --git a/entc/integration/idtype/ent/client.go b/entc/integration/idtype/ent/client.go index 899c6604d..b1f3467be 100644 --- a/entc/integration/idtype/ent/client.go +++ b/entc/integration/idtype/ent/client.go @@ -127,6 +127,16 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -264,3 +274,18 @@ func (c *UserClient) QueryFollowing(u *User) *UserQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/idtype/ent/mutation.go b/entc/integration/idtype/ent/mutation.go index 106bf80e0..34f6fbaf3 100644 --- a/entc/integration/idtype/ent/mutation.go +++ b/entc/integration/idtype/ent/mutation.go @@ -342,6 +342,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/json/ent/client.go b/entc/integration/json/ent/client.go index 55cc0563c..d43e31e4f 100644 --- a/entc/integration/json/ent/client.go +++ b/entc/integration/json/ent/client.go @@ -126,6 +126,16 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -215,3 +225,18 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/json/ent/mutation.go b/entc/integration/json/ent/mutation.go index 42bbb7503..441a4224d 100644 --- a/entc/integration/json/ent/mutation.go +++ b/entc/integration/json/ent/mutation.go @@ -692,6 +692,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/migrate/entv1/client.go b/entc/integration/migrate/entv1/client.go index dad30dd81..9bae71cc2 100644 --- a/entc/integration/migrate/entv1/client.go +++ b/entc/integration/migrate/entv1/client.go @@ -148,6 +148,22 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CarMutation: + return c.Car.mutate(ctx, m) + case *ConversionMutation: + return c.Conversion.mutate(ctx, m) + case *CustomTypeMutation: + return c.CustomType.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("entv1: unknown mutation type %T", m) + } +} + // CarClient is a client for the Car schema. type CarClient struct { config @@ -254,6 +270,21 @@ func (c *CarClient) Hooks() []Hook { return c.hooks.Car } +func (c *CarClient) mutate(ctx context.Context, m *CarMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CarCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CarUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CarDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv1: unknown Car mutation op: %q", m.Op()) + } +} + // ConversionClient is a client for the Conversion schema. type ConversionClient struct { config @@ -344,6 +375,21 @@ func (c *ConversionClient) Hooks() []Hook { return c.hooks.Conversion } +func (c *ConversionClient) mutate(ctx context.Context, m *ConversionMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ConversionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ConversionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ConversionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ConversionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv1: unknown Conversion mutation op: %q", m.Op()) + } +} + // CustomTypeClient is a client for the CustomType schema. type CustomTypeClient struct { config @@ -434,6 +480,21 @@ func (c *CustomTypeClient) Hooks() []Hook { return c.hooks.CustomType } +func (c *CustomTypeClient) mutate(ctx context.Context, m *CustomTypeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CustomTypeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CustomTypeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CustomTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CustomTypeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv1: unknown CustomType mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -587,3 +648,18 @@ func (c *UserClient) QueryCar(u *User) *CarQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv1: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/migrate/entv1/mutation.go b/entc/integration/migrate/entv1/mutation.go index 6ff64cc30..e0dc6b4e8 100644 --- a/entc/integration/migrate/entv1/mutation.go +++ b/entc/integration/migrate/entv1/mutation.go @@ -197,6 +197,11 @@ func (m *CarMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CarMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Car). func (m *CarMutation) Type() string { return m.typ @@ -1098,6 +1103,11 @@ func (m *ConversionMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *ConversionMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Conversion). func (m *ConversionMutation) Type() string { return m.typ @@ -1714,6 +1724,11 @@ func (m *CustomTypeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CustomTypeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (CustomType). func (m *CustomTypeMutation) Type() string { return m.typ @@ -2752,6 +2767,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/migrate/entv2/client.go b/entc/integration/migrate/entv2/client.go index 2acc1169f..8995aa997 100644 --- a/entc/integration/migrate/entv2/client.go +++ b/entc/integration/migrate/entv2/client.go @@ -183,6 +183,32 @@ func (c *Client) Use(hooks ...Hook) { c.Zoo.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *BlogMutation: + return c.Blog.mutate(ctx, m) + case *CarMutation: + return c.Car.mutate(ctx, m) + case *ConversionMutation: + return c.Conversion.mutate(ctx, m) + case *CustomTypeMutation: + return c.CustomType.mutate(ctx, m) + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *MediaMutation: + return c.Media.mutate(ctx, m) + case *PetMutation: + return c.Pet.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + case *ZooMutation: + return c.Zoo.mutate(ctx, m) + default: + return nil, fmt.Errorf("entv2: unknown mutation type %T", m) + } +} + // BlogClient is a client for the Blog schema. type BlogClient struct { config @@ -289,6 +315,21 @@ func (c *BlogClient) Hooks() []Hook { return c.hooks.Blog } +func (c *BlogClient) mutate(ctx context.Context, m *BlogMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&BlogCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&BlogUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&BlogUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&BlogDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv2: unknown Blog mutation op: %q", m.Op()) + } +} + // CarClient is a client for the Car schema. type CarClient struct { config @@ -395,6 +436,21 @@ func (c *CarClient) Hooks() []Hook { return c.hooks.Car } +func (c *CarClient) mutate(ctx context.Context, m *CarMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CarCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CarUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CarDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv2: unknown Car mutation op: %q", m.Op()) + } +} + // ConversionClient is a client for the Conversion schema. type ConversionClient struct { config @@ -485,6 +541,21 @@ func (c *ConversionClient) Hooks() []Hook { return c.hooks.Conversion } +func (c *ConversionClient) mutate(ctx context.Context, m *ConversionMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ConversionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ConversionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ConversionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ConversionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv2: unknown Conversion mutation op: %q", m.Op()) + } +} + // CustomTypeClient is a client for the CustomType schema. type CustomTypeClient struct { config @@ -575,6 +646,21 @@ func (c *CustomTypeClient) Hooks() []Hook { return c.hooks.CustomType } +func (c *CustomTypeClient) mutate(ctx context.Context, m *CustomTypeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CustomTypeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CustomTypeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CustomTypeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CustomTypeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv2: unknown CustomType mutation op: %q", m.Op()) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -665,6 +751,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv2: unknown Group mutation op: %q", m.Op()) + } +} + // MediaClient is a client for the Media schema. type MediaClient struct { config @@ -755,6 +856,21 @@ func (c *MediaClient) Hooks() []Hook { return c.hooks.Media } +func (c *MediaClient) mutate(ctx context.Context, m *MediaMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&MediaCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&MediaUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&MediaUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&MediaDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv2: unknown Media mutation op: %q", m.Op()) + } +} + // PetClient is a client for the Pet schema. type PetClient struct { config @@ -861,6 +977,21 @@ func (c *PetClient) Hooks() []Hook { return c.hooks.Pet } +func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv2: unknown Pet mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -999,6 +1130,21 @@ func (c *UserClient) Hooks() []Hook { return c.hooks.User } +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv2: unknown User mutation op: %q", m.Op()) + } +} + // ZooClient is a client for the Zoo schema. type ZooClient struct { config @@ -1088,3 +1234,18 @@ func (c *ZooClient) GetX(ctx context.Context, id int) *Zoo { func (c *ZooClient) Hooks() []Hook { return c.hooks.Zoo } + +func (c *ZooClient) mutate(ctx context.Context, m *ZooMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&ZooCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&ZooUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&ZooUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&ZooDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("entv2: unknown Zoo mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/migrate/entv2/mutation.go b/entc/integration/migrate/entv2/mutation.go index dbf370fff..1073d5a39 100644 --- a/entc/integration/migrate/entv2/mutation.go +++ b/entc/integration/migrate/entv2/mutation.go @@ -228,6 +228,11 @@ func (m *BlogMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *BlogMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Blog). func (m *BlogMutation) Type() string { return m.typ @@ -604,6 +609,11 @@ func (m *CarMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CarMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Car). func (m *CarMutation) Type() string { return m.typ @@ -1363,6 +1373,11 @@ func (m *ConversionMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *ConversionMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Conversion). func (m *ConversionMutation) Type() string { return m.typ @@ -1980,6 +1995,11 @@ func (m *CustomTypeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CustomTypeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (CustomType). func (m *CustomTypeMutation) Type() string { return m.typ @@ -2309,6 +2329,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -2708,6 +2733,11 @@ func (m *MediaMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *MediaMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Media). func (m *MediaMutation) Type() string { return m.typ @@ -3128,6 +3158,11 @@ func (m *PetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Pet). func (m *PetMutation) Type() string { return m.typ @@ -4543,6 +4578,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ @@ -5321,6 +5361,11 @@ func (m *ZooMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *ZooMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Zoo). func (m *ZooMutation) Type() string { return m.typ diff --git a/entc/integration/migrate/versioned/client.go b/entc/integration/migrate/versioned/client.go index a03bf2508..b1f192cfc 100644 --- a/entc/integration/migrate/versioned/client.go +++ b/entc/integration/migrate/versioned/client.go @@ -133,6 +133,18 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("versioned: unknown mutation type %T", m) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -223,6 +235,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("versioned: unknown Group mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -312,3 +339,18 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("versioned: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/migrate/versioned/mutation.go b/entc/integration/migrate/versioned/mutation.go index 3c909b370..9138a9fe8 100644 --- a/entc/integration/migrate/versioned/mutation.go +++ b/entc/integration/migrate/versioned/mutation.go @@ -189,6 +189,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -608,6 +613,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/multischema/ent/client.go b/entc/integration/multischema/ent/client.go index 1e7c49534..b1a5c347a 100644 --- a/entc/integration/multischema/ent/client.go +++ b/entc/integration/multischema/ent/client.go @@ -148,6 +148,22 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *FriendshipMutation: + return c.Friendship.mutate(ctx, m) + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *PetMutation: + return c.Pet.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // FriendshipClient is a client for the Friendship schema. type FriendshipClient struct { config @@ -276,6 +292,21 @@ func (c *FriendshipClient) Hooks() []Hook { return c.hooks.Friendship } +func (c *FriendshipClient) mutate(ctx context.Context, m *FriendshipMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FriendshipCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FriendshipUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FriendshipUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FriendshipDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Friendship mutation op: %q", m.Op()) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -385,6 +416,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // PetClient is a client for the Pet schema. type PetClient struct { config @@ -494,6 +540,21 @@ func (c *PetClient) Hooks() []Hook { return c.hooks.Pet } +func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Pet mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -659,3 +720,18 @@ func (c *UserClient) QueryFriendships(u *User) *FriendshipQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/multischema/ent/mutation.go b/entc/integration/multischema/ent/mutation.go index b3cd438c6..702a65d05 100644 --- a/entc/integration/multischema/ent/mutation.go +++ b/entc/integration/multischema/ent/mutation.go @@ -380,6 +380,11 @@ func (m *FriendshipMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *FriendshipMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Friendship). func (m *FriendshipMutation) Type() string { return m.typ @@ -858,6 +863,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -1282,6 +1292,11 @@ func (m *PetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Pet). func (m *PetMutation) Type() string { return m.typ @@ -1876,6 +1891,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/privacy/ent/client.go b/entc/integration/privacy/ent/client.go index d5f63b32d..130199f2e 100644 --- a/entc/integration/privacy/ent/client.go +++ b/entc/integration/privacy/ent/client.go @@ -141,6 +141,20 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *TaskMutation: + return c.Task.mutate(ctx, m) + case *TeamMutation: + return c.Team.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // TaskClient is a client for the Task schema. type TaskClient struct { config @@ -264,6 +278,21 @@ func (c *TaskClient) Hooks() []Hook { return append(hooks[:len(hooks):len(hooks)], task.Hooks[:]...) } +func (c *TaskClient) mutate(ctx context.Context, m *TaskMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TaskCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TaskUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TaskUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TaskDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Task mutation op: %q", m.Op()) + } +} + // TeamClient is a client for the Team schema. type TeamClient struct { config @@ -387,6 +416,21 @@ func (c *TeamClient) Hooks() []Hook { return append(hooks[:len(hooks):len(hooks)], team.Hooks[:]...) } +func (c *TeamClient) mutate(ctx context.Context, m *TeamMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TeamCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TeamUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TeamUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TeamDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Team mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -509,3 +553,18 @@ func (c *UserClient) Hooks() []Hook { hooks := c.hooks.User return append(hooks[:len(hooks):len(hooks)], user.Hooks[:]...) } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/privacy/ent/mutation.go b/entc/integration/privacy/ent/mutation.go index 69f4858b5..b8a9c0241 100644 --- a/entc/integration/privacy/ent/mutation.go +++ b/entc/integration/privacy/ent/mutation.go @@ -427,6 +427,11 @@ func (m *TaskMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TaskMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Task). func (m *TaskMutation) Type() string { return m.typ @@ -972,6 +977,11 @@ func (m *TeamMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TeamMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Team). func (m *TeamMutation) Type() string { return m.typ @@ -1531,6 +1541,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/entc/integration/template/ent/client.go b/entc/integration/template/ent/client.go index e28218033..541fc94b3 100644 --- a/entc/integration/template/ent/client.go +++ b/entc/integration/template/ent/client.go @@ -150,6 +150,20 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *PetMutation: + return c.Pet.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -241,6 +255,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // PetClient is a client for the Pet schema. type PetClient struct { config @@ -348,6 +377,21 @@ func (c *PetClient) Hooks() []Hook { return c.hooks.Pet } +func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Pet mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -470,3 +514,18 @@ func (c *UserClient) QueryFriends(u *User) *UserQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/entc/integration/template/ent/mutation.go b/entc/integration/template/ent/mutation.go index ff182e034..e785e9348 100644 --- a/entc/integration/template/ent/mutation.go +++ b/entc/integration/template/ent/mutation.go @@ -213,6 +213,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -651,6 +656,11 @@ func (m *PetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Pet). func (m *PetMutation) Type() string { return m.typ @@ -1143,6 +1153,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/edgeindex/ent/client.go b/examples/edgeindex/ent/client.go index f93038333..32a377e95 100644 --- a/examples/edgeindex/ent/client.go +++ b/examples/edgeindex/ent/client.go @@ -134,6 +134,18 @@ func (c *Client) Use(hooks ...Hook) { c.Street.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CityMutation: + return c.City.mutate(ctx, m) + case *StreetMutation: + return c.Street.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // CityClient is a client for the City schema. type CityClient struct { config @@ -240,6 +252,21 @@ func (c *CityClient) Hooks() []Hook { return c.hooks.City } +func (c *CityClient) mutate(ctx context.Context, m *CityMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CityCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CityUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CityUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CityDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown City mutation op: %q", m.Op()) + } +} + // StreetClient is a client for the Street schema. type StreetClient struct { config @@ -345,3 +372,18 @@ func (c *StreetClient) QueryCity(s *Street) *CityQuery { func (c *StreetClient) Hooks() []Hook { return c.hooks.Street } + +func (c *StreetClient) mutate(ctx context.Context, m *StreetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&StreetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&StreetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&StreetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&StreetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Street mutation op: %q", m.Op()) + } +} diff --git a/examples/edgeindex/ent/mutation.go b/examples/edgeindex/ent/mutation.go index 56987dc31..8251baa3f 100644 --- a/examples/edgeindex/ent/mutation.go +++ b/examples/edgeindex/ent/mutation.go @@ -246,6 +246,11 @@ func (m *CityMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CityMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (City). func (m *CityMutation) Type() string { return m.typ @@ -634,6 +639,11 @@ func (m *StreetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *StreetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Street). func (m *StreetMutation) Type() string { return m.typ diff --git a/examples/entcpkg/ent/client.go b/examples/entcpkg/ent/client.go index c3cbedc02..a9c8e9c69 100644 --- a/examples/entcpkg/ent/client.go +++ b/examples/entcpkg/ent/client.go @@ -126,6 +126,16 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -215,3 +225,18 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/entcpkg/ent/mutation.go b/examples/entcpkg/ent/mutation.go index f0a2c1a41..600d20507 100644 --- a/examples/entcpkg/ent/mutation.go +++ b/examples/entcpkg/ent/mutation.go @@ -272,6 +272,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/fs/ent/client.go b/examples/fs/ent/client.go index 659062e1b..a0152a8d8 100644 --- a/examples/fs/ent/client.go +++ b/examples/fs/ent/client.go @@ -127,6 +127,16 @@ func (c *Client) Use(hooks ...Hook) { c.File.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *FileMutation: + return c.File.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // FileClient is a client for the File schema. type FileClient struct { config @@ -248,3 +258,18 @@ func (c *FileClient) QueryChildren(f *File) *FileQuery { func (c *FileClient) Hooks() []Hook { return c.hooks.File } + +func (c *FileClient) mutate(ctx context.Context, m *FileMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&FileCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&FileUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&FileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&FileDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown File mutation op: %q", m.Op()) + } +} diff --git a/examples/fs/ent/mutation.go b/examples/fs/ent/mutation.go index a9d14532d..e306bdd01 100644 --- a/examples/fs/ent/mutation.go +++ b/examples/fs/ent/mutation.go @@ -358,6 +358,11 @@ func (m *FileMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *FileMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (File). func (m *FileMutation) Type() string { return m.typ diff --git a/examples/jsonencode/ent/client.go b/examples/jsonencode/ent/client.go index 193019c3a..4c3cef1dc 100644 --- a/examples/jsonencode/ent/client.go +++ b/examples/jsonencode/ent/client.go @@ -134,6 +134,18 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *PetMutation: + return c.Pet.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // PetClient is a client for the Pet schema. type PetClient struct { config @@ -240,6 +252,21 @@ func (c *PetClient) Hooks() []Hook { return c.hooks.Pet } +func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Pet mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -345,3 +372,18 @@ func (c *UserClient) QueryPets(u *User) *PetQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/jsonencode/ent/mutation.go b/examples/jsonencode/ent/mutation.go index 0f4a1e8c5..b40b3dfba 100644 --- a/examples/jsonencode/ent/mutation.go +++ b/examples/jsonencode/ent/mutation.go @@ -311,6 +311,11 @@ func (m *PetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Pet). func (m *PetMutation) Type() string { return m.typ @@ -812,6 +817,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/m2m2types/ent/client.go b/examples/m2m2types/ent/client.go index 040ef96d7..9cd4bb552 100644 --- a/examples/m2m2types/ent/client.go +++ b/examples/m2m2types/ent/client.go @@ -134,6 +134,18 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -240,6 +252,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -345,3 +372,18 @@ func (c *UserClient) QueryGroups(u *User) *GroupQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/m2m2types/ent/mutation.go b/examples/m2m2types/ent/mutation.go index d0ca554b2..b24987c3d 100644 --- a/examples/m2m2types/ent/mutation.go +++ b/examples/m2m2types/ent/mutation.go @@ -246,6 +246,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -708,6 +713,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/m2mbidi/ent/client.go b/examples/m2mbidi/ent/client.go index d523e8c9c..364da3b05 100644 --- a/examples/m2mbidi/ent/client.go +++ b/examples/m2mbidi/ent/client.go @@ -127,6 +127,16 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -232,3 +242,18 @@ func (c *UserClient) QueryFriends(u *User) *UserQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/m2mbidi/ent/mutation.go b/examples/m2mbidi/ent/mutation.go index 56298b911..d38985a69 100644 --- a/examples/m2mbidi/ent/mutation.go +++ b/examples/m2mbidi/ent/mutation.go @@ -302,6 +302,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/m2mrecur/ent/client.go b/examples/m2mrecur/ent/client.go index 1020e4f1e..df7bacd4b 100644 --- a/examples/m2mrecur/ent/client.go +++ b/examples/m2mrecur/ent/client.go @@ -127,6 +127,16 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -248,3 +258,18 @@ func (c *UserClient) QueryFollowing(u *User) *UserQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/m2mrecur/ent/mutation.go b/examples/m2mrecur/ent/mutation.go index 98efb11e7..e547262d6 100644 --- a/examples/m2mrecur/ent/mutation.go +++ b/examples/m2mrecur/ent/mutation.go @@ -359,6 +359,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/migration/ent/client.go b/examples/migration/ent/client.go index 3de4ffeca..4de61b9da 100644 --- a/examples/migration/ent/client.go +++ b/examples/migration/ent/client.go @@ -126,6 +126,16 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -215,3 +225,18 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/migration/ent/mutation.go b/examples/migration/ent/mutation.go index 0a0ea491f..ecb59d2ab 100644 --- a/examples/migration/ent/mutation.go +++ b/examples/migration/ent/mutation.go @@ -312,6 +312,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/o2m2types/ent/client.go b/examples/o2m2types/ent/client.go index ed099aeeb..926d0abe7 100644 --- a/examples/o2m2types/ent/client.go +++ b/examples/o2m2types/ent/client.go @@ -134,6 +134,18 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *PetMutation: + return c.Pet.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // PetClient is a client for the Pet schema. type PetClient struct { config @@ -240,6 +252,21 @@ func (c *PetClient) Hooks() []Hook { return c.hooks.Pet } +func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Pet mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -345,3 +372,18 @@ func (c *UserClient) QueryPets(u *User) *PetQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/o2m2types/ent/mutation.go b/examples/o2m2types/ent/mutation.go index dda7dfbcc..6a15a78f7 100644 --- a/examples/o2m2types/ent/mutation.go +++ b/examples/o2m2types/ent/mutation.go @@ -230,6 +230,11 @@ func (m *PetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Pet). func (m *PetMutation) Type() string { return m.typ @@ -682,6 +687,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/o2mrecur/ent/client.go b/examples/o2mrecur/ent/client.go index 6e02c6ac1..89941c342 100644 --- a/examples/o2mrecur/ent/client.go +++ b/examples/o2mrecur/ent/client.go @@ -127,6 +127,16 @@ func (c *Client) Use(hooks ...Hook) { c.Node.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *NodeMutation: + return c.Node.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // NodeClient is a client for the Node schema. type NodeClient struct { config @@ -248,3 +258,18 @@ func (c *NodeClient) QueryChildren(n *Node) *NodeQuery { func (c *NodeClient) Hooks() []Hook { return c.hooks.Node } + +func (c *NodeClient) mutate(ctx context.Context, m *NodeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&NodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&NodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&NodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&NodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Node mutation op: %q", m.Op()) + } +} diff --git a/examples/o2mrecur/ent/mutation.go b/examples/o2mrecur/ent/mutation.go index 781b59a4a..7c8707b39 100644 --- a/examples/o2mrecur/ent/mutation.go +++ b/examples/o2mrecur/ent/mutation.go @@ -306,6 +306,11 @@ func (m *NodeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *NodeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Node). func (m *NodeMutation) Type() string { return m.typ diff --git a/examples/o2o2types/ent/client.go b/examples/o2o2types/ent/client.go index aeb1d4afb..461ac0005 100644 --- a/examples/o2o2types/ent/client.go +++ b/examples/o2o2types/ent/client.go @@ -134,6 +134,18 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CardMutation: + return c.Card.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // CardClient is a client for the Card schema. type CardClient struct { config @@ -240,6 +252,21 @@ func (c *CardClient) Hooks() []Hook { return c.hooks.Card } +func (c *CardClient) mutate(ctx context.Context, m *CardMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CardCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CardUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CardUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CardDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Card mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -345,3 +372,18 @@ func (c *UserClient) QueryCard(u *User) *CardQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/o2o2types/ent/mutation.go b/examples/o2o2types/ent/mutation.go index fff69bd13..5961bb21f 100644 --- a/examples/o2o2types/ent/mutation.go +++ b/examples/o2o2types/ent/mutation.go @@ -268,6 +268,11 @@ func (m *CardMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CardMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Card). func (m *CardMutation) Type() string { return m.typ @@ -721,6 +726,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/o2obidi/ent/client.go b/examples/o2obidi/ent/client.go index 72f8e3d6b..e0d9cb286 100644 --- a/examples/o2obidi/ent/client.go +++ b/examples/o2obidi/ent/client.go @@ -127,6 +127,16 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -232,3 +242,18 @@ func (c *UserClient) QuerySpouse(u *User) *UserQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/o2obidi/ent/mutation.go b/examples/o2obidi/ent/mutation.go index 3977fd6b9..6909990f2 100644 --- a/examples/o2obidi/ent/mutation.go +++ b/examples/o2obidi/ent/mutation.go @@ -286,6 +286,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/o2orecur/ent/client.go b/examples/o2orecur/ent/client.go index c5c7dab16..3fefd16ed 100644 --- a/examples/o2orecur/ent/client.go +++ b/examples/o2orecur/ent/client.go @@ -127,6 +127,16 @@ func (c *Client) Use(hooks ...Hook) { c.Node.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *NodeMutation: + return c.Node.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // NodeClient is a client for the Node schema. type NodeClient struct { config @@ -248,3 +258,18 @@ func (c *NodeClient) QueryNext(n *Node) *NodeQuery { func (c *NodeClient) Hooks() []Hook { return c.hooks.Node } + +func (c *NodeClient) mutate(ctx context.Context, m *NodeMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&NodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&NodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&NodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&NodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Node mutation op: %q", m.Op()) + } +} diff --git a/examples/o2orecur/ent/mutation.go b/examples/o2orecur/ent/mutation.go index c474c7988..ea5c03593 100644 --- a/examples/o2orecur/ent/mutation.go +++ b/examples/o2orecur/ent/mutation.go @@ -290,6 +290,11 @@ func (m *NodeMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *NodeMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Node). func (m *NodeMutation) Type() string { return m.typ diff --git a/examples/privacyadmin/ent/client.go b/examples/privacyadmin/ent/client.go index 2ac5b7cac..433247a7f 100644 --- a/examples/privacyadmin/ent/client.go +++ b/examples/privacyadmin/ent/client.go @@ -126,6 +126,16 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -216,3 +226,18 @@ func (c *UserClient) Hooks() []Hook { hooks := c.hooks.User return append(hooks[:len(hooks):len(hooks)], user.Hooks[:]...) } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/privacyadmin/ent/mutation.go b/examples/privacyadmin/ent/mutation.go index 47ef873c5..07da9d9b4 100644 --- a/examples/privacyadmin/ent/mutation.go +++ b/examples/privacyadmin/ent/mutation.go @@ -187,6 +187,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/privacytenant/ent/client.go b/examples/privacytenant/ent/client.go index 57a5dec45..bb83f9d9f 100644 --- a/examples/privacytenant/ent/client.go +++ b/examples/privacytenant/ent/client.go @@ -141,6 +141,20 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *TenantMutation: + return c.Tenant.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -264,6 +278,21 @@ func (c *GroupClient) Hooks() []Hook { return append(hooks[:len(hooks):len(hooks)], group.Hooks[:]...) } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // TenantClient is a client for the Tenant schema. type TenantClient struct { config @@ -355,6 +384,21 @@ func (c *TenantClient) Hooks() []Hook { return append(hooks[:len(hooks):len(hooks)], tenant.Hooks[:]...) } +func (c *TenantClient) mutate(ctx context.Context, m *TenantMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&TenantCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&TenantUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&TenantUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&TenantDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Tenant mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -477,3 +521,18 @@ func (c *UserClient) Hooks() []Hook { hooks := c.hooks.User return append(hooks[:len(hooks):len(hooks)], user.Hooks[:]...) } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/privacytenant/ent/mutation.go b/examples/privacytenant/ent/mutation.go index 3e9fda832..108ea1ec7 100644 --- a/examples/privacytenant/ent/mutation.go +++ b/examples/privacytenant/ent/mutation.go @@ -312,6 +312,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -697,6 +702,11 @@ func (m *TenantMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *TenantMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Tenant). func (m *TenantMutation) Type() string { return m.typ @@ -1196,6 +1206,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/start/ent/client.go b/examples/start/ent/client.go index c0d3324e1..b275243cb 100644 --- a/examples/start/ent/client.go +++ b/examples/start/ent/client.go @@ -141,6 +141,20 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *CarMutation: + return c.Car.mutate(ctx, m) + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // CarClient is a client for the Car schema. type CarClient struct { config @@ -247,6 +261,21 @@ func (c *CarClient) Hooks() []Hook { return c.hooks.Car } +func (c *CarClient) mutate(ctx context.Context, m *CarMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&CarCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&CarUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&CarDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Car mutation op: %q", m.Op()) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -353,6 +382,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -474,3 +518,18 @@ func (c *UserClient) QueryGroups(u *User) *GroupQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/start/ent/mutation.go b/examples/start/ent/mutation.go index 3b8bc57b9..9987de188 100644 --- a/examples/start/ent/mutation.go +++ b/examples/start/ent/mutation.go @@ -270,6 +270,11 @@ func (m *CarMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *CarMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Car). func (m *CarMutation) Type() string { return m.typ @@ -681,6 +686,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -1200,6 +1210,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/traversal/ent/client.go b/examples/traversal/ent/client.go index 80a821e73..0cba3d142 100644 --- a/examples/traversal/ent/client.go +++ b/examples/traversal/ent/client.go @@ -141,6 +141,20 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *GroupMutation: + return c.Group.mutate(ctx, m) + case *PetMutation: + return c.Pet.mutate(ctx, m) + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // GroupClient is a client for the Group schema. type GroupClient struct { config @@ -263,6 +277,21 @@ func (c *GroupClient) Hooks() []Hook { return c.hooks.Group } +func (c *GroupClient) mutate(ctx context.Context, m *GroupMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&GroupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&GroupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&GroupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&GroupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Group mutation op: %q", m.Op()) + } +} + // PetClient is a client for the Pet schema. type PetClient struct { config @@ -385,6 +414,21 @@ func (c *PetClient) Hooks() []Hook { return c.hooks.Pet } +func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown Pet mutation op: %q", m.Op()) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -538,3 +582,18 @@ func (c *UserClient) QueryManage(u *User) *GroupQuery { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/traversal/ent/mutation.go b/examples/traversal/ent/mutation.go index beea9aaf6..0ba93a5da 100644 --- a/examples/traversal/ent/mutation.go +++ b/examples/traversal/ent/mutation.go @@ -289,6 +289,11 @@ func (m *GroupMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *GroupMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Group). func (m *GroupMutation) Type() string { return m.typ @@ -752,6 +757,11 @@ func (m *PetMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *PetMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (Pet). func (m *PetMutation) Type() string { return m.typ @@ -1403,6 +1413,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ diff --git a/examples/version/ent/client.go b/examples/version/ent/client.go index 762a84c6d..7d847ce48 100644 --- a/examples/version/ent/client.go +++ b/examples/version/ent/client.go @@ -126,6 +126,16 @@ func (c *Client) Use(hooks ...Hook) { c.User.Use(hooks...) } +// Mutate implements the ent.Mutator interface. +func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { + switch m := m.(type) { + case *UserMutation: + return c.User.mutate(ctx, m) + default: + return nil, fmt.Errorf("ent: unknown mutation type %T", m) + } +} + // UserClient is a client for the User schema. type UserClient struct { config @@ -215,3 +225,18 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User { func (c *UserClient) Hooks() []Hook { return c.hooks.User } + +func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op()) + } +} diff --git a/examples/version/ent/mutation.go b/examples/version/ent/mutation.go index 9bfa33e06..1b6b8991a 100644 --- a/examples/version/ent/mutation.go +++ b/examples/version/ent/mutation.go @@ -245,6 +245,11 @@ func (m *UserMutation) Op() Op { return m.op } +// SetOp allows setting the mutation operation. +func (m *UserMutation) SetOp(op Op) { + m.op = op +} + // Type returns the node type of this mutation (User). func (m *UserMutation) Type() string { return m.typ