session_update.go•7.91 kB
// 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/Southclaws/storyden/internal/ent/predicate"
"github.com/Southclaws/storyden/internal/ent/session"
)
// SessionUpdate is the builder for updating Session entities.
type SessionUpdate struct {
config
hooks []Hook
mutation *SessionMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the SessionUpdate builder.
func (_u *SessionUpdate) Where(ps ...predicate.Session) *SessionUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetRevokedAt sets the "revoked_at" field.
func (_u *SessionUpdate) SetRevokedAt(v time.Time) *SessionUpdate {
_u.mutation.SetRevokedAt(v)
return _u
}
// SetNillableRevokedAt sets the "revoked_at" field if the given value is not nil.
func (_u *SessionUpdate) SetNillableRevokedAt(v *time.Time) *SessionUpdate {
if v != nil {
_u.SetRevokedAt(*v)
}
return _u
}
// ClearRevokedAt clears the value of the "revoked_at" field.
func (_u *SessionUpdate) ClearRevokedAt() *SessionUpdate {
_u.mutation.ClearRevokedAt()
return _u
}
// Mutation returns the SessionMutation object of the builder.
func (_u *SessionUpdate) Mutation() *SessionMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *SessionUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *SessionUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *SessionUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *SessionUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *SessionUpdate) check() error {
if _u.mutation.AccountCleared() && len(_u.mutation.AccountIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "Session.account"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *SessionUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SessionUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *SessionUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(session.Table, session.Columns, sqlgraph.NewFieldSpec(session.FieldID, field.TypeString))
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.RevokedAt(); ok {
_spec.SetField(session.FieldRevokedAt, field.TypeTime, value)
}
if _u.mutation.RevokedAtCleared() {
_spec.ClearField(session.FieldRevokedAt, field.TypeTime)
}
_spec.AddModifiers(_u.modifiers...)
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{session.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// SessionUpdateOne is the builder for updating a single Session entity.
type SessionUpdateOne struct {
config
fields []string
hooks []Hook
mutation *SessionMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetRevokedAt sets the "revoked_at" field.
func (_u *SessionUpdateOne) SetRevokedAt(v time.Time) *SessionUpdateOne {
_u.mutation.SetRevokedAt(v)
return _u
}
// SetNillableRevokedAt sets the "revoked_at" field if the given value is not nil.
func (_u *SessionUpdateOne) SetNillableRevokedAt(v *time.Time) *SessionUpdateOne {
if v != nil {
_u.SetRevokedAt(*v)
}
return _u
}
// ClearRevokedAt clears the value of the "revoked_at" field.
func (_u *SessionUpdateOne) ClearRevokedAt() *SessionUpdateOne {
_u.mutation.ClearRevokedAt()
return _u
}
// Mutation returns the SessionMutation object of the builder.
func (_u *SessionUpdateOne) Mutation() *SessionMutation {
return _u.mutation
}
// Where appends a list predicates to the SessionUpdate builder.
func (_u *SessionUpdateOne) Where(ps ...predicate.Session) *SessionUpdateOne {
_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 *SessionUpdateOne) Select(field string, fields ...string) *SessionUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Session entity.
func (_u *SessionUpdateOne) Save(ctx context.Context) (*Session, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *SessionUpdateOne) SaveX(ctx context.Context) *Session {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *SessionUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *SessionUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *SessionUpdateOne) check() error {
if _u.mutation.AccountCleared() && len(_u.mutation.AccountIDs()) > 0 {
return errors.New(`ent: clearing a required unique edge "Session.account"`)
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *SessionUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *SessionUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *SessionUpdateOne) sqlSave(ctx context.Context) (_node *Session, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(session.Table, session.Columns, sqlgraph.NewFieldSpec(session.FieldID, field.TypeString))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Session.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, session.FieldID)
for _, f := range fields {
if !session.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != session.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.RevokedAt(); ok {
_spec.SetField(session.FieldRevokedAt, field.TypeTime, value)
}
if _u.mutation.RevokedAtCleared() {
_spec.ClearField(session.FieldRevokedAt, field.TypeTime)
}
_spec.AddModifiers(_u.modifiers...)
_node = &Session{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{session.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}