123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "w303a/server/app/gate/internal/data/ent/pushregistration"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- "github.com/google/uuid"
- )
- // PushRegistrationCreate is the builder for creating a PushRegistration entity.
- type PushRegistrationCreate struct {
- config
- mutation *PushRegistrationMutation
- hooks []Hook
- }
- // SetRegID sets the "reg_id" field.
- func (prc *PushRegistrationCreate) SetRegID(s string) *PushRegistrationCreate {
- prc.mutation.SetRegID(s)
- return prc
- }
- // SetRegistrantPlatformType sets the "registrant_platform_type" field.
- func (prc *PushRegistrationCreate) SetRegistrantPlatformType(i int8) *PushRegistrationCreate {
- prc.mutation.SetRegistrantPlatformType(i)
- return prc
- }
- // SetLanguage sets the "language" field.
- func (prc *PushRegistrationCreate) SetLanguage(s string) *PushRegistrationCreate {
- prc.mutation.SetLanguage(s)
- return prc
- }
- // SetNillableLanguage sets the "language" field if the given value is not nil.
- func (prc *PushRegistrationCreate) SetNillableLanguage(s *string) *PushRegistrationCreate {
- if s != nil {
- prc.SetLanguage(*s)
- }
- return prc
- }
- // SetDeviceModel sets the "device_model" field.
- func (prc *PushRegistrationCreate) SetDeviceModel(s string) *PushRegistrationCreate {
- prc.mutation.SetDeviceModel(s)
- return prc
- }
- // SetDeviceManufacturer sets the "device_manufacturer" field.
- func (prc *PushRegistrationCreate) SetDeviceManufacturer(s string) *PushRegistrationCreate {
- prc.mutation.SetDeviceManufacturer(s)
- return prc
- }
- // SetDeviceSystemVersion sets the "device_system_version" field.
- func (prc *PushRegistrationCreate) SetDeviceSystemVersion(s string) *PushRegistrationCreate {
- prc.mutation.SetDeviceSystemVersion(s)
- return prc
- }
- // SetDeviceSystem sets the "device_system" field.
- func (prc *PushRegistrationCreate) SetDeviceSystem(s string) *PushRegistrationCreate {
- prc.mutation.SetDeviceSystem(s)
- return prc
- }
- // SetCreatedAt sets the "created_at" field.
- func (prc *PushRegistrationCreate) SetCreatedAt(t time.Time) *PushRegistrationCreate {
- prc.mutation.SetCreatedAt(t)
- return prc
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (prc *PushRegistrationCreate) SetNillableCreatedAt(t *time.Time) *PushRegistrationCreate {
- if t != nil {
- prc.SetCreatedAt(*t)
- }
- return prc
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (prc *PushRegistrationCreate) SetUpdatedAt(t time.Time) *PushRegistrationCreate {
- prc.mutation.SetUpdatedAt(t)
- return prc
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (prc *PushRegistrationCreate) SetNillableUpdatedAt(t *time.Time) *PushRegistrationCreate {
- if t != nil {
- prc.SetUpdatedAt(*t)
- }
- return prc
- }
- // SetID sets the "id" field.
- func (prc *PushRegistrationCreate) SetID(u uuid.UUID) *PushRegistrationCreate {
- prc.mutation.SetID(u)
- return prc
- }
- // Mutation returns the PushRegistrationMutation object of the builder.
- func (prc *PushRegistrationCreate) Mutation() *PushRegistrationMutation {
- return prc.mutation
- }
- // Save creates the PushRegistration in the database.
- func (prc *PushRegistrationCreate) Save(ctx context.Context) (*PushRegistration, error) {
- prc.defaults()
- return withHooks(ctx, prc.sqlSave, prc.mutation, prc.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (prc *PushRegistrationCreate) SaveX(ctx context.Context) *PushRegistration {
- v, err := prc.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (prc *PushRegistrationCreate) Exec(ctx context.Context) error {
- _, err := prc.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (prc *PushRegistrationCreate) ExecX(ctx context.Context) {
- if err := prc.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (prc *PushRegistrationCreate) defaults() {
- if _, ok := prc.mutation.Language(); !ok {
- v := pushregistration.DefaultLanguage
- prc.mutation.SetLanguage(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (prc *PushRegistrationCreate) check() error {
- if _, ok := prc.mutation.RegID(); !ok {
- return &ValidationError{Name: "reg_id", err: errors.New(`ent: missing required field "PushRegistration.reg_id"`)}
- }
- if _, ok := prc.mutation.RegistrantPlatformType(); !ok {
- return &ValidationError{Name: "registrant_platform_type", err: errors.New(`ent: missing required field "PushRegistration.registrant_platform_type"`)}
- }
- if _, ok := prc.mutation.Language(); !ok {
- return &ValidationError{Name: "language", err: errors.New(`ent: missing required field "PushRegistration.language"`)}
- }
- if v, ok := prc.mutation.Language(); ok {
- if err := pushregistration.LanguageValidator(v); err != nil {
- return &ValidationError{Name: "language", err: fmt.Errorf(`ent: validator failed for field "PushRegistration.language": %w`, err)}
- }
- }
- if _, ok := prc.mutation.DeviceModel(); !ok {
- return &ValidationError{Name: "device_model", err: errors.New(`ent: missing required field "PushRegistration.device_model"`)}
- }
- if _, ok := prc.mutation.DeviceManufacturer(); !ok {
- return &ValidationError{Name: "device_manufacturer", err: errors.New(`ent: missing required field "PushRegistration.device_manufacturer"`)}
- }
- if _, ok := prc.mutation.DeviceSystemVersion(); !ok {
- return &ValidationError{Name: "device_system_version", err: errors.New(`ent: missing required field "PushRegistration.device_system_version"`)}
- }
- if _, ok := prc.mutation.DeviceSystem(); !ok {
- return &ValidationError{Name: "device_system", err: errors.New(`ent: missing required field "PushRegistration.device_system"`)}
- }
- return nil
- }
- func (prc *PushRegistrationCreate) sqlSave(ctx context.Context) (*PushRegistration, error) {
- if err := prc.check(); err != nil {
- return nil, err
- }
- _node, _spec := prc.createSpec()
- if err := sqlgraph.CreateNode(ctx, prc.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
- }
- }
- prc.mutation.id = &_node.ID
- prc.mutation.done = true
- return _node, nil
- }
- func (prc *PushRegistrationCreate) createSpec() (*PushRegistration, *sqlgraph.CreateSpec) {
- var (
- _node = &PushRegistration{config: prc.config}
- _spec = sqlgraph.NewCreateSpec(pushregistration.Table, sqlgraph.NewFieldSpec(pushregistration.FieldID, field.TypeUUID))
- )
- if id, ok := prc.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = &id
- }
- if value, ok := prc.mutation.RegID(); ok {
- _spec.SetField(pushregistration.FieldRegID, field.TypeString, value)
- _node.RegID = value
- }
- if value, ok := prc.mutation.RegistrantPlatformType(); ok {
- _spec.SetField(pushregistration.FieldRegistrantPlatformType, field.TypeInt8, value)
- _node.RegistrantPlatformType = value
- }
- if value, ok := prc.mutation.Language(); ok {
- _spec.SetField(pushregistration.FieldLanguage, field.TypeString, value)
- _node.Language = value
- }
- if value, ok := prc.mutation.DeviceModel(); ok {
- _spec.SetField(pushregistration.FieldDeviceModel, field.TypeString, value)
- _node.DeviceModel = &value
- }
- if value, ok := prc.mutation.DeviceManufacturer(); ok {
- _spec.SetField(pushregistration.FieldDeviceManufacturer, field.TypeString, value)
- _node.DeviceManufacturer = &value
- }
- if value, ok := prc.mutation.DeviceSystemVersion(); ok {
- _spec.SetField(pushregistration.FieldDeviceSystemVersion, field.TypeString, value)
- _node.DeviceSystemVersion = &value
- }
- if value, ok := prc.mutation.DeviceSystem(); ok {
- _spec.SetField(pushregistration.FieldDeviceSystem, field.TypeString, value)
- _node.DeviceSystem = &value
- }
- if value, ok := prc.mutation.CreatedAt(); ok {
- _spec.SetField(pushregistration.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := prc.mutation.UpdatedAt(); ok {
- _spec.SetField(pushregistration.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- return _node, _spec
- }
- // PushRegistrationCreateBulk is the builder for creating many PushRegistration entities in bulk.
- type PushRegistrationCreateBulk struct {
- config
- err error
- builders []*PushRegistrationCreate
- }
- // Save creates the PushRegistration entities in the database.
- func (prcb *PushRegistrationCreateBulk) Save(ctx context.Context) ([]*PushRegistration, error) {
- if prcb.err != nil {
- return nil, prcb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(prcb.builders))
- nodes := make([]*PushRegistration, len(prcb.builders))
- mutators := make([]Mutator, len(prcb.builders))
- for i := range prcb.builders {
- func(i int, root context.Context) {
- builder := prcb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*PushRegistrationMutation)
- 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, prcb.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, prcb.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, prcb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (prcb *PushRegistrationCreateBulk) SaveX(ctx context.Context) []*PushRegistration {
- v, err := prcb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (prcb *PushRegistrationCreateBulk) Exec(ctx context.Context) error {
- _, err := prcb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (prcb *PushRegistrationCreateBulk) ExecX(ctx context.Context) {
- if err := prcb.Exec(ctx); err != nil {
- panic(err)
- }
- }
|