| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229 |
- // 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/Wei-Shaw/sub2api/ent/announcement"
- "github.com/Wei-Shaw/sub2api/ent/announcementread"
- "github.com/Wei-Shaw/sub2api/internal/domain"
- )
- // AnnouncementCreate is the builder for creating a Announcement entity.
- type AnnouncementCreate struct {
- config
- mutation *AnnouncementMutation
- hooks []Hook
- conflict []sql.ConflictOption
- }
- // SetTitle sets the "title" field.
- func (_c *AnnouncementCreate) SetTitle(v string) *AnnouncementCreate {
- _c.mutation.SetTitle(v)
- return _c
- }
- // SetContent sets the "content" field.
- func (_c *AnnouncementCreate) SetContent(v string) *AnnouncementCreate {
- _c.mutation.SetContent(v)
- return _c
- }
- // SetStatus sets the "status" field.
- func (_c *AnnouncementCreate) SetStatus(v string) *AnnouncementCreate {
- _c.mutation.SetStatus(v)
- return _c
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (_c *AnnouncementCreate) SetNillableStatus(v *string) *AnnouncementCreate {
- if v != nil {
- _c.SetStatus(*v)
- }
- return _c
- }
- // SetNotifyMode sets the "notify_mode" field.
- func (_c *AnnouncementCreate) SetNotifyMode(v string) *AnnouncementCreate {
- _c.mutation.SetNotifyMode(v)
- return _c
- }
- // SetNillableNotifyMode sets the "notify_mode" field if the given value is not nil.
- func (_c *AnnouncementCreate) SetNillableNotifyMode(v *string) *AnnouncementCreate {
- if v != nil {
- _c.SetNotifyMode(*v)
- }
- return _c
- }
- // SetTargeting sets the "targeting" field.
- func (_c *AnnouncementCreate) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementCreate {
- _c.mutation.SetTargeting(v)
- return _c
- }
- // SetNillableTargeting sets the "targeting" field if the given value is not nil.
- func (_c *AnnouncementCreate) SetNillableTargeting(v *domain.AnnouncementTargeting) *AnnouncementCreate {
- if v != nil {
- _c.SetTargeting(*v)
- }
- return _c
- }
- // SetStartsAt sets the "starts_at" field.
- func (_c *AnnouncementCreate) SetStartsAt(v time.Time) *AnnouncementCreate {
- _c.mutation.SetStartsAt(v)
- return _c
- }
- // SetNillableStartsAt sets the "starts_at" field if the given value is not nil.
- func (_c *AnnouncementCreate) SetNillableStartsAt(v *time.Time) *AnnouncementCreate {
- if v != nil {
- _c.SetStartsAt(*v)
- }
- return _c
- }
- // SetEndsAt sets the "ends_at" field.
- func (_c *AnnouncementCreate) SetEndsAt(v time.Time) *AnnouncementCreate {
- _c.mutation.SetEndsAt(v)
- return _c
- }
- // SetNillableEndsAt sets the "ends_at" field if the given value is not nil.
- func (_c *AnnouncementCreate) SetNillableEndsAt(v *time.Time) *AnnouncementCreate {
- if v != nil {
- _c.SetEndsAt(*v)
- }
- return _c
- }
- // SetCreatedBy sets the "created_by" field.
- func (_c *AnnouncementCreate) SetCreatedBy(v int64) *AnnouncementCreate {
- _c.mutation.SetCreatedBy(v)
- return _c
- }
- // SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
- func (_c *AnnouncementCreate) SetNillableCreatedBy(v *int64) *AnnouncementCreate {
- if v != nil {
- _c.SetCreatedBy(*v)
- }
- return _c
- }
- // SetUpdatedBy sets the "updated_by" field.
- func (_c *AnnouncementCreate) SetUpdatedBy(v int64) *AnnouncementCreate {
- _c.mutation.SetUpdatedBy(v)
- return _c
- }
- // SetNillableUpdatedBy sets the "updated_by" field if the given value is not nil.
- func (_c *AnnouncementCreate) SetNillableUpdatedBy(v *int64) *AnnouncementCreate {
- if v != nil {
- _c.SetUpdatedBy(*v)
- }
- return _c
- }
- // SetCreatedAt sets the "created_at" field.
- func (_c *AnnouncementCreate) SetCreatedAt(v time.Time) *AnnouncementCreate {
- _c.mutation.SetCreatedAt(v)
- return _c
- }
- // SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
- func (_c *AnnouncementCreate) SetNillableCreatedAt(v *time.Time) *AnnouncementCreate {
- if v != nil {
- _c.SetCreatedAt(*v)
- }
- return _c
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_c *AnnouncementCreate) SetUpdatedAt(v time.Time) *AnnouncementCreate {
- _c.mutation.SetUpdatedAt(v)
- return _c
- }
- // SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
- func (_c *AnnouncementCreate) SetNillableUpdatedAt(v *time.Time) *AnnouncementCreate {
- if v != nil {
- _c.SetUpdatedAt(*v)
- }
- return _c
- }
- // AddReadIDs adds the "reads" edge to the AnnouncementRead entity by IDs.
- func (_c *AnnouncementCreate) AddReadIDs(ids ...int64) *AnnouncementCreate {
- _c.mutation.AddReadIDs(ids...)
- return _c
- }
- // AddReads adds the "reads" edges to the AnnouncementRead entity.
- func (_c *AnnouncementCreate) AddReads(v ...*AnnouncementRead) *AnnouncementCreate {
- ids := make([]int64, len(v))
- for i := range v {
- ids[i] = v[i].ID
- }
- return _c.AddReadIDs(ids...)
- }
- // Mutation returns the AnnouncementMutation object of the builder.
- func (_c *AnnouncementCreate) Mutation() *AnnouncementMutation {
- return _c.mutation
- }
- // Save creates the Announcement in the database.
- func (_c *AnnouncementCreate) Save(ctx context.Context) (*Announcement, error) {
- _c.defaults()
- return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
- }
- // SaveX calls Save and panics if Save returns an error.
- func (_c *AnnouncementCreate) SaveX(ctx context.Context) *Announcement {
- v, err := _c.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (_c *AnnouncementCreate) Exec(ctx context.Context) error {
- _, err := _c.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_c *AnnouncementCreate) ExecX(ctx context.Context) {
- if err := _c.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_c *AnnouncementCreate) defaults() {
- if _, ok := _c.mutation.Status(); !ok {
- v := announcement.DefaultStatus
- _c.mutation.SetStatus(v)
- }
- if _, ok := _c.mutation.NotifyMode(); !ok {
- v := announcement.DefaultNotifyMode
- _c.mutation.SetNotifyMode(v)
- }
- if _, ok := _c.mutation.CreatedAt(); !ok {
- v := announcement.DefaultCreatedAt()
- _c.mutation.SetCreatedAt(v)
- }
- if _, ok := _c.mutation.UpdatedAt(); !ok {
- v := announcement.DefaultUpdatedAt()
- _c.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_c *AnnouncementCreate) check() error {
- if _, ok := _c.mutation.Title(); !ok {
- return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Announcement.title"`)}
- }
- if v, ok := _c.mutation.Title(); ok {
- if err := announcement.TitleValidator(v); err != nil {
- return &ValidationError{Name: "title", err: fmt.Errorf(`ent: validator failed for field "Announcement.title": %w`, err)}
- }
- }
- if _, ok := _c.mutation.Content(); !ok {
- return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "Announcement.content"`)}
- }
- if v, ok := _c.mutation.Content(); ok {
- if err := announcement.ContentValidator(v); err != nil {
- return &ValidationError{Name: "content", err: fmt.Errorf(`ent: validator failed for field "Announcement.content": %w`, err)}
- }
- }
- if _, ok := _c.mutation.Status(); !ok {
- return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Announcement.status"`)}
- }
- if v, ok := _c.mutation.Status(); ok {
- if err := announcement.StatusValidator(v); err != nil {
- return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Announcement.status": %w`, err)}
- }
- }
- if _, ok := _c.mutation.NotifyMode(); !ok {
- return &ValidationError{Name: "notify_mode", err: errors.New(`ent: missing required field "Announcement.notify_mode"`)}
- }
- if v, ok := _c.mutation.NotifyMode(); ok {
- if err := announcement.NotifyModeValidator(v); err != nil {
- return &ValidationError{Name: "notify_mode", err: fmt.Errorf(`ent: validator failed for field "Announcement.notify_mode": %w`, err)}
- }
- }
- if _, ok := _c.mutation.CreatedAt(); !ok {
- return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Announcement.created_at"`)}
- }
- if _, ok := _c.mutation.UpdatedAt(); !ok {
- return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Announcement.updated_at"`)}
- }
- return nil
- }
- func (_c *AnnouncementCreate) sqlSave(ctx context.Context) (*Announcement, error) {
- if err := _c.check(); err != nil {
- return nil, err
- }
- _node, _spec := _c.createSpec()
- if err := sqlgraph.CreateNode(ctx, _c.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 = int64(id)
- _c.mutation.id = &_node.ID
- _c.mutation.done = true
- return _node, nil
- }
- func (_c *AnnouncementCreate) createSpec() (*Announcement, *sqlgraph.CreateSpec) {
- var (
- _node = &Announcement{config: _c.config}
- _spec = sqlgraph.NewCreateSpec(announcement.Table, sqlgraph.NewFieldSpec(announcement.FieldID, field.TypeInt64))
- )
- _spec.OnConflict = _c.conflict
- if value, ok := _c.mutation.Title(); ok {
- _spec.SetField(announcement.FieldTitle, field.TypeString, value)
- _node.Title = value
- }
- if value, ok := _c.mutation.Content(); ok {
- _spec.SetField(announcement.FieldContent, field.TypeString, value)
- _node.Content = value
- }
- if value, ok := _c.mutation.Status(); ok {
- _spec.SetField(announcement.FieldStatus, field.TypeString, value)
- _node.Status = value
- }
- if value, ok := _c.mutation.NotifyMode(); ok {
- _spec.SetField(announcement.FieldNotifyMode, field.TypeString, value)
- _node.NotifyMode = value
- }
- if value, ok := _c.mutation.Targeting(); ok {
- _spec.SetField(announcement.FieldTargeting, field.TypeJSON, value)
- _node.Targeting = value
- }
- if value, ok := _c.mutation.StartsAt(); ok {
- _spec.SetField(announcement.FieldStartsAt, field.TypeTime, value)
- _node.StartsAt = &value
- }
- if value, ok := _c.mutation.EndsAt(); ok {
- _spec.SetField(announcement.FieldEndsAt, field.TypeTime, value)
- _node.EndsAt = &value
- }
- if value, ok := _c.mutation.CreatedBy(); ok {
- _spec.SetField(announcement.FieldCreatedBy, field.TypeInt64, value)
- _node.CreatedBy = &value
- }
- if value, ok := _c.mutation.UpdatedBy(); ok {
- _spec.SetField(announcement.FieldUpdatedBy, field.TypeInt64, value)
- _node.UpdatedBy = &value
- }
- if value, ok := _c.mutation.CreatedAt(); ok {
- _spec.SetField(announcement.FieldCreatedAt, field.TypeTime, value)
- _node.CreatedAt = value
- }
- if value, ok := _c.mutation.UpdatedAt(); ok {
- _spec.SetField(announcement.FieldUpdatedAt, field.TypeTime, value)
- _node.UpdatedAt = value
- }
- if nodes := _c.mutation.ReadsIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2M,
- Inverse: false,
- Table: announcement.ReadsTable,
- Columns: []string{announcement.ReadsColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(announcementread.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _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.Announcement.Create().
- // SetTitle(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.AnnouncementUpsert) {
- // SetTitle(v+v).
- // }).
- // Exec(ctx)
- func (_c *AnnouncementCreate) OnConflict(opts ...sql.ConflictOption) *AnnouncementUpsertOne {
- _c.conflict = opts
- return &AnnouncementUpsertOne{
- create: _c,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Announcement.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (_c *AnnouncementCreate) OnConflictColumns(columns ...string) *AnnouncementUpsertOne {
- _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
- return &AnnouncementUpsertOne{
- create: _c,
- }
- }
- type (
- // AnnouncementUpsertOne is the builder for "upsert"-ing
- // one Announcement node.
- AnnouncementUpsertOne struct {
- create *AnnouncementCreate
- }
- // AnnouncementUpsert is the "OnConflict" setter.
- AnnouncementUpsert struct {
- *sql.UpdateSet
- }
- )
- // SetTitle sets the "title" field.
- func (u *AnnouncementUpsert) SetTitle(v string) *AnnouncementUpsert {
- u.Set(announcement.FieldTitle, v)
- return u
- }
- // UpdateTitle sets the "title" field to the value that was provided on create.
- func (u *AnnouncementUpsert) UpdateTitle() *AnnouncementUpsert {
- u.SetExcluded(announcement.FieldTitle)
- return u
- }
- // SetContent sets the "content" field.
- func (u *AnnouncementUpsert) SetContent(v string) *AnnouncementUpsert {
- u.Set(announcement.FieldContent, v)
- return u
- }
- // UpdateContent sets the "content" field to the value that was provided on create.
- func (u *AnnouncementUpsert) UpdateContent() *AnnouncementUpsert {
- u.SetExcluded(announcement.FieldContent)
- return u
- }
- // SetStatus sets the "status" field.
- func (u *AnnouncementUpsert) SetStatus(v string) *AnnouncementUpsert {
- u.Set(announcement.FieldStatus, v)
- return u
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *AnnouncementUpsert) UpdateStatus() *AnnouncementUpsert {
- u.SetExcluded(announcement.FieldStatus)
- return u
- }
- // SetNotifyMode sets the "notify_mode" field.
- func (u *AnnouncementUpsert) SetNotifyMode(v string) *AnnouncementUpsert {
- u.Set(announcement.FieldNotifyMode, v)
- return u
- }
- // UpdateNotifyMode sets the "notify_mode" field to the value that was provided on create.
- func (u *AnnouncementUpsert) UpdateNotifyMode() *AnnouncementUpsert {
- u.SetExcluded(announcement.FieldNotifyMode)
- return u
- }
- // SetTargeting sets the "targeting" field.
- func (u *AnnouncementUpsert) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpsert {
- u.Set(announcement.FieldTargeting, v)
- return u
- }
- // UpdateTargeting sets the "targeting" field to the value that was provided on create.
- func (u *AnnouncementUpsert) UpdateTargeting() *AnnouncementUpsert {
- u.SetExcluded(announcement.FieldTargeting)
- return u
- }
- // ClearTargeting clears the value of the "targeting" field.
- func (u *AnnouncementUpsert) ClearTargeting() *AnnouncementUpsert {
- u.SetNull(announcement.FieldTargeting)
- return u
- }
- // SetStartsAt sets the "starts_at" field.
- func (u *AnnouncementUpsert) SetStartsAt(v time.Time) *AnnouncementUpsert {
- u.Set(announcement.FieldStartsAt, v)
- return u
- }
- // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
- func (u *AnnouncementUpsert) UpdateStartsAt() *AnnouncementUpsert {
- u.SetExcluded(announcement.FieldStartsAt)
- return u
- }
- // ClearStartsAt clears the value of the "starts_at" field.
- func (u *AnnouncementUpsert) ClearStartsAt() *AnnouncementUpsert {
- u.SetNull(announcement.FieldStartsAt)
- return u
- }
- // SetEndsAt sets the "ends_at" field.
- func (u *AnnouncementUpsert) SetEndsAt(v time.Time) *AnnouncementUpsert {
- u.Set(announcement.FieldEndsAt, v)
- return u
- }
- // UpdateEndsAt sets the "ends_at" field to the value that was provided on create.
- func (u *AnnouncementUpsert) UpdateEndsAt() *AnnouncementUpsert {
- u.SetExcluded(announcement.FieldEndsAt)
- return u
- }
- // ClearEndsAt clears the value of the "ends_at" field.
- func (u *AnnouncementUpsert) ClearEndsAt() *AnnouncementUpsert {
- u.SetNull(announcement.FieldEndsAt)
- return u
- }
- // SetCreatedBy sets the "created_by" field.
- func (u *AnnouncementUpsert) SetCreatedBy(v int64) *AnnouncementUpsert {
- u.Set(announcement.FieldCreatedBy, v)
- return u
- }
- // UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
- func (u *AnnouncementUpsert) UpdateCreatedBy() *AnnouncementUpsert {
- u.SetExcluded(announcement.FieldCreatedBy)
- return u
- }
- // AddCreatedBy adds v to the "created_by" field.
- func (u *AnnouncementUpsert) AddCreatedBy(v int64) *AnnouncementUpsert {
- u.Add(announcement.FieldCreatedBy, v)
- return u
- }
- // ClearCreatedBy clears the value of the "created_by" field.
- func (u *AnnouncementUpsert) ClearCreatedBy() *AnnouncementUpsert {
- u.SetNull(announcement.FieldCreatedBy)
- return u
- }
- // SetUpdatedBy sets the "updated_by" field.
- func (u *AnnouncementUpsert) SetUpdatedBy(v int64) *AnnouncementUpsert {
- u.Set(announcement.FieldUpdatedBy, v)
- return u
- }
- // UpdateUpdatedBy sets the "updated_by" field to the value that was provided on create.
- func (u *AnnouncementUpsert) UpdateUpdatedBy() *AnnouncementUpsert {
- u.SetExcluded(announcement.FieldUpdatedBy)
- return u
- }
- // AddUpdatedBy adds v to the "updated_by" field.
- func (u *AnnouncementUpsert) AddUpdatedBy(v int64) *AnnouncementUpsert {
- u.Add(announcement.FieldUpdatedBy, v)
- return u
- }
- // ClearUpdatedBy clears the value of the "updated_by" field.
- func (u *AnnouncementUpsert) ClearUpdatedBy() *AnnouncementUpsert {
- u.SetNull(announcement.FieldUpdatedBy)
- return u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *AnnouncementUpsert) SetUpdatedAt(v time.Time) *AnnouncementUpsert {
- u.Set(announcement.FieldUpdatedAt, v)
- return u
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *AnnouncementUpsert) UpdateUpdatedAt() *AnnouncementUpsert {
- u.SetExcluded(announcement.FieldUpdatedAt)
- return u
- }
- // UpdateNewValues updates the mutable fields using the new values that were set on create.
- // Using this option is equivalent to using:
- //
- // client.Announcement.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // ).
- // Exec(ctx)
- func (u *AnnouncementUpsertOne) UpdateNewValues() *AnnouncementUpsertOne {
- 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(announcement.FieldCreatedAt)
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Announcement.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *AnnouncementUpsertOne) Ignore() *AnnouncementUpsertOne {
- 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 *AnnouncementUpsertOne) DoNothing() *AnnouncementUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the AnnouncementCreate.OnConflict
- // documentation for more info.
- func (u *AnnouncementUpsertOne) Update(set func(*AnnouncementUpsert)) *AnnouncementUpsertOne {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&AnnouncementUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetTitle sets the "title" field.
- func (u *AnnouncementUpsertOne) SetTitle(v string) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetTitle(v)
- })
- }
- // UpdateTitle sets the "title" field to the value that was provided on create.
- func (u *AnnouncementUpsertOne) UpdateTitle() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateTitle()
- })
- }
- // SetContent sets the "content" field.
- func (u *AnnouncementUpsertOne) SetContent(v string) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetContent(v)
- })
- }
- // UpdateContent sets the "content" field to the value that was provided on create.
- func (u *AnnouncementUpsertOne) UpdateContent() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateContent()
- })
- }
- // SetStatus sets the "status" field.
- func (u *AnnouncementUpsertOne) SetStatus(v string) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *AnnouncementUpsertOne) UpdateStatus() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateStatus()
- })
- }
- // SetNotifyMode sets the "notify_mode" field.
- func (u *AnnouncementUpsertOne) SetNotifyMode(v string) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetNotifyMode(v)
- })
- }
- // UpdateNotifyMode sets the "notify_mode" field to the value that was provided on create.
- func (u *AnnouncementUpsertOne) UpdateNotifyMode() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateNotifyMode()
- })
- }
- // SetTargeting sets the "targeting" field.
- func (u *AnnouncementUpsertOne) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetTargeting(v)
- })
- }
- // UpdateTargeting sets the "targeting" field to the value that was provided on create.
- func (u *AnnouncementUpsertOne) UpdateTargeting() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateTargeting()
- })
- }
- // ClearTargeting clears the value of the "targeting" field.
- func (u *AnnouncementUpsertOne) ClearTargeting() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.ClearTargeting()
- })
- }
- // SetStartsAt sets the "starts_at" field.
- func (u *AnnouncementUpsertOne) SetStartsAt(v time.Time) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetStartsAt(v)
- })
- }
- // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
- func (u *AnnouncementUpsertOne) UpdateStartsAt() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateStartsAt()
- })
- }
- // ClearStartsAt clears the value of the "starts_at" field.
- func (u *AnnouncementUpsertOne) ClearStartsAt() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.ClearStartsAt()
- })
- }
- // SetEndsAt sets the "ends_at" field.
- func (u *AnnouncementUpsertOne) SetEndsAt(v time.Time) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetEndsAt(v)
- })
- }
- // UpdateEndsAt sets the "ends_at" field to the value that was provided on create.
- func (u *AnnouncementUpsertOne) UpdateEndsAt() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateEndsAt()
- })
- }
- // ClearEndsAt clears the value of the "ends_at" field.
- func (u *AnnouncementUpsertOne) ClearEndsAt() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.ClearEndsAt()
- })
- }
- // SetCreatedBy sets the "created_by" field.
- func (u *AnnouncementUpsertOne) SetCreatedBy(v int64) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetCreatedBy(v)
- })
- }
- // AddCreatedBy adds v to the "created_by" field.
- func (u *AnnouncementUpsertOne) AddCreatedBy(v int64) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.AddCreatedBy(v)
- })
- }
- // UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
- func (u *AnnouncementUpsertOne) UpdateCreatedBy() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateCreatedBy()
- })
- }
- // ClearCreatedBy clears the value of the "created_by" field.
- func (u *AnnouncementUpsertOne) ClearCreatedBy() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.ClearCreatedBy()
- })
- }
- // SetUpdatedBy sets the "updated_by" field.
- func (u *AnnouncementUpsertOne) SetUpdatedBy(v int64) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetUpdatedBy(v)
- })
- }
- // AddUpdatedBy adds v to the "updated_by" field.
- func (u *AnnouncementUpsertOne) AddUpdatedBy(v int64) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.AddUpdatedBy(v)
- })
- }
- // UpdateUpdatedBy sets the "updated_by" field to the value that was provided on create.
- func (u *AnnouncementUpsertOne) UpdateUpdatedBy() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateUpdatedBy()
- })
- }
- // ClearUpdatedBy clears the value of the "updated_by" field.
- func (u *AnnouncementUpsertOne) ClearUpdatedBy() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.ClearUpdatedBy()
- })
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *AnnouncementUpsertOne) SetUpdatedAt(v time.Time) *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *AnnouncementUpsertOne) UpdateUpdatedAt() *AnnouncementUpsertOne {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // Exec executes the query.
- func (u *AnnouncementUpsertOne) Exec(ctx context.Context) error {
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for AnnouncementCreate.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *AnnouncementUpsertOne) 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 *AnnouncementUpsertOne) ID(ctx context.Context) (id int64, 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 *AnnouncementUpsertOne) IDX(ctx context.Context) int64 {
- id, err := u.ID(ctx)
- if err != nil {
- panic(err)
- }
- return id
- }
- // AnnouncementCreateBulk is the builder for creating many Announcement entities in bulk.
- type AnnouncementCreateBulk struct {
- config
- err error
- builders []*AnnouncementCreate
- conflict []sql.ConflictOption
- }
- // Save creates the Announcement entities in the database.
- func (_c *AnnouncementCreateBulk) Save(ctx context.Context) ([]*Announcement, error) {
- if _c.err != nil {
- return nil, _c.err
- }
- specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
- nodes := make([]*Announcement, len(_c.builders))
- mutators := make([]Mutator, len(_c.builders))
- for i := range _c.builders {
- func(i int, root context.Context) {
- builder := _c.builders[i]
- builder.defaults()
- var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
- mutation, ok := m.(*AnnouncementMutation)
- 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, _c.builders[i+1].mutation)
- } else {
- spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
- spec.OnConflict = _c.conflict
- // Invoke the actual operation on the latest mutation in the chain.
- if err = sqlgraph.BatchCreate(ctx, _c.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 = int64(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, _c.builders[0].mutation); err != nil {
- return nil, err
- }
- }
- return nodes, nil
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_c *AnnouncementCreateBulk) SaveX(ctx context.Context) []*Announcement {
- v, err := _c.Save(ctx)
- if err != nil {
- panic(err)
- }
- return v
- }
- // Exec executes the query.
- func (_c *AnnouncementCreateBulk) Exec(ctx context.Context) error {
- _, err := _c.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_c *AnnouncementCreateBulk) ExecX(ctx context.Context) {
- if err := _c.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
- // of the `INSERT` statement. For example:
- //
- // client.Announcement.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.AnnouncementUpsert) {
- // SetTitle(v+v).
- // }).
- // Exec(ctx)
- func (_c *AnnouncementCreateBulk) OnConflict(opts ...sql.ConflictOption) *AnnouncementUpsertBulk {
- _c.conflict = opts
- return &AnnouncementUpsertBulk{
- create: _c,
- }
- }
- // OnConflictColumns calls `OnConflict` and configures the columns
- // as conflict target. Using this option is equivalent to using:
- //
- // client.Announcement.Create().
- // OnConflict(sql.ConflictColumns(columns...)).
- // Exec(ctx)
- func (_c *AnnouncementCreateBulk) OnConflictColumns(columns ...string) *AnnouncementUpsertBulk {
- _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
- return &AnnouncementUpsertBulk{
- create: _c,
- }
- }
- // AnnouncementUpsertBulk is the builder for "upsert"-ing
- // a bulk of Announcement nodes.
- type AnnouncementUpsertBulk struct {
- create *AnnouncementCreateBulk
- }
- // UpdateNewValues updates the mutable fields using the new values that
- // were set on create. Using this option is equivalent to using:
- //
- // client.Announcement.Create().
- // OnConflict(
- // sql.ResolveWithNewValues(),
- // ).
- // Exec(ctx)
- func (u *AnnouncementUpsertBulk) UpdateNewValues() *AnnouncementUpsertBulk {
- 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(announcement.FieldCreatedAt)
- }
- }
- }))
- return u
- }
- // Ignore sets each column to itself in case of conflict.
- // Using this option is equivalent to using:
- //
- // client.Announcement.Create().
- // OnConflict(sql.ResolveWithIgnore()).
- // Exec(ctx)
- func (u *AnnouncementUpsertBulk) Ignore() *AnnouncementUpsertBulk {
- 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 *AnnouncementUpsertBulk) DoNothing() *AnnouncementUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.DoNothing())
- return u
- }
- // Update allows overriding fields `UPDATE` values. See the AnnouncementCreateBulk.OnConflict
- // documentation for more info.
- func (u *AnnouncementUpsertBulk) Update(set func(*AnnouncementUpsert)) *AnnouncementUpsertBulk {
- u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
- set(&AnnouncementUpsert{UpdateSet: update})
- }))
- return u
- }
- // SetTitle sets the "title" field.
- func (u *AnnouncementUpsertBulk) SetTitle(v string) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetTitle(v)
- })
- }
- // UpdateTitle sets the "title" field to the value that was provided on create.
- func (u *AnnouncementUpsertBulk) UpdateTitle() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateTitle()
- })
- }
- // SetContent sets the "content" field.
- func (u *AnnouncementUpsertBulk) SetContent(v string) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetContent(v)
- })
- }
- // UpdateContent sets the "content" field to the value that was provided on create.
- func (u *AnnouncementUpsertBulk) UpdateContent() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateContent()
- })
- }
- // SetStatus sets the "status" field.
- func (u *AnnouncementUpsertBulk) SetStatus(v string) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetStatus(v)
- })
- }
- // UpdateStatus sets the "status" field to the value that was provided on create.
- func (u *AnnouncementUpsertBulk) UpdateStatus() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateStatus()
- })
- }
- // SetNotifyMode sets the "notify_mode" field.
- func (u *AnnouncementUpsertBulk) SetNotifyMode(v string) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetNotifyMode(v)
- })
- }
- // UpdateNotifyMode sets the "notify_mode" field to the value that was provided on create.
- func (u *AnnouncementUpsertBulk) UpdateNotifyMode() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateNotifyMode()
- })
- }
- // SetTargeting sets the "targeting" field.
- func (u *AnnouncementUpsertBulk) SetTargeting(v domain.AnnouncementTargeting) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetTargeting(v)
- })
- }
- // UpdateTargeting sets the "targeting" field to the value that was provided on create.
- func (u *AnnouncementUpsertBulk) UpdateTargeting() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateTargeting()
- })
- }
- // ClearTargeting clears the value of the "targeting" field.
- func (u *AnnouncementUpsertBulk) ClearTargeting() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.ClearTargeting()
- })
- }
- // SetStartsAt sets the "starts_at" field.
- func (u *AnnouncementUpsertBulk) SetStartsAt(v time.Time) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetStartsAt(v)
- })
- }
- // UpdateStartsAt sets the "starts_at" field to the value that was provided on create.
- func (u *AnnouncementUpsertBulk) UpdateStartsAt() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateStartsAt()
- })
- }
- // ClearStartsAt clears the value of the "starts_at" field.
- func (u *AnnouncementUpsertBulk) ClearStartsAt() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.ClearStartsAt()
- })
- }
- // SetEndsAt sets the "ends_at" field.
- func (u *AnnouncementUpsertBulk) SetEndsAt(v time.Time) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetEndsAt(v)
- })
- }
- // UpdateEndsAt sets the "ends_at" field to the value that was provided on create.
- func (u *AnnouncementUpsertBulk) UpdateEndsAt() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateEndsAt()
- })
- }
- // ClearEndsAt clears the value of the "ends_at" field.
- func (u *AnnouncementUpsertBulk) ClearEndsAt() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.ClearEndsAt()
- })
- }
- // SetCreatedBy sets the "created_by" field.
- func (u *AnnouncementUpsertBulk) SetCreatedBy(v int64) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetCreatedBy(v)
- })
- }
- // AddCreatedBy adds v to the "created_by" field.
- func (u *AnnouncementUpsertBulk) AddCreatedBy(v int64) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.AddCreatedBy(v)
- })
- }
- // UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
- func (u *AnnouncementUpsertBulk) UpdateCreatedBy() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateCreatedBy()
- })
- }
- // ClearCreatedBy clears the value of the "created_by" field.
- func (u *AnnouncementUpsertBulk) ClearCreatedBy() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.ClearCreatedBy()
- })
- }
- // SetUpdatedBy sets the "updated_by" field.
- func (u *AnnouncementUpsertBulk) SetUpdatedBy(v int64) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetUpdatedBy(v)
- })
- }
- // AddUpdatedBy adds v to the "updated_by" field.
- func (u *AnnouncementUpsertBulk) AddUpdatedBy(v int64) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.AddUpdatedBy(v)
- })
- }
- // UpdateUpdatedBy sets the "updated_by" field to the value that was provided on create.
- func (u *AnnouncementUpsertBulk) UpdateUpdatedBy() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateUpdatedBy()
- })
- }
- // ClearUpdatedBy clears the value of the "updated_by" field.
- func (u *AnnouncementUpsertBulk) ClearUpdatedBy() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.ClearUpdatedBy()
- })
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (u *AnnouncementUpsertBulk) SetUpdatedAt(v time.Time) *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.SetUpdatedAt(v)
- })
- }
- // UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
- func (u *AnnouncementUpsertBulk) UpdateUpdatedAt() *AnnouncementUpsertBulk {
- return u.Update(func(s *AnnouncementUpsert) {
- s.UpdateUpdatedAt()
- })
- }
- // Exec executes the query.
- func (u *AnnouncementUpsertBulk) 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 AnnouncementCreateBulk instead", i)
- }
- }
- if len(u.create.conflict) == 0 {
- return errors.New("ent: missing options for AnnouncementCreateBulk.OnConflict")
- }
- return u.create.Exec(ctx)
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (u *AnnouncementUpsertBulk) ExecX(ctx context.Context) {
- if err := u.create.Exec(ctx); err != nil {
- panic(err)
- }
- }
|