| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- // 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/authidentity"
- "github.com/Wei-Shaw/sub2api/ent/identityadoptiondecision"
- "github.com/Wei-Shaw/sub2api/ent/pendingauthsession"
- "github.com/Wei-Shaw/sub2api/ent/predicate"
- )
- // IdentityAdoptionDecisionUpdate is the builder for updating IdentityAdoptionDecision entities.
- type IdentityAdoptionDecisionUpdate struct {
- config
- hooks []Hook
- mutation *IdentityAdoptionDecisionMutation
- }
- // Where appends a list predicates to the IdentityAdoptionDecisionUpdate builder.
- func (_u *IdentityAdoptionDecisionUpdate) Where(ps ...predicate.IdentityAdoptionDecision) *IdentityAdoptionDecisionUpdate {
- _u.mutation.Where(ps...)
- return _u
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *IdentityAdoptionDecisionUpdate) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpdate {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetPendingAuthSessionID sets the "pending_auth_session_id" field.
- func (_u *IdentityAdoptionDecisionUpdate) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpdate {
- _u.mutation.SetPendingAuthSessionID(v)
- return _u
- }
- // SetNillablePendingAuthSessionID sets the "pending_auth_session_id" field if the given value is not nil.
- func (_u *IdentityAdoptionDecisionUpdate) SetNillablePendingAuthSessionID(v *int64) *IdentityAdoptionDecisionUpdate {
- if v != nil {
- _u.SetPendingAuthSessionID(*v)
- }
- return _u
- }
- // SetIdentityID sets the "identity_id" field.
- func (_u *IdentityAdoptionDecisionUpdate) SetIdentityID(v int64) *IdentityAdoptionDecisionUpdate {
- _u.mutation.SetIdentityID(v)
- return _u
- }
- // SetNillableIdentityID sets the "identity_id" field if the given value is not nil.
- func (_u *IdentityAdoptionDecisionUpdate) SetNillableIdentityID(v *int64) *IdentityAdoptionDecisionUpdate {
- if v != nil {
- _u.SetIdentityID(*v)
- }
- return _u
- }
- // ClearIdentityID clears the value of the "identity_id" field.
- func (_u *IdentityAdoptionDecisionUpdate) ClearIdentityID() *IdentityAdoptionDecisionUpdate {
- _u.mutation.ClearIdentityID()
- return _u
- }
- // SetAdoptDisplayName sets the "adopt_display_name" field.
- func (_u *IdentityAdoptionDecisionUpdate) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpdate {
- _u.mutation.SetAdoptDisplayName(v)
- return _u
- }
- // SetNillableAdoptDisplayName sets the "adopt_display_name" field if the given value is not nil.
- func (_u *IdentityAdoptionDecisionUpdate) SetNillableAdoptDisplayName(v *bool) *IdentityAdoptionDecisionUpdate {
- if v != nil {
- _u.SetAdoptDisplayName(*v)
- }
- return _u
- }
- // SetAdoptAvatar sets the "adopt_avatar" field.
- func (_u *IdentityAdoptionDecisionUpdate) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpdate {
- _u.mutation.SetAdoptAvatar(v)
- return _u
- }
- // SetNillableAdoptAvatar sets the "adopt_avatar" field if the given value is not nil.
- func (_u *IdentityAdoptionDecisionUpdate) SetNillableAdoptAvatar(v *bool) *IdentityAdoptionDecisionUpdate {
- if v != nil {
- _u.SetAdoptAvatar(*v)
- }
- return _u
- }
- // SetPendingAuthSession sets the "pending_auth_session" edge to the PendingAuthSession entity.
- func (_u *IdentityAdoptionDecisionUpdate) SetPendingAuthSession(v *PendingAuthSession) *IdentityAdoptionDecisionUpdate {
- return _u.SetPendingAuthSessionID(v.ID)
- }
- // SetIdentity sets the "identity" edge to the AuthIdentity entity.
- func (_u *IdentityAdoptionDecisionUpdate) SetIdentity(v *AuthIdentity) *IdentityAdoptionDecisionUpdate {
- return _u.SetIdentityID(v.ID)
- }
- // Mutation returns the IdentityAdoptionDecisionMutation object of the builder.
- func (_u *IdentityAdoptionDecisionUpdate) Mutation() *IdentityAdoptionDecisionMutation {
- return _u.mutation
- }
- // ClearPendingAuthSession clears the "pending_auth_session" edge to the PendingAuthSession entity.
- func (_u *IdentityAdoptionDecisionUpdate) ClearPendingAuthSession() *IdentityAdoptionDecisionUpdate {
- _u.mutation.ClearPendingAuthSession()
- return _u
- }
- // ClearIdentity clears the "identity" edge to the AuthIdentity entity.
- func (_u *IdentityAdoptionDecisionUpdate) ClearIdentity() *IdentityAdoptionDecisionUpdate {
- _u.mutation.ClearIdentity()
- return _u
- }
- // Save executes the query and returns the number of nodes affected by the update operation.
- func (_u *IdentityAdoptionDecisionUpdate) Save(ctx context.Context) (int, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *IdentityAdoptionDecisionUpdate) SaveX(ctx context.Context) int {
- affected, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return affected
- }
- // Exec executes the query.
- func (_u *IdentityAdoptionDecisionUpdate) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *IdentityAdoptionDecisionUpdate) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *IdentityAdoptionDecisionUpdate) defaults() {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- v := identityadoptiondecision.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *IdentityAdoptionDecisionUpdate) check() error {
- if _u.mutation.PendingAuthSessionCleared() && len(_u.mutation.PendingAuthSessionIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "IdentityAdoptionDecision.pending_auth_session"`)
- }
- return nil
- }
- func (_u *IdentityAdoptionDecisionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(identityadoptiondecision.Table, identityadoptiondecision.Columns, sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64))
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(identityadoptiondecision.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.AdoptDisplayName(); ok {
- _spec.SetField(identityadoptiondecision.FieldAdoptDisplayName, field.TypeBool, value)
- }
- if value, ok := _u.mutation.AdoptAvatar(); ok {
- _spec.SetField(identityadoptiondecision.FieldAdoptAvatar, field.TypeBool, value)
- }
- if _u.mutation.PendingAuthSessionCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2O,
- Inverse: true,
- Table: identityadoptiondecision.PendingAuthSessionTable,
- Columns: []string{identityadoptiondecision.PendingAuthSessionColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.PendingAuthSessionIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2O,
- Inverse: true,
- Table: identityadoptiondecision.PendingAuthSessionTable,
- Columns: []string{identityadoptiondecision.PendingAuthSessionColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.IdentityCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: identityadoptiondecision.IdentityTable,
- Columns: []string{identityadoptiondecision.IdentityColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.IdentityIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: identityadoptiondecision.IdentityTable,
- Columns: []string{identityadoptiondecision.IdentityColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{identityadoptiondecision.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return 0, err
- }
- _u.mutation.done = true
- return _node, nil
- }
- // IdentityAdoptionDecisionUpdateOne is the builder for updating a single IdentityAdoptionDecision entity.
- type IdentityAdoptionDecisionUpdateOne struct {
- config
- fields []string
- hooks []Hook
- mutation *IdentityAdoptionDecisionMutation
- }
- // SetUpdatedAt sets the "updated_at" field.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetUpdatedAt(v time.Time) *IdentityAdoptionDecisionUpdateOne {
- _u.mutation.SetUpdatedAt(v)
- return _u
- }
- // SetPendingAuthSessionID sets the "pending_auth_session_id" field.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetPendingAuthSessionID(v int64) *IdentityAdoptionDecisionUpdateOne {
- _u.mutation.SetPendingAuthSessionID(v)
- return _u
- }
- // SetNillablePendingAuthSessionID sets the "pending_auth_session_id" field if the given value is not nil.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetNillablePendingAuthSessionID(v *int64) *IdentityAdoptionDecisionUpdateOne {
- if v != nil {
- _u.SetPendingAuthSessionID(*v)
- }
- return _u
- }
- // SetIdentityID sets the "identity_id" field.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetIdentityID(v int64) *IdentityAdoptionDecisionUpdateOne {
- _u.mutation.SetIdentityID(v)
- return _u
- }
- // SetNillableIdentityID sets the "identity_id" field if the given value is not nil.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetNillableIdentityID(v *int64) *IdentityAdoptionDecisionUpdateOne {
- if v != nil {
- _u.SetIdentityID(*v)
- }
- return _u
- }
- // ClearIdentityID clears the value of the "identity_id" field.
- func (_u *IdentityAdoptionDecisionUpdateOne) ClearIdentityID() *IdentityAdoptionDecisionUpdateOne {
- _u.mutation.ClearIdentityID()
- return _u
- }
- // SetAdoptDisplayName sets the "adopt_display_name" field.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetAdoptDisplayName(v bool) *IdentityAdoptionDecisionUpdateOne {
- _u.mutation.SetAdoptDisplayName(v)
- return _u
- }
- // SetNillableAdoptDisplayName sets the "adopt_display_name" field if the given value is not nil.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetNillableAdoptDisplayName(v *bool) *IdentityAdoptionDecisionUpdateOne {
- if v != nil {
- _u.SetAdoptDisplayName(*v)
- }
- return _u
- }
- // SetAdoptAvatar sets the "adopt_avatar" field.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetAdoptAvatar(v bool) *IdentityAdoptionDecisionUpdateOne {
- _u.mutation.SetAdoptAvatar(v)
- return _u
- }
- // SetNillableAdoptAvatar sets the "adopt_avatar" field if the given value is not nil.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetNillableAdoptAvatar(v *bool) *IdentityAdoptionDecisionUpdateOne {
- if v != nil {
- _u.SetAdoptAvatar(*v)
- }
- return _u
- }
- // SetPendingAuthSession sets the "pending_auth_session" edge to the PendingAuthSession entity.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetPendingAuthSession(v *PendingAuthSession) *IdentityAdoptionDecisionUpdateOne {
- return _u.SetPendingAuthSessionID(v.ID)
- }
- // SetIdentity sets the "identity" edge to the AuthIdentity entity.
- func (_u *IdentityAdoptionDecisionUpdateOne) SetIdentity(v *AuthIdentity) *IdentityAdoptionDecisionUpdateOne {
- return _u.SetIdentityID(v.ID)
- }
- // Mutation returns the IdentityAdoptionDecisionMutation object of the builder.
- func (_u *IdentityAdoptionDecisionUpdateOne) Mutation() *IdentityAdoptionDecisionMutation {
- return _u.mutation
- }
- // ClearPendingAuthSession clears the "pending_auth_session" edge to the PendingAuthSession entity.
- func (_u *IdentityAdoptionDecisionUpdateOne) ClearPendingAuthSession() *IdentityAdoptionDecisionUpdateOne {
- _u.mutation.ClearPendingAuthSession()
- return _u
- }
- // ClearIdentity clears the "identity" edge to the AuthIdentity entity.
- func (_u *IdentityAdoptionDecisionUpdateOne) ClearIdentity() *IdentityAdoptionDecisionUpdateOne {
- _u.mutation.ClearIdentity()
- return _u
- }
- // Where appends a list predicates to the IdentityAdoptionDecisionUpdate builder.
- func (_u *IdentityAdoptionDecisionUpdateOne) Where(ps ...predicate.IdentityAdoptionDecision) *IdentityAdoptionDecisionUpdateOne {
- _u.mutation.Where(ps...)
- return _u
- }
- // Select allows selecting one or more fields (columns) of the returned entity.
- // The default is selecting all fields defined in the entity schema.
- func (_u *IdentityAdoptionDecisionUpdateOne) Select(field string, fields ...string) *IdentityAdoptionDecisionUpdateOne {
- _u.fields = append([]string{field}, fields...)
- return _u
- }
- // Save executes the query and returns the updated IdentityAdoptionDecision entity.
- func (_u *IdentityAdoptionDecisionUpdateOne) Save(ctx context.Context) (*IdentityAdoptionDecision, error) {
- _u.defaults()
- return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
- }
- // SaveX is like Save, but panics if an error occurs.
- func (_u *IdentityAdoptionDecisionUpdateOne) SaveX(ctx context.Context) *IdentityAdoptionDecision {
- node, err := _u.Save(ctx)
- if err != nil {
- panic(err)
- }
- return node
- }
- // Exec executes the query on the entity.
- func (_u *IdentityAdoptionDecisionUpdateOne) Exec(ctx context.Context) error {
- _, err := _u.Save(ctx)
- return err
- }
- // ExecX is like Exec, but panics if an error occurs.
- func (_u *IdentityAdoptionDecisionUpdateOne) ExecX(ctx context.Context) {
- if err := _u.Exec(ctx); err != nil {
- panic(err)
- }
- }
- // defaults sets the default values of the builder before save.
- func (_u *IdentityAdoptionDecisionUpdateOne) defaults() {
- if _, ok := _u.mutation.UpdatedAt(); !ok {
- v := identityadoptiondecision.UpdateDefaultUpdatedAt()
- _u.mutation.SetUpdatedAt(v)
- }
- }
- // check runs all checks and user-defined validators on the builder.
- func (_u *IdentityAdoptionDecisionUpdateOne) check() error {
- if _u.mutation.PendingAuthSessionCleared() && len(_u.mutation.PendingAuthSessionIDs()) > 0 {
- return errors.New(`ent: clearing a required unique edge "IdentityAdoptionDecision.pending_auth_session"`)
- }
- return nil
- }
- func (_u *IdentityAdoptionDecisionUpdateOne) sqlSave(ctx context.Context) (_node *IdentityAdoptionDecision, err error) {
- if err := _u.check(); err != nil {
- return _node, err
- }
- _spec := sqlgraph.NewUpdateSpec(identityadoptiondecision.Table, identityadoptiondecision.Columns, sqlgraph.NewFieldSpec(identityadoptiondecision.FieldID, field.TypeInt64))
- id, ok := _u.mutation.ID()
- if !ok {
- return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "IdentityAdoptionDecision.id" for update`)}
- }
- _spec.Node.ID.Value = id
- if fields := _u.fields; len(fields) > 0 {
- _spec.Node.Columns = make([]string, 0, len(fields))
- _spec.Node.Columns = append(_spec.Node.Columns, identityadoptiondecision.FieldID)
- for _, f := range fields {
- if !identityadoptiondecision.ValidColumn(f) {
- return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
- }
- if f != identityadoptiondecision.FieldID {
- _spec.Node.Columns = append(_spec.Node.Columns, f)
- }
- }
- }
- if ps := _u.mutation.predicates; len(ps) > 0 {
- _spec.Predicate = func(selector *sql.Selector) {
- for i := range ps {
- ps[i](selector)
- }
- }
- }
- if value, ok := _u.mutation.UpdatedAt(); ok {
- _spec.SetField(identityadoptiondecision.FieldUpdatedAt, field.TypeTime, value)
- }
- if value, ok := _u.mutation.AdoptDisplayName(); ok {
- _spec.SetField(identityadoptiondecision.FieldAdoptDisplayName, field.TypeBool, value)
- }
- if value, ok := _u.mutation.AdoptAvatar(); ok {
- _spec.SetField(identityadoptiondecision.FieldAdoptAvatar, field.TypeBool, value)
- }
- if _u.mutation.PendingAuthSessionCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2O,
- Inverse: true,
- Table: identityadoptiondecision.PendingAuthSessionTable,
- Columns: []string{identityadoptiondecision.PendingAuthSessionColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.PendingAuthSessionIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.O2O,
- Inverse: true,
- Table: identityadoptiondecision.PendingAuthSessionTable,
- Columns: []string{identityadoptiondecision.PendingAuthSessionColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(pendingauthsession.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- if _u.mutation.IdentityCleared() {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: identityadoptiondecision.IdentityTable,
- Columns: []string{identityadoptiondecision.IdentityColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
- },
- }
- _spec.Edges.Clear = append(_spec.Edges.Clear, edge)
- }
- if nodes := _u.mutation.IdentityIDs(); len(nodes) > 0 {
- edge := &sqlgraph.EdgeSpec{
- Rel: sqlgraph.M2O,
- Inverse: true,
- Table: identityadoptiondecision.IdentityTable,
- Columns: []string{identityadoptiondecision.IdentityColumn},
- Bidi: false,
- Target: &sqlgraph.EdgeTarget{
- IDSpec: sqlgraph.NewFieldSpec(authidentity.FieldID, field.TypeInt64),
- },
- }
- for _, k := range nodes {
- edge.Target.Nodes = append(edge.Target.Nodes, k)
- }
- _spec.Edges.Add = append(_spec.Edges.Add, edge)
- }
- _node = &IdentityAdoptionDecision{config: _u.config}
- _spec.Assign = _node.assignValues
- _spec.ScanValues = _node.scanValues
- if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
- if _, ok := err.(*sqlgraph.NotFoundError); ok {
- err = &NotFoundError{identityadoptiondecision.Label}
- } else if sqlgraph.IsConstraintError(err) {
- err = &ConstraintError{msg: err.Error(), wrap: err}
- }
- return nil, err
- }
- _u.mutation.done = true
- return _node, nil
- }
|