Something went wrong. Try again.
Self-hosted file management and sharing system, supports multiple storage providers. forked from tdvorak.tngl.sh/cloudreve
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159// Code generated by ent, DO NOT EDIT.
package ent
import ( "context" "errors" "fmt" "time"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" "github.com/cloudreve/Cloudreve/v4/ent/giftcode" "github.com/cloudreve/Cloudreve/v4/ent/user")
// GiftCodeCreate is the builder for creating a GiftCode entity.type GiftCodeCreate struct { config mutation *GiftCodeMutation hooks []Hook conflict []sql.ConflictOption}
// SetCreatedAt sets the "created_at" field.func (gcc *GiftCodeCreate) SetCreatedAt(t time.Time) *GiftCodeCreate { gcc.mutation.SetCreatedAt(t) return gcc}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.func (gcc *GiftCodeCreate) SetNillableCreatedAt(t *time.Time) *GiftCodeCreate { if t != nil { gcc.SetCreatedAt(*t) } return gcc}
// SetUpdatedAt sets the "updated_at" field.func (gcc *GiftCodeCreate) SetUpdatedAt(t time.Time) *GiftCodeCreate { gcc.mutation.SetUpdatedAt(t) return gcc}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.func (gcc *GiftCodeCreate) SetNillableUpdatedAt(t *time.Time) *GiftCodeCreate { if t != nil { gcc.SetUpdatedAt(*t) } return gcc}
// SetDeletedAt sets the "deleted_at" field.func (gcc *GiftCodeCreate) SetDeletedAt(t time.Time) *GiftCodeCreate { gcc.mutation.SetDeletedAt(t) return gcc}
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.func (gcc *GiftCodeCreate) SetNillableDeletedAt(t *time.Time) *GiftCodeCreate { if t != nil { gcc.SetDeletedAt(*t) } return gcc}
// SetCode sets the "code" field.func (gcc *GiftCodeCreate) SetCode(s string) *GiftCodeCreate { gcc.mutation.SetCode(s) return gcc}
// SetType sets the "type" field.func (gcc *GiftCodeCreate) SetType(gi giftcode.Type) *GiftCodeCreate { gcc.mutation.SetType(gi) return gcc}
// SetAmount sets the "amount" field.func (gcc *GiftCodeCreate) SetAmount(i int64) *GiftCodeCreate { gcc.mutation.SetAmount(i) return gcc}
// SetDuration sets the "duration" field.func (gcc *GiftCodeCreate) SetDuration(i int64) *GiftCodeCreate { gcc.mutation.SetDuration(i) return gcc}
// SetNillableDuration sets the "duration" field if the given value is not nil.func (gcc *GiftCodeCreate) SetNillableDuration(i *int64) *GiftCodeCreate { if i != nil { gcc.SetDuration(*i) } return gcc}
// SetUsedByID sets the "used_by_id" field.func (gcc *GiftCodeCreate) SetUsedByID(i int) *GiftCodeCreate { gcc.mutation.SetUsedByID(i) return gcc}
// SetNillableUsedByID sets the "used_by_id" field if the given value is not nil.func (gcc *GiftCodeCreate) SetNillableUsedByID(i *int) *GiftCodeCreate { if i != nil { gcc.SetUsedByID(*i) } return gcc}
// SetUsedAt sets the "used_at" field.func (gcc *GiftCodeCreate) SetUsedAt(t time.Time) *GiftCodeCreate { gcc.mutation.SetUsedAt(t) return gcc}
// SetNillableUsedAt sets the "used_at" field if the given value is not nil.func (gcc *GiftCodeCreate) SetNillableUsedAt(t *time.Time) *GiftCodeCreate { if t != nil { gcc.SetUsedAt(*t) } return gcc}
// SetDes sets the "des" field.func (gcc *GiftCodeCreate) SetDes(s string) *GiftCodeCreate { gcc.mutation.SetDes(s) return gcc}
// SetNillableDes sets the "des" field if the given value is not nil.func (gcc *GiftCodeCreate) SetNillableDes(s *string) *GiftCodeCreate { if s != nil { gcc.SetDes(*s) } return gcc}
// SetRedeemerID sets the "redeemer" edge to the User entity by ID.func (gcc *GiftCodeCreate) SetRedeemerID(id int) *GiftCodeCreate { gcc.mutation.SetRedeemerID(id) return gcc}
// SetNillableRedeemerID sets the "redeemer" edge to the User entity by ID if the given value is not nil.func (gcc *GiftCodeCreate) SetNillableRedeemerID(id *int) *GiftCodeCreate { if id != nil { gcc = gcc.SetRedeemerID(*id) } return gcc}
// SetRedeemer sets the "redeemer" edge to the User entity.func (gcc *GiftCodeCreate) SetRedeemer(u *User) *GiftCodeCreate { return gcc.SetRedeemerID(u.ID)}
// Mutation returns the GiftCodeMutation object of the builder.func (gcc *GiftCodeCreate) Mutation() *GiftCodeMutation { return gcc.mutation}
// Save creates the GiftCode in the database.func (gcc *GiftCodeCreate) Save(ctx context.Context) (*GiftCode, error) { if err := gcc.defaults(); err != nil { return nil, err } return withHooks(ctx, gcc.sqlSave, gcc.mutation, gcc.hooks)}
// SaveX calls Save and panics if Save returns an error.func (gcc *GiftCodeCreate) SaveX(ctx context.Context) *GiftCode { v, err := gcc.Save(ctx) if err != nil { panic(err) } return v}
// Exec executes the query.func (gcc *GiftCodeCreate) Exec(ctx context.Context) error { _, err := gcc.Save(ctx) return err}
// ExecX is like Exec, but panics if an error occurs.func (gcc *GiftCodeCreate) ExecX(ctx context.Context) { if err := gcc.Exec(ctx); err != nil { panic(err) }}
// defaults sets the default values of the builder before save.func (gcc *GiftCodeCreate) defaults() error { if _, ok := gcc.mutation.CreatedAt(); !ok { if giftcode.DefaultCreatedAt == nil { return fmt.Errorf("ent: uninitialized giftcode.DefaultCreatedAt (forgotten import ent/runtime?)") } v := giftcode.DefaultCreatedAt() gcc.mutation.SetCreatedAt(v) } if _, ok := gcc.mutation.UpdatedAt(); !ok { if giftcode.DefaultUpdatedAt == nil { return fmt.Errorf("ent: uninitialized giftcode.DefaultUpdatedAt (forgotten import ent/runtime?)") } v := giftcode.DefaultUpdatedAt() gcc.mutation.SetUpdatedAt(v) } return nil}
// check runs all checks and user-defined validators on the builder.func (gcc *GiftCodeCreate) check() error { if _, ok := gcc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "GiftCode.created_at"`)} } if _, ok := gcc.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "GiftCode.updated_at"`)} } if _, ok := gcc.mutation.Code(); !ok { return &ValidationError{Name: "code", err: errors.New(`ent: missing required field "GiftCode.code"`)} } if _, ok := gcc.mutation.GetType(); !ok { return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "GiftCode.type"`)} } if v, ok := gcc.mutation.GetType(); ok { if err := giftcode.TypeValidator(v); err != nil { return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "GiftCode.type": %w`, err)} } } if _, ok := gcc.mutation.Amount(); !ok { return &ValidationError{Name: "amount", err: errors.New(`ent: missing required field "GiftCode.amount"`)} } return nil}
func (gcc *GiftCodeCreate) sqlSave(ctx context.Context) (*GiftCode, error) { if err := gcc.check(); err != nil { return nil, err } _node, _spec := gcc.createSpec() if err := sqlgraph.CreateNode(ctx, gcc.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) gcc.mutation.id = &_node.ID gcc.mutation.done = true return _node, nil}
func (gcc *GiftCodeCreate) createSpec() (*GiftCode, *sqlgraph.CreateSpec) { var ( _node = &GiftCode{config: gcc.config} _spec = sqlgraph.NewCreateSpec(giftcode.Table, sqlgraph.NewFieldSpec(giftcode.FieldID, field.TypeInt)) )
if id, ok := gcc.mutation.ID(); ok { _node.ID = id id64 := int64(id) _spec.ID.Value = id64 }
_spec.OnConflict = gcc.conflict if value, ok := gcc.mutation.CreatedAt(); ok { _spec.SetField(giftcode.FieldCreatedAt, field.TypeTime, value) _node.CreatedAt = value } if value, ok := gcc.mutation.UpdatedAt(); ok { _spec.SetField(giftcode.FieldUpdatedAt, field.TypeTime, value) _node.UpdatedAt = value } if value, ok := gcc.mutation.DeletedAt(); ok { _spec.SetField(giftcode.FieldDeletedAt, field.TypeTime, value) _node.DeletedAt = &value } if value, ok := gcc.mutation.Code(); ok { _spec.SetField(giftcode.FieldCode, field.TypeString, value) _node.Code = value } if value, ok := gcc.mutation.GetType(); ok { _spec.SetField(giftcode.FieldType, field.TypeEnum, value) _node.Type = value } if value, ok := gcc.mutation.Amount(); ok { _spec.SetField(giftcode.FieldAmount, field.TypeInt64, value) _node.Amount = value } if value, ok := gcc.mutation.Duration(); ok { _spec.SetField(giftcode.FieldDuration, field.TypeInt64, value) _node.Duration = value } if value, ok := gcc.mutation.UsedAt(); ok { _spec.SetField(giftcode.FieldUsedAt, field.TypeTime, value) _node.UsedAt = &value } if value, ok := gcc.mutation.Des(); ok { _spec.SetField(giftcode.FieldDes, field.TypeString, value) _node.Des = value } if nodes := gcc.mutation.RedeemerIDs(); len(nodes) > 0 { edge := &sqlgraph.EdgeSpec{ Rel: sqlgraph.M2O, Inverse: true, Table: giftcode.RedeemerTable, Columns: []string{giftcode.RedeemerColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt), }, } for _, k := range nodes { edge.Target.Nodes = append(edge.Target.Nodes, k) } _node.UsedByID = nodes[0] _spec.Edges = append(_spec.Edges, edge) } return _node, _spec}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause// of the `INSERT` statement. For example://// client.GiftCode.Create().// SetCreatedAt(v).// OnConflict(// // Update the row with the new values// // the was proposed for insertion.// sql.ResolveWithNewValues(),// ).// // Override some of the fields with custom// // update values.// Update(func(u *ent.GiftCodeUpsert) {// SetCreatedAt(v+v).// }).// Exec(ctx)func (gcc *GiftCodeCreate) OnConflict(opts ...sql.ConflictOption) *GiftCodeUpsertOne { gcc.conflict = opts return &GiftCodeUpsertOne{ create: gcc, }}
// OnConflictColumns calls `OnConflict` and configures the columns// as conflict target. Using this option is equivalent to using://// client.GiftCode.Create().// OnConflict(sql.ConflictColumns(columns...)).// Exec(ctx)func (gcc *GiftCodeCreate) OnConflictColumns(columns ...string) *GiftCodeUpsertOne { gcc.conflict = append(gcc.conflict, sql.ConflictColumns(columns...)) return &GiftCodeUpsertOne{ create: gcc, }}
type ( // GiftCodeUpsertOne is the builder for "upsert"-ing // one GiftCode node. GiftCodeUpsertOne struct { create *GiftCodeCreate }
// GiftCodeUpsert is the "OnConflict" setter. GiftCodeUpsert struct { *sql.UpdateSet })
// SetUpdatedAt sets the "updated_at" field.func (u *GiftCodeUpsert) SetUpdatedAt(v time.Time) *GiftCodeUpsert { u.Set(giftcode.FieldUpdatedAt, v) return u}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.func (u *GiftCodeUpsert) UpdateUpdatedAt() *GiftCodeUpsert { u.SetExcluded(giftcode.FieldUpdatedAt) return u}
// SetDeletedAt sets the "deleted_at" field.func (u *GiftCodeUpsert) SetDeletedAt(v time.Time) *GiftCodeUpsert { u.Set(giftcode.FieldDeletedAt, v) return u}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.func (u *GiftCodeUpsert) UpdateDeletedAt() *GiftCodeUpsert { u.SetExcluded(giftcode.FieldDeletedAt) return u}
// ClearDeletedAt clears the value of the "deleted_at" field.func (u *GiftCodeUpsert) ClearDeletedAt() *GiftCodeUpsert { u.SetNull(giftcode.FieldDeletedAt) return u}
// SetCode sets the "code" field.func (u *GiftCodeUpsert) SetCode(v string) *GiftCodeUpsert { u.Set(giftcode.FieldCode, v) return u}
// UpdateCode sets the "code" field to the value that was provided on create.func (u *GiftCodeUpsert) UpdateCode() *GiftCodeUpsert { u.SetExcluded(giftcode.FieldCode) return u}
// SetType sets the "type" field.func (u *GiftCodeUpsert) SetType(v giftcode.Type) *GiftCodeUpsert { u.Set(giftcode.FieldType, v) return u}
// UpdateType sets the "type" field to the value that was provided on create.func (u *GiftCodeUpsert) UpdateType() *GiftCodeUpsert { u.SetExcluded(giftcode.FieldType) return u}
// SetAmount sets the "amount" field.func (u *GiftCodeUpsert) SetAmount(v int64) *GiftCodeUpsert { u.Set(giftcode.FieldAmount, v) return u}
// UpdateAmount sets the "amount" field to the value that was provided on create.func (u *GiftCodeUpsert) UpdateAmount() *GiftCodeUpsert { u.SetExcluded(giftcode.FieldAmount) return u}
// AddAmount adds v to the "amount" field.func (u *GiftCodeUpsert) AddAmount(v int64) *GiftCodeUpsert { u.Add(giftcode.FieldAmount, v) return u}
// SetDuration sets the "duration" field.func (u *GiftCodeUpsert) SetDuration(v int64) *GiftCodeUpsert { u.Set(giftcode.FieldDuration, v) return u}
// UpdateDuration sets the "duration" field to the value that was provided on create.func (u *GiftCodeUpsert) UpdateDuration() *GiftCodeUpsert { u.SetExcluded(giftcode.FieldDuration) return u}
// AddDuration adds v to the "duration" field.func (u *GiftCodeUpsert) AddDuration(v int64) *GiftCodeUpsert { u.Add(giftcode.FieldDuration, v) return u}
// ClearDuration clears the value of the "duration" field.func (u *GiftCodeUpsert) ClearDuration() *GiftCodeUpsert { u.SetNull(giftcode.FieldDuration) return u}
// SetUsedByID sets the "used_by_id" field.func (u *GiftCodeUpsert) SetUsedByID(v int) *GiftCodeUpsert { u.Set(giftcode.FieldUsedByID, v) return u}
// UpdateUsedByID sets the "used_by_id" field to the value that was provided on create.func (u *GiftCodeUpsert) UpdateUsedByID() *GiftCodeUpsert { u.SetExcluded(giftcode.FieldUsedByID) return u}
// ClearUsedByID clears the value of the "used_by_id" field.func (u *GiftCodeUpsert) ClearUsedByID() *GiftCodeUpsert { u.SetNull(giftcode.FieldUsedByID) return u}
// SetUsedAt sets the "used_at" field.func (u *GiftCodeUpsert) SetUsedAt(v time.Time) *GiftCodeUpsert { u.Set(giftcode.FieldUsedAt, v) return u}
// UpdateUsedAt sets the "used_at" field to the value that was provided on create.func (u *GiftCodeUpsert) UpdateUsedAt() *GiftCodeUpsert { u.SetExcluded(giftcode.FieldUsedAt) return u}
// ClearUsedAt clears the value of the "used_at" field.func (u *GiftCodeUpsert) ClearUsedAt() *GiftCodeUpsert { u.SetNull(giftcode.FieldUsedAt) return u}
// SetDes sets the "des" field.func (u *GiftCodeUpsert) SetDes(v string) *GiftCodeUpsert { u.Set(giftcode.FieldDes, v) return u}
// UpdateDes sets the "des" field to the value that was provided on create.func (u *GiftCodeUpsert) UpdateDes() *GiftCodeUpsert { u.SetExcluded(giftcode.FieldDes) return u}
// ClearDes clears the value of the "des" field.func (u *GiftCodeUpsert) ClearDes() *GiftCodeUpsert { u.SetNull(giftcode.FieldDes) return u}
// UpdateNewValues updates the mutable fields using the new values that were set on create.// Using this option is equivalent to using://// client.GiftCode.Create().// OnConflict(// sql.ResolveWithNewValues(),// ).// Exec(ctx)func (u *GiftCodeUpsertOne) UpdateNewValues() *GiftCodeUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { if _, exists := u.create.mutation.CreatedAt(); exists { s.SetIgnore(giftcode.FieldCreatedAt) } })) return u}
// Ignore sets each column to itself in case of conflict.// Using this option is equivalent to using://// client.GiftCode.Create().// OnConflict(sql.ResolveWithIgnore()).// Exec(ctx)func (u *GiftCodeUpsertOne) Ignore() *GiftCodeUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u}
// DoNothing configures the conflict_action to `DO NOTHING`.// Supported only by SQLite and PostgreSQL.func (u *GiftCodeUpsertOne) DoNothing() *GiftCodeUpsertOne { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u}
// Update allows overriding fields `UPDATE` values. See the GiftCodeCreate.OnConflict// documentation for more info.func (u *GiftCodeUpsertOne) Update(set func(*GiftCodeUpsert)) *GiftCodeUpsertOne { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&GiftCodeUpsert{UpdateSet: update}) })) return u}
// SetUpdatedAt sets the "updated_at" field.func (u *GiftCodeUpsertOne) SetUpdatedAt(v time.Time) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.SetUpdatedAt(v) })}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.func (u *GiftCodeUpsertOne) UpdateUpdatedAt() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.UpdateUpdatedAt() })}
// SetDeletedAt sets the "deleted_at" field.func (u *GiftCodeUpsertOne) SetDeletedAt(v time.Time) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.SetDeletedAt(v) })}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.func (u *GiftCodeUpsertOne) UpdateDeletedAt() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.UpdateDeletedAt() })}
// ClearDeletedAt clears the value of the "deleted_at" field.func (u *GiftCodeUpsertOne) ClearDeletedAt() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.ClearDeletedAt() })}
// SetCode sets the "code" field.func (u *GiftCodeUpsertOne) SetCode(v string) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.SetCode(v) })}
// UpdateCode sets the "code" field to the value that was provided on create.func (u *GiftCodeUpsertOne) UpdateCode() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.UpdateCode() })}
// SetType sets the "type" field.func (u *GiftCodeUpsertOne) SetType(v giftcode.Type) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.SetType(v) })}
// UpdateType sets the "type" field to the value that was provided on create.func (u *GiftCodeUpsertOne) UpdateType() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.UpdateType() })}
// SetAmount sets the "amount" field.func (u *GiftCodeUpsertOne) SetAmount(v int64) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.SetAmount(v) })}
// AddAmount adds v to the "amount" field.func (u *GiftCodeUpsertOne) AddAmount(v int64) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.AddAmount(v) })}
// UpdateAmount sets the "amount" field to the value that was provided on create.func (u *GiftCodeUpsertOne) UpdateAmount() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.UpdateAmount() })}
// SetDuration sets the "duration" field.func (u *GiftCodeUpsertOne) SetDuration(v int64) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.SetDuration(v) })}
// AddDuration adds v to the "duration" field.func (u *GiftCodeUpsertOne) AddDuration(v int64) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.AddDuration(v) })}
// UpdateDuration sets the "duration" field to the value that was provided on create.func (u *GiftCodeUpsertOne) UpdateDuration() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.UpdateDuration() })}
// ClearDuration clears the value of the "duration" field.func (u *GiftCodeUpsertOne) ClearDuration() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.ClearDuration() })}
// SetUsedByID sets the "used_by_id" field.func (u *GiftCodeUpsertOne) SetUsedByID(v int) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.SetUsedByID(v) })}
// UpdateUsedByID sets the "used_by_id" field to the value that was provided on create.func (u *GiftCodeUpsertOne) UpdateUsedByID() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.UpdateUsedByID() })}
// ClearUsedByID clears the value of the "used_by_id" field.func (u *GiftCodeUpsertOne) ClearUsedByID() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.ClearUsedByID() })}
// SetUsedAt sets the "used_at" field.func (u *GiftCodeUpsertOne) SetUsedAt(v time.Time) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.SetUsedAt(v) })}
// UpdateUsedAt sets the "used_at" field to the value that was provided on create.func (u *GiftCodeUpsertOne) UpdateUsedAt() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.UpdateUsedAt() })}
// ClearUsedAt clears the value of the "used_at" field.func (u *GiftCodeUpsertOne) ClearUsedAt() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.ClearUsedAt() })}
// SetDes sets the "des" field.func (u *GiftCodeUpsertOne) SetDes(v string) *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.SetDes(v) })}
// UpdateDes sets the "des" field to the value that was provided on create.func (u *GiftCodeUpsertOne) UpdateDes() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.UpdateDes() })}
// ClearDes clears the value of the "des" field.func (u *GiftCodeUpsertOne) ClearDes() *GiftCodeUpsertOne { return u.Update(func(s *GiftCodeUpsert) { s.ClearDes() })}
// Exec executes the query.func (u *GiftCodeUpsertOne) Exec(ctx context.Context) error { if len(u.create.conflict) == 0 { return errors.New("ent: missing options for GiftCodeCreate.OnConflict") } return u.create.Exec(ctx)}
// ExecX is like Exec, but panics if an error occurs.func (u *GiftCodeUpsertOne) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) }}
// Exec executes the UPSERT query and returns the inserted/updated ID.func (u *GiftCodeUpsertOne) ID(ctx context.Context) (id int, err error) { node, err := u.create.Save(ctx) if err != nil { return id, err } return node.ID, nil}
// IDX is like ID, but panics if an error occurs.func (u *GiftCodeUpsertOne) IDX(ctx context.Context) int { id, err := u.ID(ctx) if err != nil { panic(err) } return id}
func (m *GiftCodeCreate) SetRawID(t int) *GiftCodeCreate { m.mutation.SetRawID(t) return m}
// GiftCodeCreateBulk is the builder for creating many GiftCode entities in bulk.type GiftCodeCreateBulk struct { config err error builders []*GiftCodeCreate conflict []sql.ConflictOption}
// Save creates the GiftCode entities in the database.func (gccb *GiftCodeCreateBulk) Save(ctx context.Context) ([]*GiftCode, error) { if gccb.err != nil { return nil, gccb.err } specs := make([]*sqlgraph.CreateSpec, len(gccb.builders)) nodes := make([]*GiftCode, len(gccb.builders)) mutators := make([]Mutator, len(gccb.builders)) for i := range gccb.builders { func(i int, root context.Context) { builder := gccb.builders[i] builder.defaults() var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { mutation, ok := m.(*GiftCodeMutation) 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, gccb.builders[i+1].mutation) } else { spec := &sqlgraph.BatchCreateSpec{Nodes: specs} spec.OnConflict = gccb.conflict // Invoke the actual operation on the latest mutation in the chain. if err = sqlgraph.BatchCreate(ctx, gccb.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, gccb.builders[0].mutation); err != nil { return nil, err } } return nodes, nil}
// SaveX is like Save, but panics if an error occurs.func (gccb *GiftCodeCreateBulk) SaveX(ctx context.Context) []*GiftCode { v, err := gccb.Save(ctx) if err != nil { panic(err) } return v}
// Exec executes the query.func (gccb *GiftCodeCreateBulk) Exec(ctx context.Context) error { _, err := gccb.Save(ctx) return err}
// ExecX is like Exec, but panics if an error occurs.func (gccb *GiftCodeCreateBulk) ExecX(ctx context.Context) { if err := gccb.Exec(ctx); err != nil { panic(err) }}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause// of the `INSERT` statement. For example://// client.GiftCode.CreateBulk(builders...).// OnConflict(// // Update the row with the new values// // the was proposed for insertion.// sql.ResolveWithNewValues(),// ).// // Override some of the fields with custom// // update values.// Update(func(u *ent.GiftCodeUpsert) {// SetCreatedAt(v+v).// }).// Exec(ctx)func (gccb *GiftCodeCreateBulk) OnConflict(opts ...sql.ConflictOption) *GiftCodeUpsertBulk { gccb.conflict = opts return &GiftCodeUpsertBulk{ create: gccb, }}
// OnConflictColumns calls `OnConflict` and configures the columns// as conflict target. Using this option is equivalent to using://// client.GiftCode.Create().// OnConflict(sql.ConflictColumns(columns...)).// Exec(ctx)func (gccb *GiftCodeCreateBulk) OnConflictColumns(columns ...string) *GiftCodeUpsertBulk { gccb.conflict = append(gccb.conflict, sql.ConflictColumns(columns...)) return &GiftCodeUpsertBulk{ create: gccb, }}
// GiftCodeUpsertBulk is the builder for "upsert"-ing// a bulk of GiftCode nodes.type GiftCodeUpsertBulk struct { create *GiftCodeCreateBulk}
// UpdateNewValues updates the mutable fields using the new values that// were set on create. Using this option is equivalent to using://// client.GiftCode.Create().// OnConflict(// sql.ResolveWithNewValues(),// ).// Exec(ctx)func (u *GiftCodeUpsertBulk) UpdateNewValues() *GiftCodeUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { for _, b := range u.create.builders { if _, exists := b.mutation.CreatedAt(); exists { s.SetIgnore(giftcode.FieldCreatedAt) } } })) return u}
// Ignore sets each column to itself in case of conflict.// Using this option is equivalent to using://// client.GiftCode.Create().// OnConflict(sql.ResolveWithIgnore()).// Exec(ctx)func (u *GiftCodeUpsertBulk) Ignore() *GiftCodeUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) return u}
// DoNothing configures the conflict_action to `DO NOTHING`.// Supported only by SQLite and PostgreSQL.func (u *GiftCodeUpsertBulk) DoNothing() *GiftCodeUpsertBulk { u.create.conflict = append(u.create.conflict, sql.DoNothing()) return u}
// Update allows overriding fields `UPDATE` values. See the GiftCodeCreateBulk.OnConflict// documentation for more info.func (u *GiftCodeUpsertBulk) Update(set func(*GiftCodeUpsert)) *GiftCodeUpsertBulk { u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { set(&GiftCodeUpsert{UpdateSet: update}) })) return u}
// SetUpdatedAt sets the "updated_at" field.func (u *GiftCodeUpsertBulk) SetUpdatedAt(v time.Time) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.SetUpdatedAt(v) })}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.func (u *GiftCodeUpsertBulk) UpdateUpdatedAt() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.UpdateUpdatedAt() })}
// SetDeletedAt sets the "deleted_at" field.func (u *GiftCodeUpsertBulk) SetDeletedAt(v time.Time) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.SetDeletedAt(v) })}
// UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.func (u *GiftCodeUpsertBulk) UpdateDeletedAt() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.UpdateDeletedAt() })}
// ClearDeletedAt clears the value of the "deleted_at" field.func (u *GiftCodeUpsertBulk) ClearDeletedAt() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.ClearDeletedAt() })}
// SetCode sets the "code" field.func (u *GiftCodeUpsertBulk) SetCode(v string) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.SetCode(v) })}
// UpdateCode sets the "code" field to the value that was provided on create.func (u *GiftCodeUpsertBulk) UpdateCode() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.UpdateCode() })}
// SetType sets the "type" field.func (u *GiftCodeUpsertBulk) SetType(v giftcode.Type) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.SetType(v) })}
// UpdateType sets the "type" field to the value that was provided on create.func (u *GiftCodeUpsertBulk) UpdateType() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.UpdateType() })}
// SetAmount sets the "amount" field.func (u *GiftCodeUpsertBulk) SetAmount(v int64) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.SetAmount(v) })}
// AddAmount adds v to the "amount" field.func (u *GiftCodeUpsertBulk) AddAmount(v int64) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.AddAmount(v) })}
// UpdateAmount sets the "amount" field to the value that was provided on create.func (u *GiftCodeUpsertBulk) UpdateAmount() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.UpdateAmount() })}
// SetDuration sets the "duration" field.func (u *GiftCodeUpsertBulk) SetDuration(v int64) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.SetDuration(v) })}
// AddDuration adds v to the "duration" field.func (u *GiftCodeUpsertBulk) AddDuration(v int64) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.AddDuration(v) })}
// UpdateDuration sets the "duration" field to the value that was provided on create.func (u *GiftCodeUpsertBulk) UpdateDuration() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.UpdateDuration() })}
// ClearDuration clears the value of the "duration" field.func (u *GiftCodeUpsertBulk) ClearDuration() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.ClearDuration() })}
// SetUsedByID sets the "used_by_id" field.func (u *GiftCodeUpsertBulk) SetUsedByID(v int) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.SetUsedByID(v) })}
// UpdateUsedByID sets the "used_by_id" field to the value that was provided on create.func (u *GiftCodeUpsertBulk) UpdateUsedByID() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.UpdateUsedByID() })}
// ClearUsedByID clears the value of the "used_by_id" field.func (u *GiftCodeUpsertBulk) ClearUsedByID() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.ClearUsedByID() })}
// SetUsedAt sets the "used_at" field.func (u *GiftCodeUpsertBulk) SetUsedAt(v time.Time) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.SetUsedAt(v) })}
// UpdateUsedAt sets the "used_at" field to the value that was provided on create.func (u *GiftCodeUpsertBulk) UpdateUsedAt() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.UpdateUsedAt() })}
// ClearUsedAt clears the value of the "used_at" field.func (u *GiftCodeUpsertBulk) ClearUsedAt() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.ClearUsedAt() })}
// SetDes sets the "des" field.func (u *GiftCodeUpsertBulk) SetDes(v string) *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.SetDes(v) })}
// UpdateDes sets the "des" field to the value that was provided on create.func (u *GiftCodeUpsertBulk) UpdateDes() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.UpdateDes() })}
// ClearDes clears the value of the "des" field.func (u *GiftCodeUpsertBulk) ClearDes() *GiftCodeUpsertBulk { return u.Update(func(s *GiftCodeUpsert) { s.ClearDes() })}
// Exec executes the query.func (u *GiftCodeUpsertBulk) Exec(ctx context.Context) error { if u.create.err != nil { return u.create.err } for i, b := range u.create.builders { if len(b.conflict) != 0 { return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the GiftCodeCreateBulk instead", i) } } if len(u.create.conflict) == 0 { return errors.New("ent: missing options for GiftCodeCreateBulk.OnConflict") } return u.create.Exec(ctx)}
// ExecX is like Exec, but panics if an error occurs.func (u *GiftCodeUpsertBulk) ExecX(ctx context.Context) { if err := u.create.Exec(ctx); err != nil { panic(err) }}