123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "sikey/w303a/http/internal/data/ent/child"
- "sikey/w303a/http/internal/data/ent/childref"
- "sikey/w303a/http/internal/data/ent/contacts"
- "sikey/w303a/http/internal/data/ent/devicebind"
- "time"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- "github.com/google/uuid"
- )
- // ChildCreate is the builder for creating a Child entity.
- type ChildCreate struct {
- config
- mutation *ChildMutation
- hooks []Hook
- }
- // SetCreatedAt sets the "created_at" field.
- func (cc *ChildCreate) SetCreatedAt(t time.Time) *ChildCreate {
- cc.mutation.SetCreatedAt(t)
- return cc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableCreatedAt(t *time.Time) *ChildCreate {
- if t != nil {
- cc.SetCreatedAt(*t)
- }
- return cc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (cc *ChildCreate) SetUpdatedAt(t time.Time) *ChildCreate {
- cc.mutation.SetUpdatedAt(t)
- return cc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableUpdatedAt(t *time.Time) *ChildCreate {
- if t != nil {
- cc.SetUpdatedAt(*t)
- }
- return cc
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (cc *ChildCreate) SetDeletedAt(t time.Time) *ChildCreate {
- cc.mutation.SetDeletedAt(t)
- return cc
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableDeletedAt(t *time.Time) *ChildCreate {
- if t != nil {
- cc.SetDeletedAt(*t)
- }
- return cc
- }
- // SetChildName sets the "child_name" field.
- func (cc *ChildCreate) SetChildName(s string) *ChildCreate {
- cc.mutation.SetChildName(s)
- return cc
- }
- // SetPhoneNumber sets the "phone_number" field.
- func (cc *ChildCreate) SetPhoneNumber(s string) *ChildCreate {
- cc.mutation.SetPhoneNumber(s)
- return cc
- }
- // SetAreaCode sets the "area_code" field.
- func (cc *ChildCreate) SetAreaCode(s string) *ChildCreate {
- cc.mutation.SetAreaCode(s)
- return cc
- }
- // SetNillableAreaCode sets the "area_code" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableAreaCode(s *string) *ChildCreate {
- if s != nil {
- cc.SetAreaCode(*s)
- }
- return cc
- }
- // SetAvatar sets the "avatar" field.
- func (cc *ChildCreate) SetAvatar(s string) *ChildCreate {
- cc.mutation.SetAvatar(s)
- return cc
- }
- // SetNillableAvatar sets the "avatar" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableAvatar(s *string) *ChildCreate {
- if s != nil {
- cc.SetAvatar(*s)
- }
- return cc
- }
- // SetGender sets the "gender" field.
- func (cc *ChildCreate) SetGender(i int8) *ChildCreate {
- cc.mutation.SetGender(i)
- return cc
- }
- // SetNillableGender sets the "gender" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableGender(i *int8) *ChildCreate {
- if i != nil {
- cc.SetGender(*i)
- }
- return cc
- }
- // SetHeight sets the "height" field.
- func (cc *ChildCreate) SetHeight(i int32) *ChildCreate {
- cc.mutation.SetHeight(i)
- return cc
- }
- // SetNillableHeight sets the "height" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableHeight(i *int32) *ChildCreate {
- if i != nil {
- cc.SetHeight(*i)
- }
- return cc
- }
- // SetWeight sets the "weight" field.
- func (cc *ChildCreate) SetWeight(i int32) *ChildCreate {
- cc.mutation.SetWeight(i)
- return cc
- }
- // SetNillableWeight sets the "weight" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableWeight(i *int32) *ChildCreate {
- if i != nil {
- cc.SetWeight(*i)
- }
- return cc
- }
- // SetBirthday sets the "birthday" field.
- func (cc *ChildCreate) SetBirthday(s string) *ChildCreate {
- cc.mutation.SetBirthday(s)
- return cc
- }
- // SetNillableBirthday sets the "birthday" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableBirthday(s *string) *ChildCreate {
- if s != nil {
- cc.SetBirthday(*s)
- }
- return cc
- }
- // SetIsEnableBlockUnknownCall sets the "is_enable_block_unknown_call" field.
- func (cc *ChildCreate) SetIsEnableBlockUnknownCall(b bool) *ChildCreate {
- cc.mutation.SetIsEnableBlockUnknownCall(b)
- return cc
- }
- // SetNillableIsEnableBlockUnknownCall sets the "is_enable_block_unknown_call" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableIsEnableBlockUnknownCall(b *bool) *ChildCreate {
- if b != nil {
- cc.SetIsEnableBlockUnknownCall(*b)
- }
- return cc
- }
- // SetIsEnableFence sets the "is_enable_fence" field.
- func (cc *ChildCreate) SetIsEnableFence(b bool) *ChildCreate {
- cc.mutation.SetIsEnableFence(b)
- return cc
- }
- // SetNillableIsEnableFence sets the "is_enable_fence" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableIsEnableFence(b *bool) *ChildCreate {
- if b != nil {
- cc.SetIsEnableFence(*b)
- }
- return cc
- }
- // SetID sets the "id" field.
- func (cc *ChildCreate) SetID(u uuid.UUID) *ChildCreate {
- cc.mutation.SetID(u)
- return cc
- }
- // SetNillableID sets the "id" field if the given value is not nil.
- func (cc *ChildCreate) SetNillableID(u *uuid.UUID) *ChildCreate {
- if u != nil {
- cc.SetID(*u)
- }
- return cc
- }
- // AddChildRefIDs adds the "childRefs" edge to the ChildRef entity by IDs.
- func (cc *ChildCreate) AddChildRefIDs(ids ...int64) *ChildCreate {
- cc.mutation.AddChildRefIDs(ids...)
- return cc
- }
- // AddChildRefs adds the "childRefs" edges to the ChildRef entity.
- func (cc *ChildCreate) AddChildRefs(c ...*ChildRef) *ChildCreate {
- ids := make([]int64, len(c))
- for i := range c {
- ids[i] = c[i].ID
- }
- return cc.AddChildRefIDs(ids...)
- }
- // AddChildDeviceIDs adds the "childDevice" edge to the DeviceBind entity by IDs.
- func (cc *ChildCreate) AddChildDeviceIDs(ids ...int64) *ChildCreate {
- cc.mutation.AddChildDeviceIDs(ids...)
- return cc
- }
- // AddChildDevice adds the "childDevice" edges to the DeviceBind entity.
- func (cc *ChildCreate) AddChildDevice(d ...*DeviceBind) *ChildCreate {
- ids := make([]int64, len(d))
- for i := range d {
- ids[i] = d[i].ID
- }
- return cc.AddChildDeviceIDs(ids...)
- }
- // AddChildContactIDs adds the "childContacts" edge to the Contacts entity by IDs.
- func (cc *ChildCreate) AddChildContactIDs(ids ...int) *ChildCreate {
- cc.mutation.AddChildContactIDs(ids...)
- return cc
- }
- // AddChildContacts adds the "childContacts" edges to the Contacts entity.
- func (cc *ChildCreate) AddChildContacts(c ...*Contacts) *ChildCreate {
- ids := make([]int, len(c))
- for i := range c {
- ids[i] = c[i].ID
- }
- return cc.AddChildContactIDs(ids...)
- }
- // Mutation returns the ChildMutation object of the builder.
- func (cc *ChildCreate) Mutation() *ChildMutation {
- return cc.mutation
- }
- // Save creates the Child in the database.
- func (cc *ChildCreate) Save(ctx context.Context) (*Child, error) {
- cc.defaults()
- return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (cc *ChildCreate) SaveX(ctx context.Context) *Child {
- v, err := cc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (cc *ChildCreate) Exec(ctx context.Context) error {
- _, err := cc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (cc *ChildCreate) ExecX(ctx context.Context) {
- if err := cc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (cc *ChildCreate) defaults() {
- if _, ok := cc.mutation.CreatedAt(); !ok {
- v := child.DefaultCreatedAt()
- cc.mutation.SetCreatedAt(v)
- }
- if _, ok := cc.mutation.UpdatedAt(); !ok {
- v := child.DefaultUpdatedAt()
- cc.mutation.SetUpdatedAt(v)
- }
- if _, ok := cc.mutation.AreaCode(); !ok {
- v := child.DefaultAreaCode
- cc.mutation.SetAreaCode(v)
- }
- if _, ok := cc.mutation.Gender(); !ok {
- v := child.DefaultGender
- cc.mutation.SetGender(v)
- }
- if _, ok := cc.mutation.Height(); !ok {
- v := child.DefaultHeight
- cc.mutation.SetHeight(v)
- }
- if _, ok := cc.mutation.Weight(); !ok {
- v := child.DefaultWeight
- cc.mutation.SetWeight(v)
- }
- if _, ok := cc.mutation.IsEnableBlockUnknownCall(); !ok {
- v := child.DefaultIsEnableBlockUnknownCall
- cc.mutation.SetIsEnableBlockUnknownCall(v)
- }
- if _, ok := cc.mutation.IsEnableFence(); !ok {
- v := child.DefaultIsEnableFence
- cc.mutation.SetIsEnableFence(v)
- }
- if _, ok := cc.mutation.ID(); !ok {
- v := child.DefaultID()
- cc.mutation.SetID(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (cc *ChildCreate) check() error {
- if _, ok := cc.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Child.created_at"`)}
- }
- if _, ok := cc.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Child.updated_at"`)}
- }
- if _, ok := cc.mutation.ChildName(); !ok {
- return &ValidationError{Name: "child_name", err: errors.New(`ent: missing required field "Child.child_name"`)}
- }
- if v, ok := cc.mutation.ChildName(); ok {
- if err := child.ChildNameValidator(v); err != nil {
- return &ValidationError{Name: "child_name", err: fmt.Errorf(`ent: validator failed for field "Child.child_name": %w`, err)}
- }
- }
- if _, ok := cc.mutation.PhoneNumber(); !ok {
- return &ValidationError{Name: "phone_number", err: errors.New(`ent: missing required field "Child.phone_number"`)}
- }
- if v, ok := cc.mutation.PhoneNumber(); ok {
- if err := child.PhoneNumberValidator(v); err != nil {
- return &ValidationError{Name: "phone_number", err: fmt.Errorf(`ent: validator failed for field "Child.phone_number": %w`, err)}
- }
- }
- if _, ok := cc.mutation.AreaCode(); !ok {
- return &ValidationError{Name: "area_code", err: errors.New(`ent: missing required field "Child.area_code"`)}
- }
- if v, ok := cc.mutation.AreaCode(); ok {
- if err := child.AreaCodeValidator(v); err != nil {
- return &ValidationError{Name: "area_code", err: fmt.Errorf(`ent: validator failed for field "Child.area_code": %w`, err)}
- }
- }
- if v, ok := cc.mutation.Avatar(); ok {
- if err := child.AvatarValidator(v); err != nil {
- return &ValidationError{Name: "avatar", err: fmt.Errorf(`ent: validator failed for field "Child.avatar": %w`, err)}
- }
- }
- if _, ok := cc.mutation.Gender(); !ok {
- return &ValidationError{Name: "gender", err: errors.New(`ent: missing required field "Child.gender"`)}
- }
- if v, ok := cc.mutation.Gender(); ok {
- if err := child.GenderValidator(v); err != nil {
- return &ValidationError{Name: "gender", err: fmt.Errorf(`ent: validator failed for field "Child.gender": %w`, err)}
- }
- }
- if _, ok := cc.mutation.Height(); !ok {
- return &ValidationError{Name: "height", err: errors.New(`ent: missing required field "Child.height"`)}
- }
- if v, ok := cc.mutation.Height(); ok {
- if err := child.HeightValidator(v); err != nil {
- return &ValidationError{Name: "height", err: fmt.Errorf(`ent: validator failed for field "Child.height": %w`, err)}
- }
- }
- if _, ok := cc.mutation.Weight(); !ok {
- return &ValidationError{Name: "weight", err: errors.New(`ent: missing required field "Child.weight"`)}
- }
- if v, ok := cc.mutation.Weight(); ok {
- if err := child.WeightValidator(v); err != nil {
- return &ValidationError{Name: "weight", err: fmt.Errorf(`ent: validator failed for field "Child.weight": %w`, err)}
- }
- }
- if v, ok := cc.mutation.Birthday(); ok {
- if err := child.BirthdayValidator(v); err != nil {
- return &ValidationError{Name: "birthday", err: fmt.Errorf(`ent: validator failed for field "Child.birthday": %w`, err)}
- }
- }
- if _, ok := cc.mutation.IsEnableBlockUnknownCall(); !ok {
- return &ValidationError{Name: "is_enable_block_unknown_call", err: errors.New(`ent: missing required field "Child.is_enable_block_unknown_call"`)}
- }
- if _, ok := cc.mutation.IsEnableFence(); !ok {
- return &ValidationError{Name: "is_enable_fence", err: errors.New(`ent: missing required field "Child.is_enable_fence"`)}
- }
- return nil
- }
- func (cc *ChildCreate) sqlSave(ctx context.Context) (*Child, error) {
- if err := cc.check(); err != nil {
- return nil, err
- }
- _node, _spec := cc.createSpec()
- if err := sqlgraph.CreateNode(ctx, cc.driver, _spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- if _spec.ID.Value != nil {
- if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
- _node.ID = *id
- } else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
- return nil, err
- }
- }
- cc.mutation.id = &_node.ID
- cc.mutation.done = true
- return _node, nil
- }
- func (cc *ChildCreate) createSpec() (*Child, *sqlgraph.CreateSpec) {
- var (
- _node = &Child{config: cc.config}
- _spec = sqlgraph.NewCreateSpec(child.Table, sqlgraph.NewFieldSpec(child.FieldID, field.TypeUUID))
- )
- if id, ok := cc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = &id
- }
- if value, ok := cc.mutation.CreatedAt(); ok {
- _spec.SetField(child.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := cc.mutation.UpdatedAt(); ok {
- _spec.SetField(child.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := cc.mutation.DeletedAt(); ok {
- _spec.SetField(child.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = &value
- }
- if value, ok := cc.mutation.ChildName(); ok {
- _spec.SetField(child.FieldChildName, field.TypeString, value)
- _node.ChildName = value
- }
- if value, ok := cc.mutation.PhoneNumber(); ok {
- _spec.SetField(child.FieldPhoneNumber, field.TypeString, value)
- _node.PhoneNumber = value
- }
- if value, ok := cc.mutation.AreaCode(); ok {
- _spec.SetField(child.FieldAreaCode, field.TypeString, value)
- _node.AreaCode = value
- }
- if value, ok := cc.mutation.Avatar(); ok {
- _spec.SetField(child.FieldAvatar, field.TypeString, value)
- _node.Avatar = &value
- }
- if value, ok := cc.mutation.Gender(); ok {
- _spec.SetField(child.FieldGender, field.TypeInt8, value)
- _node.Gender = value
- }
- if value, ok := cc.mutation.Height(); ok {
- _spec.SetField(child.FieldHeight, field.TypeInt32, value)
- _node.Height = value
- }
- if value, ok := cc.mutation.Weight(); ok {
- _spec.SetField(child.FieldWeight, field.TypeInt32, value)
- _node.Weight = value
- }
- if value, ok := cc.mutation.Birthday(); ok {
- _spec.SetField(child.FieldBirthday, field.TypeString, value)
- _node.Birthday = &value
- }
- if value, ok := cc.mutation.IsEnableBlockUnknownCall(); ok {
- _spec.SetField(child.FieldIsEnableBlockUnknownCall, field.TypeBool, value)
- _node.IsEnableBlockUnknownCall = value
- }
- if value, ok := cc.mutation.IsEnableFence(); ok {
- _spec.SetField(child.FieldIsEnableFence, field.TypeBool, value)
- _node.IsEnableFence = value
- }
- if nodes := cc.mutation.ChildRefsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: child.ChildRefsTable,
- Columns: []string{child.ChildRefsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(childref.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges = append(_spec.Edges, edge)
- }
- if nodes := cc.mutation.ChildDeviceIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: child.ChildDeviceTable,
- Columns: []string{child.ChildDeviceColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(devicebind.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges = append(_spec.Edges, edge)
- }
- if nodes := cc.mutation.ChildContactsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: child.ChildContactsTable,
- Columns: []string{child.ChildContactsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(contacts.FieldID, field.TypeInt),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges = append(_spec.Edges, edge)
- }
- return _node, _spec
- }
- // ChildCreateBulk is the builder for creating many Child entities in bulk.
- type ChildCreateBulk struct {
- config
- err error
- builders []*ChildCreate
- }
- // Save creates the Child entities in the database.
- func (ccb *ChildCreateBulk) Save(ctx context.Context) ([]*Child, error) {
- if ccb.err != nil {
- return nil, ccb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(ccb.builders))
- nodes := make([]*Child, len(ccb.builders))
- mutators := make([]Mutator, len(ccb.builders))
- for i := range ccb.builders {
- func(i int, root context.Context) {
- builder := ccb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*ChildMutation)
- 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, ccb.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, ccb.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
- 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, ccb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (ccb *ChildCreateBulk) SaveX(ctx context.Context) []*Child {
- v, err := ccb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (ccb *ChildCreateBulk) Exec(ctx context.Context) error {
- _, err := ccb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (ccb *ChildCreateBulk) ExecX(ctx context.Context) {
- if err := ccb.Exec(ctx); err != nil {
- panic(err)
- }
- }
|