123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773 |
- // Code generated by ent, DO NOT EDIT.
- package ent
- import (
- "context"
- "errors"
- "fmt"
- "time"
- "wechat-api/ent/agent"
- "wechat-api/ent/apikey"
- "wechat-api/ent/predicate"
- "entgo.io/ent/dialect/sql"
- "entgo.io/ent/dialect/sql/sqlgraph"
- "entgo.io/ent/schema/field"
- )
- // ApiKeyUpdate is the builder for updating ApiKey entities.
- type ApiKeyUpdate struct {
- config
- hooks []Hook
- mutation *ApiKeyMutation
- }
- // Where appends a list predicates to the ApiKeyUpdate builder.
- func (aku *ApiKeyUpdate) Where(ps ...predicate.ApiKey) *ApiKeyUpdate {
- aku.mutation.Where(ps...)
- return aku
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (aku *ApiKeyUpdate) SetUpdatedAt(t time.Time) *ApiKeyUpdate {
- aku.mutation.SetUpdatedAt(t)
- return aku
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (aku *ApiKeyUpdate) SetDeletedAt(t time.Time) *ApiKeyUpdate {
- aku.mutation.SetDeletedAt(t)
- return aku
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (aku *ApiKeyUpdate) SetNillableDeletedAt(t *time.Time) *ApiKeyUpdate {
- if t != nil {
- aku.SetDeletedAt(*t)
- }
- return aku
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (aku *ApiKeyUpdate) ClearDeletedAt() *ApiKeyUpdate {
- aku.mutation.ClearDeletedAt()
- return aku
- }
- // SetTitle sets the "title" field.
- func (aku *ApiKeyUpdate) SetTitle(s string) *ApiKeyUpdate {
- aku.mutation.SetTitle(s)
- return aku
- }
- // SetNillableTitle sets the "title" field if the given value is not nil.
- func (aku *ApiKeyUpdate) SetNillableTitle(s *string) *ApiKeyUpdate {
- if s != nil {
- aku.SetTitle(*s)
- }
- return aku
- }
- // ClearTitle clears the value of the "title" field.
- func (aku *ApiKeyUpdate) ClearTitle() *ApiKeyUpdate {
- aku.mutation.ClearTitle()
- return aku
- }
- // SetKey sets the "key" field.
- func (aku *ApiKeyUpdate) SetKey(s string) *ApiKeyUpdate {
- aku.mutation.SetKey(s)
- return aku
- }
- // SetNillableKey sets the "key" field if the given value is not nil.
- func (aku *ApiKeyUpdate) SetNillableKey(s *string) *ApiKeyUpdate {
- if s != nil {
- aku.SetKey(*s)
- }
- return aku
- }
- // ClearKey clears the value of the "key" field.
- func (aku *ApiKeyUpdate) ClearKey() *ApiKeyUpdate {
- aku.mutation.ClearKey()
- return aku
- }
- // SetOrganizationID sets the "organization_id" field.
- func (aku *ApiKeyUpdate) SetOrganizationID(u uint64) *ApiKeyUpdate {
- aku.mutation.ResetOrganizationID()
- aku.mutation.SetOrganizationID(u)
- return aku
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (aku *ApiKeyUpdate) SetNillableOrganizationID(u *uint64) *ApiKeyUpdate {
- if u != nil {
- aku.SetOrganizationID(*u)
- }
- return aku
- }
- // AddOrganizationID adds u to the "organization_id" field.
- func (aku *ApiKeyUpdate) AddOrganizationID(u int64) *ApiKeyUpdate {
- aku.mutation.AddOrganizationID(u)
- return aku
- }
- // SetAgentID sets the "agent_id" field.
- func (aku *ApiKeyUpdate) SetAgentID(u uint64) *ApiKeyUpdate {
- aku.mutation.SetAgentID(u)
- return aku
- }
- // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
- func (aku *ApiKeyUpdate) SetNillableAgentID(u *uint64) *ApiKeyUpdate {
- if u != nil {
- aku.SetAgentID(*u)
- }
- return aku
- }
- // SetCustomAgentBase sets the "custom_agent_base" field.
- func (aku *ApiKeyUpdate) SetCustomAgentBase(s string) *ApiKeyUpdate {
- aku.mutation.SetCustomAgentBase(s)
- return aku
- }
- // SetNillableCustomAgentBase sets the "custom_agent_base" field if the given value is not nil.
- func (aku *ApiKeyUpdate) SetNillableCustomAgentBase(s *string) *ApiKeyUpdate {
- if s != nil {
- aku.SetCustomAgentBase(*s)
- }
- return aku
- }
- // ClearCustomAgentBase clears the value of the "custom_agent_base" field.
- func (aku *ApiKeyUpdate) ClearCustomAgentBase() *ApiKeyUpdate {
- aku.mutation.ClearCustomAgentBase()
- return aku
- }
- // SetCustomAgentKey sets the "custom_agent_key" field.
- func (aku *ApiKeyUpdate) SetCustomAgentKey(s string) *ApiKeyUpdate {
- aku.mutation.SetCustomAgentKey(s)
- return aku
- }
- // SetNillableCustomAgentKey sets the "custom_agent_key" field if the given value is not nil.
- func (aku *ApiKeyUpdate) SetNillableCustomAgentKey(s *string) *ApiKeyUpdate {
- if s != nil {
- aku.SetCustomAgentKey(*s)
- }
- return aku
- }
- // ClearCustomAgentKey clears the value of the "custom_agent_key" field.
- func (aku *ApiKeyUpdate) ClearCustomAgentKey() *ApiKeyUpdate {
- aku.mutation.ClearCustomAgentKey()
- return aku
- }
- // SetOpenaiBase sets the "openai_base" field.
- func (aku *ApiKeyUpdate) SetOpenaiBase(s string) *ApiKeyUpdate {
- aku.mutation.SetOpenaiBase(s)
- return aku
- }
- // SetNillableOpenaiBase sets the "openai_base" field if the given value is not nil.
- func (aku *ApiKeyUpdate) SetNillableOpenaiBase(s *string) *ApiKeyUpdate {
- if s != nil {
- aku.SetOpenaiBase(*s)
- }
- return aku
- }
- // ClearOpenaiBase clears the value of the "openai_base" field.
- func (aku *ApiKeyUpdate) ClearOpenaiBase() *ApiKeyUpdate {
- aku.mutation.ClearOpenaiBase()
- return aku
- }
- // SetOpenaiKey sets the "openai_key" field.
- func (aku *ApiKeyUpdate) SetOpenaiKey(s string) *ApiKeyUpdate {
- aku.mutation.SetOpenaiKey(s)
- return aku
- }
- // SetNillableOpenaiKey sets the "openai_key" field if the given value is not nil.
- func (aku *ApiKeyUpdate) SetNillableOpenaiKey(s *string) *ApiKeyUpdate {
- if s != nil {
- aku.SetOpenaiKey(*s)
- }
- return aku
- }
- // ClearOpenaiKey clears the value of the "openai_key" field.
- func (aku *ApiKeyUpdate) ClearOpenaiKey() *ApiKeyUpdate {
- aku.mutation.ClearOpenaiKey()
- return aku
- }
- // SetAgent sets the "agent" edge to the Agent entity.
- func (aku *ApiKeyUpdate) SetAgent(a *Agent) *ApiKeyUpdate {
- return aku.SetAgentID(a.ID)
- }
- // Mutation returns the ApiKeyMutation object of the builder.
- func (aku *ApiKeyUpdate) Mutation() *ApiKeyMutation {
- return aku.mutation
- }
- // ClearAgent clears the "agent" edge to the Agent entity.
- func (aku *ApiKeyUpdate) ClearAgent() *ApiKeyUpdate {
- aku.mutation.ClearAgent()
- return aku
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (aku *ApiKeyUpdate) Save(ctx context.Context) (int, error) {
- if err := aku.defaults(); err != nil {
- return 0, err
- }
- return withHooks(ctx, aku.sqlSave, aku.mutation, aku.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (aku *ApiKeyUpdate) SaveX(ctx context.Context) int {
- affected, err := aku.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (aku *ApiKeyUpdate) Exec(ctx context.Context) error {
- _, err := aku.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (aku *ApiKeyUpdate) ExecX(ctx context.Context) {
- if err := aku.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (aku *ApiKeyUpdate) defaults() error {
- if _, ok := aku.mutation.UpdatedAt(); !ok {
- if apikey.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized apikey.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := apikey.UpdateDefaultUpdatedAt()
- aku.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (aku *ApiKeyUpdate) check() error {
- if _, ok := aku.mutation.AgentID(); aku.mutation.AgentCleared() && !ok {
- return errors.New(`ent: clearing a required unique edge "ApiKey.agent"`)
- }
- return nil
- }
- func (aku *ApiKeyUpdate) sqlSave(ctx context.Context) (n int, err error) {
- if err := aku.check(); err != nil {
- return n, err
- }
- _spec := sqlgraph.NewUpdateSpec(apikey.Table, apikey.Columns, sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64))
- if ps := aku.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := aku.mutation.UpdatedAt(); ok {
- _spec.SetField(apikey.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := aku.mutation.DeletedAt(); ok {
- _spec.SetField(apikey.FieldDeletedAt, field.TypeTime, value)
- }
- if aku.mutation.DeletedAtCleared() {
- _spec.ClearField(apikey.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := aku.mutation.Title(); ok {
- _spec.SetField(apikey.FieldTitle, field.TypeString, value)
- }
- if aku.mutation.TitleCleared() {
- _spec.ClearField(apikey.FieldTitle, field.TypeString)
- }
- if value, ok := aku.mutation.Key(); ok {
- _spec.SetField(apikey.FieldKey, field.TypeString, value)
- }
- if aku.mutation.KeyCleared() {
- _spec.ClearField(apikey.FieldKey, field.TypeString)
- }
- if value, ok := aku.mutation.OrganizationID(); ok {
- _spec.SetField(apikey.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := aku.mutation.AddedOrganizationID(); ok {
- _spec.AddField(apikey.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := aku.mutation.CustomAgentBase(); ok {
- _spec.SetField(apikey.FieldCustomAgentBase, field.TypeString, value)
- }
- if aku.mutation.CustomAgentBaseCleared() {
- _spec.ClearField(apikey.FieldCustomAgentBase, field.TypeString)
- }
- if value, ok := aku.mutation.CustomAgentKey(); ok {
- _spec.SetField(apikey.FieldCustomAgentKey, field.TypeString, value)
- }
- if aku.mutation.CustomAgentKeyCleared() {
- _spec.ClearField(apikey.FieldCustomAgentKey, field.TypeString)
- }
- if value, ok := aku.mutation.OpenaiBase(); ok {
- _spec.SetField(apikey.FieldOpenaiBase, field.TypeString, value)
- }
- if aku.mutation.OpenaiBaseCleared() {
- _spec.ClearField(apikey.FieldOpenaiBase, field.TypeString)
- }
- if value, ok := aku.mutation.OpenaiKey(); ok {
- _spec.SetField(apikey.FieldOpenaiKey, field.TypeString, value)
- }
- if aku.mutation.OpenaiKeyCleared() {
- _spec.ClearField(apikey.FieldOpenaiKey, field.TypeString)
- }
- if aku.mutation.AgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: apikey.AgentTable,
- Columns: []string{apikey.AgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := aku.mutation.AgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: apikey.AgentTable,
- Columns: []string{apikey.AgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if n, err = sqlgraph.UpdateNodes(ctx, aku.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{apikey.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- aku.mutation.done = true
- return n, nil
- }
- // ApiKeyUpdateOne is the builder for updating a single ApiKey entity.
- type ApiKeyUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *ApiKeyMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (akuo *ApiKeyUpdateOne) SetUpdatedAt(t time.Time) *ApiKeyUpdateOne {
- akuo.mutation.SetUpdatedAt(t)
- return akuo
- }
- // SetDeletedAt sets the "deleted_at" field.
- func (akuo *ApiKeyUpdateOne) SetDeletedAt(t time.Time) *ApiKeyUpdateOne {
- akuo.mutation.SetDeletedAt(t)
- return akuo
- }
- // SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
- func (akuo *ApiKeyUpdateOne) SetNillableDeletedAt(t *time.Time) *ApiKeyUpdateOne {
- if t != nil {
- akuo.SetDeletedAt(*t)
- }
- return akuo
- }
- // ClearDeletedAt clears the value of the "deleted_at" field.
- func (akuo *ApiKeyUpdateOne) ClearDeletedAt() *ApiKeyUpdateOne {
- akuo.mutation.ClearDeletedAt()
- return akuo
- }
- // SetTitle sets the "title" field.
- func (akuo *ApiKeyUpdateOne) SetTitle(s string) *ApiKeyUpdateOne {
- akuo.mutation.SetTitle(s)
- return akuo
- }
- // SetNillableTitle sets the "title" field if the given value is not nil.
- func (akuo *ApiKeyUpdateOne) SetNillableTitle(s *string) *ApiKeyUpdateOne {
- if s != nil {
- akuo.SetTitle(*s)
- }
- return akuo
- }
- // ClearTitle clears the value of the "title" field.
- func (akuo *ApiKeyUpdateOne) ClearTitle() *ApiKeyUpdateOne {
- akuo.mutation.ClearTitle()
- return akuo
- }
- // SetKey sets the "key" field.
- func (akuo *ApiKeyUpdateOne) SetKey(s string) *ApiKeyUpdateOne {
- akuo.mutation.SetKey(s)
- return akuo
- }
- // SetNillableKey sets the "key" field if the given value is not nil.
- func (akuo *ApiKeyUpdateOne) SetNillableKey(s *string) *ApiKeyUpdateOne {
- if s != nil {
- akuo.SetKey(*s)
- }
- return akuo
- }
- // ClearKey clears the value of the "key" field.
- func (akuo *ApiKeyUpdateOne) ClearKey() *ApiKeyUpdateOne {
- akuo.mutation.ClearKey()
- return akuo
- }
- // SetOrganizationID sets the "organization_id" field.
- func (akuo *ApiKeyUpdateOne) SetOrganizationID(u uint64) *ApiKeyUpdateOne {
- akuo.mutation.ResetOrganizationID()
- akuo.mutation.SetOrganizationID(u)
- return akuo
- }
- // SetNillableOrganizationID sets the "organization_id" field if the given value is not nil.
- func (akuo *ApiKeyUpdateOne) SetNillableOrganizationID(u *uint64) *ApiKeyUpdateOne {
- if u != nil {
- akuo.SetOrganizationID(*u)
- }
- return akuo
- }
- // AddOrganizationID adds u to the "organization_id" field.
- func (akuo *ApiKeyUpdateOne) AddOrganizationID(u int64) *ApiKeyUpdateOne {
- akuo.mutation.AddOrganizationID(u)
- return akuo
- }
- // SetAgentID sets the "agent_id" field.
- func (akuo *ApiKeyUpdateOne) SetAgentID(u uint64) *ApiKeyUpdateOne {
- akuo.mutation.SetAgentID(u)
- return akuo
- }
- // SetNillableAgentID sets the "agent_id" field if the given value is not nil.
- func (akuo *ApiKeyUpdateOne) SetNillableAgentID(u *uint64) *ApiKeyUpdateOne {
- if u != nil {
- akuo.SetAgentID(*u)
- }
- return akuo
- }
- // SetCustomAgentBase sets the "custom_agent_base" field.
- func (akuo *ApiKeyUpdateOne) SetCustomAgentBase(s string) *ApiKeyUpdateOne {
- akuo.mutation.SetCustomAgentBase(s)
- return akuo
- }
- // SetNillableCustomAgentBase sets the "custom_agent_base" field if the given value is not nil.
- func (akuo *ApiKeyUpdateOne) SetNillableCustomAgentBase(s *string) *ApiKeyUpdateOne {
- if s != nil {
- akuo.SetCustomAgentBase(*s)
- }
- return akuo
- }
- // ClearCustomAgentBase clears the value of the "custom_agent_base" field.
- func (akuo *ApiKeyUpdateOne) ClearCustomAgentBase() *ApiKeyUpdateOne {
- akuo.mutation.ClearCustomAgentBase()
- return akuo
- }
- // SetCustomAgentKey sets the "custom_agent_key" field.
- func (akuo *ApiKeyUpdateOne) SetCustomAgentKey(s string) *ApiKeyUpdateOne {
- akuo.mutation.SetCustomAgentKey(s)
- return akuo
- }
- // SetNillableCustomAgentKey sets the "custom_agent_key" field if the given value is not nil.
- func (akuo *ApiKeyUpdateOne) SetNillableCustomAgentKey(s *string) *ApiKeyUpdateOne {
- if s != nil {
- akuo.SetCustomAgentKey(*s)
- }
- return akuo
- }
- // ClearCustomAgentKey clears the value of the "custom_agent_key" field.
- func (akuo *ApiKeyUpdateOne) ClearCustomAgentKey() *ApiKeyUpdateOne {
- akuo.mutation.ClearCustomAgentKey()
- return akuo
- }
- // SetOpenaiBase sets the "openai_base" field.
- func (akuo *ApiKeyUpdateOne) SetOpenaiBase(s string) *ApiKeyUpdateOne {
- akuo.mutation.SetOpenaiBase(s)
- return akuo
- }
- // SetNillableOpenaiBase sets the "openai_base" field if the given value is not nil.
- func (akuo *ApiKeyUpdateOne) SetNillableOpenaiBase(s *string) *ApiKeyUpdateOne {
- if s != nil {
- akuo.SetOpenaiBase(*s)
- }
- return akuo
- }
- // ClearOpenaiBase clears the value of the "openai_base" field.
- func (akuo *ApiKeyUpdateOne) ClearOpenaiBase() *ApiKeyUpdateOne {
- akuo.mutation.ClearOpenaiBase()
- return akuo
- }
- // SetOpenaiKey sets the "openai_key" field.
- func (akuo *ApiKeyUpdateOne) SetOpenaiKey(s string) *ApiKeyUpdateOne {
- akuo.mutation.SetOpenaiKey(s)
- return akuo
- }
- // SetNillableOpenaiKey sets the "openai_key" field if the given value is not nil.
- func (akuo *ApiKeyUpdateOne) SetNillableOpenaiKey(s *string) *ApiKeyUpdateOne {
- if s != nil {
- akuo.SetOpenaiKey(*s)
- }
- return akuo
- }
- // ClearOpenaiKey clears the value of the "openai_key" field.
- func (akuo *ApiKeyUpdateOne) ClearOpenaiKey() *ApiKeyUpdateOne {
- akuo.mutation.ClearOpenaiKey()
- return akuo
- }
- // SetAgent sets the "agent" edge to the Agent entity.
- func (akuo *ApiKeyUpdateOne) SetAgent(a *Agent) *ApiKeyUpdateOne {
- return akuo.SetAgentID(a.ID)
- }
- // Mutation returns the ApiKeyMutation object of the builder.
- func (akuo *ApiKeyUpdateOne) Mutation() *ApiKeyMutation {
- return akuo.mutation
- }
- // ClearAgent clears the "agent" edge to the Agent entity.
- func (akuo *ApiKeyUpdateOne) ClearAgent() *ApiKeyUpdateOne {
- akuo.mutation.ClearAgent()
- return akuo
- }
- // Where appends a list predicates to the ApiKeyUpdate builder.
- func (akuo *ApiKeyUpdateOne) Where(ps ...predicate.ApiKey) *ApiKeyUpdateOne {
- akuo.mutation.Where(ps...)
- return akuo
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (akuo *ApiKeyUpdateOne) Select(field string, fields ...string) *ApiKeyUpdateOne {
- akuo.fields = append([]string{field}, fields...)
- return akuo
- }
- // Save executes the query and returns the updated ApiKey entity.
- func (akuo *ApiKeyUpdateOne) Save(ctx context.Context) (*ApiKey, error) {
- if err := akuo.defaults(); err != nil {
- return nil, err
- }
- return withHooks(ctx, akuo.sqlSave, akuo.mutation, akuo.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (akuo *ApiKeyUpdateOne) SaveX(ctx context.Context) *ApiKey {
- node, err := akuo.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (akuo *ApiKeyUpdateOne) Exec(ctx context.Context) error {
- _, err := akuo.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (akuo *ApiKeyUpdateOne) ExecX(ctx context.Context) {
- if err := akuo.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (akuo *ApiKeyUpdateOne) defaults() error {
- if _, ok := akuo.mutation.UpdatedAt(); !ok {
- if apikey.UpdateDefaultUpdatedAt == nil {
- return fmt.Errorf("ent: uninitialized apikey.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
- }
- v := apikey.UpdateDefaultUpdatedAt()
- akuo.mutation.SetUpdatedAt(v)
- }
- return nil
- }
- // check runs all checks and user-defined validators on the builder.
- func (akuo *ApiKeyUpdateOne) check() error {
- if _, ok := akuo.mutation.AgentID(); akuo.mutation.AgentCleared() && !ok {
- return errors.New(`ent: clearing a required unique edge "ApiKey.agent"`)
- }
- return nil
- }
- func (akuo *ApiKeyUpdateOne) sqlSave(ctx context.Context) (_node *ApiKey, err error) {
- if err := akuo.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(apikey.Table, apikey.Columns, sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeUint64))
- id, ok := akuo.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ApiKey.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := akuo.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, apikey.FieldID)
- for _, f := range fields {
- if !apikey.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != apikey.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := akuo.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := akuo.mutation.UpdatedAt(); ok {
- _spec.SetField(apikey.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := akuo.mutation.DeletedAt(); ok {
- _spec.SetField(apikey.FieldDeletedAt, field.TypeTime, value)
- }
- if akuo.mutation.DeletedAtCleared() {
- _spec.ClearField(apikey.FieldDeletedAt, field.TypeTime)
- }
- if value, ok := akuo.mutation.Title(); ok {
- _spec.SetField(apikey.FieldTitle, field.TypeString, value)
- }
- if akuo.mutation.TitleCleared() {
- _spec.ClearField(apikey.FieldTitle, field.TypeString)
- }
- if value, ok := akuo.mutation.Key(); ok {
- _spec.SetField(apikey.FieldKey, field.TypeString, value)
- }
- if akuo.mutation.KeyCleared() {
- _spec.ClearField(apikey.FieldKey, field.TypeString)
- }
- if value, ok := akuo.mutation.OrganizationID(); ok {
- _spec.SetField(apikey.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := akuo.mutation.AddedOrganizationID(); ok {
- _spec.AddField(apikey.FieldOrganizationID, field.TypeUint64, value)
- }
- if value, ok := akuo.mutation.CustomAgentBase(); ok {
- _spec.SetField(apikey.FieldCustomAgentBase, field.TypeString, value)
- }
- if akuo.mutation.CustomAgentBaseCleared() {
- _spec.ClearField(apikey.FieldCustomAgentBase, field.TypeString)
- }
- if value, ok := akuo.mutation.CustomAgentKey(); ok {
- _spec.SetField(apikey.FieldCustomAgentKey, field.TypeString, value)
- }
- if akuo.mutation.CustomAgentKeyCleared() {
- _spec.ClearField(apikey.FieldCustomAgentKey, field.TypeString)
- }
- if value, ok := akuo.mutation.OpenaiBase(); ok {
- _spec.SetField(apikey.FieldOpenaiBase, field.TypeString, value)
- }
- if akuo.mutation.OpenaiBaseCleared() {
- _spec.ClearField(apikey.FieldOpenaiBase, field.TypeString)
- }
- if value, ok := akuo.mutation.OpenaiKey(); ok {
- _spec.SetField(apikey.FieldOpenaiKey, field.TypeString, value)
- }
- if akuo.mutation.OpenaiKeyCleared() {
- _spec.ClearField(apikey.FieldOpenaiKey, field.TypeString)
- }
- if akuo.mutation.AgentCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: apikey.AgentTable,
- Columns: []string{apikey.AgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := akuo.mutation.AgentIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: apikey.AgentTable,
- Columns: []string{apikey.AgentColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(agent.FieldID, field.TypeUint64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &ApiKey{config: akuo.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, akuo.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{apikey.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- akuo.mutation.done = true
- return _node, nil
- }
|