1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/predicate"
- "wechat-api/ent/whatsapp"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/dialect/sql/sqljson"
- "entgo.io/ent/schema/field"
- )
- // WhatsappUpdate is the builder for updating Whatsapp entities.
- type WhatsappUpdate struct {
- config
- hooks []Hook
- mutation *WhatsappMutation
- }
- // Where appends a list predicates to the WhatsappUpdate builder.
- func (wu *WhatsappUpdate) Where(ps ...predicate.Whatsapp) *WhatsappUpdate {
- wu.mutation.Where(ps...)
- return wu
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (wu *WhatsappUpdate) SetUpdatedAt(t time.Time) *WhatsappUpdate {
- wu.mutation.SetUpdatedAt(t)
- return wu
- }
- // SetStatus sets the "status" field.
- func (wu *WhatsappUpdate) SetStatus(u uint8) *WhatsappUpdate {
- wu.mutation.ResetStatus()
- wu.mutation.SetStatus(u)
- return wu
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableStatus(u *uint8) *WhatsappUpdate {
- if u != nil {
- wu.SetStatus(*u)
- }
- return wu
- }
- // AddStatus adds u to the "status" field.
- func (wu *WhatsappUpdate) AddStatus(u int8) *WhatsappUpdate {
- wu.mutation.AddStatus(u)
- return wu
- }
- // ClearStatus clears the value of the "status" field.
- func (wu *WhatsappUpdate) ClearStatus() *WhatsappUpdate {
- wu.mutation.ClearStatus()
- return wu
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (wu *WhatsappUpdate) SetDeletedAt(t time.Time) *WhatsappUpdate {
- wu.mutation.SetDeletedAt(t)
- return wu
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableDeletedAt(t *time.Time) *WhatsappUpdate {
- if t != nil {
- wu.SetDeletedAt(*t)
- }
- return wu
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (wu *WhatsappUpdate) ClearDeletedAt() *WhatsappUpdate {
- wu.mutation.ClearDeletedAt()
- return wu
- }
- // SetAk sets the "ak" field.
- func (wu *WhatsappUpdate) SetAk(s string) *WhatsappUpdate {
- wu.mutation.SetAk(s)
- return wu
- }
- // SetNillableAk sets the "ak" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableAk(s *string) *WhatsappUpdate {
- if s != nil {
- wu.SetAk(*s)
- }
- return wu
- }
- // ClearAk clears the value of the "ak" field.
- func (wu *WhatsappUpdate) ClearAk() *WhatsappUpdate {
- wu.mutation.ClearAk()
- return wu
- }
- // SetSk sets the "sk" field.
- func (wu *WhatsappUpdate) SetSk(s string) *WhatsappUpdate {
- wu.mutation.SetSk(s)
- return wu
- }
- // SetNillableSk sets the "sk" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableSk(s *string) *WhatsappUpdate {
- if s != nil {
- wu.SetSk(*s)
- }
- return wu
- }
- // SetCallback sets the "callback" field.
- func (wu *WhatsappUpdate) SetCallback(s string) *WhatsappUpdate {
- wu.mutation.SetCallback(s)
- return wu
- }
- // SetNillableCallback sets the "callback" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableCallback(s *string) *WhatsappUpdate {
- if s != nil {
- wu.SetCallback(*s)
- }
- return wu
- }
- // SetAccount sets the "account" field.
- func (wu *WhatsappUpdate) SetAccount(s string) *WhatsappUpdate {
- wu.mutation.SetAccount(s)
- return wu
- }
- // SetNillableAccount sets the "account" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableAccount(s *string) *WhatsappUpdate {
- if s != nil {
- wu.SetAccount(*s)
- }
- return wu
- }
- // SetNickname sets the "nickname" field.
- func (wu *WhatsappUpdate) SetNickname(s string) *WhatsappUpdate {
- wu.mutation.SetNickname(s)
- return wu
- }
- // SetNillableNickname sets the "nickname" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableNickname(s *string) *WhatsappUpdate {
- if s != nil {
- wu.SetNickname(*s)
- }
- return wu
- }
- // SetPhone sets the "phone" field.
- func (wu *WhatsappUpdate) SetPhone(s string) *WhatsappUpdate {
- wu.mutation.SetPhone(s)
- return wu
- }
- // SetNillablePhone sets the "phone" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillablePhone(s *string) *WhatsappUpdate {
- if s != nil {
- wu.SetPhone(*s)
- }
- return wu
- }
- // SetOrganizationID sets the "organization_id" field.
- func (wu *WhatsappUpdate) SetOrganizationID(u uint64) *WhatsappUpdate {
- wu.mutation.ResetOrganizationID()
- wu.mutation.SetOrganizationID(u)
- return wu
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableOrganizationID(u *uint64) *WhatsappUpdate {
- if u != nil {
- wu.SetOrganizationID(*u)
- }
- return wu
- }
- // AddOrganizationID adds u to the "organization_id" field.
- func (wu *WhatsappUpdate) AddOrganizationID(u int64) *WhatsappUpdate {
- wu.mutation.AddOrganizationID(u)
- return wu
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (wu *WhatsappUpdate) ClearOrganizationID() *WhatsappUpdate {
- wu.mutation.ClearOrganizationID()
- return wu
- }
- // SetAgentID sets the "agent_id" field.
- func (wu *WhatsappUpdate) SetAgentID(u uint64) *WhatsappUpdate {
- wu.mutation.ResetAgentID()
- wu.mutation.SetAgentID(u)
- return wu
- }
- // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableAgentID(u *uint64) *WhatsappUpdate {
- if u != nil {
- wu.SetAgentID(*u)
- }
- return wu
- }
- // AddAgentID adds u to the "agent_id" field.
- func (wu *WhatsappUpdate) AddAgentID(u int64) *WhatsappUpdate {
- wu.mutation.AddAgentID(u)
- return wu
- }
- // SetAPIBase sets the "api_base" field.
- func (wu *WhatsappUpdate) SetAPIBase(s string) *WhatsappUpdate {
- wu.mutation.SetAPIBase(s)
- return wu
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableAPIBase(s *string) *WhatsappUpdate {
- if s != nil {
- wu.SetAPIBase(*s)
- }
- return wu
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (wu *WhatsappUpdate) ClearAPIBase() *WhatsappUpdate {
- wu.mutation.ClearAPIBase()
- return wu
- }
- // SetAPIKey sets the "api_key" field.
- func (wu *WhatsappUpdate) SetAPIKey(s string) *WhatsappUpdate {
- wu.mutation.SetAPIKey(s)
- return wu
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (wu *WhatsappUpdate) SetNillableAPIKey(s *string) *WhatsappUpdate {
- if s != nil {
- wu.SetAPIKey(*s)
- }
- return wu
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (wu *WhatsappUpdate) ClearAPIKey() *WhatsappUpdate {
- wu.mutation.ClearAPIKey()
- return wu
- }
- // SetAllowList sets the "allow_list" field.
- func (wu *WhatsappUpdate) SetAllowList(s []string) *WhatsappUpdate {
- wu.mutation.SetAllowList(s)
- return wu
- }
- // AppendAllowList appends s to the "allow_list" field.
- func (wu *WhatsappUpdate) AppendAllowList(s []string) *WhatsappUpdate {
- wu.mutation.AppendAllowList(s)
- return wu
- }
- // ClearAllowList clears the value of the "allow_list" field.
- func (wu *WhatsappUpdate) ClearAllowList() *WhatsappUpdate {
- wu.mutation.ClearAllowList()
- return wu
- }
- // SetGroupAllowList sets the "group_allow_list" field.
- func (wu *WhatsappUpdate) SetGroupAllowList(s []string) *WhatsappUpdate {
- wu.mutation.SetGroupAllowList(s)
- return wu
- }
- // AppendGroupAllowList appends s to the "group_allow_list" field.
- func (wu *WhatsappUpdate) AppendGroupAllowList(s []string) *WhatsappUpdate {
- wu.mutation.AppendGroupAllowList(s)
- return wu
- }
- // ClearGroupAllowList clears the value of the "group_allow_list" field.
- func (wu *WhatsappUpdate) ClearGroupAllowList() *WhatsappUpdate {
- wu.mutation.ClearGroupAllowList()
- return wu
- }
- // SetBlockList sets the "block_list" field.
- func (wu *WhatsappUpdate) SetBlockList(s []string) *WhatsappUpdate {
- wu.mutation.SetBlockList(s)
- return wu
- }
- // AppendBlockList appends s to the "block_list" field.
- func (wu *WhatsappUpdate) AppendBlockList(s []string) *WhatsappUpdate {
- wu.mutation.AppendBlockList(s)
- return wu
- }
- // ClearBlockList clears the value of the "block_list" field.
- func (wu *WhatsappUpdate) ClearBlockList() *WhatsappUpdate {
- wu.mutation.ClearBlockList()
- return wu
- }
- // SetGroupBlockList sets the "group_block_list" field.
- func (wu *WhatsappUpdate) SetGroupBlockList(s []string) *WhatsappUpdate {
- wu.mutation.SetGroupBlockList(s)
- return wu
- }
- // AppendGroupBlockList appends s to the "group_block_list" field.
- func (wu *WhatsappUpdate) AppendGroupBlockList(s []string) *WhatsappUpdate {
- wu.mutation.AppendGroupBlockList(s)
- return wu
- }
- // ClearGroupBlockList clears the value of the "group_block_list" field.
- func (wu *WhatsappUpdate) ClearGroupBlockList() *WhatsappUpdate {
- wu.mutation.ClearGroupBlockList()
- return wu
- }
- // Mutation returns the WhatsappMutation object of the builder.
- func (wu *WhatsappUpdate) Mutation() *WhatsappMutation {
- return wu.mutation
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (wu *WhatsappUpdate) Save(ctx context.Context) (int, error) {
- if err := wu.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, wu.sqlSave, wu.mutation, wu.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (wu *WhatsappUpdate) SaveX(ctx context.Context) int {
- affected, err := wu.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (wu *WhatsappUpdate) Exec(ctx context.Context) error {
- _, err := wu.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (wu *WhatsappUpdate) ExecX(ctx context.Context) {
- if err := wu.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (wu *WhatsappUpdate) defaults() error {
- if _, ok := wu.mutation.UpdatedAt(); !ok {
- if whatsapp.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized whatsapp.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := whatsapp.UpdateDefaultUpdatedAt()
- wu.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- func (wu *WhatsappUpdate) sqlSave(ctx context.Context) (n int, err error) {
- _spec := sqlgraph.NewUpdateSpec(whatsapp.Table, whatsapp.Columns, sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64))
- if ps := wu.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := wu.mutation.UpdatedAt(); ok {
- _spec.SetField(whatsapp.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := wu.mutation.Status(); ok {
- _spec.SetField(whatsapp.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := wu.mutation.AddedStatus(); ok {
- _spec.AddField(whatsapp.FieldStatus, field.TypeUint8, value)
- }
- if wu.mutation.StatusCleared() {
- _spec.ClearField(whatsapp.FieldStatus, field.TypeUint8)
- }
- if value, ok := wu.mutation.DeletedAt(); ok {
- _spec.SetField(whatsapp.FieldDeletedAt, field.TypeTime, value)
- }
- if wu.mutation.DeletedAtCleared() {
- _spec.ClearField(whatsapp.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := wu.mutation.Ak(); ok {
- _spec.SetField(whatsapp.FieldAk, field.TypeString, value)
- }
- if wu.mutation.AkCleared() {
- _spec.ClearField(whatsapp.FieldAk, field.TypeString)
- }
- if value, ok := wu.mutation.Sk(); ok {
- _spec.SetField(whatsapp.FieldSk, field.TypeString, value)
- }
- if value, ok := wu.mutation.Callback(); ok {
- _spec.SetField(whatsapp.FieldCallback, field.TypeString, value)
- }
- if value, ok := wu.mutation.Account(); ok {
- _spec.SetField(whatsapp.FieldAccount, field.TypeString, value)
- }
- if value, ok := wu.mutation.Nickname(); ok {
- _spec.SetField(whatsapp.FieldNickname, field.TypeString, value)
- }
- if value, ok := wu.mutation.Phone(); ok {
- _spec.SetField(whatsapp.FieldPhone, field.TypeString, value)
- }
- if value, ok := wu.mutation.OrganizationID(); ok {
- _spec.SetField(whatsapp.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := wu.mutation.AddedOrganizationID(); ok {
- _spec.AddField(whatsapp.FieldOrganizationID, field.TypeUint64, value)
- }
- if wu.mutation.OrganizationIDCleared() {
- _spec.ClearField(whatsapp.FieldOrganizationID, field.TypeUint64)
- }
- if value, ok := wu.mutation.AgentID(); ok {
- _spec.SetField(whatsapp.FieldAgentID, field.TypeUint64, value)
- }
- if value, ok := wu.mutation.AddedAgentID(); ok {
- _spec.AddField(whatsapp.FieldAgentID, field.TypeUint64, value)
- }
- if value, ok := wu.mutation.APIBase(); ok {
- _spec.SetField(whatsapp.FieldAPIBase, field.TypeString, value)
- }
- if wu.mutation.APIBaseCleared() {
- _spec.ClearField(whatsapp.FieldAPIBase, field.TypeString)
- }
- if value, ok := wu.mutation.APIKey(); ok {
- _spec.SetField(whatsapp.FieldAPIKey, field.TypeString, value)
- }
- if wu.mutation.APIKeyCleared() {
- _spec.ClearField(whatsapp.FieldAPIKey, field.TypeString)
- }
- if value, ok := wu.mutation.AllowList(); ok {
- _spec.SetField(whatsapp.FieldAllowList, field.TypeJSON, value)
- }
- if value, ok := wu.mutation.AppendedAllowList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, whatsapp.FieldAllowList, value)
- })
- }
- if wu.mutation.AllowListCleared() {
- _spec.ClearField(whatsapp.FieldAllowList, field.TypeJSON)
- }
- if value, ok := wu.mutation.GroupAllowList(); ok {
- _spec.SetField(whatsapp.FieldGroupAllowList, field.TypeJSON, value)
- }
- if value, ok := wu.mutation.AppendedGroupAllowList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, whatsapp.FieldGroupAllowList, value)
- })
- }
- if wu.mutation.GroupAllowListCleared() {
- _spec.ClearField(whatsapp.FieldGroupAllowList, field.TypeJSON)
- }
- if value, ok := wu.mutation.BlockList(); ok {
- _spec.SetField(whatsapp.FieldBlockList, field.TypeJSON, value)
- }
- if value, ok := wu.mutation.AppendedBlockList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, whatsapp.FieldBlockList, value)
- })
- }
- if wu.mutation.BlockListCleared() {
- _spec.ClearField(whatsapp.FieldBlockList, field.TypeJSON)
- }
- if value, ok := wu.mutation.GroupBlockList(); ok {
- _spec.SetField(whatsapp.FieldGroupBlockList, field.TypeJSON, value)
- }
- if value, ok := wu.mutation.AppendedGroupBlockList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, whatsapp.FieldGroupBlockList, value)
- })
- }
- if wu.mutation.GroupBlockListCleared() {
- _spec.ClearField(whatsapp.FieldGroupBlockList, field.TypeJSON)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, wu.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{whatsapp.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- wu.mutation.done = true
- return n, nil
- }
- // WhatsappUpdateOne is the builder for updating a single Whatsapp entity.
- type WhatsappUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *WhatsappMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (wuo *WhatsappUpdateOne) SetUpdatedAt(t time.Time) *WhatsappUpdateOne {
- wuo.mutation.SetUpdatedAt(t)
- return wuo
- }
- // SetStatus sets the "status" field.
- func (wuo *WhatsappUpdateOne) SetStatus(u uint8) *WhatsappUpdateOne {
- wuo.mutation.ResetStatus()
- wuo.mutation.SetStatus(u)
- return wuo
- }
- // SetNillableStatus sets the "status" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableStatus(u *uint8) *WhatsappUpdateOne {
- if u != nil {
- wuo.SetStatus(*u)
- }
- return wuo
- }
- // AddStatus adds u to the "status" field.
- func (wuo *WhatsappUpdateOne) AddStatus(u int8) *WhatsappUpdateOne {
- wuo.mutation.AddStatus(u)
- return wuo
- }
- // ClearStatus clears the value of the "status" field.
- func (wuo *WhatsappUpdateOne) ClearStatus() *WhatsappUpdateOne {
- wuo.mutation.ClearStatus()
- return wuo
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (wuo *WhatsappUpdateOne) SetDeletedAt(t time.Time) *WhatsappUpdateOne {
- wuo.mutation.SetDeletedAt(t)
- return wuo
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableDeletedAt(t *time.Time) *WhatsappUpdateOne {
- if t != nil {
- wuo.SetDeletedAt(*t)
- }
- return wuo
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (wuo *WhatsappUpdateOne) ClearDeletedAt() *WhatsappUpdateOne {
- wuo.mutation.ClearDeletedAt()
- return wuo
- }
- // SetAk sets the "ak" field.
- func (wuo *WhatsappUpdateOne) SetAk(s string) *WhatsappUpdateOne {
- wuo.mutation.SetAk(s)
- return wuo
- }
- // SetNillableAk sets the "ak" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableAk(s *string) *WhatsappUpdateOne {
- if s != nil {
- wuo.SetAk(*s)
- }
- return wuo
- }
- // ClearAk clears the value of the "ak" field.
- func (wuo *WhatsappUpdateOne) ClearAk() *WhatsappUpdateOne {
- wuo.mutation.ClearAk()
- return wuo
- }
- // SetSk sets the "sk" field.
- func (wuo *WhatsappUpdateOne) SetSk(s string) *WhatsappUpdateOne {
- wuo.mutation.SetSk(s)
- return wuo
- }
- // SetNillableSk sets the "sk" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableSk(s *string) *WhatsappUpdateOne {
- if s != nil {
- wuo.SetSk(*s)
- }
- return wuo
- }
- // SetCallback sets the "callback" field.
- func (wuo *WhatsappUpdateOne) SetCallback(s string) *WhatsappUpdateOne {
- wuo.mutation.SetCallback(s)
- return wuo
- }
- // SetNillableCallback sets the "callback" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableCallback(s *string) *WhatsappUpdateOne {
- if s != nil {
- wuo.SetCallback(*s)
- }
- return wuo
- }
- // SetAccount sets the "account" field.
- func (wuo *WhatsappUpdateOne) SetAccount(s string) *WhatsappUpdateOne {
- wuo.mutation.SetAccount(s)
- return wuo
- }
- // SetNillableAccount sets the "account" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableAccount(s *string) *WhatsappUpdateOne {
- if s != nil {
- wuo.SetAccount(*s)
- }
- return wuo
- }
- // SetNickname sets the "nickname" field.
- func (wuo *WhatsappUpdateOne) SetNickname(s string) *WhatsappUpdateOne {
- wuo.mutation.SetNickname(s)
- return wuo
- }
- // SetNillableNickname sets the "nickname" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableNickname(s *string) *WhatsappUpdateOne {
- if s != nil {
- wuo.SetNickname(*s)
- }
- return wuo
- }
- // SetPhone sets the "phone" field.
- func (wuo *WhatsappUpdateOne) SetPhone(s string) *WhatsappUpdateOne {
- wuo.mutation.SetPhone(s)
- return wuo
- }
- // SetNillablePhone sets the "phone" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillablePhone(s *string) *WhatsappUpdateOne {
- if s != nil {
- wuo.SetPhone(*s)
- }
- return wuo
- }
- // SetOrganizationID sets the "organization_id" field.
- func (wuo *WhatsappUpdateOne) SetOrganizationID(u uint64) *WhatsappUpdateOne {
- wuo.mutation.ResetOrganizationID()
- wuo.mutation.SetOrganizationID(u)
- return wuo
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableOrganizationID(u *uint64) *WhatsappUpdateOne {
- if u != nil {
- wuo.SetOrganizationID(*u)
- }
- return wuo
- }
- // AddOrganizationID adds u to the "organization_id" field.
- func (wuo *WhatsappUpdateOne) AddOrganizationID(u int64) *WhatsappUpdateOne {
- wuo.mutation.AddOrganizationID(u)
- return wuo
- }
- // ClearOrganizationID clears the value of the "organization_id" field.
- func (wuo *WhatsappUpdateOne) ClearOrganizationID() *WhatsappUpdateOne {
- wuo.mutation.ClearOrganizationID()
- return wuo
- }
- // SetAgentID sets the "agent_id" field.
- func (wuo *WhatsappUpdateOne) SetAgentID(u uint64) *WhatsappUpdateOne {
- wuo.mutation.ResetAgentID()
- wuo.mutation.SetAgentID(u)
- return wuo
- }
- // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableAgentID(u *uint64) *WhatsappUpdateOne {
- if u != nil {
- wuo.SetAgentID(*u)
- }
- return wuo
- }
- // AddAgentID adds u to the "agent_id" field.
- func (wuo *WhatsappUpdateOne) AddAgentID(u int64) *WhatsappUpdateOne {
- wuo.mutation.AddAgentID(u)
- return wuo
- }
- // SetAPIBase sets the "api_base" field.
- func (wuo *WhatsappUpdateOne) SetAPIBase(s string) *WhatsappUpdateOne {
- wuo.mutation.SetAPIBase(s)
- return wuo
- }
- // SetNillableAPIBase sets the "api_base" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableAPIBase(s *string) *WhatsappUpdateOne {
- if s != nil {
- wuo.SetAPIBase(*s)
- }
- return wuo
- }
- // ClearAPIBase clears the value of the "api_base" field.
- func (wuo *WhatsappUpdateOne) ClearAPIBase() *WhatsappUpdateOne {
- wuo.mutation.ClearAPIBase()
- return wuo
- }
- // SetAPIKey sets the "api_key" field.
- func (wuo *WhatsappUpdateOne) SetAPIKey(s string) *WhatsappUpdateOne {
- wuo.mutation.SetAPIKey(s)
- return wuo
- }
- // SetNillableAPIKey sets the "api_key" field if the given value is not nil.
- func (wuo *WhatsappUpdateOne) SetNillableAPIKey(s *string) *WhatsappUpdateOne {
- if s != nil {
- wuo.SetAPIKey(*s)
- }
- return wuo
- }
- // ClearAPIKey clears the value of the "api_key" field.
- func (wuo *WhatsappUpdateOne) ClearAPIKey() *WhatsappUpdateOne {
- wuo.mutation.ClearAPIKey()
- return wuo
- }
- // SetAllowList sets the "allow_list" field.
- func (wuo *WhatsappUpdateOne) SetAllowList(s []string) *WhatsappUpdateOne {
- wuo.mutation.SetAllowList(s)
- return wuo
- }
- // AppendAllowList appends s to the "allow_list" field.
- func (wuo *WhatsappUpdateOne) AppendAllowList(s []string) *WhatsappUpdateOne {
- wuo.mutation.AppendAllowList(s)
- return wuo
- }
- // ClearAllowList clears the value of the "allow_list" field.
- func (wuo *WhatsappUpdateOne) ClearAllowList() *WhatsappUpdateOne {
- wuo.mutation.ClearAllowList()
- return wuo
- }
- // SetGroupAllowList sets the "group_allow_list" field.
- func (wuo *WhatsappUpdateOne) SetGroupAllowList(s []string) *WhatsappUpdateOne {
- wuo.mutation.SetGroupAllowList(s)
- return wuo
- }
- // AppendGroupAllowList appends s to the "group_allow_list" field.
- func (wuo *WhatsappUpdateOne) AppendGroupAllowList(s []string) *WhatsappUpdateOne {
- wuo.mutation.AppendGroupAllowList(s)
- return wuo
- }
- // ClearGroupAllowList clears the value of the "group_allow_list" field.
- func (wuo *WhatsappUpdateOne) ClearGroupAllowList() *WhatsappUpdateOne {
- wuo.mutation.ClearGroupAllowList()
- return wuo
- }
- // SetBlockList sets the "block_list" field.
- func (wuo *WhatsappUpdateOne) SetBlockList(s []string) *WhatsappUpdateOne {
- wuo.mutation.SetBlockList(s)
- return wuo
- }
- // AppendBlockList appends s to the "block_list" field.
- func (wuo *WhatsappUpdateOne) AppendBlockList(s []string) *WhatsappUpdateOne {
- wuo.mutation.AppendBlockList(s)
- return wuo
- }
- // ClearBlockList clears the value of the "block_list" field.
- func (wuo *WhatsappUpdateOne) ClearBlockList() *WhatsappUpdateOne {
- wuo.mutation.ClearBlockList()
- return wuo
- }
- // SetGroupBlockList sets the "group_block_list" field.
- func (wuo *WhatsappUpdateOne) SetGroupBlockList(s []string) *WhatsappUpdateOne {
- wuo.mutation.SetGroupBlockList(s)
- return wuo
- }
- // AppendGroupBlockList appends s to the "group_block_list" field.
- func (wuo *WhatsappUpdateOne) AppendGroupBlockList(s []string) *WhatsappUpdateOne {
- wuo.mutation.AppendGroupBlockList(s)
- return wuo
- }
- // ClearGroupBlockList clears the value of the "group_block_list" field.
- func (wuo *WhatsappUpdateOne) ClearGroupBlockList() *WhatsappUpdateOne {
- wuo.mutation.ClearGroupBlockList()
- return wuo
- }
- // Mutation returns the WhatsappMutation object of the builder.
- func (wuo *WhatsappUpdateOne) Mutation() *WhatsappMutation {
- return wuo.mutation
- }
- // Where appends a list predicates to the WhatsappUpdate builder.
- func (wuo *WhatsappUpdateOne) Where(ps ...predicate.Whatsapp) *WhatsappUpdateOne {
- wuo.mutation.Where(ps...)
- return wuo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (wuo *WhatsappUpdateOne) Select(field string, fields ...string) *WhatsappUpdateOne {
- wuo.fields = append([]string{field}, fields...)
- return wuo
- }
- // Save executes the query and returns the updated Whatsapp entity.
- func (wuo *WhatsappUpdateOne) Save(ctx context.Context) (*Whatsapp, error) {
- if err := wuo.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, wuo.sqlSave, wuo.mutation, wuo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (wuo *WhatsappUpdateOne) SaveX(ctx context.Context) *Whatsapp {
- node, err := wuo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (wuo *WhatsappUpdateOne) Exec(ctx context.Context) error {
- _, err := wuo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (wuo *WhatsappUpdateOne) ExecX(ctx context.Context) {
- if err := wuo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (wuo *WhatsappUpdateOne) defaults() error {
- if _, ok := wuo.mutation.UpdatedAt(); !ok {
- if whatsapp.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized whatsapp.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := whatsapp.UpdateDefaultUpdatedAt()
- wuo.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- func (wuo *WhatsappUpdateOne) sqlSave(ctx context.Context) (_node *Whatsapp, err error) {
- _spec := sqlgraph.NewUpdateSpec(whatsapp.Table, whatsapp.Columns, sqlgraph.NewFieldSpec(whatsapp.FieldID, field.TypeUint64))
- id, ok := wuo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Whatsapp.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := wuo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, whatsapp.FieldID)
- for _, f := range fields {
- if !whatsapp.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != whatsapp.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := wuo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := wuo.mutation.UpdatedAt(); ok {
- _spec.SetField(whatsapp.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := wuo.mutation.Status(); ok {
- _spec.SetField(whatsapp.FieldStatus, field.TypeUint8, value)
- }
- if value, ok := wuo.mutation.AddedStatus(); ok {
- _spec.AddField(whatsapp.FieldStatus, field.TypeUint8, value)
- }
- if wuo.mutation.StatusCleared() {
- _spec.ClearField(whatsapp.FieldStatus, field.TypeUint8)
- }
- if value, ok := wuo.mutation.DeletedAt(); ok {
- _spec.SetField(whatsapp.FieldDeletedAt, field.TypeTime, value)
- }
- if wuo.mutation.DeletedAtCleared() {
- _spec.ClearField(whatsapp.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := wuo.mutation.Ak(); ok {
- _spec.SetField(whatsapp.FieldAk, field.TypeString, value)
- }
- if wuo.mutation.AkCleared() {
- _spec.ClearField(whatsapp.FieldAk, field.TypeString)
- }
- if value, ok := wuo.mutation.Sk(); ok {
- _spec.SetField(whatsapp.FieldSk, field.TypeString, value)
- }
- if value, ok := wuo.mutation.Callback(); ok {
- _spec.SetField(whatsapp.FieldCallback, field.TypeString, value)
- }
- if value, ok := wuo.mutation.Account(); ok {
- _spec.SetField(whatsapp.FieldAccount, field.TypeString, value)
- }
- if value, ok := wuo.mutation.Nickname(); ok {
- _spec.SetField(whatsapp.FieldNickname, field.TypeString, value)
- }
- if value, ok := wuo.mutation.Phone(); ok {
- _spec.SetField(whatsapp.FieldPhone, field.TypeString, value)
- }
- if value, ok := wuo.mutation.OrganizationID(); ok {
- _spec.SetField(whatsapp.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := wuo.mutation.AddedOrganizationID(); ok {
- _spec.AddField(whatsapp.FieldOrganizationID, field.TypeUint64, value)
- }
- if wuo.mutation.OrganizationIDCleared() {
- _spec.ClearField(whatsapp.FieldOrganizationID, field.TypeUint64)
- }
- if value, ok := wuo.mutation.AgentID(); ok {
- _spec.SetField(whatsapp.FieldAgentID, field.TypeUint64, value)
- }
- if value, ok := wuo.mutation.AddedAgentID(); ok {
- _spec.AddField(whatsapp.FieldAgentID, field.TypeUint64, value)
- }
- if value, ok := wuo.mutation.APIBase(); ok {
- _spec.SetField(whatsapp.FieldAPIBase, field.TypeString, value)
- }
- if wuo.mutation.APIBaseCleared() {
- _spec.ClearField(whatsapp.FieldAPIBase, field.TypeString)
- }
- if value, ok := wuo.mutation.APIKey(); ok {
- _spec.SetField(whatsapp.FieldAPIKey, field.TypeString, value)
- }
- if wuo.mutation.APIKeyCleared() {
- _spec.ClearField(whatsapp.FieldAPIKey, field.TypeString)
- }
- if value, ok := wuo.mutation.AllowList(); ok {
- _spec.SetField(whatsapp.FieldAllowList, field.TypeJSON, value)
- }
- if value, ok := wuo.mutation.AppendedAllowList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, whatsapp.FieldAllowList, value)
- })
- }
- if wuo.mutation.AllowListCleared() {
- _spec.ClearField(whatsapp.FieldAllowList, field.TypeJSON)
- }
- if value, ok := wuo.mutation.GroupAllowList(); ok {
- _spec.SetField(whatsapp.FieldGroupAllowList, field.TypeJSON, value)
- }
- if value, ok := wuo.mutation.AppendedGroupAllowList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, whatsapp.FieldGroupAllowList, value)
- })
- }
- if wuo.mutation.GroupAllowListCleared() {
- _spec.ClearField(whatsapp.FieldGroupAllowList, field.TypeJSON)
- }
- if value, ok := wuo.mutation.BlockList(); ok {
- _spec.SetField(whatsapp.FieldBlockList, field.TypeJSON, value)
- }
- if value, ok := wuo.mutation.AppendedBlockList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, whatsapp.FieldBlockList, value)
- })
- }
- if wuo.mutation.BlockListCleared() {
- _spec.ClearField(whatsapp.FieldBlockList, field.TypeJSON)
- }
- if value, ok := wuo.mutation.GroupBlockList(); ok {
- _spec.SetField(whatsapp.FieldGroupBlockList, field.TypeJSON, value)
- }
- if value, ok := wuo.mutation.AppendedGroupBlockList(); ok {
- _spec.AddModifier(func(u *sql.UpdateBuilder) {
- sqljson.Append(u, whatsapp.FieldGroupBlockList, value)
- })
- }
- if wuo.mutation.GroupBlockListCleared() {
- _spec.ClearField(whatsapp.FieldGroupBlockList, field.TypeJSON)
- }
- _node = &Whatsapp{config: wuo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, wuo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{whatsapp.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- wuo.mutation.done = true
- return _node, nil
- }
|