diff --git a/entproto/README.md b/entproto/README.md index 0b0de7f98..26358bc7d 100644 --- a/entproto/README.md +++ b/entproto/README.md @@ -430,6 +430,8 @@ The Proto Style Guide suggests that we use `CAPS_WITH_UNDERSCORES` for value nam - If no default value is defined for the enum, we generate a `_UNSPECIFIED = 0;` option on the enum and verify that no option received the 0 number in the enproto.Enum Options field. - If a default value is defined for the enum, we verify that it receives the 0 value on the Options field. +Ent allows special characters in enum values. For such values, any special character is replaced by an underscore to preserve the `CAPS_WITH_UNDERSCORES` protobuf format. + ## Edges Edges are annotated in the same way as fields: using `entproto.Field` annotation to specify the field number for the generated field. Unique relations are mapped to normal fields, non-unique relations are mapped to `repeated` fields. diff --git a/entproto/adapter.go b/entproto/adapter.go index 9886d85a3..1611c2502 100644 --- a/entproto/adapter.go +++ b/entproto/adapter.go @@ -441,7 +441,7 @@ func toProtoEnumDescriptor(fld *gen.Field) (*descriptorpb.EnumDescriptorProto, e }) } for _, opt := range fld.Enums { - n := strings.ToUpper(snake(opt.Value)) + n := strings.ToUpper(snake(NormalizeEnumIdentifier(opt.Value))) if !enumAnnotation.OmitFieldPrefix { n = strings.ToUpper(snake(fld.Name)) + "_" + n } diff --git a/entproto/cmd/protoc-gen-entgrpc/main.go b/entproto/cmd/protoc-gen-entgrpc/main.go index cf5da7321..5e98698ed 100644 --- a/entproto/cmd/protoc-gen-entgrpc/main.go +++ b/entproto/cmd/protoc-gen-entgrpc/main.go @@ -125,6 +125,7 @@ func (g *serviceGenerator) generate() error { "qualify": func(pkg, ident string) string { return g.QualifiedGoIdent(protogen.GoImportPath(pkg).Ident(ident)) }, + "protoIdentNormalize": entproto.NormalizeEnumIdentifier, "statusErr": func(code, msg string) string { return fmt.Sprintf("%s(%s, %q)", g.QualifiedGoIdent(status.Ident("Error")), diff --git a/entproto/cmd/protoc-gen-entgrpc/template/enums.tmpl b/entproto/cmd/protoc-gen-entgrpc/template/enums.tmpl index 571c6509b..40a2c3d6b 100644 --- a/entproto/cmd/protoc-gen-entgrpc/template/enums.tmpl +++ b/entproto/cmd/protoc-gen-entgrpc/template/enums.tmpl @@ -8,8 +8,13 @@ {{ $entEnumIdent := entIdent $entLcase .PbStructField }} {{ $enumFieldPrefix := snake $enumType.GetName | upper | printf "%s_" }} {{ $omitPrefix := .EntField.Annotations.ProtoEnum.OmitFieldPrefix }} - func toProto{{ $pbEnumIdent.GoName }} (e {{ ident $entEnumIdent }}) {{ ident $pbEnumIdent }} { - if v, ok := {{ $pbEnumIdent.GoName }}_value[{{ qualify "strings" "ToUpper" }}({{ if not $omitPrefix }}"{{ $enumFieldPrefix }}" +{{ end }} string(e))]; ok { + var protoIdentNormalizeRegexp{{ $pbEnumIdent.GoName }} = {{ qualify "regexp" "MustCompile" }}(`[^a-zA-Z0-9_]+`) + func protoIdentNormalize{{ $pbEnumIdent.GoName }}(e string) string { + return protoIdentNormalizeRegexp{{ $pbEnumIdent.GoName }}.ReplaceAllString(e, "_") + } + + func toProto{{ $pbEnumIdent.GoName }} (e {{ ident $entEnumIdent }}) {{ ident $pbEnumIdent }} { + if v, ok := {{ $pbEnumIdent.GoName }}_value[{{ qualify "strings" "ToUpper" }}({{ if not $omitPrefix }}"{{ $enumFieldPrefix }}" + {{ end }}protoIdentNormalize{{ $pbEnumIdent.GoName }}(string(e)))]; ok { return {{ $pbEnumIdent | ident }}(v) } return {{ $pbEnumIdent | ident }}(0) @@ -19,7 +24,7 @@ if v, ok := {{ $pbEnumIdent.GoName }}_name[int32(e)]; ok { entVal := map[string]string{ {{- range .EntField.Enums }} - "{{ if not $omitPrefix }}{{ $enumFieldPrefix }}{{ end }}{{ upper .Value }}": "{{ .Value }}", + "{{ if not $omitPrefix }}{{ $enumFieldPrefix }}{{ end }}{{ protoIdentNormalize .Value }}": "{{ .Value }}", {{- end }} }[v] return {{ ident $entEnumIdent }}(entVal) diff --git a/entproto/enum.go b/entproto/enum.go index 7911f21eb..dabf45497 100644 --- a/entproto/enum.go +++ b/entproto/enum.go @@ -17,6 +17,8 @@ package entproto import ( "errors" "fmt" + "regexp" + "strings" "github.com/mitchellh/mapstructure" @@ -29,6 +31,7 @@ const ( var ( ErrEnumFieldsNotAnnotated = errors.New("entproto: all Enum options must be covered with an entproto.Enum annotation") + normalizeEnumIdent = regexp.MustCompile(`[^a-zA-Z0-9_]+`) ) type EnumOption func(*enum) @@ -76,11 +79,18 @@ func (e *enum) Verify(fld *gen.Field) error { if len(e.Options) != len(fld.Enums) { return ErrEnumFieldsNotAnnotated } + pbIdentifiers := make(map[string]struct{}, len(fld.Enums)) for _, opt := range fld.Enums { if _, ok := e.Options[opt.Value]; !ok { return fmt.Errorf("entproto: Enum option %s is not annotated with"+ " a pbfield number using entproto.Enum", opt.Name) } + pbIdent := NormalizeEnumIdentifier(opt.Value) + if _, ok := pbIdentifiers[pbIdent]; ok { + return fmt.Errorf("entproto: Enum option %q produces conflicting pbfield"+ + " name %q after normalization", opt.Name, pbIdent) + } + pbIdentifiers[pbIdent] = struct{}{} } // If default value is set on the pbfield, make sure it's option number is zero. @@ -126,3 +136,9 @@ func extractEnumAnnotation(fld *gen.Field) (*enum, error) { return &out, nil } + +// NormalizeEnumIdentifier normalizes the identifier of an enum pbfield +// to match the Proto Style Guide. +func NormalizeEnumIdentifier(s string) string { + return strings.ToUpper(normalizeEnumIdent.ReplaceAllString(s, "_")) +} diff --git a/entproto/internal/entprototest/adapter_test.go b/entproto/internal/entprototest/adapter_test.go index a17eb8ece..cedc44521 100644 --- a/entproto/internal/entprototest/adapter_test.go +++ b/entproto/internal/entprototest/adapter_test.go @@ -123,6 +123,11 @@ func (suite *AdapterTestSuite) TestInvalidField() { suite.EqualError(err, "unsupported field type \"TypeJSON\"") } +func (suite *AdapterTestSuite) TestEnumWithConflictingValue() { + _, err := suite.adapter.GetFileDescriptor("EnumWithConflictingValue") + suite.EqualError(err, "entproto: Enum option \"EnumJpegAlt\" produces conflicting pbfield name \"IMAGE_JPEG\" after normalization") +} + func (suite *AdapterTestSuite) TestDuplicateNumber() { _, err := suite.adapter.GetFileDescriptor("DuplicateNumberMessage") suite.EqualError(err, "entproto: field 2 already defined on message \"DuplicateNumberMessage\"") @@ -180,7 +185,7 @@ func (suite *AdapterTestSuite) TestEnumMessage() { suite.NoError(err) message := fd.FindMessage("entpb.MessageWithEnum") - suite.Len(message.GetFields(), 3) + suite.Len(message.GetFields(), 4) // an enum field with defaults enumField := message.FindFieldByName("enum_type") @@ -202,6 +207,16 @@ func (suite *AdapterTestSuite) TestEnumMessage() { suite.EqualValues(0, enumDesc.FindValueByName("ENUM_WITHOUT_DEFAULT_UNSPECIFIED").GetNumber()) suite.EqualValues(1, enumDesc.FindValueByName("ENUM_WITHOUT_DEFAULT_FIRST").GetNumber()) suite.EqualValues(2, enumDesc.FindValueByName("ENUM_WITHOUT_DEFAULT_SECOND").GetNumber()) + + // an enum field with special characters + enumField = message.FindFieldByName("enum_with_special_characters") + suite.EqualValues(4, enumField.GetNumber()) + suite.EqualValues(descriptorpb.FieldDescriptorProto_TYPE_ENUM, enumField.GetType()) + enumDesc = enumField.GetEnumType() + suite.EqualValues("entpb.MessageWithEnum.EnumWithSpecialCharacters", enumDesc.GetFullyQualifiedName()) + suite.EqualValues(0, enumDesc.FindValueByName("ENUM_WITH_SPECIAL_CHARACTERS_UNSPECIFIED").GetNumber()) + suite.EqualValues(1, enumDesc.FindValueByName("ENUM_WITH_SPECIAL_CHARACTERS_IMAGE_JPEG").GetNumber()) + suite.EqualValues(2, enumDesc.FindValueByName("ENUM_WITH_SPECIAL_CHARACTERS_IMAGE_PNG").GetNumber()) } func (suite *AdapterTestSuite) TestMessageWithId() { diff --git a/entproto/internal/entprototest/ent/client.go b/entproto/internal/entprototest/ent/client.go index e6dbe8dab..9bd8f2af3 100644 --- a/entproto/internal/entprototest/ent/client.go +++ b/entproto/internal/entprototest/ent/client.go @@ -17,6 +17,7 @@ import ( "entgo.io/contrib/entproto/internal/entprototest/ent/category" "entgo.io/contrib/entproto/internal/entprototest/ent/dependsonskipped" "entgo.io/contrib/entproto/internal/entprototest/ent/duplicatenumbermessage" + "entgo.io/contrib/entproto/internal/entprototest/ent/enumwithconflictingvalue" "entgo.io/contrib/entproto/internal/entprototest/ent/explicitskippedmessage" "entgo.io/contrib/entproto/internal/entprototest/ent/image" "entgo.io/contrib/entproto/internal/entprototest/ent/implicitskippedmessage" @@ -54,6 +55,8 @@ type Client struct { DependsOnSkipped *DependsOnSkippedClient // DuplicateNumberMessage is the client for interacting with the DuplicateNumberMessage builders. DuplicateNumberMessage *DuplicateNumberMessageClient + // EnumWithConflictingValue is the client for interacting with the EnumWithConflictingValue builders. + EnumWithConflictingValue *EnumWithConflictingValueClient // ExplicitSkippedMessage is the client for interacting with the ExplicitSkippedMessage builders. ExplicitSkippedMessage *ExplicitSkippedMessageClient // Image is the client for interacting with the Image builders. @@ -106,6 +109,7 @@ func (c *Client) init() { c.Category = NewCategoryClient(c.config) c.DependsOnSkipped = NewDependsOnSkippedClient(c.config) c.DuplicateNumberMessage = NewDuplicateNumberMessageClient(c.config) + c.EnumWithConflictingValue = NewEnumWithConflictingValueClient(c.config) c.ExplicitSkippedMessage = NewExplicitSkippedMessageClient(c.config) c.Image = NewImageClient(c.config) c.ImplicitSkippedMessage = NewImplicitSkippedMessageClient(c.config) @@ -203,30 +207,31 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { cfg := c.config cfg.driver = tx return &Tx{ - ctx: ctx, - config: cfg, - AllMethodsService: NewAllMethodsServiceClient(cfg), - BlogPost: NewBlogPostClient(cfg), - Category: NewCategoryClient(cfg), - DependsOnSkipped: NewDependsOnSkippedClient(cfg), - DuplicateNumberMessage: NewDuplicateNumberMessageClient(cfg), - ExplicitSkippedMessage: NewExplicitSkippedMessageClient(cfg), - Image: NewImageClient(cfg), - ImplicitSkippedMessage: NewImplicitSkippedMessageClient(cfg), - InvalidFieldMessage: NewInvalidFieldMessageClient(cfg), - MessageWithEnum: NewMessageWithEnumClient(cfg), - MessageWithFieldOne: NewMessageWithFieldOneClient(cfg), - MessageWithID: NewMessageWithIDClient(cfg), - MessageWithOptionals: NewMessageWithOptionalsClient(cfg), - MessageWithPackageName: NewMessageWithPackageNameClient(cfg), - MessageWithStrings: NewMessageWithStringsClient(cfg), - NoBackref: NewNoBackrefClient(cfg), - OneMethodService: NewOneMethodServiceClient(cfg), - Portal: NewPortalClient(cfg), - SkipEdgeExample: NewSkipEdgeExampleClient(cfg), - TwoMethodService: NewTwoMethodServiceClient(cfg), - User: NewUserClient(cfg), - ValidMessage: NewValidMessageClient(cfg), + ctx: ctx, + config: cfg, + AllMethodsService: NewAllMethodsServiceClient(cfg), + BlogPost: NewBlogPostClient(cfg), + Category: NewCategoryClient(cfg), + DependsOnSkipped: NewDependsOnSkippedClient(cfg), + DuplicateNumberMessage: NewDuplicateNumberMessageClient(cfg), + EnumWithConflictingValue: NewEnumWithConflictingValueClient(cfg), + ExplicitSkippedMessage: NewExplicitSkippedMessageClient(cfg), + Image: NewImageClient(cfg), + ImplicitSkippedMessage: NewImplicitSkippedMessageClient(cfg), + InvalidFieldMessage: NewInvalidFieldMessageClient(cfg), + MessageWithEnum: NewMessageWithEnumClient(cfg), + MessageWithFieldOne: NewMessageWithFieldOneClient(cfg), + MessageWithID: NewMessageWithIDClient(cfg), + MessageWithOptionals: NewMessageWithOptionalsClient(cfg), + MessageWithPackageName: NewMessageWithPackageNameClient(cfg), + MessageWithStrings: NewMessageWithStringsClient(cfg), + NoBackref: NewNoBackrefClient(cfg), + OneMethodService: NewOneMethodServiceClient(cfg), + Portal: NewPortalClient(cfg), + SkipEdgeExample: NewSkipEdgeExampleClient(cfg), + TwoMethodService: NewTwoMethodServiceClient(cfg), + User: NewUserClient(cfg), + ValidMessage: NewValidMessageClient(cfg), }, nil } @@ -244,30 +249,31 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) cfg := c.config cfg.driver = &txDriver{tx: tx, drv: c.driver} return &Tx{ - ctx: ctx, - config: cfg, - AllMethodsService: NewAllMethodsServiceClient(cfg), - BlogPost: NewBlogPostClient(cfg), - Category: NewCategoryClient(cfg), - DependsOnSkipped: NewDependsOnSkippedClient(cfg), - DuplicateNumberMessage: NewDuplicateNumberMessageClient(cfg), - ExplicitSkippedMessage: NewExplicitSkippedMessageClient(cfg), - Image: NewImageClient(cfg), - ImplicitSkippedMessage: NewImplicitSkippedMessageClient(cfg), - InvalidFieldMessage: NewInvalidFieldMessageClient(cfg), - MessageWithEnum: NewMessageWithEnumClient(cfg), - MessageWithFieldOne: NewMessageWithFieldOneClient(cfg), - MessageWithID: NewMessageWithIDClient(cfg), - MessageWithOptionals: NewMessageWithOptionalsClient(cfg), - MessageWithPackageName: NewMessageWithPackageNameClient(cfg), - MessageWithStrings: NewMessageWithStringsClient(cfg), - NoBackref: NewNoBackrefClient(cfg), - OneMethodService: NewOneMethodServiceClient(cfg), - Portal: NewPortalClient(cfg), - SkipEdgeExample: NewSkipEdgeExampleClient(cfg), - TwoMethodService: NewTwoMethodServiceClient(cfg), - User: NewUserClient(cfg), - ValidMessage: NewValidMessageClient(cfg), + ctx: ctx, + config: cfg, + AllMethodsService: NewAllMethodsServiceClient(cfg), + BlogPost: NewBlogPostClient(cfg), + Category: NewCategoryClient(cfg), + DependsOnSkipped: NewDependsOnSkippedClient(cfg), + DuplicateNumberMessage: NewDuplicateNumberMessageClient(cfg), + EnumWithConflictingValue: NewEnumWithConflictingValueClient(cfg), + ExplicitSkippedMessage: NewExplicitSkippedMessageClient(cfg), + Image: NewImageClient(cfg), + ImplicitSkippedMessage: NewImplicitSkippedMessageClient(cfg), + InvalidFieldMessage: NewInvalidFieldMessageClient(cfg), + MessageWithEnum: NewMessageWithEnumClient(cfg), + MessageWithFieldOne: NewMessageWithFieldOneClient(cfg), + MessageWithID: NewMessageWithIDClient(cfg), + MessageWithOptionals: NewMessageWithOptionalsClient(cfg), + MessageWithPackageName: NewMessageWithPackageNameClient(cfg), + MessageWithStrings: NewMessageWithStringsClient(cfg), + NoBackref: NewNoBackrefClient(cfg), + OneMethodService: NewOneMethodServiceClient(cfg), + Portal: NewPortalClient(cfg), + SkipEdgeExample: NewSkipEdgeExampleClient(cfg), + TwoMethodService: NewTwoMethodServiceClient(cfg), + User: NewUserClient(cfg), + ValidMessage: NewValidMessageClient(cfg), }, nil } @@ -298,8 +304,8 @@ func (c *Client) Close() error { func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ c.AllMethodsService, c.BlogPost, c.Category, c.DependsOnSkipped, - c.DuplicateNumberMessage, c.ExplicitSkippedMessage, c.Image, - c.ImplicitSkippedMessage, c.InvalidFieldMessage, c.MessageWithEnum, + c.DuplicateNumberMessage, c.EnumWithConflictingValue, c.ExplicitSkippedMessage, + c.Image, c.ImplicitSkippedMessage, c.InvalidFieldMessage, c.MessageWithEnum, c.MessageWithFieldOne, c.MessageWithID, c.MessageWithOptionals, c.MessageWithPackageName, c.MessageWithStrings, c.NoBackref, c.OneMethodService, c.Portal, c.SkipEdgeExample, c.TwoMethodService, c.User, @@ -314,8 +320,8 @@ func (c *Client) Use(hooks ...Hook) { func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ c.AllMethodsService, c.BlogPost, c.Category, c.DependsOnSkipped, - c.DuplicateNumberMessage, c.ExplicitSkippedMessage, c.Image, - c.ImplicitSkippedMessage, c.InvalidFieldMessage, c.MessageWithEnum, + c.DuplicateNumberMessage, c.EnumWithConflictingValue, c.ExplicitSkippedMessage, + c.Image, c.ImplicitSkippedMessage, c.InvalidFieldMessage, c.MessageWithEnum, c.MessageWithFieldOne, c.MessageWithID, c.MessageWithOptionals, c.MessageWithPackageName, c.MessageWithStrings, c.NoBackref, c.OneMethodService, c.Portal, c.SkipEdgeExample, c.TwoMethodService, c.User, @@ -338,6 +344,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { return c.DependsOnSkipped.mutate(ctx, m) case *DuplicateNumberMessageMutation: return c.DuplicateNumberMessage.mutate(ctx, m) + case *EnumWithConflictingValueMutation: + return c.EnumWithConflictingValue.mutate(ctx, m) case *ExplicitSkippedMessageMutation: return c.ExplicitSkippedMessage.mutate(ctx, m) case *ImageMutation: @@ -1031,6 +1039,124 @@ func (c *DuplicateNumberMessageClient) mutate(ctx context.Context, m *DuplicateN } } +// EnumWithConflictingValueClient is a client for the EnumWithConflictingValue schema. +type EnumWithConflictingValueClient struct { + config +} + +// NewEnumWithConflictingValueClient returns a client for the EnumWithConflictingValue from the given config. +func NewEnumWithConflictingValueClient(c config) *EnumWithConflictingValueClient { + return &EnumWithConflictingValueClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `enumwithconflictingvalue.Hooks(f(g(h())))`. +func (c *EnumWithConflictingValueClient) Use(hooks ...Hook) { + c.hooks.EnumWithConflictingValue = append(c.hooks.EnumWithConflictingValue, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `enumwithconflictingvalue.Intercept(f(g(h())))`. +func (c *EnumWithConflictingValueClient) Intercept(interceptors ...Interceptor) { + c.inters.EnumWithConflictingValue = append(c.inters.EnumWithConflictingValue, interceptors...) +} + +// Create returns a builder for creating a EnumWithConflictingValue entity. +func (c *EnumWithConflictingValueClient) Create() *EnumWithConflictingValueCreate { + mutation := newEnumWithConflictingValueMutation(c.config, OpCreate) + return &EnumWithConflictingValueCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of EnumWithConflictingValue entities. +func (c *EnumWithConflictingValueClient) CreateBulk(builders ...*EnumWithConflictingValueCreate) *EnumWithConflictingValueCreateBulk { + return &EnumWithConflictingValueCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for EnumWithConflictingValue. +func (c *EnumWithConflictingValueClient) Update() *EnumWithConflictingValueUpdate { + mutation := newEnumWithConflictingValueMutation(c.config, OpUpdate) + return &EnumWithConflictingValueUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *EnumWithConflictingValueClient) UpdateOne(ewcv *EnumWithConflictingValue) *EnumWithConflictingValueUpdateOne { + mutation := newEnumWithConflictingValueMutation(c.config, OpUpdateOne, withEnumWithConflictingValue(ewcv)) + return &EnumWithConflictingValueUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *EnumWithConflictingValueClient) UpdateOneID(id int) *EnumWithConflictingValueUpdateOne { + mutation := newEnumWithConflictingValueMutation(c.config, OpUpdateOne, withEnumWithConflictingValueID(id)) + return &EnumWithConflictingValueUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for EnumWithConflictingValue. +func (c *EnumWithConflictingValueClient) Delete() *EnumWithConflictingValueDelete { + mutation := newEnumWithConflictingValueMutation(c.config, OpDelete) + return &EnumWithConflictingValueDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *EnumWithConflictingValueClient) DeleteOne(ewcv *EnumWithConflictingValue) *EnumWithConflictingValueDeleteOne { + return c.DeleteOneID(ewcv.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *EnumWithConflictingValueClient) DeleteOneID(id int) *EnumWithConflictingValueDeleteOne { + builder := c.Delete().Where(enumwithconflictingvalue.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &EnumWithConflictingValueDeleteOne{builder} +} + +// Query returns a query builder for EnumWithConflictingValue. +func (c *EnumWithConflictingValueClient) Query() *EnumWithConflictingValueQuery { + return &EnumWithConflictingValueQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeEnumWithConflictingValue}, + inters: c.Interceptors(), + } +} + +// Get returns a EnumWithConflictingValue entity by its id. +func (c *EnumWithConflictingValueClient) Get(ctx context.Context, id int) (*EnumWithConflictingValue, error) { + return c.Query().Where(enumwithconflictingvalue.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *EnumWithConflictingValueClient) GetX(ctx context.Context, id int) *EnumWithConflictingValue { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *EnumWithConflictingValueClient) Hooks() []Hook { + return c.hooks.EnumWithConflictingValue +} + +// Interceptors returns the client interceptors. +func (c *EnumWithConflictingValueClient) Interceptors() []Interceptor { + return c.inters.EnumWithConflictingValue +} + +func (c *EnumWithConflictingValueClient) mutate(ctx context.Context, m *EnumWithConflictingValueMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&EnumWithConflictingValueCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&EnumWithConflictingValueUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&EnumWithConflictingValueUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&EnumWithConflictingValueDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown EnumWithConflictingValue mutation op: %q", m.Op()) + } +} + // ExplicitSkippedMessageClient is a client for the ExplicitSkippedMessage schema. type ExplicitSkippedMessageClient struct { config @@ -3153,15 +3279,17 @@ func (c *ValidMessageClient) mutate(ctx context.Context, m *ValidMessageMutation type ( hooks struct { AllMethodsService, BlogPost, Category, DependsOnSkipped, DuplicateNumberMessage, - ExplicitSkippedMessage, Image, ImplicitSkippedMessage, InvalidFieldMessage, - MessageWithEnum, MessageWithFieldOne, MessageWithID, MessageWithOptionals, + EnumWithConflictingValue, ExplicitSkippedMessage, Image, + ImplicitSkippedMessage, InvalidFieldMessage, MessageWithEnum, + MessageWithFieldOne, MessageWithID, MessageWithOptionals, MessageWithPackageName, MessageWithStrings, NoBackref, OneMethodService, Portal, SkipEdgeExample, TwoMethodService, User, ValidMessage []ent.Hook } inters struct { AllMethodsService, BlogPost, Category, DependsOnSkipped, DuplicateNumberMessage, - ExplicitSkippedMessage, Image, ImplicitSkippedMessage, InvalidFieldMessage, - MessageWithEnum, MessageWithFieldOne, MessageWithID, MessageWithOptionals, + EnumWithConflictingValue, ExplicitSkippedMessage, Image, + ImplicitSkippedMessage, InvalidFieldMessage, MessageWithEnum, + MessageWithFieldOne, MessageWithID, MessageWithOptionals, MessageWithPackageName, MessageWithStrings, NoBackref, OneMethodService, Portal, SkipEdgeExample, TwoMethodService, User, ValidMessage []ent.Interceptor } diff --git a/entproto/internal/entprototest/ent/ent.go b/entproto/internal/entprototest/ent/ent.go index 55c8384e2..ee7f24249 100644 --- a/entproto/internal/entprototest/ent/ent.go +++ b/entproto/internal/entprototest/ent/ent.go @@ -14,6 +14,7 @@ import ( "entgo.io/contrib/entproto/internal/entprototest/ent/category" "entgo.io/contrib/entproto/internal/entprototest/ent/dependsonskipped" "entgo.io/contrib/entproto/internal/entprototest/ent/duplicatenumbermessage" + "entgo.io/contrib/entproto/internal/entprototest/ent/enumwithconflictingvalue" "entgo.io/contrib/entproto/internal/entprototest/ent/explicitskippedmessage" "entgo.io/contrib/entproto/internal/entprototest/ent/image" "entgo.io/contrib/entproto/internal/entprototest/ent/implicitskippedmessage" @@ -94,28 +95,29 @@ var ( func checkColumn(table, column string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ - allmethodsservice.Table: allmethodsservice.ValidColumn, - blogpost.Table: blogpost.ValidColumn, - category.Table: category.ValidColumn, - dependsonskipped.Table: dependsonskipped.ValidColumn, - duplicatenumbermessage.Table: duplicatenumbermessage.ValidColumn, - explicitskippedmessage.Table: explicitskippedmessage.ValidColumn, - image.Table: image.ValidColumn, - implicitskippedmessage.Table: implicitskippedmessage.ValidColumn, - invalidfieldmessage.Table: invalidfieldmessage.ValidColumn, - messagewithenum.Table: messagewithenum.ValidColumn, - messagewithfieldone.Table: messagewithfieldone.ValidColumn, - messagewithid.Table: messagewithid.ValidColumn, - messagewithoptionals.Table: messagewithoptionals.ValidColumn, - messagewithpackagename.Table: messagewithpackagename.ValidColumn, - messagewithstrings.Table: messagewithstrings.ValidColumn, - nobackref.Table: nobackref.ValidColumn, - onemethodservice.Table: onemethodservice.ValidColumn, - portal.Table: portal.ValidColumn, - skipedgeexample.Table: skipedgeexample.ValidColumn, - twomethodservice.Table: twomethodservice.ValidColumn, - user.Table: user.ValidColumn, - validmessage.Table: validmessage.ValidColumn, + allmethodsservice.Table: allmethodsservice.ValidColumn, + blogpost.Table: blogpost.ValidColumn, + category.Table: category.ValidColumn, + dependsonskipped.Table: dependsonskipped.ValidColumn, + duplicatenumbermessage.Table: duplicatenumbermessage.ValidColumn, + enumwithconflictingvalue.Table: enumwithconflictingvalue.ValidColumn, + explicitskippedmessage.Table: explicitskippedmessage.ValidColumn, + image.Table: image.ValidColumn, + implicitskippedmessage.Table: implicitskippedmessage.ValidColumn, + invalidfieldmessage.Table: invalidfieldmessage.ValidColumn, + messagewithenum.Table: messagewithenum.ValidColumn, + messagewithfieldone.Table: messagewithfieldone.ValidColumn, + messagewithid.Table: messagewithid.ValidColumn, + messagewithoptionals.Table: messagewithoptionals.ValidColumn, + messagewithpackagename.Table: messagewithpackagename.ValidColumn, + messagewithstrings.Table: messagewithstrings.ValidColumn, + nobackref.Table: nobackref.ValidColumn, + onemethodservice.Table: onemethodservice.ValidColumn, + portal.Table: portal.ValidColumn, + skipedgeexample.Table: skipedgeexample.ValidColumn, + twomethodservice.Table: twomethodservice.ValidColumn, + user.Table: user.ValidColumn, + validmessage.Table: validmessage.ValidColumn, }) }) return columnCheck(table, column) diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue.go new file mode 100644 index 000000000..801f2764b --- /dev/null +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue.go @@ -0,0 +1,103 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + + "entgo.io/contrib/entproto/internal/entprototest/ent/enumwithconflictingvalue" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// EnumWithConflictingValue is the model entity for the EnumWithConflictingValue schema. +type EnumWithConflictingValue struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // Enum holds the value of the "enum" field. + Enum enumwithconflictingvalue.Enum `json:"enum,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*EnumWithConflictingValue) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case enumwithconflictingvalue.FieldID: + values[i] = new(sql.NullInt64) + case enumwithconflictingvalue.FieldEnum: + values[i] = new(sql.NullString) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the EnumWithConflictingValue fields. +func (ewcv *EnumWithConflictingValue) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case enumwithconflictingvalue.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + ewcv.ID = int(value.Int64) + case enumwithconflictingvalue.FieldEnum: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field enum", values[i]) + } else if value.Valid { + ewcv.Enum = enumwithconflictingvalue.Enum(value.String) + } + default: + ewcv.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the EnumWithConflictingValue. +// This includes values selected through modifiers, order, etc. +func (ewcv *EnumWithConflictingValue) Value(name string) (ent.Value, error) { + return ewcv.selectValues.Get(name) +} + +// Update returns a builder for updating this EnumWithConflictingValue. +// Note that you need to call EnumWithConflictingValue.Unwrap() before calling this method if this EnumWithConflictingValue +// was returned from a transaction, and the transaction was committed or rolled back. +func (ewcv *EnumWithConflictingValue) Update() *EnumWithConflictingValueUpdateOne { + return NewEnumWithConflictingValueClient(ewcv.config).UpdateOne(ewcv) +} + +// Unwrap unwraps the EnumWithConflictingValue entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (ewcv *EnumWithConflictingValue) Unwrap() *EnumWithConflictingValue { + _tx, ok := ewcv.config.driver.(*txDriver) + if !ok { + panic("ent: EnumWithConflictingValue is not a transactional entity") + } + ewcv.config.driver = _tx.drv + return ewcv +} + +// String implements the fmt.Stringer. +func (ewcv *EnumWithConflictingValue) String() string { + var builder strings.Builder + builder.WriteString("EnumWithConflictingValue(") + builder.WriteString(fmt.Sprintf("id=%v, ", ewcv.ID)) + builder.WriteString("enum=") + builder.WriteString(fmt.Sprintf("%v", ewcv.Enum)) + builder.WriteByte(')') + return builder.String() +} + +// EnumWithConflictingValues is a parsable slice of EnumWithConflictingValue. +type EnumWithConflictingValues []*EnumWithConflictingValue diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue/enumwithconflictingvalue.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue/enumwithconflictingvalue.go new file mode 100644 index 000000000..0261af61b --- /dev/null +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue/enumwithconflictingvalue.go @@ -0,0 +1,72 @@ +// Code generated by ent, DO NOT EDIT. + +package enumwithconflictingvalue + +import ( + "fmt" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the enumwithconflictingvalue type in the database. + Label = "enum_with_conflicting_value" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldEnum holds the string denoting the enum field in the database. + FieldEnum = "enum" + // Table holds the table name of the enumwithconflictingvalue in the database. + Table = "enum_with_conflicting_values" +) + +// Columns holds all SQL columns for enumwithconflictingvalue fields. +var Columns = []string{ + FieldID, + FieldEnum, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +// Enum defines the type for the "enum" enum field. +type Enum string + +// Enum values. +const ( + EnumJpeg Enum = "image/jpeg" + EnumJpegAlt Enum = "IMAGE_JPEG" +) + +func (e Enum) String() string { + return string(e) +} + +// EnumValidator is a validator for the "enum" field enum values. It is called by the builders before save. +func EnumValidator(e Enum) error { + switch e { + case EnumJpeg, EnumJpegAlt: + return nil + default: + return fmt.Errorf("enumwithconflictingvalue: invalid enum value for enum field: %q", e) + } +} + +// OrderOption defines the ordering options for the EnumWithConflictingValue queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByEnum orders the results by the enum field. +func ByEnum(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEnum, opts...).ToFunc() +} diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue/where.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue/where.go new file mode 100644 index 000000000..5e7f32408 --- /dev/null +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue/where.go @@ -0,0 +1,105 @@ +// Code generated by ent, DO NOT EDIT. + +package enumwithconflictingvalue + +import ( + "entgo.io/contrib/entproto/internal/entprototest/ent/predicate" + "entgo.io/ent/dialect/sql" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldLTE(FieldID, id)) +} + +// EnumEQ applies the EQ predicate on the "enum" field. +func EnumEQ(v Enum) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldEQ(FieldEnum, v)) +} + +// EnumNEQ applies the NEQ predicate on the "enum" field. +func EnumNEQ(v Enum) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldNEQ(FieldEnum, v)) +} + +// EnumIn applies the In predicate on the "enum" field. +func EnumIn(vs ...Enum) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldIn(FieldEnum, vs...)) +} + +// EnumNotIn applies the NotIn predicate on the "enum" field. +func EnumNotIn(vs ...Enum) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(sql.FieldNotIn(FieldEnum, vs...)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.EnumWithConflictingValue) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for _, p := range predicates { + p(s1) + } + s.Where(s1.P()) + }) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.EnumWithConflictingValue) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for i, p := range predicates { + if i > 0 { + s1.Or() + } + p(s1) + } + s.Where(s1.P()) + }) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.EnumWithConflictingValue) predicate.EnumWithConflictingValue { + return predicate.EnumWithConflictingValue(func(s *sql.Selector) { + p(s.Not()) + }) +} diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue_create.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue_create.go new file mode 100644 index 000000000..883816782 --- /dev/null +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue_create.go @@ -0,0 +1,184 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "entgo.io/contrib/entproto/internal/entprototest/ent/enumwithconflictingvalue" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// EnumWithConflictingValueCreate is the builder for creating a EnumWithConflictingValue entity. +type EnumWithConflictingValueCreate struct { + config + mutation *EnumWithConflictingValueMutation + hooks []Hook +} + +// SetEnum sets the "enum" field. +func (ewcvc *EnumWithConflictingValueCreate) SetEnum(e enumwithconflictingvalue.Enum) *EnumWithConflictingValueCreate { + ewcvc.mutation.SetEnum(e) + return ewcvc +} + +// Mutation returns the EnumWithConflictingValueMutation object of the builder. +func (ewcvc *EnumWithConflictingValueCreate) Mutation() *EnumWithConflictingValueMutation { + return ewcvc.mutation +} + +// Save creates the EnumWithConflictingValue in the database. +func (ewcvc *EnumWithConflictingValueCreate) Save(ctx context.Context) (*EnumWithConflictingValue, error) { + return withHooks[*EnumWithConflictingValue, EnumWithConflictingValueMutation](ctx, ewcvc.sqlSave, ewcvc.mutation, ewcvc.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (ewcvc *EnumWithConflictingValueCreate) SaveX(ctx context.Context) *EnumWithConflictingValue { + v, err := ewcvc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (ewcvc *EnumWithConflictingValueCreate) Exec(ctx context.Context) error { + _, err := ewcvc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ewcvc *EnumWithConflictingValueCreate) ExecX(ctx context.Context) { + if err := ewcvc.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (ewcvc *EnumWithConflictingValueCreate) check() error { + if _, ok := ewcvc.mutation.Enum(); !ok { + return &ValidationError{Name: "enum", err: errors.New(`ent: missing required field "EnumWithConflictingValue.enum"`)} + } + if v, ok := ewcvc.mutation.Enum(); ok { + if err := enumwithconflictingvalue.EnumValidator(v); err != nil { + return &ValidationError{Name: "enum", err: fmt.Errorf(`ent: validator failed for field "EnumWithConflictingValue.enum": %w`, err)} + } + } + return nil +} + +func (ewcvc *EnumWithConflictingValueCreate) sqlSave(ctx context.Context) (*EnumWithConflictingValue, error) { + if err := ewcvc.check(); err != nil { + return nil, err + } + _node, _spec := ewcvc.createSpec() + if err := sqlgraph.CreateNode(ctx, ewcvc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + ewcvc.mutation.id = &_node.ID + ewcvc.mutation.done = true + return _node, nil +} + +func (ewcvc *EnumWithConflictingValueCreate) createSpec() (*EnumWithConflictingValue, *sqlgraph.CreateSpec) { + var ( + _node = &EnumWithConflictingValue{config: ewcvc.config} + _spec = sqlgraph.NewCreateSpec(enumwithconflictingvalue.Table, sqlgraph.NewFieldSpec(enumwithconflictingvalue.FieldID, field.TypeInt)) + ) + if value, ok := ewcvc.mutation.Enum(); ok { + _spec.SetField(enumwithconflictingvalue.FieldEnum, field.TypeEnum, value) + _node.Enum = value + } + return _node, _spec +} + +// EnumWithConflictingValueCreateBulk is the builder for creating many EnumWithConflictingValue entities in bulk. +type EnumWithConflictingValueCreateBulk struct { + config + builders []*EnumWithConflictingValueCreate +} + +// Save creates the EnumWithConflictingValue entities in the database. +func (ewcvcb *EnumWithConflictingValueCreateBulk) Save(ctx context.Context) ([]*EnumWithConflictingValue, error) { + specs := make([]*sqlgraph.CreateSpec, len(ewcvcb.builders)) + nodes := make([]*EnumWithConflictingValue, len(ewcvcb.builders)) + mutators := make([]Mutator, len(ewcvcb.builders)) + for i := range ewcvcb.builders { + func(i int, root context.Context) { + builder := ewcvcb.builders[i] + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*EnumWithConflictingValueMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + var err error + nodes[i], specs[i] = builder.createSpec() + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, ewcvcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, ewcvcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + if specs[i].ID.Value != nil { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int(id) + } + mutation.done = true + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, ewcvcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (ewcvcb *EnumWithConflictingValueCreateBulk) SaveX(ctx context.Context) []*EnumWithConflictingValue { + v, err := ewcvcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (ewcvcb *EnumWithConflictingValueCreateBulk) Exec(ctx context.Context) error { + _, err := ewcvcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ewcvcb *EnumWithConflictingValueCreateBulk) ExecX(ctx context.Context) { + if err := ewcvcb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue_delete.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue_delete.go new file mode 100644 index 000000000..66d6841db --- /dev/null +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + + "entgo.io/contrib/entproto/internal/entprototest/ent/enumwithconflictingvalue" + "entgo.io/contrib/entproto/internal/entprototest/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// EnumWithConflictingValueDelete is the builder for deleting a EnumWithConflictingValue entity. +type EnumWithConflictingValueDelete struct { + config + hooks []Hook + mutation *EnumWithConflictingValueMutation +} + +// Where appends a list predicates to the EnumWithConflictingValueDelete builder. +func (ewcvd *EnumWithConflictingValueDelete) Where(ps ...predicate.EnumWithConflictingValue) *EnumWithConflictingValueDelete { + ewcvd.mutation.Where(ps...) + return ewcvd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (ewcvd *EnumWithConflictingValueDelete) Exec(ctx context.Context) (int, error) { + return withHooks[int, EnumWithConflictingValueMutation](ctx, ewcvd.sqlExec, ewcvd.mutation, ewcvd.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (ewcvd *EnumWithConflictingValueDelete) ExecX(ctx context.Context) int { + n, err := ewcvd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (ewcvd *EnumWithConflictingValueDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(enumwithconflictingvalue.Table, sqlgraph.NewFieldSpec(enumwithconflictingvalue.FieldID, field.TypeInt)) + if ps := ewcvd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, ewcvd.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + ewcvd.mutation.done = true + return affected, err +} + +// EnumWithConflictingValueDeleteOne is the builder for deleting a single EnumWithConflictingValue entity. +type EnumWithConflictingValueDeleteOne struct { + ewcvd *EnumWithConflictingValueDelete +} + +// Where appends a list predicates to the EnumWithConflictingValueDelete builder. +func (ewcvdo *EnumWithConflictingValueDeleteOne) Where(ps ...predicate.EnumWithConflictingValue) *EnumWithConflictingValueDeleteOne { + ewcvdo.ewcvd.mutation.Where(ps...) + return ewcvdo +} + +// Exec executes the deletion query. +func (ewcvdo *EnumWithConflictingValueDeleteOne) Exec(ctx context.Context) error { + n, err := ewcvdo.ewcvd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{enumwithconflictingvalue.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (ewcvdo *EnumWithConflictingValueDeleteOne) ExecX(ctx context.Context) { + if err := ewcvdo.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue_query.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue_query.go new file mode 100644 index 000000000..3ebcc8db8 --- /dev/null +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue_query.go @@ -0,0 +1,526 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "math" + + "entgo.io/contrib/entproto/internal/entprototest/ent/enumwithconflictingvalue" + "entgo.io/contrib/entproto/internal/entprototest/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// EnumWithConflictingValueQuery is the builder for querying EnumWithConflictingValue entities. +type EnumWithConflictingValueQuery struct { + config + ctx *QueryContext + order []enumwithconflictingvalue.OrderOption + inters []Interceptor + predicates []predicate.EnumWithConflictingValue + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the EnumWithConflictingValueQuery builder. +func (ewcvq *EnumWithConflictingValueQuery) Where(ps ...predicate.EnumWithConflictingValue) *EnumWithConflictingValueQuery { + ewcvq.predicates = append(ewcvq.predicates, ps...) + return ewcvq +} + +// Limit the number of records to be returned by this query. +func (ewcvq *EnumWithConflictingValueQuery) Limit(limit int) *EnumWithConflictingValueQuery { + ewcvq.ctx.Limit = &limit + return ewcvq +} + +// Offset to start from. +func (ewcvq *EnumWithConflictingValueQuery) Offset(offset int) *EnumWithConflictingValueQuery { + ewcvq.ctx.Offset = &offset + return ewcvq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (ewcvq *EnumWithConflictingValueQuery) Unique(unique bool) *EnumWithConflictingValueQuery { + ewcvq.ctx.Unique = &unique + return ewcvq +} + +// Order specifies how the records should be ordered. +func (ewcvq *EnumWithConflictingValueQuery) Order(o ...enumwithconflictingvalue.OrderOption) *EnumWithConflictingValueQuery { + ewcvq.order = append(ewcvq.order, o...) + return ewcvq +} + +// First returns the first EnumWithConflictingValue entity from the query. +// Returns a *NotFoundError when no EnumWithConflictingValue was found. +func (ewcvq *EnumWithConflictingValueQuery) First(ctx context.Context) (*EnumWithConflictingValue, error) { + nodes, err := ewcvq.Limit(1).All(setContextOp(ctx, ewcvq.ctx, "First")) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{enumwithconflictingvalue.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (ewcvq *EnumWithConflictingValueQuery) FirstX(ctx context.Context) *EnumWithConflictingValue { + node, err := ewcvq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first EnumWithConflictingValue ID from the query. +// Returns a *NotFoundError when no EnumWithConflictingValue ID was found. +func (ewcvq *EnumWithConflictingValueQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = ewcvq.Limit(1).IDs(setContextOp(ctx, ewcvq.ctx, "FirstID")); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{enumwithconflictingvalue.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (ewcvq *EnumWithConflictingValueQuery) FirstIDX(ctx context.Context) int { + id, err := ewcvq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single EnumWithConflictingValue entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one EnumWithConflictingValue entity is found. +// Returns a *NotFoundError when no EnumWithConflictingValue entities are found. +func (ewcvq *EnumWithConflictingValueQuery) Only(ctx context.Context) (*EnumWithConflictingValue, error) { + nodes, err := ewcvq.Limit(2).All(setContextOp(ctx, ewcvq.ctx, "Only")) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{enumwithconflictingvalue.Label} + default: + return nil, &NotSingularError{enumwithconflictingvalue.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (ewcvq *EnumWithConflictingValueQuery) OnlyX(ctx context.Context) *EnumWithConflictingValue { + node, err := ewcvq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only EnumWithConflictingValue ID in the query. +// Returns a *NotSingularError when more than one EnumWithConflictingValue ID is found. +// Returns a *NotFoundError when no entities are found. +func (ewcvq *EnumWithConflictingValueQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = ewcvq.Limit(2).IDs(setContextOp(ctx, ewcvq.ctx, "OnlyID")); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{enumwithconflictingvalue.Label} + default: + err = &NotSingularError{enumwithconflictingvalue.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (ewcvq *EnumWithConflictingValueQuery) OnlyIDX(ctx context.Context) int { + id, err := ewcvq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of EnumWithConflictingValues. +func (ewcvq *EnumWithConflictingValueQuery) All(ctx context.Context) ([]*EnumWithConflictingValue, error) { + ctx = setContextOp(ctx, ewcvq.ctx, "All") + if err := ewcvq.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*EnumWithConflictingValue, *EnumWithConflictingValueQuery]() + return withInterceptors[[]*EnumWithConflictingValue](ctx, ewcvq, qr, ewcvq.inters) +} + +// AllX is like All, but panics if an error occurs. +func (ewcvq *EnumWithConflictingValueQuery) AllX(ctx context.Context) []*EnumWithConflictingValue { + nodes, err := ewcvq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of EnumWithConflictingValue IDs. +func (ewcvq *EnumWithConflictingValueQuery) IDs(ctx context.Context) (ids []int, err error) { + if ewcvq.ctx.Unique == nil && ewcvq.path != nil { + ewcvq.Unique(true) + } + ctx = setContextOp(ctx, ewcvq.ctx, "IDs") + if err = ewcvq.Select(enumwithconflictingvalue.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (ewcvq *EnumWithConflictingValueQuery) IDsX(ctx context.Context) []int { + ids, err := ewcvq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (ewcvq *EnumWithConflictingValueQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, ewcvq.ctx, "Count") + if err := ewcvq.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, ewcvq, querierCount[*EnumWithConflictingValueQuery](), ewcvq.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (ewcvq *EnumWithConflictingValueQuery) CountX(ctx context.Context) int { + count, err := ewcvq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (ewcvq *EnumWithConflictingValueQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, ewcvq.ctx, "Exist") + switch _, err := ewcvq.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (ewcvq *EnumWithConflictingValueQuery) ExistX(ctx context.Context) bool { + exist, err := ewcvq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the EnumWithConflictingValueQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (ewcvq *EnumWithConflictingValueQuery) Clone() *EnumWithConflictingValueQuery { + if ewcvq == nil { + return nil + } + return &EnumWithConflictingValueQuery{ + config: ewcvq.config, + ctx: ewcvq.ctx.Clone(), + order: append([]enumwithconflictingvalue.OrderOption{}, ewcvq.order...), + inters: append([]Interceptor{}, ewcvq.inters...), + predicates: append([]predicate.EnumWithConflictingValue{}, ewcvq.predicates...), + // clone intermediate query. + sql: ewcvq.sql.Clone(), + path: ewcvq.path, + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Enum enumwithconflictingvalue.Enum `json:"enum,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.EnumWithConflictingValue.Query(). +// GroupBy(enumwithconflictingvalue.FieldEnum). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (ewcvq *EnumWithConflictingValueQuery) GroupBy(field string, fields ...string) *EnumWithConflictingValueGroupBy { + ewcvq.ctx.Fields = append([]string{field}, fields...) + grbuild := &EnumWithConflictingValueGroupBy{build: ewcvq} + grbuild.flds = &ewcvq.ctx.Fields + grbuild.label = enumwithconflictingvalue.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Enum enumwithconflictingvalue.Enum `json:"enum,omitempty"` +// } +// +// client.EnumWithConflictingValue.Query(). +// Select(enumwithconflictingvalue.FieldEnum). +// Scan(ctx, &v) +func (ewcvq *EnumWithConflictingValueQuery) Select(fields ...string) *EnumWithConflictingValueSelect { + ewcvq.ctx.Fields = append(ewcvq.ctx.Fields, fields...) + sbuild := &EnumWithConflictingValueSelect{EnumWithConflictingValueQuery: ewcvq} + sbuild.label = enumwithconflictingvalue.Label + sbuild.flds, sbuild.scan = &ewcvq.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a EnumWithConflictingValueSelect configured with the given aggregations. +func (ewcvq *EnumWithConflictingValueQuery) Aggregate(fns ...AggregateFunc) *EnumWithConflictingValueSelect { + return ewcvq.Select().Aggregate(fns...) +} + +func (ewcvq *EnumWithConflictingValueQuery) prepareQuery(ctx context.Context) error { + for _, inter := range ewcvq.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, ewcvq); err != nil { + return err + } + } + } + for _, f := range ewcvq.ctx.Fields { + if !enumwithconflictingvalue.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if ewcvq.path != nil { + prev, err := ewcvq.path(ctx) + if err != nil { + return err + } + ewcvq.sql = prev + } + return nil +} + +func (ewcvq *EnumWithConflictingValueQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*EnumWithConflictingValue, error) { + var ( + nodes = []*EnumWithConflictingValue{} + _spec = ewcvq.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*EnumWithConflictingValue).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &EnumWithConflictingValue{config: ewcvq.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, ewcvq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (ewcvq *EnumWithConflictingValueQuery) sqlCount(ctx context.Context) (int, error) { + _spec := ewcvq.querySpec() + _spec.Node.Columns = ewcvq.ctx.Fields + if len(ewcvq.ctx.Fields) > 0 { + _spec.Unique = ewcvq.ctx.Unique != nil && *ewcvq.ctx.Unique + } + return sqlgraph.CountNodes(ctx, ewcvq.driver, _spec) +} + +func (ewcvq *EnumWithConflictingValueQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(enumwithconflictingvalue.Table, enumwithconflictingvalue.Columns, sqlgraph.NewFieldSpec(enumwithconflictingvalue.FieldID, field.TypeInt)) + _spec.From = ewcvq.sql + if unique := ewcvq.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if ewcvq.path != nil { + _spec.Unique = true + } + if fields := ewcvq.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, enumwithconflictingvalue.FieldID) + for i := range fields { + if fields[i] != enumwithconflictingvalue.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := ewcvq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := ewcvq.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := ewcvq.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := ewcvq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (ewcvq *EnumWithConflictingValueQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(ewcvq.driver.Dialect()) + t1 := builder.Table(enumwithconflictingvalue.Table) + columns := ewcvq.ctx.Fields + if len(columns) == 0 { + columns = enumwithconflictingvalue.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if ewcvq.sql != nil { + selector = ewcvq.sql + selector.Select(selector.Columns(columns...)...) + } + if ewcvq.ctx.Unique != nil && *ewcvq.ctx.Unique { + selector.Distinct() + } + for _, p := range ewcvq.predicates { + p(selector) + } + for _, p := range ewcvq.order { + p(selector) + } + if offset := ewcvq.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := ewcvq.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// EnumWithConflictingValueGroupBy is the group-by builder for EnumWithConflictingValue entities. +type EnumWithConflictingValueGroupBy struct { + selector + build *EnumWithConflictingValueQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (ewcvgb *EnumWithConflictingValueGroupBy) Aggregate(fns ...AggregateFunc) *EnumWithConflictingValueGroupBy { + ewcvgb.fns = append(ewcvgb.fns, fns...) + return ewcvgb +} + +// Scan applies the selector query and scans the result into the given value. +func (ewcvgb *EnumWithConflictingValueGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ewcvgb.build.ctx, "GroupBy") + if err := ewcvgb.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*EnumWithConflictingValueQuery, *EnumWithConflictingValueGroupBy](ctx, ewcvgb.build, ewcvgb, ewcvgb.build.inters, v) +} + +func (ewcvgb *EnumWithConflictingValueGroupBy) sqlScan(ctx context.Context, root *EnumWithConflictingValueQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(ewcvgb.fns)) + for _, fn := range ewcvgb.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*ewcvgb.flds)+len(ewcvgb.fns)) + for _, f := range *ewcvgb.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*ewcvgb.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := ewcvgb.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// EnumWithConflictingValueSelect is the builder for selecting fields of EnumWithConflictingValue entities. +type EnumWithConflictingValueSelect struct { + *EnumWithConflictingValueQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (ewcvs *EnumWithConflictingValueSelect) Aggregate(fns ...AggregateFunc) *EnumWithConflictingValueSelect { + ewcvs.fns = append(ewcvs.fns, fns...) + return ewcvs +} + +// Scan applies the selector query and scans the result into the given value. +func (ewcvs *EnumWithConflictingValueSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, ewcvs.ctx, "Select") + if err := ewcvs.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*EnumWithConflictingValueQuery, *EnumWithConflictingValueSelect](ctx, ewcvs.EnumWithConflictingValueQuery, ewcvs, ewcvs.inters, v) +} + +func (ewcvs *EnumWithConflictingValueSelect) sqlScan(ctx context.Context, root *EnumWithConflictingValueQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(ewcvs.fns)) + for _, fn := range ewcvs.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*ewcvs.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := ewcvs.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/entproto/internal/entprototest/ent/enumwithconflictingvalue_update.go b/entproto/internal/entprototest/ent/enumwithconflictingvalue_update.go new file mode 100644 index 000000000..b28937758 --- /dev/null +++ b/entproto/internal/entprototest/ent/enumwithconflictingvalue_update.go @@ -0,0 +1,219 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "entgo.io/contrib/entproto/internal/entprototest/ent/enumwithconflictingvalue" + "entgo.io/contrib/entproto/internal/entprototest/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// EnumWithConflictingValueUpdate is the builder for updating EnumWithConflictingValue entities. +type EnumWithConflictingValueUpdate struct { + config + hooks []Hook + mutation *EnumWithConflictingValueMutation +} + +// Where appends a list predicates to the EnumWithConflictingValueUpdate builder. +func (ewcvu *EnumWithConflictingValueUpdate) Where(ps ...predicate.EnumWithConflictingValue) *EnumWithConflictingValueUpdate { + ewcvu.mutation.Where(ps...) + return ewcvu +} + +// SetEnum sets the "enum" field. +func (ewcvu *EnumWithConflictingValueUpdate) SetEnum(e enumwithconflictingvalue.Enum) *EnumWithConflictingValueUpdate { + ewcvu.mutation.SetEnum(e) + return ewcvu +} + +// Mutation returns the EnumWithConflictingValueMutation object of the builder. +func (ewcvu *EnumWithConflictingValueUpdate) Mutation() *EnumWithConflictingValueMutation { + return ewcvu.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (ewcvu *EnumWithConflictingValueUpdate) Save(ctx context.Context) (int, error) { + return withHooks[int, EnumWithConflictingValueMutation](ctx, ewcvu.sqlSave, ewcvu.mutation, ewcvu.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (ewcvu *EnumWithConflictingValueUpdate) SaveX(ctx context.Context) int { + affected, err := ewcvu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (ewcvu *EnumWithConflictingValueUpdate) Exec(ctx context.Context) error { + _, err := ewcvu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ewcvu *EnumWithConflictingValueUpdate) ExecX(ctx context.Context) { + if err := ewcvu.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (ewcvu *EnumWithConflictingValueUpdate) check() error { + if v, ok := ewcvu.mutation.Enum(); ok { + if err := enumwithconflictingvalue.EnumValidator(v); err != nil { + return &ValidationError{Name: "enum", err: fmt.Errorf(`ent: validator failed for field "EnumWithConflictingValue.enum": %w`, err)} + } + } + return nil +} + +func (ewcvu *EnumWithConflictingValueUpdate) sqlSave(ctx context.Context) (n int, err error) { + if err := ewcvu.check(); err != nil { + return n, err + } + _spec := sqlgraph.NewUpdateSpec(enumwithconflictingvalue.Table, enumwithconflictingvalue.Columns, sqlgraph.NewFieldSpec(enumwithconflictingvalue.FieldID, field.TypeInt)) + if ps := ewcvu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := ewcvu.mutation.Enum(); ok { + _spec.SetField(enumwithconflictingvalue.FieldEnum, field.TypeEnum, value) + } + if n, err = sqlgraph.UpdateNodes(ctx, ewcvu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{enumwithconflictingvalue.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + ewcvu.mutation.done = true + return n, nil +} + +// EnumWithConflictingValueUpdateOne is the builder for updating a single EnumWithConflictingValue entity. +type EnumWithConflictingValueUpdateOne struct { + config + fields []string + hooks []Hook + mutation *EnumWithConflictingValueMutation +} + +// SetEnum sets the "enum" field. +func (ewcvuo *EnumWithConflictingValueUpdateOne) SetEnum(e enumwithconflictingvalue.Enum) *EnumWithConflictingValueUpdateOne { + ewcvuo.mutation.SetEnum(e) + return ewcvuo +} + +// Mutation returns the EnumWithConflictingValueMutation object of the builder. +func (ewcvuo *EnumWithConflictingValueUpdateOne) Mutation() *EnumWithConflictingValueMutation { + return ewcvuo.mutation +} + +// Where appends a list predicates to the EnumWithConflictingValueUpdate builder. +func (ewcvuo *EnumWithConflictingValueUpdateOne) Where(ps ...predicate.EnumWithConflictingValue) *EnumWithConflictingValueUpdateOne { + ewcvuo.mutation.Where(ps...) + return ewcvuo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (ewcvuo *EnumWithConflictingValueUpdateOne) Select(field string, fields ...string) *EnumWithConflictingValueUpdateOne { + ewcvuo.fields = append([]string{field}, fields...) + return ewcvuo +} + +// Save executes the query and returns the updated EnumWithConflictingValue entity. +func (ewcvuo *EnumWithConflictingValueUpdateOne) Save(ctx context.Context) (*EnumWithConflictingValue, error) { + return withHooks[*EnumWithConflictingValue, EnumWithConflictingValueMutation](ctx, ewcvuo.sqlSave, ewcvuo.mutation, ewcvuo.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (ewcvuo *EnumWithConflictingValueUpdateOne) SaveX(ctx context.Context) *EnumWithConflictingValue { + node, err := ewcvuo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (ewcvuo *EnumWithConflictingValueUpdateOne) Exec(ctx context.Context) error { + _, err := ewcvuo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ewcvuo *EnumWithConflictingValueUpdateOne) ExecX(ctx context.Context) { + if err := ewcvuo.Exec(ctx); err != nil { + panic(err) + } +} + +// check runs all checks and user-defined validators on the builder. +func (ewcvuo *EnumWithConflictingValueUpdateOne) check() error { + if v, ok := ewcvuo.mutation.Enum(); ok { + if err := enumwithconflictingvalue.EnumValidator(v); err != nil { + return &ValidationError{Name: "enum", err: fmt.Errorf(`ent: validator failed for field "EnumWithConflictingValue.enum": %w`, err)} + } + } + return nil +} + +func (ewcvuo *EnumWithConflictingValueUpdateOne) sqlSave(ctx context.Context) (_node *EnumWithConflictingValue, err error) { + if err := ewcvuo.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(enumwithconflictingvalue.Table, enumwithconflictingvalue.Columns, sqlgraph.NewFieldSpec(enumwithconflictingvalue.FieldID, field.TypeInt)) + id, ok := ewcvuo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "EnumWithConflictingValue.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := ewcvuo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, enumwithconflictingvalue.FieldID) + for _, f := range fields { + if !enumwithconflictingvalue.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != enumwithconflictingvalue.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := ewcvuo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := ewcvuo.mutation.Enum(); ok { + _spec.SetField(enumwithconflictingvalue.FieldEnum, field.TypeEnum, value) + } + _node = &EnumWithConflictingValue{config: ewcvuo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, ewcvuo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{enumwithconflictingvalue.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + ewcvuo.mutation.done = true + return _node, nil +} diff --git a/entproto/internal/entprototest/ent/hook/hook.go b/entproto/internal/entprototest/ent/hook/hook.go index 950daf3b7..4e00d8587 100644 --- a/entproto/internal/entprototest/ent/hook/hook.go +++ b/entproto/internal/entprototest/ent/hook/hook.go @@ -69,6 +69,18 @@ func (f DuplicateNumberMessageFunc) Mutate(ctx context.Context, m ent.Mutation) return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DuplicateNumberMessageMutation", m) } +// The EnumWithConflictingValueFunc type is an adapter to allow the use of ordinary +// function as EnumWithConflictingValue mutator. +type EnumWithConflictingValueFunc func(context.Context, *ent.EnumWithConflictingValueMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f EnumWithConflictingValueFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.EnumWithConflictingValueMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.EnumWithConflictingValueMutation", m) +} + // The ExplicitSkippedMessageFunc type is an adapter to allow the use of ordinary // function as ExplicitSkippedMessage mutator. type ExplicitSkippedMessageFunc func(context.Context, *ent.ExplicitSkippedMessageMutation) (ent.Value, error) diff --git a/entproto/internal/entprototest/ent/messagewithenum.go b/entproto/internal/entprototest/ent/messagewithenum.go index 836e94f83..c67b08845 100644 --- a/entproto/internal/entprototest/ent/messagewithenum.go +++ b/entproto/internal/entprototest/ent/messagewithenum.go @@ -20,7 +20,9 @@ type MessageWithEnum struct { EnumType messagewithenum.EnumType `json:"enum_type,omitempty"` // EnumWithoutDefault holds the value of the "enum_without_default" field. EnumWithoutDefault messagewithenum.EnumWithoutDefault `json:"enum_without_default,omitempty"` - selectValues sql.SelectValues + // EnumWithSpecialCharacters holds the value of the "enum_with_special_characters" field. + EnumWithSpecialCharacters messagewithenum.EnumWithSpecialCharacters `json:"enum_with_special_characters,omitempty"` + selectValues sql.SelectValues } // scanValues returns the types for scanning values from sql.Rows. @@ -30,7 +32,7 @@ func (*MessageWithEnum) scanValues(columns []string) ([]any, error) { switch columns[i] { case messagewithenum.FieldID: values[i] = new(sql.NullInt64) - case messagewithenum.FieldEnumType, messagewithenum.FieldEnumWithoutDefault: + case messagewithenum.FieldEnumType, messagewithenum.FieldEnumWithoutDefault, messagewithenum.FieldEnumWithSpecialCharacters: values[i] = new(sql.NullString) default: values[i] = new(sql.UnknownType) @@ -65,6 +67,12 @@ func (mwe *MessageWithEnum) assignValues(columns []string, values []any) error { } else if value.Valid { mwe.EnumWithoutDefault = messagewithenum.EnumWithoutDefault(value.String) } + case messagewithenum.FieldEnumWithSpecialCharacters: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field enum_with_special_characters", values[i]) + } else if value.Valid { + mwe.EnumWithSpecialCharacters = messagewithenum.EnumWithSpecialCharacters(value.String) + } default: mwe.selectValues.Set(columns[i], values[i]) } @@ -106,6 +114,9 @@ func (mwe *MessageWithEnum) String() string { builder.WriteString(", ") builder.WriteString("enum_without_default=") builder.WriteString(fmt.Sprintf("%v", mwe.EnumWithoutDefault)) + builder.WriteString(", ") + builder.WriteString("enum_with_special_characters=") + builder.WriteString(fmt.Sprintf("%v", mwe.EnumWithSpecialCharacters)) builder.WriteByte(')') return builder.String() } diff --git a/entproto/internal/entprototest/ent/messagewithenum/messagewithenum.go b/entproto/internal/entprototest/ent/messagewithenum/messagewithenum.go index 5e4d81264..350f3dab0 100644 --- a/entproto/internal/entprototest/ent/messagewithenum/messagewithenum.go +++ b/entproto/internal/entprototest/ent/messagewithenum/messagewithenum.go @@ -17,6 +17,8 @@ const ( FieldEnumType = "enum_type" // FieldEnumWithoutDefault holds the string denoting the enum_without_default field in the database. FieldEnumWithoutDefault = "enum_without_default" + // FieldEnumWithSpecialCharacters holds the string denoting the enum_with_special_characters field in the database. + FieldEnumWithSpecialCharacters = "enum_with_special_characters" // Table holds the table name of the messagewithenum in the database. Table = "message_with_enums" ) @@ -26,6 +28,7 @@ var Columns = []string{ FieldID, FieldEnumType, FieldEnumWithoutDefault, + FieldEnumWithSpecialCharacters, } // ValidColumn reports if the column name is valid (part of the table columns). @@ -89,6 +92,29 @@ func EnumWithoutDefaultValidator(ewd EnumWithoutDefault) error { } } +// EnumWithSpecialCharacters defines the type for the "enum_with_special_characters" enum field. +type EnumWithSpecialCharacters string + +// EnumWithSpecialCharacters values. +const ( + EnumWithSpecialCharactersJpeg EnumWithSpecialCharacters = "image/jpeg" + EnumWithSpecialCharactersPng EnumWithSpecialCharacters = "image/png" +) + +func (ewsc EnumWithSpecialCharacters) String() string { + return string(ewsc) +} + +// EnumWithSpecialCharactersValidator is a validator for the "enum_with_special_characters" field enum values. It is called by the builders before save. +func EnumWithSpecialCharactersValidator(ewsc EnumWithSpecialCharacters) error { + switch ewsc { + case EnumWithSpecialCharactersJpeg, EnumWithSpecialCharactersPng: + return nil + default: + return fmt.Errorf("messagewithenum: invalid enum value for enum_with_special_characters field: %q", ewsc) + } +} + // OrderOption defines the ordering options for the MessageWithEnum queries. type OrderOption func(*sql.Selector) @@ -106,3 +132,8 @@ func ByEnumType(opts ...sql.OrderTermOption) OrderOption { func ByEnumWithoutDefault(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldEnumWithoutDefault, opts...).ToFunc() } + +// ByEnumWithSpecialCharacters orders the results by the enum_with_special_characters field. +func ByEnumWithSpecialCharacters(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEnumWithSpecialCharacters, opts...).ToFunc() +} diff --git a/entproto/internal/entprototest/ent/messagewithenum/where.go b/entproto/internal/entprototest/ent/messagewithenum/where.go index f781d8932..4b2c7587c 100644 --- a/entproto/internal/entprototest/ent/messagewithenum/where.go +++ b/entproto/internal/entprototest/ent/messagewithenum/where.go @@ -92,6 +92,26 @@ func EnumWithoutDefaultNotIn(vs ...EnumWithoutDefault) predicate.MessageWithEnum return predicate.MessageWithEnum(sql.FieldNotIn(FieldEnumWithoutDefault, vs...)) } +// EnumWithSpecialCharactersEQ applies the EQ predicate on the "enum_with_special_characters" field. +func EnumWithSpecialCharactersEQ(v EnumWithSpecialCharacters) predicate.MessageWithEnum { + return predicate.MessageWithEnum(sql.FieldEQ(FieldEnumWithSpecialCharacters, v)) +} + +// EnumWithSpecialCharactersNEQ applies the NEQ predicate on the "enum_with_special_characters" field. +func EnumWithSpecialCharactersNEQ(v EnumWithSpecialCharacters) predicate.MessageWithEnum { + return predicate.MessageWithEnum(sql.FieldNEQ(FieldEnumWithSpecialCharacters, v)) +} + +// EnumWithSpecialCharactersIn applies the In predicate on the "enum_with_special_characters" field. +func EnumWithSpecialCharactersIn(vs ...EnumWithSpecialCharacters) predicate.MessageWithEnum { + return predicate.MessageWithEnum(sql.FieldIn(FieldEnumWithSpecialCharacters, vs...)) +} + +// EnumWithSpecialCharactersNotIn applies the NotIn predicate on the "enum_with_special_characters" field. +func EnumWithSpecialCharactersNotIn(vs ...EnumWithSpecialCharacters) predicate.MessageWithEnum { + return predicate.MessageWithEnum(sql.FieldNotIn(FieldEnumWithSpecialCharacters, vs...)) +} + // And groups predicates with the AND operator between them. func And(predicates ...predicate.MessageWithEnum) predicate.MessageWithEnum { return predicate.MessageWithEnum(func(s *sql.Selector) { diff --git a/entproto/internal/entprototest/ent/messagewithenum_create.go b/entproto/internal/entprototest/ent/messagewithenum_create.go index 33fa887a6..bf6b41745 100644 --- a/entproto/internal/entprototest/ent/messagewithenum_create.go +++ b/entproto/internal/entprototest/ent/messagewithenum_create.go @@ -39,6 +39,12 @@ func (mwec *MessageWithEnumCreate) SetEnumWithoutDefault(mwd messagewithenum.Enu return mwec } +// SetEnumWithSpecialCharacters sets the "enum_with_special_characters" field. +func (mwec *MessageWithEnumCreate) SetEnumWithSpecialCharacters(mwsc messagewithenum.EnumWithSpecialCharacters) *MessageWithEnumCreate { + mwec.mutation.SetEnumWithSpecialCharacters(mwsc) + return mwec +} + // Mutation returns the MessageWithEnumMutation object of the builder. func (mwec *MessageWithEnumCreate) Mutation() *MessageWithEnumMutation { return mwec.mutation @@ -98,6 +104,14 @@ func (mwec *MessageWithEnumCreate) check() error { return &ValidationError{Name: "enum_without_default", err: fmt.Errorf(`ent: validator failed for field "MessageWithEnum.enum_without_default": %w`, err)} } } + if _, ok := mwec.mutation.EnumWithSpecialCharacters(); !ok { + return &ValidationError{Name: "enum_with_special_characters", err: errors.New(`ent: missing required field "MessageWithEnum.enum_with_special_characters"`)} + } + if v, ok := mwec.mutation.EnumWithSpecialCharacters(); ok { + if err := messagewithenum.EnumWithSpecialCharactersValidator(v); err != nil { + return &ValidationError{Name: "enum_with_special_characters", err: fmt.Errorf(`ent: validator failed for field "MessageWithEnum.enum_with_special_characters": %w`, err)} + } + } return nil } @@ -132,6 +146,10 @@ func (mwec *MessageWithEnumCreate) createSpec() (*MessageWithEnum, *sqlgraph.Cre _spec.SetField(messagewithenum.FieldEnumWithoutDefault, field.TypeEnum, value) _node.EnumWithoutDefault = value } + if value, ok := mwec.mutation.EnumWithSpecialCharacters(); ok { + _spec.SetField(messagewithenum.FieldEnumWithSpecialCharacters, field.TypeEnum, value) + _node.EnumWithSpecialCharacters = value + } return _node, _spec } diff --git a/entproto/internal/entprototest/ent/messagewithenum_update.go b/entproto/internal/entprototest/ent/messagewithenum_update.go index b30452eb4..fbc918c72 100644 --- a/entproto/internal/entprototest/ent/messagewithenum_update.go +++ b/entproto/internal/entprototest/ent/messagewithenum_update.go @@ -47,6 +47,12 @@ func (mweu *MessageWithEnumUpdate) SetEnumWithoutDefault(mwd messagewithenum.Enu return mweu } +// SetEnumWithSpecialCharacters sets the "enum_with_special_characters" field. +func (mweu *MessageWithEnumUpdate) SetEnumWithSpecialCharacters(mwsc messagewithenum.EnumWithSpecialCharacters) *MessageWithEnumUpdate { + mweu.mutation.SetEnumWithSpecialCharacters(mwsc) + return mweu +} + // Mutation returns the MessageWithEnumMutation object of the builder. func (mweu *MessageWithEnumUpdate) Mutation() *MessageWithEnumMutation { return mweu.mutation @@ -91,6 +97,11 @@ func (mweu *MessageWithEnumUpdate) check() error { return &ValidationError{Name: "enum_without_default", err: fmt.Errorf(`ent: validator failed for field "MessageWithEnum.enum_without_default": %w`, err)} } } + if v, ok := mweu.mutation.EnumWithSpecialCharacters(); ok { + if err := messagewithenum.EnumWithSpecialCharactersValidator(v); err != nil { + return &ValidationError{Name: "enum_with_special_characters", err: fmt.Errorf(`ent: validator failed for field "MessageWithEnum.enum_with_special_characters": %w`, err)} + } + } return nil } @@ -112,6 +123,9 @@ func (mweu *MessageWithEnumUpdate) sqlSave(ctx context.Context) (n int, err erro if value, ok := mweu.mutation.EnumWithoutDefault(); ok { _spec.SetField(messagewithenum.FieldEnumWithoutDefault, field.TypeEnum, value) } + if value, ok := mweu.mutation.EnumWithSpecialCharacters(); ok { + _spec.SetField(messagewithenum.FieldEnumWithSpecialCharacters, field.TypeEnum, value) + } if n, err = sqlgraph.UpdateNodes(ctx, mweu.driver, _spec); err != nil { if _, ok := err.(*sqlgraph.NotFoundError); ok { err = &NotFoundError{messagewithenum.Label} @@ -152,6 +166,12 @@ func (mweuo *MessageWithEnumUpdateOne) SetEnumWithoutDefault(mwd messagewithenum return mweuo } +// SetEnumWithSpecialCharacters sets the "enum_with_special_characters" field. +func (mweuo *MessageWithEnumUpdateOne) SetEnumWithSpecialCharacters(mwsc messagewithenum.EnumWithSpecialCharacters) *MessageWithEnumUpdateOne { + mweuo.mutation.SetEnumWithSpecialCharacters(mwsc) + return mweuo +} + // Mutation returns the MessageWithEnumMutation object of the builder. func (mweuo *MessageWithEnumUpdateOne) Mutation() *MessageWithEnumMutation { return mweuo.mutation @@ -209,6 +229,11 @@ func (mweuo *MessageWithEnumUpdateOne) check() error { return &ValidationError{Name: "enum_without_default", err: fmt.Errorf(`ent: validator failed for field "MessageWithEnum.enum_without_default": %w`, err)} } } + if v, ok := mweuo.mutation.EnumWithSpecialCharacters(); ok { + if err := messagewithenum.EnumWithSpecialCharactersValidator(v); err != nil { + return &ValidationError{Name: "enum_with_special_characters", err: fmt.Errorf(`ent: validator failed for field "MessageWithEnum.enum_with_special_characters": %w`, err)} + } + } return nil } @@ -247,6 +272,9 @@ func (mweuo *MessageWithEnumUpdateOne) sqlSave(ctx context.Context) (_node *Mess if value, ok := mweuo.mutation.EnumWithoutDefault(); ok { _spec.SetField(messagewithenum.FieldEnumWithoutDefault, field.TypeEnum, value) } + if value, ok := mweuo.mutation.EnumWithSpecialCharacters(); ok { + _spec.SetField(messagewithenum.FieldEnumWithSpecialCharacters, field.TypeEnum, value) + } _node = &MessageWithEnum{config: mweuo.config} _spec.Assign = _node.assignValues _spec.ScanValues = _node.scanValues diff --git a/entproto/internal/entprototest/ent/migrate/schema.go b/entproto/internal/entprototest/ent/migrate/schema.go index 0db4ec2b1..57110d49c 100644 --- a/entproto/internal/entprototest/ent/migrate/schema.go +++ b/entproto/internal/entprototest/ent/migrate/schema.go @@ -75,6 +75,17 @@ var ( Columns: DuplicateNumberMessagesColumns, PrimaryKey: []*schema.Column{DuplicateNumberMessagesColumns[0]}, } + // EnumWithConflictingValuesColumns holds the columns for the "enum_with_conflicting_values" table. + EnumWithConflictingValuesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "enum", Type: field.TypeEnum, Enums: []string{"image/jpeg", "IMAGE_JPEG"}}, + } + // EnumWithConflictingValuesTable holds the schema information for the "enum_with_conflicting_values" table. + EnumWithConflictingValuesTable = &schema.Table{ + Name: "enum_with_conflicting_values", + Columns: EnumWithConflictingValuesColumns, + PrimaryKey: []*schema.Column{EnumWithConflictingValuesColumns[0]}, + } // ExplicitSkippedMessagesColumns holds the columns for the "explicit_skipped_messages" table. ExplicitSkippedMessagesColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -140,6 +151,7 @@ var ( {Name: "id", Type: field.TypeInt, Increment: true}, {Name: "enum_type", Type: field.TypeEnum, Enums: []string{"pending", "active", "suspended", "deleted"}, Default: "pending"}, {Name: "enum_without_default", Type: field.TypeEnum, Enums: []string{"first", "second"}}, + {Name: "enum_with_special_characters", Type: field.TypeEnum, Enums: []string{"image/jpeg", "image/png"}}, } // MessageWithEnumsTable holds the schema information for the "message_with_enums" table. MessageWithEnumsTable = &schema.Table{ @@ -347,6 +359,7 @@ var ( CategoriesTable, DependsOnSkippedsTable, DuplicateNumberMessagesTable, + EnumWithConflictingValuesTable, ExplicitSkippedMessagesTable, ImagesTable, ImplicitSkippedMessagesTable, diff --git a/entproto/internal/entprototest/ent/mutation.go b/entproto/internal/entprototest/ent/mutation.go index 55475468a..e702b7e1f 100644 --- a/entproto/internal/entprototest/ent/mutation.go +++ b/entproto/internal/entprototest/ent/mutation.go @@ -13,6 +13,7 @@ import ( "entgo.io/contrib/entproto/internal/entprototest/ent/category" "entgo.io/contrib/entproto/internal/entprototest/ent/dependsonskipped" "entgo.io/contrib/entproto/internal/entprototest/ent/duplicatenumbermessage" + "entgo.io/contrib/entproto/internal/entprototest/ent/enumwithconflictingvalue" "entgo.io/contrib/entproto/internal/entprototest/ent/image" "entgo.io/contrib/entproto/internal/entprototest/ent/invalidfieldmessage" "entgo.io/contrib/entproto/internal/entprototest/ent/messagewithenum" @@ -41,28 +42,29 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. - TypeAllMethodsService = "AllMethodsService" - TypeBlogPost = "BlogPost" - TypeCategory = "Category" - TypeDependsOnSkipped = "DependsOnSkipped" - TypeDuplicateNumberMessage = "DuplicateNumberMessage" - TypeExplicitSkippedMessage = "ExplicitSkippedMessage" - TypeImage = "Image" - TypeImplicitSkippedMessage = "ImplicitSkippedMessage" - TypeInvalidFieldMessage = "InvalidFieldMessage" - TypeMessageWithEnum = "MessageWithEnum" - TypeMessageWithFieldOne = "MessageWithFieldOne" - TypeMessageWithID = "MessageWithID" - TypeMessageWithOptionals = "MessageWithOptionals" - TypeMessageWithPackageName = "MessageWithPackageName" - TypeMessageWithStrings = "MessageWithStrings" - TypeNoBackref = "NoBackref" - TypeOneMethodService = "OneMethodService" - TypePortal = "Portal" - TypeSkipEdgeExample = "SkipEdgeExample" - TypeTwoMethodService = "TwoMethodService" - TypeUser = "User" - TypeValidMessage = "ValidMessage" + TypeAllMethodsService = "AllMethodsService" + TypeBlogPost = "BlogPost" + TypeCategory = "Category" + TypeDependsOnSkipped = "DependsOnSkipped" + TypeDuplicateNumberMessage = "DuplicateNumberMessage" + TypeEnumWithConflictingValue = "EnumWithConflictingValue" + TypeExplicitSkippedMessage = "ExplicitSkippedMessage" + TypeImage = "Image" + TypeImplicitSkippedMessage = "ImplicitSkippedMessage" + TypeInvalidFieldMessage = "InvalidFieldMessage" + TypeMessageWithEnum = "MessageWithEnum" + TypeMessageWithFieldOne = "MessageWithFieldOne" + TypeMessageWithID = "MessageWithID" + TypeMessageWithOptionals = "MessageWithOptionals" + TypeMessageWithPackageName = "MessageWithPackageName" + TypeMessageWithStrings = "MessageWithStrings" + TypeNoBackref = "NoBackref" + TypeOneMethodService = "OneMethodService" + TypePortal = "Portal" + TypeSkipEdgeExample = "SkipEdgeExample" + TypeTwoMethodService = "TwoMethodService" + TypeUser = "User" + TypeValidMessage = "ValidMessage" ) // AllMethodsServiceMutation represents an operation that mutates the AllMethodsService nodes in the graph. @@ -2223,6 +2225,332 @@ func (m *DuplicateNumberMessageMutation) ResetEdge(name string) error { return fmt.Errorf("unknown DuplicateNumberMessage edge %s", name) } +// EnumWithConflictingValueMutation represents an operation that mutates the EnumWithConflictingValue nodes in the graph. +type EnumWithConflictingValueMutation struct { + config + op Op + typ string + id *int + enum *enumwithconflictingvalue.Enum + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*EnumWithConflictingValue, error) + predicates []predicate.EnumWithConflictingValue +} + +var _ ent.Mutation = (*EnumWithConflictingValueMutation)(nil) + +// enumwithconflictingvalueOption allows management of the mutation configuration using functional options. +type enumwithconflictingvalueOption func(*EnumWithConflictingValueMutation) + +// newEnumWithConflictingValueMutation creates new mutation for the EnumWithConflictingValue entity. +func newEnumWithConflictingValueMutation(c config, op Op, opts ...enumwithconflictingvalueOption) *EnumWithConflictingValueMutation { + m := &EnumWithConflictingValueMutation{ + config: c, + op: op, + typ: TypeEnumWithConflictingValue, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withEnumWithConflictingValueID sets the ID field of the mutation. +func withEnumWithConflictingValueID(id int) enumwithconflictingvalueOption { + return func(m *EnumWithConflictingValueMutation) { + var ( + err error + once sync.Once + value *EnumWithConflictingValue + ) + m.oldValue = func(ctx context.Context) (*EnumWithConflictingValue, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().EnumWithConflictingValue.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withEnumWithConflictingValue sets the old EnumWithConflictingValue of the mutation. +func withEnumWithConflictingValue(node *EnumWithConflictingValue) enumwithconflictingvalueOption { + return func(m *EnumWithConflictingValueMutation) { + m.oldValue = func(context.Context) (*EnumWithConflictingValue, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m EnumWithConflictingValueMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m EnumWithConflictingValueMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *EnumWithConflictingValueMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *EnumWithConflictingValueMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().EnumWithConflictingValue.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetEnum sets the "enum" field. +func (m *EnumWithConflictingValueMutation) SetEnum(e enumwithconflictingvalue.Enum) { + m.enum = &e +} + +// Enum returns the value of the "enum" field in the mutation. +func (m *EnumWithConflictingValueMutation) Enum() (r enumwithconflictingvalue.Enum, exists bool) { + v := m.enum + if v == nil { + return + } + return *v, true +} + +// OldEnum returns the old "enum" field's value of the EnumWithConflictingValue entity. +// If the EnumWithConflictingValue 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 *EnumWithConflictingValueMutation) OldEnum(ctx context.Context) (v enumwithconflictingvalue.Enum, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEnum is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEnum requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEnum: %w", err) + } + return oldValue.Enum, nil +} + +// ResetEnum resets all changes to the "enum" field. +func (m *EnumWithConflictingValueMutation) ResetEnum() { + m.enum = nil +} + +// Where appends a list predicates to the EnumWithConflictingValueMutation builder. +func (m *EnumWithConflictingValueMutation) Where(ps ...predicate.EnumWithConflictingValue) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the EnumWithConflictingValueMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *EnumWithConflictingValueMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.EnumWithConflictingValue, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *EnumWithConflictingValueMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *EnumWithConflictingValueMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (EnumWithConflictingValue). +func (m *EnumWithConflictingValueMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *EnumWithConflictingValueMutation) Fields() []string { + fields := make([]string, 0, 1) + if m.enum != nil { + fields = append(fields, enumwithconflictingvalue.FieldEnum) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *EnumWithConflictingValueMutation) Field(name string) (ent.Value, bool) { + switch name { + case enumwithconflictingvalue.FieldEnum: + return m.Enum() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *EnumWithConflictingValueMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case enumwithconflictingvalue.FieldEnum: + return m.OldEnum(ctx) + } + return nil, fmt.Errorf("unknown EnumWithConflictingValue field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *EnumWithConflictingValueMutation) SetField(name string, value ent.Value) error { + switch name { + case enumwithconflictingvalue.FieldEnum: + v, ok := value.(enumwithconflictingvalue.Enum) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEnum(v) + return nil + } + return fmt.Errorf("unknown EnumWithConflictingValue field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *EnumWithConflictingValueMutation) AddedFields() []string { + return nil +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *EnumWithConflictingValueMutation) AddedField(name string) (ent.Value, bool) { + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *EnumWithConflictingValueMutation) AddField(name string, value ent.Value) error { + switch name { + } + return fmt.Errorf("unknown EnumWithConflictingValue numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *EnumWithConflictingValueMutation) ClearedFields() []string { + return nil +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *EnumWithConflictingValueMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *EnumWithConflictingValueMutation) ClearField(name string) error { + return fmt.Errorf("unknown EnumWithConflictingValue nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *EnumWithConflictingValueMutation) ResetField(name string) error { + switch name { + case enumwithconflictingvalue.FieldEnum: + m.ResetEnum() + return nil + } + return fmt.Errorf("unknown EnumWithConflictingValue field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *EnumWithConflictingValueMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *EnumWithConflictingValueMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *EnumWithConflictingValueMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *EnumWithConflictingValueMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *EnumWithConflictingValueMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *EnumWithConflictingValueMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *EnumWithConflictingValueMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown EnumWithConflictingValue unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *EnumWithConflictingValueMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown EnumWithConflictingValue edge %s", name) +} + // ExplicitSkippedMessageMutation represents an operation that mutates the ExplicitSkippedMessage nodes in the graph. type ExplicitSkippedMessageMutation struct { config @@ -3505,15 +3833,16 @@ func (m *InvalidFieldMessageMutation) ResetEdge(name string) error { // MessageWithEnumMutation represents an operation that mutates the MessageWithEnum nodes in the graph. type MessageWithEnumMutation struct { config - op Op - typ string - id *int - enum_type *messagewithenum.EnumType - enum_without_default *messagewithenum.EnumWithoutDefault - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*MessageWithEnum, error) - predicates []predicate.MessageWithEnum + op Op + typ string + id *int + enum_type *messagewithenum.EnumType + enum_without_default *messagewithenum.EnumWithoutDefault + enum_with_special_characters *messagewithenum.EnumWithSpecialCharacters + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*MessageWithEnum, error) + predicates []predicate.MessageWithEnum } var _ ent.Mutation = (*MessageWithEnumMutation)(nil) @@ -3686,6 +4015,42 @@ func (m *MessageWithEnumMutation) ResetEnumWithoutDefault() { m.enum_without_default = nil } +// SetEnumWithSpecialCharacters sets the "enum_with_special_characters" field. +func (m *MessageWithEnumMutation) SetEnumWithSpecialCharacters(mwsc messagewithenum.EnumWithSpecialCharacters) { + m.enum_with_special_characters = &mwsc +} + +// EnumWithSpecialCharacters returns the value of the "enum_with_special_characters" field in the mutation. +func (m *MessageWithEnumMutation) EnumWithSpecialCharacters() (r messagewithenum.EnumWithSpecialCharacters, exists bool) { + v := m.enum_with_special_characters + if v == nil { + return + } + return *v, true +} + +// OldEnumWithSpecialCharacters returns the old "enum_with_special_characters" field's value of the MessageWithEnum entity. +// If the MessageWithEnum 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 *MessageWithEnumMutation) OldEnumWithSpecialCharacters(ctx context.Context) (v messagewithenum.EnumWithSpecialCharacters, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEnumWithSpecialCharacters is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEnumWithSpecialCharacters requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEnumWithSpecialCharacters: %w", err) + } + return oldValue.EnumWithSpecialCharacters, nil +} + +// ResetEnumWithSpecialCharacters resets all changes to the "enum_with_special_characters" field. +func (m *MessageWithEnumMutation) ResetEnumWithSpecialCharacters() { + m.enum_with_special_characters = nil +} + // Where appends a list predicates to the MessageWithEnumMutation builder. func (m *MessageWithEnumMutation) Where(ps ...predicate.MessageWithEnum) { m.predicates = append(m.predicates, ps...) @@ -3720,13 +4085,16 @@ func (m *MessageWithEnumMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *MessageWithEnumMutation) Fields() []string { - fields := make([]string, 0, 2) + fields := make([]string, 0, 3) if m.enum_type != nil { fields = append(fields, messagewithenum.FieldEnumType) } if m.enum_without_default != nil { fields = append(fields, messagewithenum.FieldEnumWithoutDefault) } + if m.enum_with_special_characters != nil { + fields = append(fields, messagewithenum.FieldEnumWithSpecialCharacters) + } return fields } @@ -3739,6 +4107,8 @@ func (m *MessageWithEnumMutation) Field(name string) (ent.Value, bool) { return m.EnumType() case messagewithenum.FieldEnumWithoutDefault: return m.EnumWithoutDefault() + case messagewithenum.FieldEnumWithSpecialCharacters: + return m.EnumWithSpecialCharacters() } return nil, false } @@ -3752,6 +4122,8 @@ func (m *MessageWithEnumMutation) OldField(ctx context.Context, name string) (en return m.OldEnumType(ctx) case messagewithenum.FieldEnumWithoutDefault: return m.OldEnumWithoutDefault(ctx) + case messagewithenum.FieldEnumWithSpecialCharacters: + return m.OldEnumWithSpecialCharacters(ctx) } return nil, fmt.Errorf("unknown MessageWithEnum field %s", name) } @@ -3775,6 +4147,13 @@ func (m *MessageWithEnumMutation) SetField(name string, value ent.Value) error { } m.SetEnumWithoutDefault(v) return nil + case messagewithenum.FieldEnumWithSpecialCharacters: + v, ok := value.(messagewithenum.EnumWithSpecialCharacters) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEnumWithSpecialCharacters(v) + return nil } return fmt.Errorf("unknown MessageWithEnum field %s", name) } @@ -3830,6 +4209,9 @@ func (m *MessageWithEnumMutation) ResetField(name string) error { case messagewithenum.FieldEnumWithoutDefault: m.ResetEnumWithoutDefault() return nil + case messagewithenum.FieldEnumWithSpecialCharacters: + m.ResetEnumWithSpecialCharacters() + return nil } return fmt.Errorf("unknown MessageWithEnum field %s", name) } diff --git a/entproto/internal/entprototest/ent/predicate/predicate.go b/entproto/internal/entprototest/ent/predicate/predicate.go index c6fc195ee..650cda171 100644 --- a/entproto/internal/entprototest/ent/predicate/predicate.go +++ b/entproto/internal/entprototest/ent/predicate/predicate.go @@ -21,6 +21,9 @@ type DependsOnSkipped func(*sql.Selector) // DuplicateNumberMessage is the predicate function for duplicatenumbermessage builders. type DuplicateNumberMessage func(*sql.Selector) +// EnumWithConflictingValue is the predicate function for enumwithconflictingvalue builders. +type EnumWithConflictingValue func(*sql.Selector) + // ExplicitSkippedMessage is the predicate function for explicitskippedmessage builders. type ExplicitSkippedMessage func(*sql.Selector) diff --git a/entproto/internal/entprototest/ent/schema/enum_with_conflicting_value.go b/entproto/internal/entprototest/ent/schema/enum_with_conflicting_value.go new file mode 100644 index 000000000..7c509479c --- /dev/null +++ b/entproto/internal/entprototest/ent/schema/enum_with_conflicting_value.go @@ -0,0 +1,48 @@ +// Copyright 2019-present Facebook +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package schema + +import ( + "entgo.io/contrib/entproto" + "entgo.io/ent" + "entgo.io/ent/schema" + "entgo.io/ent/schema/field" +) + +// EnumWithConflictingValue holds the schema definition for the EnumWithConflictingValue entity. +type EnumWithConflictingValue struct { + ent.Schema +} + +// Fields of the EnumWithConflictingValue. +func (EnumWithConflictingValue) Fields() []ent.Field { + return []ent.Field{ + field.Enum("enum"). + NamedValues( + "jpeg", "image/jpeg", + "jpegAlt", "IMAGE_JPEG"). + Annotations( + entproto.Field(4), + entproto.Enum(map[string]int32{ + "image/jpeg": 1, + "IMAGE_JPEG": 2, + }), + ), + } +} + +func (EnumWithConflictingValue) Annotations() []schema.Annotation { + return []schema.Annotation{entproto.Message()} +} diff --git a/entproto/internal/entprototest/ent/schema/message_with_enum.go b/entproto/internal/entprototest/ent/schema/message_with_enum.go index 1b0d6219d..231b88f41 100644 --- a/entproto/internal/entprototest/ent/schema/message_with_enum.go +++ b/entproto/internal/entprototest/ent/schema/message_with_enum.go @@ -50,6 +50,17 @@ func (MessageWithEnum) Fields() []ent.Field { "second": 2, }), ), + field.Enum("enum_with_special_characters"). + NamedValues( + "jpeg", "image/jpeg", + "png", "image/png"). + Annotations( + entproto.Field(4), + entproto.Enum(map[string]int32{ + "image/jpeg": 1, + "image/png": 2, + }), + ), } } diff --git a/entproto/internal/entprototest/ent/tx.go b/entproto/internal/entprototest/ent/tx.go index 116d1637d..8f3474806 100644 --- a/entproto/internal/entprototest/ent/tx.go +++ b/entproto/internal/entprototest/ent/tx.go @@ -22,6 +22,8 @@ type Tx struct { DependsOnSkipped *DependsOnSkippedClient // DuplicateNumberMessage is the client for interacting with the DuplicateNumberMessage builders. DuplicateNumberMessage *DuplicateNumberMessageClient + // EnumWithConflictingValue is the client for interacting with the EnumWithConflictingValue builders. + EnumWithConflictingValue *EnumWithConflictingValueClient // ExplicitSkippedMessage is the client for interacting with the ExplicitSkippedMessage builders. ExplicitSkippedMessage *ExplicitSkippedMessageClient // Image is the client for interacting with the Image builders. @@ -192,6 +194,7 @@ func (tx *Tx) init() { tx.Category = NewCategoryClient(tx.config) tx.DependsOnSkipped = NewDependsOnSkippedClient(tx.config) tx.DuplicateNumberMessage = NewDuplicateNumberMessageClient(tx.config) + tx.EnumWithConflictingValue = NewEnumWithConflictingValueClient(tx.config) tx.ExplicitSkippedMessage = NewExplicitSkippedMessageClient(tx.config) tx.Image = NewImageClient(tx.config) tx.ImplicitSkippedMessage = NewImplicitSkippedMessageClient(tx.config) diff --git a/entproto/internal/todo/ent/migrate/schema.go b/entproto/internal/todo/ent/migrate/schema.go index faa9a7de2..4d6098aa3 100644 --- a/entproto/internal/todo/ent/migrate/schema.go +++ b/entproto/internal/todo/ent/migrate/schema.go @@ -162,6 +162,7 @@ var ( {Name: "labels", Type: field.TypeJSON, Nullable: true}, {Name: "device_type", Type: field.TypeEnum, Enums: []string{"GLOWY9000", "SPEEDY300"}, Default: "GLOWY9000"}, {Name: "omit_prefix", Type: field.TypeEnum, Enums: []string{"foo", "bar"}}, + {Name: "mime_type", Type: field.TypeEnum, Enums: []string{"image/png", "image/xml+svg"}}, {Name: "user_group", Type: field.TypeInt, Nullable: true}, } // UsersTable holds the schema information for the "users" table. @@ -172,7 +173,7 @@ var ( ForeignKeys: []*schema.ForeignKey{ { Symbol: "users_groups_group", - Columns: []*schema.Column{UsersColumns[22]}, + Columns: []*schema.Column{UsersColumns[23]}, RefColumns: []*schema.Column{GroupsColumns[0]}, OnDelete: schema.SetNull, }, diff --git a/entproto/internal/todo/ent/mutation.go b/entproto/internal/todo/ent/mutation.go index 214d3a785..1f4566352 100644 --- a/entproto/internal/todo/ent/mutation.go +++ b/entproto/internal/todo/ent/mutation.go @@ -3189,6 +3189,7 @@ type UserMutation struct { appendlabels []string device_type *user.DeviceType omit_prefix *user.OmitPrefix + mime_type *user.MimeType clearedFields map[string]struct{} group *int clearedgroup bool @@ -4348,6 +4349,42 @@ func (m *UserMutation) ResetOmitPrefix() { m.omit_prefix = nil } +// SetMimeType sets the "mime_type" field. +func (m *UserMutation) SetMimeType(ut user.MimeType) { + m.mime_type = &ut +} + +// MimeType returns the value of the "mime_type" field in the mutation. +func (m *UserMutation) MimeType() (r user.MimeType, exists bool) { + v := m.mime_type + if v == nil { + return + } + return *v, true +} + +// OldMimeType returns the old "mime_type" field's value of the User entity. +// If the User 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 *UserMutation) OldMimeType(ctx context.Context) (v user.MimeType, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldMimeType is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldMimeType requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldMimeType: %w", err) + } + return oldValue.MimeType, nil +} + +// ResetMimeType resets all changes to the "mime_type" field. +func (m *UserMutation) ResetMimeType() { + m.mime_type = nil +} + // SetGroupID sets the "group" edge to the Group entity by id. func (m *UserMutation) SetGroupID(id int) { m.group = &id @@ -4592,7 +4629,7 @@ func (m *UserMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *UserMutation) Fields() []string { - fields := make([]string, 0, 21) + fields := make([]string, 0, 22) if m.user_name != nil { fields = append(fields, user.FieldUserName) } @@ -4656,6 +4693,9 @@ func (m *UserMutation) Fields() []string { if m.omit_prefix != nil { fields = append(fields, user.FieldOmitPrefix) } + if m.mime_type != nil { + fields = append(fields, user.FieldMimeType) + } return fields } @@ -4706,6 +4746,8 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) { return m.DeviceType() case user.FieldOmitPrefix: return m.OmitPrefix() + case user.FieldMimeType: + return m.MimeType() } return nil, false } @@ -4757,6 +4799,8 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldDeviceType(ctx) case user.FieldOmitPrefix: return m.OldOmitPrefix(ctx) + case user.FieldMimeType: + return m.OldMimeType(ctx) } return nil, fmt.Errorf("unknown User field %s", name) } @@ -4913,6 +4957,13 @@ func (m *UserMutation) SetField(name string, value ent.Value) error { } m.SetOmitPrefix(v) return nil + case user.FieldMimeType: + v, ok := value.(user.MimeType) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetMimeType(v) + return nil } return fmt.Errorf("unknown User field %s", name) } @@ -5175,6 +5226,9 @@ func (m *UserMutation) ResetField(name string) error { case user.FieldOmitPrefix: m.ResetOmitPrefix() return nil + case user.FieldMimeType: + m.ResetMimeType() + return nil } return fmt.Errorf("unknown User field %s", name) } diff --git a/entproto/internal/todo/ent/proto/entpb/attachment_service_test.go b/entproto/internal/todo/ent/proto/entpb/attachment_service_test.go index 976d06779..e67599cb9 100644 --- a/entproto/internal/todo/ent/proto/entpb/attachment_service_test.go +++ b/entproto/internal/todo/ent/proto/entpb/attachment_service_test.go @@ -71,6 +71,7 @@ func TestAttachmentService_MultiEdge(t *testing.T) { SetCustomPb(1). SetLabels(nil). SetOmitPrefix(user.OmitPrefixFoo). + SetMimeType(user.MimeTypeSvg). SaveX(ctx)) } att, err := svc.Create(ctx, &CreateAttachmentRequest{Attachment: &Attachment{ diff --git a/entproto/internal/todo/ent/proto/entpb/entpb.pb.go b/entproto/internal/todo/ent/proto/entpb/entpb.pb.go index 18fca8b71..ae28627f3 100644 --- a/entproto/internal/todo/ent/proto/entpb/entpb.pb.go +++ b/entproto/internal/todo/ent/proto/entpb/entpb.pb.go @@ -656,6 +656,55 @@ func (User_OmitPrefix) EnumDescriptor() ([]byte, []int) { return file_entpb_entpb_proto_rawDescGZIP(), []int{42, 2} } +type User_MimeType int32 + +const ( + User_MIME_TYPE_UNSPECIFIED User_MimeType = 0 + User_MIME_TYPE_IMAGE_PNG User_MimeType = 1 + User_MIME_TYPE_IMAGE_XML_SVG User_MimeType = 2 +) + +// Enum value maps for User_MimeType. +var ( + User_MimeType_name = map[int32]string{ + 0: "MIME_TYPE_UNSPECIFIED", + 1: "MIME_TYPE_IMAGE_PNG", + 2: "MIME_TYPE_IMAGE_XML_SVG", + } + User_MimeType_value = map[string]int32{ + "MIME_TYPE_UNSPECIFIED": 0, + "MIME_TYPE_IMAGE_PNG": 1, + "MIME_TYPE_IMAGE_XML_SVG": 2, + } +) + +func (x User_MimeType) Enum() *User_MimeType { + p := new(User_MimeType) + *p = x + return p +} + +func (x User_MimeType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (User_MimeType) Descriptor() protoreflect.EnumDescriptor { + return file_entpb_entpb_proto_enumTypes[13].Descriptor() +} + +func (User_MimeType) Type() protoreflect.EnumType { + return &file_entpb_entpb_proto_enumTypes[13] +} + +func (x User_MimeType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use User_MimeType.Descriptor instead. +func (User_MimeType) EnumDescriptor() ([]byte, []int) { + return file_entpb_entpb_proto_rawDescGZIP(), []int{42, 3} +} + type GetUserRequest_View int32 const ( @@ -689,11 +738,11 @@ func (x GetUserRequest_View) String() string { } func (GetUserRequest_View) Descriptor() protoreflect.EnumDescriptor { - return file_entpb_entpb_proto_enumTypes[13].Descriptor() + return file_entpb_entpb_proto_enumTypes[14].Descriptor() } func (GetUserRequest_View) Type() protoreflect.EnumType { - return &file_entpb_entpb_proto_enumTypes[13] + return &file_entpb_entpb_proto_enumTypes[14] } func (x GetUserRequest_View) Number() protoreflect.EnumNumber { @@ -738,11 +787,11 @@ func (x ListUserRequest_View) String() string { } func (ListUserRequest_View) Descriptor() protoreflect.EnumDescriptor { - return file_entpb_entpb_proto_enumTypes[14].Descriptor() + return file_entpb_entpb_proto_enumTypes[15].Descriptor() } func (ListUserRequest_View) Type() protoreflect.EnumType { - return &file_entpb_entpb_proto_enumTypes[14] + return &file_entpb_entpb_proto_enumTypes[15] } func (x ListUserRequest_View) Number() protoreflect.EnumNumber { @@ -2986,6 +3035,7 @@ type User struct { Labels []string `protobuf:"bytes,24,rep,name=labels,proto3" json:"labels,omitempty"` DeviceType User_DeviceType `protobuf:"varint,100,opt,name=device_type,json=deviceType,proto3,enum=entpb.User_DeviceType" json:"device_type,omitempty"` OmitPrefix User_OmitPrefix `protobuf:"varint,103,opt,name=omit_prefix,json=omitPrefix,proto3,enum=entpb.User_OmitPrefix" json:"omit_prefix,omitempty"` + MimeType User_MimeType `protobuf:"varint,104,opt,name=mime_type,json=mimeType,proto3,enum=entpb.User_MimeType" json:"mime_type,omitempty"` Group *Group `protobuf:"bytes,7,opt,name=group,proto3" json:"group,omitempty"` Attachment *Attachment `protobuf:"bytes,11,opt,name=attachment,proto3" json:"attachment,omitempty"` Received_1 []*Attachment `protobuf:"bytes,16,rep,name=received_1,json=received1,proto3" json:"received_1,omitempty"` @@ -3171,6 +3221,13 @@ func (x *User) GetOmitPrefix() User_OmitPrefix { return User_OMIT_PREFIX_UNSPECIFIED } +func (x *User) GetMimeType() User_MimeType { + if x != nil { + return x.MimeType + } + return User_MIME_TYPE_UNSPECIFIED +} + func (x *User) GetGroup() *Group { if x != nil { return x.Group @@ -3892,7 +3949,7 @@ var file_entpb_entpb_proto_rawDesc = []byte{ 0x12, 0x12, 0x0a, 0x0e, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x4e, 0x47, 0x10, 0x00, 0x12, 0x16, 0x0a, 0x12, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x49, 0x4e, 0x5f, 0x50, 0x52, 0x4f, 0x47, 0x52, 0x45, 0x53, 0x53, 0x10, 0x01, 0x12, 0x0f, 0x0a, 0x0b, - 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x44, 0x4f, 0x4e, 0x45, 0x10, 0x02, 0x22, 0xb4, 0x09, + 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x44, 0x4f, 0x4e, 0x45, 0x10, 0x02, 0x22, 0xc4, 0x0a, 0x0a, 0x04, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x75, 0x73, 0x65, 0x72, 0x4e, @@ -3945,30 +4002,39 @@ var file_entpb_entpb_proto_rawDesc = []byte{ 0x69, 0x74, 0x5f, 0x70, 0x72, 0x65, 0x66, 0x69, 0x78, 0x18, 0x67, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x16, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x2e, 0x4f, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x52, 0x0a, 0x6f, 0x6d, 0x69, 0x74, 0x50, 0x72, 0x65, - 0x66, 0x69, 0x78, 0x12, 0x22, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x07, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x47, 0x72, 0x6f, 0x75, 0x70, - 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x31, 0x0a, 0x0a, 0x61, 0x74, 0x74, 0x61, 0x63, - 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x65, 0x6e, - 0x74, 0x70, 0x62, 0x2e, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x0a, - 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x30, 0x0a, 0x0a, 0x72, 0x65, - 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x5f, 0x31, 0x18, 0x10, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, + 0x66, 0x69, 0x78, 0x12, 0x31, 0x0a, 0x09, 0x6d, 0x69, 0x6d, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, + 0x18, 0x68, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x14, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, + 0x73, 0x65, 0x72, 0x2e, 0x4d, 0x69, 0x6d, 0x65, 0x54, 0x79, 0x70, 0x65, 0x52, 0x08, 0x6d, 0x69, + 0x6d, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x22, 0x0a, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, + 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x47, 0x72, + 0x6f, 0x75, 0x70, 0x52, 0x05, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x31, 0x0a, 0x0a, 0x61, 0x74, + 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, - 0x74, 0x52, 0x09, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x31, 0x12, 0x1c, 0x0a, 0x03, - 0x70, 0x65, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x65, 0x6e, 0x74, 0x70, - 0x62, 0x2e, 0x50, 0x65, 0x74, 0x52, 0x03, 0x70, 0x65, 0x74, 0x22, 0x47, 0x0a, 0x06, 0x53, 0x74, - 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x12, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x55, - 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x12, 0x0a, 0x0e, - 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x4e, 0x47, 0x10, 0x01, - 0x12, 0x11, 0x0a, 0x0d, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x41, 0x43, 0x54, 0x49, 0x56, - 0x45, 0x10, 0x02, 0x22, 0x42, 0x0a, 0x0a, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x54, 0x79, 0x70, - 0x65, 0x12, 0x19, 0x0a, 0x15, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, - 0x5f, 0x47, 0x4c, 0x4f, 0x57, 0x59, 0x39, 0x30, 0x30, 0x30, 0x10, 0x00, 0x12, 0x19, 0x0a, 0x15, - 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, 0x50, 0x45, 0x45, - 0x44, 0x59, 0x33, 0x30, 0x30, 0x10, 0x01, 0x22, 0x3b, 0x0a, 0x0a, 0x4f, 0x6d, 0x69, 0x74, 0x50, - 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, 0x1b, 0x0a, 0x17, 0x4f, 0x4d, 0x49, 0x54, 0x5f, 0x50, 0x52, - 0x45, 0x46, 0x49, 0x58, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, - 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x46, 0x4f, 0x4f, 0x10, 0x01, 0x12, 0x07, 0x0a, 0x03, 0x42, - 0x41, 0x52, 0x10, 0x02, 0x22, 0x34, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, + 0x74, 0x52, 0x0a, 0x61, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x30, 0x0a, + 0x0a, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x5f, 0x31, 0x18, 0x10, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x11, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, + 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x09, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x31, 0x12, + 0x1c, 0x0a, 0x03, 0x70, 0x65, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x65, + 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x50, 0x65, 0x74, 0x52, 0x03, 0x70, 0x65, 0x74, 0x22, 0x47, 0x0a, + 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x12, 0x53, 0x54, 0x41, 0x54, 0x55, + 0x53, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, + 0x12, 0x0a, 0x0e, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x4e, + 0x47, 0x10, 0x01, 0x12, 0x11, 0x0a, 0x0d, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x41, 0x43, + 0x54, 0x49, 0x56, 0x45, 0x10, 0x02, 0x22, 0x42, 0x0a, 0x0a, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, + 0x54, 0x79, 0x70, 0x65, 0x12, 0x19, 0x0a, 0x15, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5f, 0x54, + 0x59, 0x50, 0x45, 0x5f, 0x47, 0x4c, 0x4f, 0x57, 0x59, 0x39, 0x30, 0x30, 0x30, 0x10, 0x00, 0x12, + 0x19, 0x0a, 0x15, 0x44, 0x45, 0x56, 0x49, 0x43, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x53, + 0x50, 0x45, 0x45, 0x44, 0x59, 0x33, 0x30, 0x30, 0x10, 0x01, 0x22, 0x3b, 0x0a, 0x0a, 0x4f, 0x6d, + 0x69, 0x74, 0x50, 0x72, 0x65, 0x66, 0x69, 0x78, 0x12, 0x1b, 0x0a, 0x17, 0x4f, 0x4d, 0x49, 0x54, + 0x5f, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, + 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x46, 0x4f, 0x4f, 0x10, 0x01, 0x12, 0x07, + 0x0a, 0x03, 0x42, 0x41, 0x52, 0x10, 0x02, 0x22, 0x5b, 0x0a, 0x08, 0x4d, 0x69, 0x6d, 0x65, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x19, 0x0a, 0x15, 0x4d, 0x49, 0x4d, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, + 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x17, + 0x0a, 0x13, 0x4d, 0x49, 0x4d, 0x45, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x4d, 0x41, 0x47, + 0x45, 0x5f, 0x50, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x1b, 0x0a, 0x17, 0x4d, 0x49, 0x4d, 0x45, 0x5f, + 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x4d, 0x41, 0x47, 0x45, 0x5f, 0x58, 0x4d, 0x4c, 0x5f, 0x53, + 0x56, 0x47, 0x10, 0x02, 0x22, 0x34, 0x0a, 0x11, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x65, 0x6e, 0x74, 0x70, 0x62, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x8c, 0x01, 0x0a, 0x0e, 0x47, @@ -4165,7 +4231,7 @@ func file_entpb_entpb_proto_rawDescGZIP() []byte { return file_entpb_entpb_proto_rawDescData } -var file_entpb_entpb_proto_enumTypes = make([]protoimpl.EnumInfo, 15) +var file_entpb_entpb_proto_enumTypes = make([]protoimpl.EnumInfo, 16) var file_entpb_entpb_proto_msgTypes = make([]protoimpl.MessageInfo, 51) var file_entpb_entpb_proto_goTypes = []interface{}{ (GetAttachmentRequest_View)(0), // 0: entpb.GetAttachmentRequest.View @@ -4181,195 +4247,197 @@ var file_entpb_entpb_proto_goTypes = []interface{}{ (User_Status)(0), // 10: entpb.User.Status (User_DeviceType)(0), // 11: entpb.User.DeviceType (User_OmitPrefix)(0), // 12: entpb.User.OmitPrefix - (GetUserRequest_View)(0), // 13: entpb.GetUserRequest.View - (ListUserRequest_View)(0), // 14: entpb.ListUserRequest.View - (*Attachment)(nil), // 15: entpb.Attachment - (*CreateAttachmentRequest)(nil), // 16: entpb.CreateAttachmentRequest - (*GetAttachmentRequest)(nil), // 17: entpb.GetAttachmentRequest - (*UpdateAttachmentRequest)(nil), // 18: entpb.UpdateAttachmentRequest - (*DeleteAttachmentRequest)(nil), // 19: entpb.DeleteAttachmentRequest - (*ListAttachmentRequest)(nil), // 20: entpb.ListAttachmentRequest - (*ListAttachmentResponse)(nil), // 21: entpb.ListAttachmentResponse - (*BatchCreateAttachmentsRequest)(nil), // 22: entpb.BatchCreateAttachmentsRequest - (*BatchCreateAttachmentsResponse)(nil), // 23: entpb.BatchCreateAttachmentsResponse - (*Group)(nil), // 24: entpb.Group - (*MultiWordSchema)(nil), // 25: entpb.MultiWordSchema - (*CreateMultiWordSchemaRequest)(nil), // 26: entpb.CreateMultiWordSchemaRequest - (*GetMultiWordSchemaRequest)(nil), // 27: entpb.GetMultiWordSchemaRequest - (*UpdateMultiWordSchemaRequest)(nil), // 28: entpb.UpdateMultiWordSchemaRequest - (*DeleteMultiWordSchemaRequest)(nil), // 29: entpb.DeleteMultiWordSchemaRequest - (*ListMultiWordSchemaRequest)(nil), // 30: entpb.ListMultiWordSchemaRequest - (*ListMultiWordSchemaResponse)(nil), // 31: entpb.ListMultiWordSchemaResponse - (*BatchCreateMultiWordSchemasRequest)(nil), // 32: entpb.BatchCreateMultiWordSchemasRequest - (*BatchCreateMultiWordSchemasResponse)(nil), // 33: entpb.BatchCreateMultiWordSchemasResponse - (*NilExample)(nil), // 34: entpb.NilExample - (*CreateNilExampleRequest)(nil), // 35: entpb.CreateNilExampleRequest - (*GetNilExampleRequest)(nil), // 36: entpb.GetNilExampleRequest - (*UpdateNilExampleRequest)(nil), // 37: entpb.UpdateNilExampleRequest - (*DeleteNilExampleRequest)(nil), // 38: entpb.DeleteNilExampleRequest - (*ListNilExampleRequest)(nil), // 39: entpb.ListNilExampleRequest - (*ListNilExampleResponse)(nil), // 40: entpb.ListNilExampleResponse - (*BatchCreateNilExamplesRequest)(nil), // 41: entpb.BatchCreateNilExamplesRequest - (*BatchCreateNilExamplesResponse)(nil), // 42: entpb.BatchCreateNilExamplesResponse - (*Pet)(nil), // 43: entpb.Pet - (*CreatePetRequest)(nil), // 44: entpb.CreatePetRequest - (*GetPetRequest)(nil), // 45: entpb.GetPetRequest - (*UpdatePetRequest)(nil), // 46: entpb.UpdatePetRequest - (*DeletePetRequest)(nil), // 47: entpb.DeletePetRequest - (*ListPetRequest)(nil), // 48: entpb.ListPetRequest - (*ListPetResponse)(nil), // 49: entpb.ListPetResponse - (*BatchCreatePetsRequest)(nil), // 50: entpb.BatchCreatePetsRequest - (*BatchCreatePetsResponse)(nil), // 51: entpb.BatchCreatePetsResponse - (*Pony)(nil), // 52: entpb.Pony - (*CreatePonyRequest)(nil), // 53: entpb.CreatePonyRequest - (*BatchCreatePoniesRequest)(nil), // 54: entpb.BatchCreatePoniesRequest - (*BatchCreatePoniesResponse)(nil), // 55: entpb.BatchCreatePoniesResponse - (*Todo)(nil), // 56: entpb.Todo - (*User)(nil), // 57: entpb.User - (*CreateUserRequest)(nil), // 58: entpb.CreateUserRequest - (*GetUserRequest)(nil), // 59: entpb.GetUserRequest - (*UpdateUserRequest)(nil), // 60: entpb.UpdateUserRequest - (*DeleteUserRequest)(nil), // 61: entpb.DeleteUserRequest - (*ListUserRequest)(nil), // 62: entpb.ListUserRequest - (*ListUserResponse)(nil), // 63: entpb.ListUserResponse - (*BatchCreateUsersRequest)(nil), // 64: entpb.BatchCreateUsersRequest - (*BatchCreateUsersResponse)(nil), // 65: entpb.BatchCreateUsersResponse - (*wrapperspb.StringValue)(nil), // 66: google.protobuf.StringValue - (*timestamppb.Timestamp)(nil), // 67: google.protobuf.Timestamp - (*wrapperspb.Int64Value)(nil), // 68: google.protobuf.Int64Value - (*wrapperspb.BoolValue)(nil), // 69: google.protobuf.BoolValue - (*emptypb.Empty)(nil), // 70: google.protobuf.Empty + (User_MimeType)(0), // 13: entpb.User.MimeType + (GetUserRequest_View)(0), // 14: entpb.GetUserRequest.View + (ListUserRequest_View)(0), // 15: entpb.ListUserRequest.View + (*Attachment)(nil), // 16: entpb.Attachment + (*CreateAttachmentRequest)(nil), // 17: entpb.CreateAttachmentRequest + (*GetAttachmentRequest)(nil), // 18: entpb.GetAttachmentRequest + (*UpdateAttachmentRequest)(nil), // 19: entpb.UpdateAttachmentRequest + (*DeleteAttachmentRequest)(nil), // 20: entpb.DeleteAttachmentRequest + (*ListAttachmentRequest)(nil), // 21: entpb.ListAttachmentRequest + (*ListAttachmentResponse)(nil), // 22: entpb.ListAttachmentResponse + (*BatchCreateAttachmentsRequest)(nil), // 23: entpb.BatchCreateAttachmentsRequest + (*BatchCreateAttachmentsResponse)(nil), // 24: entpb.BatchCreateAttachmentsResponse + (*Group)(nil), // 25: entpb.Group + (*MultiWordSchema)(nil), // 26: entpb.MultiWordSchema + (*CreateMultiWordSchemaRequest)(nil), // 27: entpb.CreateMultiWordSchemaRequest + (*GetMultiWordSchemaRequest)(nil), // 28: entpb.GetMultiWordSchemaRequest + (*UpdateMultiWordSchemaRequest)(nil), // 29: entpb.UpdateMultiWordSchemaRequest + (*DeleteMultiWordSchemaRequest)(nil), // 30: entpb.DeleteMultiWordSchemaRequest + (*ListMultiWordSchemaRequest)(nil), // 31: entpb.ListMultiWordSchemaRequest + (*ListMultiWordSchemaResponse)(nil), // 32: entpb.ListMultiWordSchemaResponse + (*BatchCreateMultiWordSchemasRequest)(nil), // 33: entpb.BatchCreateMultiWordSchemasRequest + (*BatchCreateMultiWordSchemasResponse)(nil), // 34: entpb.BatchCreateMultiWordSchemasResponse + (*NilExample)(nil), // 35: entpb.NilExample + (*CreateNilExampleRequest)(nil), // 36: entpb.CreateNilExampleRequest + (*GetNilExampleRequest)(nil), // 37: entpb.GetNilExampleRequest + (*UpdateNilExampleRequest)(nil), // 38: entpb.UpdateNilExampleRequest + (*DeleteNilExampleRequest)(nil), // 39: entpb.DeleteNilExampleRequest + (*ListNilExampleRequest)(nil), // 40: entpb.ListNilExampleRequest + (*ListNilExampleResponse)(nil), // 41: entpb.ListNilExampleResponse + (*BatchCreateNilExamplesRequest)(nil), // 42: entpb.BatchCreateNilExamplesRequest + (*BatchCreateNilExamplesResponse)(nil), // 43: entpb.BatchCreateNilExamplesResponse + (*Pet)(nil), // 44: entpb.Pet + (*CreatePetRequest)(nil), // 45: entpb.CreatePetRequest + (*GetPetRequest)(nil), // 46: entpb.GetPetRequest + (*UpdatePetRequest)(nil), // 47: entpb.UpdatePetRequest + (*DeletePetRequest)(nil), // 48: entpb.DeletePetRequest + (*ListPetRequest)(nil), // 49: entpb.ListPetRequest + (*ListPetResponse)(nil), // 50: entpb.ListPetResponse + (*BatchCreatePetsRequest)(nil), // 51: entpb.BatchCreatePetsRequest + (*BatchCreatePetsResponse)(nil), // 52: entpb.BatchCreatePetsResponse + (*Pony)(nil), // 53: entpb.Pony + (*CreatePonyRequest)(nil), // 54: entpb.CreatePonyRequest + (*BatchCreatePoniesRequest)(nil), // 55: entpb.BatchCreatePoniesRequest + (*BatchCreatePoniesResponse)(nil), // 56: entpb.BatchCreatePoniesResponse + (*Todo)(nil), // 57: entpb.Todo + (*User)(nil), // 58: entpb.User + (*CreateUserRequest)(nil), // 59: entpb.CreateUserRequest + (*GetUserRequest)(nil), // 60: entpb.GetUserRequest + (*UpdateUserRequest)(nil), // 61: entpb.UpdateUserRequest + (*DeleteUserRequest)(nil), // 62: entpb.DeleteUserRequest + (*ListUserRequest)(nil), // 63: entpb.ListUserRequest + (*ListUserResponse)(nil), // 64: entpb.ListUserResponse + (*BatchCreateUsersRequest)(nil), // 65: entpb.BatchCreateUsersRequest + (*BatchCreateUsersResponse)(nil), // 66: entpb.BatchCreateUsersResponse + (*wrapperspb.StringValue)(nil), // 67: google.protobuf.StringValue + (*timestamppb.Timestamp)(nil), // 68: google.protobuf.Timestamp + (*wrapperspb.Int64Value)(nil), // 69: google.protobuf.Int64Value + (*wrapperspb.BoolValue)(nil), // 70: google.protobuf.BoolValue + (*emptypb.Empty)(nil), // 71: google.protobuf.Empty } var file_entpb_entpb_proto_depIdxs = []int32{ - 57, // 0: entpb.Attachment.user:type_name -> entpb.User - 57, // 1: entpb.Attachment.recipients:type_name -> entpb.User - 15, // 2: entpb.CreateAttachmentRequest.attachment:type_name -> entpb.Attachment + 58, // 0: entpb.Attachment.user:type_name -> entpb.User + 58, // 1: entpb.Attachment.recipients:type_name -> entpb.User + 16, // 2: entpb.CreateAttachmentRequest.attachment:type_name -> entpb.Attachment 0, // 3: entpb.GetAttachmentRequest.view:type_name -> entpb.GetAttachmentRequest.View - 15, // 4: entpb.UpdateAttachmentRequest.attachment:type_name -> entpb.Attachment + 16, // 4: entpb.UpdateAttachmentRequest.attachment:type_name -> entpb.Attachment 1, // 5: entpb.ListAttachmentRequest.view:type_name -> entpb.ListAttachmentRequest.View - 15, // 6: entpb.ListAttachmentResponse.attachment_list:type_name -> entpb.Attachment - 16, // 7: entpb.BatchCreateAttachmentsRequest.requests:type_name -> entpb.CreateAttachmentRequest - 15, // 8: entpb.BatchCreateAttachmentsResponse.attachments:type_name -> entpb.Attachment - 57, // 9: entpb.Group.users:type_name -> entpb.User + 16, // 6: entpb.ListAttachmentResponse.attachment_list:type_name -> entpb.Attachment + 17, // 7: entpb.BatchCreateAttachmentsRequest.requests:type_name -> entpb.CreateAttachmentRequest + 16, // 8: entpb.BatchCreateAttachmentsResponse.attachments:type_name -> entpb.Attachment + 58, // 9: entpb.Group.users:type_name -> entpb.User 2, // 10: entpb.MultiWordSchema.unit:type_name -> entpb.MultiWordSchema.Unit - 25, // 11: entpb.CreateMultiWordSchemaRequest.multi_word_schema:type_name -> entpb.MultiWordSchema + 26, // 11: entpb.CreateMultiWordSchemaRequest.multi_word_schema:type_name -> entpb.MultiWordSchema 3, // 12: entpb.GetMultiWordSchemaRequest.view:type_name -> entpb.GetMultiWordSchemaRequest.View - 25, // 13: entpb.UpdateMultiWordSchemaRequest.multi_word_schema:type_name -> entpb.MultiWordSchema + 26, // 13: entpb.UpdateMultiWordSchemaRequest.multi_word_schema:type_name -> entpb.MultiWordSchema 4, // 14: entpb.ListMultiWordSchemaRequest.view:type_name -> entpb.ListMultiWordSchemaRequest.View - 25, // 15: entpb.ListMultiWordSchemaResponse.multi_word_schema_list:type_name -> entpb.MultiWordSchema - 26, // 16: entpb.BatchCreateMultiWordSchemasRequest.requests:type_name -> entpb.CreateMultiWordSchemaRequest - 25, // 17: entpb.BatchCreateMultiWordSchemasResponse.multi_word_schemas:type_name -> entpb.MultiWordSchema - 66, // 18: entpb.NilExample.str_nil:type_name -> google.protobuf.StringValue - 67, // 19: entpb.NilExample.time_nil:type_name -> google.protobuf.Timestamp - 34, // 20: entpb.CreateNilExampleRequest.nil_example:type_name -> entpb.NilExample + 26, // 15: entpb.ListMultiWordSchemaResponse.multi_word_schema_list:type_name -> entpb.MultiWordSchema + 27, // 16: entpb.BatchCreateMultiWordSchemasRequest.requests:type_name -> entpb.CreateMultiWordSchemaRequest + 26, // 17: entpb.BatchCreateMultiWordSchemasResponse.multi_word_schemas:type_name -> entpb.MultiWordSchema + 67, // 18: entpb.NilExample.str_nil:type_name -> google.protobuf.StringValue + 68, // 19: entpb.NilExample.time_nil:type_name -> google.protobuf.Timestamp + 35, // 20: entpb.CreateNilExampleRequest.nil_example:type_name -> entpb.NilExample 5, // 21: entpb.GetNilExampleRequest.view:type_name -> entpb.GetNilExampleRequest.View - 34, // 22: entpb.UpdateNilExampleRequest.nil_example:type_name -> entpb.NilExample + 35, // 22: entpb.UpdateNilExampleRequest.nil_example:type_name -> entpb.NilExample 6, // 23: entpb.ListNilExampleRequest.view:type_name -> entpb.ListNilExampleRequest.View - 34, // 24: entpb.ListNilExampleResponse.nil_example_list:type_name -> entpb.NilExample - 35, // 25: entpb.BatchCreateNilExamplesRequest.requests:type_name -> entpb.CreateNilExampleRequest - 34, // 26: entpb.BatchCreateNilExamplesResponse.nil_examples:type_name -> entpb.NilExample - 57, // 27: entpb.Pet.owner:type_name -> entpb.User - 15, // 28: entpb.Pet.attachment:type_name -> entpb.Attachment - 43, // 29: entpb.CreatePetRequest.pet:type_name -> entpb.Pet + 35, // 24: entpb.ListNilExampleResponse.nil_example_list:type_name -> entpb.NilExample + 36, // 25: entpb.BatchCreateNilExamplesRequest.requests:type_name -> entpb.CreateNilExampleRequest + 35, // 26: entpb.BatchCreateNilExamplesResponse.nil_examples:type_name -> entpb.NilExample + 58, // 27: entpb.Pet.owner:type_name -> entpb.User + 16, // 28: entpb.Pet.attachment:type_name -> entpb.Attachment + 44, // 29: entpb.CreatePetRequest.pet:type_name -> entpb.Pet 7, // 30: entpb.GetPetRequest.view:type_name -> entpb.GetPetRequest.View - 43, // 31: entpb.UpdatePetRequest.pet:type_name -> entpb.Pet + 44, // 31: entpb.UpdatePetRequest.pet:type_name -> entpb.Pet 8, // 32: entpb.ListPetRequest.view:type_name -> entpb.ListPetRequest.View - 43, // 33: entpb.ListPetResponse.pet_list:type_name -> entpb.Pet - 44, // 34: entpb.BatchCreatePetsRequest.requests:type_name -> entpb.CreatePetRequest - 43, // 35: entpb.BatchCreatePetsResponse.pets:type_name -> entpb.Pet - 52, // 36: entpb.CreatePonyRequest.pony:type_name -> entpb.Pony - 53, // 37: entpb.BatchCreatePoniesRequest.requests:type_name -> entpb.CreatePonyRequest - 52, // 38: entpb.BatchCreatePoniesResponse.ponies:type_name -> entpb.Pony + 44, // 33: entpb.ListPetResponse.pet_list:type_name -> entpb.Pet + 45, // 34: entpb.BatchCreatePetsRequest.requests:type_name -> entpb.CreatePetRequest + 44, // 35: entpb.BatchCreatePetsResponse.pets:type_name -> entpb.Pet + 53, // 36: entpb.CreatePonyRequest.pony:type_name -> entpb.Pony + 54, // 37: entpb.BatchCreatePoniesRequest.requests:type_name -> entpb.CreatePonyRequest + 53, // 38: entpb.BatchCreatePoniesResponse.ponies:type_name -> entpb.Pony 9, // 39: entpb.Todo.status:type_name -> entpb.Todo.Status - 57, // 40: entpb.Todo.user:type_name -> entpb.User - 67, // 41: entpb.User.joined:type_name -> google.protobuf.Timestamp + 58, // 40: entpb.Todo.user:type_name -> entpb.User + 68, // 41: entpb.User.joined:type_name -> google.protobuf.Timestamp 10, // 42: entpb.User.status:type_name -> entpb.User.Status - 68, // 43: entpb.User.opt_num:type_name -> google.protobuf.Int64Value - 66, // 44: entpb.User.opt_str:type_name -> google.protobuf.StringValue - 69, // 45: entpb.User.opt_bool:type_name -> google.protobuf.BoolValue - 66, // 46: entpb.User.big_int:type_name -> google.protobuf.StringValue - 68, // 47: entpb.User.b_user_1:type_name -> google.protobuf.Int64Value - 66, // 48: entpb.User.type:type_name -> google.protobuf.StringValue + 69, // 43: entpb.User.opt_num:type_name -> google.protobuf.Int64Value + 67, // 44: entpb.User.opt_str:type_name -> google.protobuf.StringValue + 70, // 45: entpb.User.opt_bool:type_name -> google.protobuf.BoolValue + 67, // 46: entpb.User.big_int:type_name -> google.protobuf.StringValue + 69, // 47: entpb.User.b_user_1:type_name -> google.protobuf.Int64Value + 67, // 48: entpb.User.type:type_name -> google.protobuf.StringValue 11, // 49: entpb.User.device_type:type_name -> entpb.User.DeviceType 12, // 50: entpb.User.omit_prefix:type_name -> entpb.User.OmitPrefix - 24, // 51: entpb.User.group:type_name -> entpb.Group - 15, // 52: entpb.User.attachment:type_name -> entpb.Attachment - 15, // 53: entpb.User.received_1:type_name -> entpb.Attachment - 43, // 54: entpb.User.pet:type_name -> entpb.Pet - 57, // 55: entpb.CreateUserRequest.user:type_name -> entpb.User - 13, // 56: entpb.GetUserRequest.view:type_name -> entpb.GetUserRequest.View - 57, // 57: entpb.UpdateUserRequest.user:type_name -> entpb.User - 14, // 58: entpb.ListUserRequest.view:type_name -> entpb.ListUserRequest.View - 57, // 59: entpb.ListUserResponse.user_list:type_name -> entpb.User - 58, // 60: entpb.BatchCreateUsersRequest.requests:type_name -> entpb.CreateUserRequest - 57, // 61: entpb.BatchCreateUsersResponse.users:type_name -> entpb.User - 16, // 62: entpb.AttachmentService.Create:input_type -> entpb.CreateAttachmentRequest - 17, // 63: entpb.AttachmentService.Get:input_type -> entpb.GetAttachmentRequest - 18, // 64: entpb.AttachmentService.Update:input_type -> entpb.UpdateAttachmentRequest - 19, // 65: entpb.AttachmentService.Delete:input_type -> entpb.DeleteAttachmentRequest - 20, // 66: entpb.AttachmentService.List:input_type -> entpb.ListAttachmentRequest - 22, // 67: entpb.AttachmentService.BatchCreate:input_type -> entpb.BatchCreateAttachmentsRequest - 26, // 68: entpb.MultiWordSchemaService.Create:input_type -> entpb.CreateMultiWordSchemaRequest - 27, // 69: entpb.MultiWordSchemaService.Get:input_type -> entpb.GetMultiWordSchemaRequest - 28, // 70: entpb.MultiWordSchemaService.Update:input_type -> entpb.UpdateMultiWordSchemaRequest - 29, // 71: entpb.MultiWordSchemaService.Delete:input_type -> entpb.DeleteMultiWordSchemaRequest - 30, // 72: entpb.MultiWordSchemaService.List:input_type -> entpb.ListMultiWordSchemaRequest - 32, // 73: entpb.MultiWordSchemaService.BatchCreate:input_type -> entpb.BatchCreateMultiWordSchemasRequest - 35, // 74: entpb.NilExampleService.Create:input_type -> entpb.CreateNilExampleRequest - 36, // 75: entpb.NilExampleService.Get:input_type -> entpb.GetNilExampleRequest - 37, // 76: entpb.NilExampleService.Update:input_type -> entpb.UpdateNilExampleRequest - 38, // 77: entpb.NilExampleService.Delete:input_type -> entpb.DeleteNilExampleRequest - 39, // 78: entpb.NilExampleService.List:input_type -> entpb.ListNilExampleRequest - 41, // 79: entpb.NilExampleService.BatchCreate:input_type -> entpb.BatchCreateNilExamplesRequest - 44, // 80: entpb.PetService.Create:input_type -> entpb.CreatePetRequest - 45, // 81: entpb.PetService.Get:input_type -> entpb.GetPetRequest - 46, // 82: entpb.PetService.Update:input_type -> entpb.UpdatePetRequest - 47, // 83: entpb.PetService.Delete:input_type -> entpb.DeletePetRequest - 48, // 84: entpb.PetService.List:input_type -> entpb.ListPetRequest - 50, // 85: entpb.PetService.BatchCreate:input_type -> entpb.BatchCreatePetsRequest - 54, // 86: entpb.PonyService.BatchCreate:input_type -> entpb.BatchCreatePoniesRequest - 58, // 87: entpb.UserService.Create:input_type -> entpb.CreateUserRequest - 59, // 88: entpb.UserService.Get:input_type -> entpb.GetUserRequest - 60, // 89: entpb.UserService.Update:input_type -> entpb.UpdateUserRequest - 61, // 90: entpb.UserService.Delete:input_type -> entpb.DeleteUserRequest - 62, // 91: entpb.UserService.List:input_type -> entpb.ListUserRequest - 64, // 92: entpb.UserService.BatchCreate:input_type -> entpb.BatchCreateUsersRequest - 15, // 93: entpb.AttachmentService.Create:output_type -> entpb.Attachment - 15, // 94: entpb.AttachmentService.Get:output_type -> entpb.Attachment - 15, // 95: entpb.AttachmentService.Update:output_type -> entpb.Attachment - 70, // 96: entpb.AttachmentService.Delete:output_type -> google.protobuf.Empty - 21, // 97: entpb.AttachmentService.List:output_type -> entpb.ListAttachmentResponse - 23, // 98: entpb.AttachmentService.BatchCreate:output_type -> entpb.BatchCreateAttachmentsResponse - 25, // 99: entpb.MultiWordSchemaService.Create:output_type -> entpb.MultiWordSchema - 25, // 100: entpb.MultiWordSchemaService.Get:output_type -> entpb.MultiWordSchema - 25, // 101: entpb.MultiWordSchemaService.Update:output_type -> entpb.MultiWordSchema - 70, // 102: entpb.MultiWordSchemaService.Delete:output_type -> google.protobuf.Empty - 31, // 103: entpb.MultiWordSchemaService.List:output_type -> entpb.ListMultiWordSchemaResponse - 33, // 104: entpb.MultiWordSchemaService.BatchCreate:output_type -> entpb.BatchCreateMultiWordSchemasResponse - 34, // 105: entpb.NilExampleService.Create:output_type -> entpb.NilExample - 34, // 106: entpb.NilExampleService.Get:output_type -> entpb.NilExample - 34, // 107: entpb.NilExampleService.Update:output_type -> entpb.NilExample - 70, // 108: entpb.NilExampleService.Delete:output_type -> google.protobuf.Empty - 40, // 109: entpb.NilExampleService.List:output_type -> entpb.ListNilExampleResponse - 42, // 110: entpb.NilExampleService.BatchCreate:output_type -> entpb.BatchCreateNilExamplesResponse - 43, // 111: entpb.PetService.Create:output_type -> entpb.Pet - 43, // 112: entpb.PetService.Get:output_type -> entpb.Pet - 43, // 113: entpb.PetService.Update:output_type -> entpb.Pet - 70, // 114: entpb.PetService.Delete:output_type -> google.protobuf.Empty - 49, // 115: entpb.PetService.List:output_type -> entpb.ListPetResponse - 51, // 116: entpb.PetService.BatchCreate:output_type -> entpb.BatchCreatePetsResponse - 55, // 117: entpb.PonyService.BatchCreate:output_type -> entpb.BatchCreatePoniesResponse - 57, // 118: entpb.UserService.Create:output_type -> entpb.User - 57, // 119: entpb.UserService.Get:output_type -> entpb.User - 57, // 120: entpb.UserService.Update:output_type -> entpb.User - 70, // 121: entpb.UserService.Delete:output_type -> google.protobuf.Empty - 63, // 122: entpb.UserService.List:output_type -> entpb.ListUserResponse - 65, // 123: entpb.UserService.BatchCreate:output_type -> entpb.BatchCreateUsersResponse - 93, // [93:124] is the sub-list for method output_type - 62, // [62:93] is the sub-list for method input_type - 62, // [62:62] is the sub-list for extension type_name - 62, // [62:62] is the sub-list for extension extendee - 0, // [0:62] is the sub-list for field type_name + 13, // 51: entpb.User.mime_type:type_name -> entpb.User.MimeType + 25, // 52: entpb.User.group:type_name -> entpb.Group + 16, // 53: entpb.User.attachment:type_name -> entpb.Attachment + 16, // 54: entpb.User.received_1:type_name -> entpb.Attachment + 44, // 55: entpb.User.pet:type_name -> entpb.Pet + 58, // 56: entpb.CreateUserRequest.user:type_name -> entpb.User + 14, // 57: entpb.GetUserRequest.view:type_name -> entpb.GetUserRequest.View + 58, // 58: entpb.UpdateUserRequest.user:type_name -> entpb.User + 15, // 59: entpb.ListUserRequest.view:type_name -> entpb.ListUserRequest.View + 58, // 60: entpb.ListUserResponse.user_list:type_name -> entpb.User + 59, // 61: entpb.BatchCreateUsersRequest.requests:type_name -> entpb.CreateUserRequest + 58, // 62: entpb.BatchCreateUsersResponse.users:type_name -> entpb.User + 17, // 63: entpb.AttachmentService.Create:input_type -> entpb.CreateAttachmentRequest + 18, // 64: entpb.AttachmentService.Get:input_type -> entpb.GetAttachmentRequest + 19, // 65: entpb.AttachmentService.Update:input_type -> entpb.UpdateAttachmentRequest + 20, // 66: entpb.AttachmentService.Delete:input_type -> entpb.DeleteAttachmentRequest + 21, // 67: entpb.AttachmentService.List:input_type -> entpb.ListAttachmentRequest + 23, // 68: entpb.AttachmentService.BatchCreate:input_type -> entpb.BatchCreateAttachmentsRequest + 27, // 69: entpb.MultiWordSchemaService.Create:input_type -> entpb.CreateMultiWordSchemaRequest + 28, // 70: entpb.MultiWordSchemaService.Get:input_type -> entpb.GetMultiWordSchemaRequest + 29, // 71: entpb.MultiWordSchemaService.Update:input_type -> entpb.UpdateMultiWordSchemaRequest + 30, // 72: entpb.MultiWordSchemaService.Delete:input_type -> entpb.DeleteMultiWordSchemaRequest + 31, // 73: entpb.MultiWordSchemaService.List:input_type -> entpb.ListMultiWordSchemaRequest + 33, // 74: entpb.MultiWordSchemaService.BatchCreate:input_type -> entpb.BatchCreateMultiWordSchemasRequest + 36, // 75: entpb.NilExampleService.Create:input_type -> entpb.CreateNilExampleRequest + 37, // 76: entpb.NilExampleService.Get:input_type -> entpb.GetNilExampleRequest + 38, // 77: entpb.NilExampleService.Update:input_type -> entpb.UpdateNilExampleRequest + 39, // 78: entpb.NilExampleService.Delete:input_type -> entpb.DeleteNilExampleRequest + 40, // 79: entpb.NilExampleService.List:input_type -> entpb.ListNilExampleRequest + 42, // 80: entpb.NilExampleService.BatchCreate:input_type -> entpb.BatchCreateNilExamplesRequest + 45, // 81: entpb.PetService.Create:input_type -> entpb.CreatePetRequest + 46, // 82: entpb.PetService.Get:input_type -> entpb.GetPetRequest + 47, // 83: entpb.PetService.Update:input_type -> entpb.UpdatePetRequest + 48, // 84: entpb.PetService.Delete:input_type -> entpb.DeletePetRequest + 49, // 85: entpb.PetService.List:input_type -> entpb.ListPetRequest + 51, // 86: entpb.PetService.BatchCreate:input_type -> entpb.BatchCreatePetsRequest + 55, // 87: entpb.PonyService.BatchCreate:input_type -> entpb.BatchCreatePoniesRequest + 59, // 88: entpb.UserService.Create:input_type -> entpb.CreateUserRequest + 60, // 89: entpb.UserService.Get:input_type -> entpb.GetUserRequest + 61, // 90: entpb.UserService.Update:input_type -> entpb.UpdateUserRequest + 62, // 91: entpb.UserService.Delete:input_type -> entpb.DeleteUserRequest + 63, // 92: entpb.UserService.List:input_type -> entpb.ListUserRequest + 65, // 93: entpb.UserService.BatchCreate:input_type -> entpb.BatchCreateUsersRequest + 16, // 94: entpb.AttachmentService.Create:output_type -> entpb.Attachment + 16, // 95: entpb.AttachmentService.Get:output_type -> entpb.Attachment + 16, // 96: entpb.AttachmentService.Update:output_type -> entpb.Attachment + 71, // 97: entpb.AttachmentService.Delete:output_type -> google.protobuf.Empty + 22, // 98: entpb.AttachmentService.List:output_type -> entpb.ListAttachmentResponse + 24, // 99: entpb.AttachmentService.BatchCreate:output_type -> entpb.BatchCreateAttachmentsResponse + 26, // 100: entpb.MultiWordSchemaService.Create:output_type -> entpb.MultiWordSchema + 26, // 101: entpb.MultiWordSchemaService.Get:output_type -> entpb.MultiWordSchema + 26, // 102: entpb.MultiWordSchemaService.Update:output_type -> entpb.MultiWordSchema + 71, // 103: entpb.MultiWordSchemaService.Delete:output_type -> google.protobuf.Empty + 32, // 104: entpb.MultiWordSchemaService.List:output_type -> entpb.ListMultiWordSchemaResponse + 34, // 105: entpb.MultiWordSchemaService.BatchCreate:output_type -> entpb.BatchCreateMultiWordSchemasResponse + 35, // 106: entpb.NilExampleService.Create:output_type -> entpb.NilExample + 35, // 107: entpb.NilExampleService.Get:output_type -> entpb.NilExample + 35, // 108: entpb.NilExampleService.Update:output_type -> entpb.NilExample + 71, // 109: entpb.NilExampleService.Delete:output_type -> google.protobuf.Empty + 41, // 110: entpb.NilExampleService.List:output_type -> entpb.ListNilExampleResponse + 43, // 111: entpb.NilExampleService.BatchCreate:output_type -> entpb.BatchCreateNilExamplesResponse + 44, // 112: entpb.PetService.Create:output_type -> entpb.Pet + 44, // 113: entpb.PetService.Get:output_type -> entpb.Pet + 44, // 114: entpb.PetService.Update:output_type -> entpb.Pet + 71, // 115: entpb.PetService.Delete:output_type -> google.protobuf.Empty + 50, // 116: entpb.PetService.List:output_type -> entpb.ListPetResponse + 52, // 117: entpb.PetService.BatchCreate:output_type -> entpb.BatchCreatePetsResponse + 56, // 118: entpb.PonyService.BatchCreate:output_type -> entpb.BatchCreatePoniesResponse + 58, // 119: entpb.UserService.Create:output_type -> entpb.User + 58, // 120: entpb.UserService.Get:output_type -> entpb.User + 58, // 121: entpb.UserService.Update:output_type -> entpb.User + 71, // 122: entpb.UserService.Delete:output_type -> google.protobuf.Empty + 64, // 123: entpb.UserService.List:output_type -> entpb.ListUserResponse + 66, // 124: entpb.UserService.BatchCreate:output_type -> entpb.BatchCreateUsersResponse + 94, // [94:125] is the sub-list for method output_type + 63, // [63:94] is the sub-list for method input_type + 63, // [63:63] is the sub-list for extension type_name + 63, // [63:63] is the sub-list for extension extendee + 0, // [0:63] is the sub-list for field type_name } func init() { file_entpb_entpb_proto_init() } @@ -4996,7 +5064,7 @@ func file_entpb_entpb_proto_init() { File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_entpb_entpb_proto_rawDesc, - NumEnums: 15, + NumEnums: 16, NumMessages: 51, NumExtensions: 0, NumServices: 6, diff --git a/entproto/internal/todo/ent/proto/entpb/entpb.proto b/entproto/internal/todo/ent/proto/entpb/entpb.proto index d3bc081dd..ca26270fc 100644 --- a/entproto/internal/todo/ent/proto/entpb/entpb.proto +++ b/entproto/internal/todo/ent/proto/entpb/entpb.proto @@ -358,6 +358,8 @@ message User { OmitPrefix omit_prefix = 103; + MimeType mime_type = 104; + Group group = 7; Attachment attachment = 11; @@ -387,6 +389,14 @@ message User { BAR = 2; } + + enum MimeType { + MIME_TYPE_UNSPECIFIED = 0; + + MIME_TYPE_IMAGE_PNG = 1; + + MIME_TYPE_IMAGE_XML_SVG = 2; + } } message CreateUserRequest { diff --git a/entproto/internal/todo/ent/proto/entpb/entpb_multi_word_schema_service.go b/entproto/internal/todo/ent/proto/entpb/entpb_multi_word_schema_service.go index ef6154833..e6c41ddf4 100644 --- a/entproto/internal/todo/ent/proto/entpb/entpb_multi_word_schema_service.go +++ b/entproto/internal/todo/ent/proto/entpb/entpb_multi_word_schema_service.go @@ -12,6 +12,7 @@ import ( codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" emptypb "google.golang.org/protobuf/types/known/emptypb" + regexp "regexp" strconv "strconv" strings "strings" ) @@ -29,8 +30,14 @@ func NewMultiWordSchemaService(client *ent.Client) *MultiWordSchemaService { } } +var protoIdentNormalizeRegexpMultiWordSchema_Unit = regexp.MustCompile(`[^a-zA-Z0-9_]+`) + +func protoIdentNormalizeMultiWordSchema_Unit(e string) string { + return protoIdentNormalizeRegexpMultiWordSchema_Unit.ReplaceAllString(e, "_") +} + func toProtoMultiWordSchema_Unit(e multiwordschema.Unit) MultiWordSchema_Unit { - if v, ok := MultiWordSchema_Unit_value[strings.ToUpper("UNIT_"+string(e))]; ok { + if v, ok := MultiWordSchema_Unit_value[strings.ToUpper("UNIT_"+protoIdentNormalizeMultiWordSchema_Unit(string(e)))]; ok { return MultiWordSchema_Unit(v) } return MultiWordSchema_Unit(0) diff --git a/entproto/internal/todo/ent/proto/entpb/entpb_user_service.go b/entproto/internal/todo/ent/proto/entpb/entpb_user_service.go index a993ff907..25bd81265 100644 --- a/entproto/internal/todo/ent/proto/entpb/entpb_user_service.go +++ b/entproto/internal/todo/ent/proto/entpb/entpb_user_service.go @@ -21,6 +21,7 @@ import ( emptypb "google.golang.org/protobuf/types/known/emptypb" timestamppb "google.golang.org/protobuf/types/known/timestamppb" wrapperspb "google.golang.org/protobuf/types/known/wrapperspb" + regexp "regexp" strconv "strconv" strings "strings" ) @@ -38,8 +39,14 @@ func NewUserService(client *ent.Client) *UserService { } } +var protoIdentNormalizeRegexpUser_DeviceType = regexp.MustCompile(`[^a-zA-Z0-9_]+`) + +func protoIdentNormalizeUser_DeviceType(e string) string { + return protoIdentNormalizeRegexpUser_DeviceType.ReplaceAllString(e, "_") +} + func toProtoUser_DeviceType(e user.DeviceType) User_DeviceType { - if v, ok := User_DeviceType_value[strings.ToUpper("DEVICE_TYPE_"+string(e))]; ok { + if v, ok := User_DeviceType_value[strings.ToUpper("DEVICE_TYPE_"+protoIdentNormalizeUser_DeviceType(string(e)))]; ok { return User_DeviceType(v) } return User_DeviceType(0) @@ -56,8 +63,38 @@ func toEntUser_DeviceType(e User_DeviceType) user.DeviceType { return "" } +var protoIdentNormalizeRegexpUser_MimeType = regexp.MustCompile(`[^a-zA-Z0-9_]+`) + +func protoIdentNormalizeUser_MimeType(e string) string { + return protoIdentNormalizeRegexpUser_MimeType.ReplaceAllString(e, "_") +} + +func toProtoUser_MimeType(e user.MimeType) User_MimeType { + if v, ok := User_MimeType_value[strings.ToUpper("MIME_TYPE_"+protoIdentNormalizeUser_MimeType(string(e)))]; ok { + return User_MimeType(v) + } + return User_MimeType(0) +} + +func toEntUser_MimeType(e User_MimeType) user.MimeType { + if v, ok := User_MimeType_name[int32(e)]; ok { + entVal := map[string]string{ + "MIME_TYPE_IMAGE_PNG": "image/png", + "MIME_TYPE_IMAGE_XML_SVG": "image/xml+svg", + }[v] + return user.MimeType(entVal) + } + return "" +} + +var protoIdentNormalizeRegexpUser_OmitPrefix = regexp.MustCompile(`[^a-zA-Z0-9_]+`) + +func protoIdentNormalizeUser_OmitPrefix(e string) string { + return protoIdentNormalizeRegexpUser_OmitPrefix.ReplaceAllString(e, "_") +} + func toProtoUser_OmitPrefix(e user.OmitPrefix) User_OmitPrefix { - if v, ok := User_OmitPrefix_value[strings.ToUpper(string(e))]; ok { + if v, ok := User_OmitPrefix_value[strings.ToUpper(protoIdentNormalizeUser_OmitPrefix(string(e)))]; ok { return User_OmitPrefix(v) } return User_OmitPrefix(0) @@ -74,8 +111,14 @@ func toEntUser_OmitPrefix(e User_OmitPrefix) user.OmitPrefix { return "" } +var protoIdentNormalizeRegexpUser_Status = regexp.MustCompile(`[^a-zA-Z0-9_]+`) + +func protoIdentNormalizeUser_Status(e string) string { + return protoIdentNormalizeRegexpUser_Status.ReplaceAllString(e, "_") +} + func toProtoUser_Status(e user.Status) User_Status { - if v, ok := User_Status_value[strings.ToUpper("STATUS_"+string(e))]; ok { + if v, ok := User_Status_value[strings.ToUpper("STATUS_"+protoIdentNormalizeUser_Status(string(e)))]; ok { return User_Status(v) } return User_Status(0) @@ -132,6 +175,8 @@ func toProtoUser(e *ent.User) (*User, error) { v.Joined = joined labels := e.Labels v.Labels = labels + mime_type := toProtoUser_MimeType(e.MimeType) + v.MimeType = mime_type omit_prefix := toProtoUser_OmitPrefix(e.OmitPrefix) v.OmitPrefix = omit_prefix opt_bool := wrapperspb.Bool(e.OptBool) @@ -298,6 +343,8 @@ func (svc *UserService) Update(ctx context.Context, req *UpdateUserRequest) (*Us userLabels := user.GetLabels() m.SetLabels(userLabels) } + userMimeType := toEntUser_MimeType(user.GetMimeType()) + m.SetMimeType(userMimeType) userOmitPrefix := toEntUser_OmitPrefix(user.GetOmitPrefix()) m.SetOmitPrefix(userOmitPrefix) if user.GetOptBool() != nil { @@ -523,6 +570,8 @@ func (svc *UserService) createBuilder(user *User) (*ent.UserCreate, error) { userLabels := user.GetLabels() m.SetLabels(userLabels) } + userMimeType := toEntUser_MimeType(user.GetMimeType()) + m.SetMimeType(userMimeType) userOmitPrefix := toEntUser_OmitPrefix(user.GetOmitPrefix()) m.SetOmitPrefix(userOmitPrefix) if user.GetOptBool() != nil { diff --git a/entproto/internal/todo/ent/proto/entpb/user_service_test.go b/entproto/internal/todo/ent/proto/entpb/user_service_test.go index 73d046298..4a40d9b59 100644 --- a/entproto/internal/todo/ent/proto/entpb/user_service_test.go +++ b/entproto/internal/todo/ent/proto/entpb/user_service_test.go @@ -17,6 +17,7 @@ package entpb import ( "context" "fmt" + "regexp" "strings" "testing" "time" @@ -63,6 +64,7 @@ func TestUserService_Create(t *testing.T) { AccountBalance: 2000.50, Labels: []string{"member", "production"}, OmitPrefix: User_BAR, + MimeType: User_MIME_TYPE_IMAGE_XML_SVG, } created, err := svc.Create(ctx, &CreateUserRequest{ User: inputUser, @@ -80,6 +82,7 @@ func TestUserService_Create(t *testing.T) { require.EqualValues(t, inputUser.HeightInCm, fromDB.HeightInCm) require.EqualValues(t, inputUser.AccountBalance, fromDB.AccountBalance) require.EqualValues(t, inputUser.Labels, fromDB.Labels) + require.EqualValues(t, inputUser.MimeType.String(), strings.ToUpper("MIME_TYPE_"+regexp.MustCompile("[^a-zA-Z0-9_]+").ReplaceAllString(string(fromDB.MimeType), "_"))) // preexisting user _, err = svc.Create(ctx, &CreateUserRequest{ @@ -108,6 +111,7 @@ func TestUserService_Get(t *testing.T) { SetAccountBalance(2000.50). SetLabels([]string{"on", "off"}). SetOmitPrefix(user.OmitPrefixBar). + SetMimeType(user.MimeTypeSvg). SaveX(ctx) get, err := svc.Get(ctx, &GetUserRequest{ Id: created.ID, @@ -121,6 +125,7 @@ func TestUserService_Get(t *testing.T) { require.EqualValues(t, created.AccountBalance, get.AccountBalance) require.EqualValues(t, created.Labels, get.Labels) require.EqualValues(t, User_BAR, get.OmitPrefix) + require.EqualValues(t, User_MIME_TYPE_IMAGE_XML_SVG, get.MimeType) get, err = svc.Get(ctx, &GetUserRequest{ Id: 1000, }) @@ -145,6 +150,7 @@ func TestUserService_Delete(t *testing.T) { SetCrmID(uuid.New()). SetCustomPb(1). SetOmitPrefix(user.OmitPrefixBar). + SetMimeType(user.MimeTypeSvg). SaveX(ctx) d, err := svc.Delete(ctx, &DeleteUserRequest{ Id: created.ID, @@ -182,6 +188,7 @@ func TestUserService_Update(t *testing.T) { SetAccountBalance(2000.50). SetLabels(nil). SetOmitPrefix(user.OmitPrefixFoo). + SetMimeType(user.MimeTypeSvg). SaveX(ctx) attachmentID, err := attachment.ID.MarshalBinary() @@ -208,6 +215,7 @@ func TestUserService_Update(t *testing.T) { HeightInCm: 175.18, AccountBalance: 5000.75, OmitPrefix: User_FOO, + MimeType: User_MIME_TYPE_IMAGE_PNG, } updated, err := svc.Update(ctx, &UpdateUserRequest{ User: inputUser, @@ -218,6 +226,7 @@ func TestUserService_Update(t *testing.T) { afterUpd := client.User.GetX(ctx, created.ID) require.EqualValues(t, inputUser.Exp, afterUpd.Exp) require.EqualValues(t, user.OmitPrefixFoo, afterUpd.OmitPrefix) + require.EqualValues(t, user.MimeTypePng, afterUpd.MimeType) } func TestUserService_List(t *testing.T) { @@ -239,6 +248,7 @@ func TestUserService_List(t *testing.T) { SetCustomPb(1). SetLabels(nil). SetOmitPrefix(user.OmitPrefixBar). + SetMimeType(user.MimeTypeSvg). SaveX(ctx) } @@ -321,6 +331,7 @@ func TestUserService_BatchCreate(t *testing.T) { Labels: nil, Status: User_STATUS_ACTIVE, OmitPrefix: User_BAR, + MimeType: User_MIME_TYPE_IMAGE_PNG, }, } requests = append(requests, request) diff --git a/entproto/internal/todo/ent/schema/user.go b/entproto/internal/todo/ent/schema/user.go index 60c642d9b..6869cb51b 100644 --- a/entproto/internal/todo/ent/schema/user.go +++ b/entproto/internal/todo/ent/schema/user.go @@ -141,6 +141,20 @@ func (User) Fields() []ent.Field { entproto.OmitFieldPrefix(), ), ), + field.Enum("mime_type"). + NamedValues( + "png", "image/png", + "svg", "image/xml+svg", + ). + Annotations( + entproto.Field(104), + entproto.Enum( + map[string]int32{ + "image/png": 1, + "image/xml+svg": 2, + }, + ), + ), } } diff --git a/entproto/internal/todo/ent/user.go b/entproto/internal/todo/ent/user.go index 044df2c41..ffd1149df 100644 --- a/entproto/internal/todo/ent/user.go +++ b/entproto/internal/todo/ent/user.go @@ -66,6 +66,8 @@ type User struct { DeviceType user.DeviceType `json:"device_type,omitempty"` // OmitPrefix holds the value of the "omit_prefix" field. OmitPrefix user.OmitPrefix `json:"omit_prefix,omitempty"` + // MimeType holds the value of the "mime_type" field. + MimeType user.MimeType `json:"mime_type,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the UserQuery when eager-loading is set. Edges UserEdges `json:"edges"` @@ -166,7 +168,7 @@ func (*User) scanValues(columns []string) ([]any, error) { values[i] = new(sql.NullFloat64) case user.FieldID, user.FieldPoints, user.FieldExp, user.FieldExternalID, user.FieldCustomPb, user.FieldOptNum, user.FieldBUser1: values[i] = new(sql.NullInt64) - case user.FieldUserName, user.FieldStatus, user.FieldOptStr, user.FieldUnnecessary, user.FieldType, user.FieldDeviceType, user.FieldOmitPrefix: + case user.FieldUserName, user.FieldStatus, user.FieldOptStr, user.FieldUnnecessary, user.FieldType, user.FieldDeviceType, user.FieldOmitPrefix, user.FieldMimeType: values[i] = new(sql.NullString) case user.FieldJoined: values[i] = new(sql.NullTime) @@ -323,6 +325,12 @@ func (u *User) assignValues(columns []string, values []any) error { } else if value.Valid { u.OmitPrefix = user.OmitPrefix(value.String) } + case user.FieldMimeType: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field mime_type", values[i]) + } else if value.Valid { + u.MimeType = user.MimeType(value.String) + } case user.ForeignKeys[0]: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for edge-field user_group", value) @@ -453,6 +461,9 @@ func (u *User) String() string { builder.WriteString(", ") builder.WriteString("omit_prefix=") builder.WriteString(fmt.Sprintf("%v", u.OmitPrefix)) + builder.WriteString(", ") + builder.WriteString("mime_type=") + builder.WriteString(fmt.Sprintf("%v", u.MimeType)) builder.WriteByte(')') return builder.String() } diff --git a/entproto/internal/todo/ent/user/user.go b/entproto/internal/todo/ent/user/user.go index 0143923e8..e398ae1d9 100644 --- a/entproto/internal/todo/ent/user/user.go +++ b/entproto/internal/todo/ent/user/user.go @@ -56,6 +56,8 @@ const ( FieldDeviceType = "device_type" // FieldOmitPrefix holds the string denoting the omit_prefix field in the database. FieldOmitPrefix = "omit_prefix" + // FieldMimeType holds the string denoting the mime_type field in the database. + FieldMimeType = "mime_type" // EdgeGroup holds the string denoting the group edge name in mutations. EdgeGroup = "group" // EdgeAttachment holds the string denoting the attachment edge name in mutations. @@ -135,6 +137,7 @@ var Columns = []string{ FieldLabels, FieldDeviceType, FieldOmitPrefix, + FieldMimeType, } // ForeignKeys holds the SQL foreign-keys that are owned by the "users" @@ -245,6 +248,29 @@ func OmitPrefixValidator(op OmitPrefix) error { } } +// MimeType defines the type for the "mime_type" enum field. +type MimeType string + +// MimeType values. +const ( + MimeTypePng MimeType = "image/png" + MimeTypeSvg MimeType = "image/xml+svg" +) + +func (mt MimeType) String() string { + return string(mt) +} + +// MimeTypeValidator is a validator for the "mime_type" field enum values. It is called by the builders before save. +func MimeTypeValidator(mt MimeType) error { + switch mt { + case MimeTypePng, MimeTypeSvg: + return nil + default: + return fmt.Errorf("user: invalid enum value for mime_type field: %q", mt) + } +} + // OrderOption defines the ordering options for the User queries. type OrderOption func(*sql.Selector) @@ -353,6 +379,11 @@ func ByOmitPrefix(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldOmitPrefix, opts...).ToFunc() } +// ByMimeType orders the results by the mime_type field. +func ByMimeType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMimeType, opts...).ToFunc() +} + // ByGroupField orders the results by group field. func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption { return func(s *sql.Selector) { diff --git a/entproto/internal/todo/ent/user/where.go b/entproto/internal/todo/ent/user/where.go index e32ba1c0b..9e7f5f23b 100644 --- a/entproto/internal/todo/ent/user/where.go +++ b/entproto/internal/todo/ent/user/where.go @@ -1002,6 +1002,26 @@ func OmitPrefixNotIn(vs ...OmitPrefix) predicate.User { return predicate.User(sql.FieldNotIn(FieldOmitPrefix, vs...)) } +// MimeTypeEQ applies the EQ predicate on the "mime_type" field. +func MimeTypeEQ(v MimeType) predicate.User { + return predicate.User(sql.FieldEQ(FieldMimeType, v)) +} + +// MimeTypeNEQ applies the NEQ predicate on the "mime_type" field. +func MimeTypeNEQ(v MimeType) predicate.User { + return predicate.User(sql.FieldNEQ(FieldMimeType, v)) +} + +// MimeTypeIn applies the In predicate on the "mime_type" field. +func MimeTypeIn(vs ...MimeType) predicate.User { + return predicate.User(sql.FieldIn(FieldMimeType, vs...)) +} + +// MimeTypeNotIn applies the NotIn predicate on the "mime_type" field. +func MimeTypeNotIn(vs ...MimeType) predicate.User { + return predicate.User(sql.FieldNotIn(FieldMimeType, vs...)) +} + // HasGroup applies the HasEdge predicate on the "group" edge. func HasGroup() predicate.User { return predicate.User(func(s *sql.Selector) { diff --git a/entproto/internal/todo/ent/user_create.go b/entproto/internal/todo/ent/user_create.go index ffdba1c43..efbde1916 100644 --- a/entproto/internal/todo/ent/user_create.go +++ b/entproto/internal/todo/ent/user_create.go @@ -240,6 +240,12 @@ func (uc *UserCreate) SetOmitPrefix(up user.OmitPrefix) *UserCreate { return uc } +// SetMimeType sets the "mime_type" field. +func (uc *UserCreate) SetMimeType(ut user.MimeType) *UserCreate { + uc.mutation.SetMimeType(ut) + return uc +} + // SetID sets the "id" field. func (uc *UserCreate) SetID(u uint32) *UserCreate { uc.mutation.SetID(u) @@ -446,6 +452,14 @@ func (uc *UserCreate) check() error { return &ValidationError{Name: "omit_prefix", err: fmt.Errorf(`ent: validator failed for field "User.omit_prefix": %w`, err)} } } + if _, ok := uc.mutation.MimeType(); !ok { + return &ValidationError{Name: "mime_type", err: errors.New(`ent: missing required field "User.mime_type"`)} + } + if v, ok := uc.mutation.MimeType(); ok { + if err := user.MimeTypeValidator(v); err != nil { + return &ValidationError{Name: "mime_type", err: fmt.Errorf(`ent: validator failed for field "User.mime_type": %w`, err)} + } + } return nil } @@ -562,6 +576,10 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { _spec.SetField(user.FieldOmitPrefix, field.TypeEnum, value) _node.OmitPrefix = value } + if value, ok := uc.mutation.MimeType(); ok { + _spec.SetField(user.FieldMimeType, field.TypeEnum, value) + _node.MimeType = value + } if nodes := uc.mutation.GroupIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, diff --git a/entproto/internal/todo/ent/user_update.go b/entproto/internal/todo/ent/user_update.go index 8b38d8325..d7f5ffccb 100644 --- a/entproto/internal/todo/ent/user_update.go +++ b/entproto/internal/todo/ent/user_update.go @@ -352,6 +352,12 @@ func (uu *UserUpdate) SetOmitPrefix(up user.OmitPrefix) *UserUpdate { return uu } +// SetMimeType sets the "mime_type" field. +func (uu *UserUpdate) SetMimeType(ut user.MimeType) *UserUpdate { + uu.mutation.SetMimeType(ut) + return uu +} + // SetGroupID sets the "group" edge to the Group entity by ID. func (uu *UserUpdate) SetGroupID(id int) *UserUpdate { uu.mutation.SetGroupID(id) @@ -537,6 +543,11 @@ func (uu *UserUpdate) check() error { return &ValidationError{Name: "omit_prefix", err: fmt.Errorf(`ent: validator failed for field "User.omit_prefix": %w`, err)} } } + if v, ok := uu.mutation.MimeType(); ok { + if err := user.MimeTypeValidator(v); err != nil { + return &ValidationError{Name: "mime_type", err: fmt.Errorf(`ent: validator failed for field "User.mime_type": %w`, err)} + } + } return nil } @@ -665,6 +676,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { if value, ok := uu.mutation.OmitPrefix(); ok { _spec.SetField(user.FieldOmitPrefix, field.TypeEnum, value) } + if value, ok := uu.mutation.MimeType(); ok { + _spec.SetField(user.FieldMimeType, field.TypeEnum, value) + } if uu.mutation.GroupCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, @@ -1164,6 +1178,12 @@ func (uuo *UserUpdateOne) SetOmitPrefix(up user.OmitPrefix) *UserUpdateOne { return uuo } +// SetMimeType sets the "mime_type" field. +func (uuo *UserUpdateOne) SetMimeType(ut user.MimeType) *UserUpdateOne { + uuo.mutation.SetMimeType(ut) + return uuo +} + // SetGroupID sets the "group" edge to the Group entity by ID. func (uuo *UserUpdateOne) SetGroupID(id int) *UserUpdateOne { uuo.mutation.SetGroupID(id) @@ -1362,6 +1382,11 @@ func (uuo *UserUpdateOne) check() error { return &ValidationError{Name: "omit_prefix", err: fmt.Errorf(`ent: validator failed for field "User.omit_prefix": %w`, err)} } } + if v, ok := uuo.mutation.MimeType(); ok { + if err := user.MimeTypeValidator(v); err != nil { + return &ValidationError{Name: "mime_type", err: fmt.Errorf(`ent: validator failed for field "User.mime_type": %w`, err)} + } + } return nil } @@ -1507,6 +1532,9 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) if value, ok := uuo.mutation.OmitPrefix(); ok { _spec.SetField(user.FieldOmitPrefix, field.TypeEnum, value) } + if value, ok := uuo.mutation.MimeType(); ok { + _spec.SetField(user.FieldMimeType, field.TypeEnum, value) + } if uuo.mutation.GroupCleared() { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O,