123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/employee"
- "wechat-api/ent/workexperience"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // WorkExperienceCreate is the builder for creating a WorkExperience entity.
- type WorkExperienceCreate struct {
- config
- mutation *WorkExperienceMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetCreatedAt sets the "created_at" field.
- func (wec *WorkExperienceCreate) SetCreatedAt(t time.Time) *WorkExperienceCreate {
- wec.mutation.SetCreatedAt(t)
- return wec
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (wec *WorkExperienceCreate) SetNillableCreatedAt(t *time.Time) *WorkExperienceCreate {
- if t != nil {
- wec.SetCreatedAt(*t)
- }
- return wec
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (wec *WorkExperienceCreate) SetUpdatedAt(t time.Time) *WorkExperienceCreate {
- wec.mutation.SetUpdatedAt(t)
- return wec
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (wec *WorkExperienceCreate) SetNillableUpdatedAt(t *time.Time) *WorkExperienceCreate {
- if t != nil {
- wec.SetUpdatedAt(*t)
- }
- return wec
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (wec *WorkExperienceCreate) SetDeletedAt(t time.Time) *WorkExperienceCreate {
- wec.mutation.SetDeletedAt(t)
- return wec
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (wec *WorkExperienceCreate) SetNillableDeletedAt(t *time.Time) *WorkExperienceCreate {
- if t != nil {
- wec.SetDeletedAt(*t)
- }
- return wec
- }
- // SetEmployeeID sets the "employee_id" field.
- func (wec *WorkExperienceCreate) SetEmployeeID(u uint64) *WorkExperienceCreate {
- wec.mutation.SetEmployeeID(u)
- return wec
- }
- // SetStartDate sets the "start_date" field.
- func (wec *WorkExperienceCreate) SetStartDate(t time.Time) *WorkExperienceCreate {
- wec.mutation.SetStartDate(t)
- return wec
- }
- // SetEndDate sets the "end_date" field.
- func (wec *WorkExperienceCreate) SetEndDate(t time.Time) *WorkExperienceCreate {
- wec.mutation.SetEndDate(t)
- return wec
- }
- // SetCompany sets the "company" field.
- func (wec *WorkExperienceCreate) SetCompany(s string) *WorkExperienceCreate {
- wec.mutation.SetCompany(s)
- return wec
- }
- // SetExperience sets the "experience" field.
- func (wec *WorkExperienceCreate) SetExperience(s string) *WorkExperienceCreate {
- wec.mutation.SetExperience(s)
- return wec
- }
- // SetOrganizationID sets the "organization_id" field.
- func (wec *WorkExperienceCreate) SetOrganizationID(u uint64) *WorkExperienceCreate {
- wec.mutation.SetOrganizationID(u)
- return wec
- }
- // SetID sets the "id" field.
- func (wec *WorkExperienceCreate) SetID(u uint64) *WorkExperienceCreate {
- wec.mutation.SetID(u)
- return wec
- }
- // SetEmployee sets the "employee" edge to the Employee entity.
- func (wec *WorkExperienceCreate) SetEmployee(e *Employee) *WorkExperienceCreate {
- return wec.SetEmployeeID(e.ID)
- }
- // Mutation returns the WorkExperienceMutation object of the builder.
- func (wec *WorkExperienceCreate) Mutation() *WorkExperienceMutation {
- return wec.mutation
- }
- // Save creates the WorkExperience in the database.
- func (wec *WorkExperienceCreate) Save(ctx context.Context) (*WorkExperience, error) {
- if err := wec.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, wec.sqlSave, wec.mutation, wec.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (wec *WorkExperienceCreate) SaveX(ctx context.Context) *WorkExperience {
- v, err := wec.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (wec *WorkExperienceCreate) Exec(ctx context.Context) error {
- _, err := wec.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (wec *WorkExperienceCreate) ExecX(ctx context.Context) {
- if err := wec.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (wec *WorkExperienceCreate) defaults() error {
- if _, ok := wec.mutation.CreatedAt(); !ok {
- if workexperience.DefaultCreatedAt == nil {
- return fmt.Errorf("ent: uninitialized workexperience.DefaultCreatedAt (forgotten import ent/runtime?)")
- }
- v := workexperience.DefaultCreatedAt()
- wec.mutation.SetCreatedAt(v)
- }
- if _, ok := wec.mutation.UpdatedAt(); !ok {
- if workexperience.DefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized workexperience.DefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := workexperience.DefaultUpdatedAt()
- wec.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (wec *WorkExperienceCreate) check() error {
- if _, ok := wec.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "WorkExperience.created_at"`)}
- }
- if _, ok := wec.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "WorkExperience.updated_at"`)}
- }
- if _, ok := wec.mutation.EmployeeID(); !ok {
- return &ValidationError{Name: "employee_id", err: errors.New(`ent: missing required field "WorkExperience.employee_id"`)}
- }
- if _, ok := wec.mutation.StartDate(); !ok {
- return &ValidationError{Name: "start_date", err: errors.New(`ent: missing required field "WorkExperience.start_date"`)}
- }
- if _, ok := wec.mutation.EndDate(); !ok {
- return &ValidationError{Name: "end_date", err: errors.New(`ent: missing required field "WorkExperience.end_date"`)}
- }
- if _, ok := wec.mutation.Company(); !ok {
- return &ValidationError{Name: "company", err: errors.New(`ent: missing required field "WorkExperience.company"`)}
- }
- if _, ok := wec.mutation.Experience(); !ok {
- return &ValidationError{Name: "experience", err: errors.New(`ent: missing required field "WorkExperience.experience"`)}
- }
- if _, ok := wec.mutation.OrganizationID(); !ok {
- return &ValidationError{Name: "organization_id", err: errors.New(`ent: missing required field "WorkExperience.organization_id"`)}
- }
- if _, ok := wec.mutation.EmployeeID(); !ok {
- return &ValidationError{Name: "employee", err: errors.New(`ent: missing required edge "WorkExperience.employee"`)}
- }
- return nil
- }
- func (wec *WorkExperienceCreate) sqlSave(ctx context.Context) (*WorkExperience, error) {
- if err := wec.check(); err != nil {
- return nil, err
- }
- _node, _spec := wec.createSpec()
- if err := sqlgraph.CreateNode(ctx, wec.driver, _spec); err != nil {
- if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- if _spec.ID.Value != _node.ID {
- id := _spec.ID.Value.(int64)
- _node.ID = uint64(id)
- }
- wec.mutation.id = &_node.ID
- wec.mutation.done = true
- return _node, nil
- }
- func (wec *WorkExperienceCreate) createSpec() (*WorkExperience, *sqlgraph.CreateSpec) {
- var (
- _node = &WorkExperience{config: wec.config}
- _spec = sqlgraph.NewCreateSpec(workexperience.Table, sqlgraph.NewFieldSpec(workexperience.FieldID, field.TypeUint64))
- )
- _spec.OnConflict = wec.conflict
- if id, ok := wec.mutation.ID(); ok {
- _node.ID = id
- _spec.ID.Value = id
- }
- if value, ok := wec.mutation.CreatedAt(); ok {
- _spec.SetField(workexperience.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := wec.mutation.UpdatedAt(); ok {
- _spec.SetField(workexperience.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if value, ok := wec.mutation.DeletedAt(); ok {
- _spec.SetField(workexperience.FieldDeletedAt, field.TypeTime, value)
- _node.DeletedAt = value
- }
- if value, ok := wec.mutation.StartDate(); ok {
- _spec.SetField(workexperience.FieldStartDate, field.TypeTime, value)
- _node.StartDate = value
- }
- if value, ok := wec.mutation.EndDate(); ok {
- _spec.SetField(workexperience.FieldEndDate, field.TypeTime, value)
- _node.EndDate = value
- }
- if value, ok := wec.mutation.Company(); ok {
- _spec.SetField(workexperience.FieldCompany, field.TypeString, value)
- _node.Company = value
- }
- if value, ok := wec.mutation.Experience(); ok {
- _spec.SetField(workexperience.FieldExperience, field.TypeString, value)
- _node.Experience = value
- }
- if value, ok := wec.mutation.OrganizationID(); ok {
- _spec.SetField(workexperience.FieldOrganizationID, field.TypeUint64, value)
- _node.OrganizationID = value
- }
- if nodes := wec.mutation.EmployeeIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: workexperience.EmployeeTable,
- Columns: []string{workexperience.EmployeeColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(employee.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _node.EmployeeID = 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.WorkExperience.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.WorkExperienceUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (wec *WorkExperienceCreate) OnConflict(opts ...sql.ConflictOption) *WorkExperienceUpsertOne {
- wec.conflict = opts
- return &WorkExperienceUpsertOne{
- create: wec,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.WorkExperience.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (wec *WorkExperienceCreate) OnConflictColumns(columns ...string) *WorkExperienceUpsertOne {
- wec.conflict = append(wec.conflict, sql.ConflictColumns(columns...))
- return &WorkExperienceUpsertOne{
- create: wec,
- }
- }
- type (
- // WorkExperienceUpsertOne is the builder for "upsert"-ing
- // one WorkExperience node.
- WorkExperienceUpsertOne struct {
- create *WorkExperienceCreate
- }
- // WorkExperienceUpsert is the "OnConflict" setter.
- WorkExperienceUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetUpdatedAt sets the "updated_at" field.
- func (u *WorkExperienceUpsert) SetUpdatedAt(v time.Time) *WorkExperienceUpsert {
- u.Set(workexperience.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *WorkExperienceUpsert) UpdateUpdatedAt() *WorkExperienceUpsert {
- u.SetExcluded(workexperience.FieldUpdatedAt)
- return u
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *WorkExperienceUpsert) SetDeletedAt(v time.Time) *WorkExperienceUpsert {
- u.Set(workexperience.FieldDeletedAt, v)
- return u
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *WorkExperienceUpsert) UpdateDeletedAt() *WorkExperienceUpsert {
- u.SetExcluded(workexperience.FieldDeletedAt)
- return u
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *WorkExperienceUpsert) ClearDeletedAt() *WorkExperienceUpsert {
- u.SetNull(workexperience.FieldDeletedAt)
- return u
- }
- // SetEmployeeID sets the "employee_id" field.
- func (u *WorkExperienceUpsert) SetEmployeeID(v uint64) *WorkExperienceUpsert {
- u.Set(workexperience.FieldEmployeeID, v)
- return u
- }
- // UpdateEmployeeID sets the "employee_id" field to the value that was provided on create.
- func (u *WorkExperienceUpsert) UpdateEmployeeID() *WorkExperienceUpsert {
- u.SetExcluded(workexperience.FieldEmployeeID)
- return u
- }
- // SetStartDate sets the "start_date" field.
- func (u *WorkExperienceUpsert) SetStartDate(v time.Time) *WorkExperienceUpsert {
- u.Set(workexperience.FieldStartDate, v)
- return u
- }
- // UpdateStartDate sets the "start_date" field to the value that was provided on create.
- func (u *WorkExperienceUpsert) UpdateStartDate() *WorkExperienceUpsert {
- u.SetExcluded(workexperience.FieldStartDate)
- return u
- }
- // SetEndDate sets the "end_date" field.
- func (u *WorkExperienceUpsert) SetEndDate(v time.Time) *WorkExperienceUpsert {
- u.Set(workexperience.FieldEndDate, v)
- return u
- }
- // UpdateEndDate sets the "end_date" field to the value that was provided on create.
- func (u *WorkExperienceUpsert) UpdateEndDate() *WorkExperienceUpsert {
- u.SetExcluded(workexperience.FieldEndDate)
- return u
- }
- // SetCompany sets the "company" field.
- func (u *WorkExperienceUpsert) SetCompany(v string) *WorkExperienceUpsert {
- u.Set(workexperience.FieldCompany, v)
- return u
- }
- // UpdateCompany sets the "company" field to the value that was provided on create.
- func (u *WorkExperienceUpsert) UpdateCompany() *WorkExperienceUpsert {
- u.SetExcluded(workexperience.FieldCompany)
- return u
- }
- // SetExperience sets the "experience" field.
- func (u *WorkExperienceUpsert) SetExperience(v string) *WorkExperienceUpsert {
- u.Set(workexperience.FieldExperience, v)
- return u
- }
- // UpdateExperience sets the "experience" field to the value that was provided on create.
- func (u *WorkExperienceUpsert) UpdateExperience() *WorkExperienceUpsert {
- u.SetExcluded(workexperience.FieldExperience)
- return u
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *WorkExperienceUpsert) SetOrganizationID(v uint64) *WorkExperienceUpsert {
- u.Set(workexperience.FieldOrganizationID, v)
- return u
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *WorkExperienceUpsert) UpdateOrganizationID() *WorkExperienceUpsert {
- u.SetExcluded(workexperience.FieldOrganizationID)
- return u
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *WorkExperienceUpsert) AddOrganizationID(v uint64) *WorkExperienceUpsert {
- u.Add(workexperience.FieldOrganizationID, v)
- return u
- }
- // UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field.
- // Using this option is equivalent to using:
- //
- // client.WorkExperience.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(workexperience.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *WorkExperienceUpsertOne) UpdateNewValues() *WorkExperienceUpsertOne {
- 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.ID(); exists {
- s.SetIgnore(workexperience.FieldID)
- }
- if _, exists := u.create.mutation.CreatedAt(); exists {
- s.SetIgnore(workexperience.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.WorkExperience.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *WorkExperienceUpsertOne) Ignore() *WorkExperienceUpsertOne {
- 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 *WorkExperienceUpsertOne) DoNothing() *WorkExperienceUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the WorkExperienceCreate.OnConflict
- // documentation for more info.
- func (u *WorkExperienceUpsertOne) Update(set func(*WorkExperienceUpsert)) *WorkExperienceUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&WorkExperienceUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *WorkExperienceUpsertOne) SetUpdatedAt(v time.Time) *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *WorkExperienceUpsertOne) UpdateUpdatedAt() *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *WorkExperienceUpsertOne) SetDeletedAt(v time.Time) *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *WorkExperienceUpsertOne) UpdateDeletedAt() *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *WorkExperienceUpsertOne) ClearDeletedAt() *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetEmployeeID sets the "employee_id" field.
- func (u *WorkExperienceUpsertOne) SetEmployeeID(v uint64) *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetEmployeeID(v)
- })
- }
- // UpdateEmployeeID sets the "employee_id" field to the value that was provided on create.
- func (u *WorkExperienceUpsertOne) UpdateEmployeeID() *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateEmployeeID()
- })
- }
- // SetStartDate sets the "start_date" field.
- func (u *WorkExperienceUpsertOne) SetStartDate(v time.Time) *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetStartDate(v)
- })
- }
- // UpdateStartDate sets the "start_date" field to the value that was provided on create.
- func (u *WorkExperienceUpsertOne) UpdateStartDate() *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateStartDate()
- })
- }
- // SetEndDate sets the "end_date" field.
- func (u *WorkExperienceUpsertOne) SetEndDate(v time.Time) *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetEndDate(v)
- })
- }
- // UpdateEndDate sets the "end_date" field to the value that was provided on create.
- func (u *WorkExperienceUpsertOne) UpdateEndDate() *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateEndDate()
- })
- }
- // SetCompany sets the "company" field.
- func (u *WorkExperienceUpsertOne) SetCompany(v string) *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetCompany(v)
- })
- }
- // UpdateCompany sets the "company" field to the value that was provided on create.
- func (u *WorkExperienceUpsertOne) UpdateCompany() *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateCompany()
- })
- }
- // SetExperience sets the "experience" field.
- func (u *WorkExperienceUpsertOne) SetExperience(v string) *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetExperience(v)
- })
- }
- // UpdateExperience sets the "experience" field to the value that was provided on create.
- func (u *WorkExperienceUpsertOne) UpdateExperience() *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateExperience()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *WorkExperienceUpsertOne) SetOrganizationID(v uint64) *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *WorkExperienceUpsertOne) AddOrganizationID(v uint64) *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *WorkExperienceUpsertOne) UpdateOrganizationID() *WorkExperienceUpsertOne {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // Exec executes the query.
- func (u *WorkExperienceUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for WorkExperienceCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *WorkExperienceUpsertOne) 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 *WorkExperienceUpsertOne) ID(ctx context.Context) (id uint64, 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 *WorkExperienceUpsertOne) IDX(ctx context.Context) uint64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // WorkExperienceCreateBulk is the builder for creating many WorkExperience entities in bulk.
- type WorkExperienceCreateBulk struct {
- config
- err error
- builders []*WorkExperienceCreate
- conflict []sql.ConflictOption
- }
- // Save creates the WorkExperience entities in the database.
- func (wecb *WorkExperienceCreateBulk) Save(ctx context.Context) ([]*WorkExperience, error) {
- if wecb.err != nil {
- return nil, wecb.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(wecb.builders))
- nodes := make([]*WorkExperience, len(wecb.builders))
- mutators := make([]Mutator, len(wecb.builders))
- for i := range wecb.builders {
- func(i int, root context.Context) {
- builder := wecb.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*WorkExperienceMutation)
- 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, wecb.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = wecb.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, wecb.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 && nodes[i].ID == 0 {
- id := specs[i].ID.Value.(int64)
- nodes[i].ID = uint64(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, wecb.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (wecb *WorkExperienceCreateBulk) SaveX(ctx context.Context) []*WorkExperience {
- v, err := wecb.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (wecb *WorkExperienceCreateBulk) Exec(ctx context.Context) error {
- _, err := wecb.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (wecb *WorkExperienceCreateBulk) ExecX(ctx context.Context) {
- if err := wecb.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.WorkExperience.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.WorkExperienceUpsert) {
- // SetCreatedAt(v+v).
- // }).
- // Exec(ctx)
- func (wecb *WorkExperienceCreateBulk) OnConflict(opts ...sql.ConflictOption) *WorkExperienceUpsertBulk {
- wecb.conflict = opts
- return &WorkExperienceUpsertBulk{
- create: wecb,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.WorkExperience.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (wecb *WorkExperienceCreateBulk) OnConflictColumns(columns ...string) *WorkExperienceUpsertBulk {
- wecb.conflict = append(wecb.conflict, sql.ConflictColumns(columns...))
- return &WorkExperienceUpsertBulk{
- create: wecb,
- }
- }
- // WorkExperienceUpsertBulk is the builder for "upsert"-ing
- // a bulk of WorkExperience nodes.
- type WorkExperienceUpsertBulk struct {
- create *WorkExperienceCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.WorkExperience.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // sql.ResolveWith(func(u *sql.UpdateSet) {
- // u.SetIgnore(workexperience.FieldID)
- // }),
- // ).
- // Exec(ctx)
- func (u *WorkExperienceUpsertBulk) UpdateNewValues() *WorkExperienceUpsertBulk {
- 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.ID(); exists {
- s.SetIgnore(workexperience.FieldID)
- }
- if _, exists := b.mutation.CreatedAt(); exists {
- s.SetIgnore(workexperience.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.WorkExperience.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *WorkExperienceUpsertBulk) Ignore() *WorkExperienceUpsertBulk {
- 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 *WorkExperienceUpsertBulk) DoNothing() *WorkExperienceUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the WorkExperienceCreateBulk.OnConflict
- // documentation for more info.
- func (u *WorkExperienceUpsertBulk) Update(set func(*WorkExperienceUpsert)) *WorkExperienceUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&WorkExperienceUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *WorkExperienceUpsertBulk) SetUpdatedAt(v time.Time) *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *WorkExperienceUpsertBulk) UpdateUpdatedAt() *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (u *WorkExperienceUpsertBulk) SetDeletedAt(v time.Time) *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetDeletedAt(v)
- })
- }
- // UpdateDeletedAt sets the "deleted_at" field to the value that was provided on create.
- func (u *WorkExperienceUpsertBulk) UpdateDeletedAt() *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateDeletedAt()
- })
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (u *WorkExperienceUpsertBulk) ClearDeletedAt() *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.ClearDeletedAt()
- })
- }
- // SetEmployeeID sets the "employee_id" field.
- func (u *WorkExperienceUpsertBulk) SetEmployeeID(v uint64) *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetEmployeeID(v)
- })
- }
- // UpdateEmployeeID sets the "employee_id" field to the value that was provided on create.
- func (u *WorkExperienceUpsertBulk) UpdateEmployeeID() *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateEmployeeID()
- })
- }
- // SetStartDate sets the "start_date" field.
- func (u *WorkExperienceUpsertBulk) SetStartDate(v time.Time) *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetStartDate(v)
- })
- }
- // UpdateStartDate sets the "start_date" field to the value that was provided on create.
- func (u *WorkExperienceUpsertBulk) UpdateStartDate() *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateStartDate()
- })
- }
- // SetEndDate sets the "end_date" field.
- func (u *WorkExperienceUpsertBulk) SetEndDate(v time.Time) *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetEndDate(v)
- })
- }
- // UpdateEndDate sets the "end_date" field to the value that was provided on create.
- func (u *WorkExperienceUpsertBulk) UpdateEndDate() *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateEndDate()
- })
- }
- // SetCompany sets the "company" field.
- func (u *WorkExperienceUpsertBulk) SetCompany(v string) *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetCompany(v)
- })
- }
- // UpdateCompany sets the "company" field to the value that was provided on create.
- func (u *WorkExperienceUpsertBulk) UpdateCompany() *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateCompany()
- })
- }
- // SetExperience sets the "experience" field.
- func (u *WorkExperienceUpsertBulk) SetExperience(v string) *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetExperience(v)
- })
- }
- // UpdateExperience sets the "experience" field to the value that was provided on create.
- func (u *WorkExperienceUpsertBulk) UpdateExperience() *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateExperience()
- })
- }
- // SetOrganizationID sets the "organization_id" field.
- func (u *WorkExperienceUpsertBulk) SetOrganizationID(v uint64) *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.SetOrganizationID(v)
- })
- }
- // AddOrganizationID adds v to the "organization_id" field.
- func (u *WorkExperienceUpsertBulk) AddOrganizationID(v uint64) *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.AddOrganizationID(v)
- })
- }
- // UpdateOrganizationID sets the "organization_id" field to the value that was provided on create.
- func (u *WorkExperienceUpsertBulk) UpdateOrganizationID() *WorkExperienceUpsertBulk {
- return u.Update(func(s *WorkExperienceUpsert) {
- s.UpdateOrganizationID()
- })
- }
- // Exec executes the query.
- func (u *WorkExperienceUpsertBulk) 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 WorkExperienceCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for WorkExperienceCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *WorkExperienceUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|