333 lines
9.2 KiB
Go
333 lines
9.2 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"leafdev.top/leaf/rag/ent/library"
|
|
"leafdev.top/leaf/rag/ent/predicate"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// LibraryUpdate is the builder for updating Library entities.
|
|
type LibraryUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *LibraryMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the LibraryUpdate builder.
|
|
func (lu *LibraryUpdate) Where(ps ...predicate.Library) *LibraryUpdate {
|
|
lu.mutation.Where(ps...)
|
|
return lu
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (lu *LibraryUpdate) SetName(s string) *LibraryUpdate {
|
|
lu.mutation.SetName(s)
|
|
return lu
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (lu *LibraryUpdate) SetNillableName(s *string) *LibraryUpdate {
|
|
if s != nil {
|
|
lu.SetName(*s)
|
|
}
|
|
return lu
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (lu *LibraryUpdate) SetUserID(u uint64) *LibraryUpdate {
|
|
lu.mutation.ResetUserID()
|
|
lu.mutation.SetUserID(u)
|
|
return lu
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (lu *LibraryUpdate) SetNillableUserID(u *uint64) *LibraryUpdate {
|
|
if u != nil {
|
|
lu.SetUserID(*u)
|
|
}
|
|
return lu
|
|
}
|
|
|
|
// AddUserID adds u to the "user_id" field.
|
|
func (lu *LibraryUpdate) AddUserID(u int64) *LibraryUpdate {
|
|
lu.mutation.AddUserID(u)
|
|
return lu
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (lu *LibraryUpdate) SetCreatedAt(t time.Time) *LibraryUpdate {
|
|
lu.mutation.SetCreatedAt(t)
|
|
return lu
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (lu *LibraryUpdate) SetNillableCreatedAt(t *time.Time) *LibraryUpdate {
|
|
if t != nil {
|
|
lu.SetCreatedAt(*t)
|
|
}
|
|
return lu
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (lu *LibraryUpdate) SetUpdatedAt(t time.Time) *LibraryUpdate {
|
|
lu.mutation.SetUpdatedAt(t)
|
|
return lu
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (lu *LibraryUpdate) SetNillableUpdatedAt(t *time.Time) *LibraryUpdate {
|
|
if t != nil {
|
|
lu.SetUpdatedAt(*t)
|
|
}
|
|
return lu
|
|
}
|
|
|
|
// Mutation returns the LibraryMutation object of the builder.
|
|
func (lu *LibraryUpdate) Mutation() *LibraryMutation {
|
|
return lu.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (lu *LibraryUpdate) Save(ctx context.Context) (int, error) {
|
|
return withHooks(ctx, lu.sqlSave, lu.mutation, lu.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (lu *LibraryUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := lu.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (lu *LibraryUpdate) Exec(ctx context.Context) error {
|
|
_, err := lu.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (lu *LibraryUpdate) ExecX(ctx context.Context) {
|
|
if err := lu.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (lu *LibraryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(library.Table, library.Columns, sqlgraph.NewFieldSpec(library.FieldID, field.TypeInt))
|
|
if ps := lu.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := lu.mutation.Name(); ok {
|
|
_spec.SetField(library.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := lu.mutation.UserID(); ok {
|
|
_spec.SetField(library.FieldUserID, field.TypeUint64, value)
|
|
}
|
|
if value, ok := lu.mutation.AddedUserID(); ok {
|
|
_spec.AddField(library.FieldUserID, field.TypeUint64, value)
|
|
}
|
|
if value, ok := lu.mutation.CreatedAt(); ok {
|
|
_spec.SetField(library.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := lu.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(library.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
if n, err = sqlgraph.UpdateNodes(ctx, lu.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{library.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
lu.mutation.done = true
|
|
return n, nil
|
|
}
|
|
|
|
// LibraryUpdateOne is the builder for updating a single Library entity.
|
|
type LibraryUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *LibraryMutation
|
|
}
|
|
|
|
// SetName sets the "name" field.
|
|
func (luo *LibraryUpdateOne) SetName(s string) *LibraryUpdateOne {
|
|
luo.mutation.SetName(s)
|
|
return luo
|
|
}
|
|
|
|
// SetNillableName sets the "name" field if the given value is not nil.
|
|
func (luo *LibraryUpdateOne) SetNillableName(s *string) *LibraryUpdateOne {
|
|
if s != nil {
|
|
luo.SetName(*s)
|
|
}
|
|
return luo
|
|
}
|
|
|
|
// SetUserID sets the "user_id" field.
|
|
func (luo *LibraryUpdateOne) SetUserID(u uint64) *LibraryUpdateOne {
|
|
luo.mutation.ResetUserID()
|
|
luo.mutation.SetUserID(u)
|
|
return luo
|
|
}
|
|
|
|
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
|
func (luo *LibraryUpdateOne) SetNillableUserID(u *uint64) *LibraryUpdateOne {
|
|
if u != nil {
|
|
luo.SetUserID(*u)
|
|
}
|
|
return luo
|
|
}
|
|
|
|
// AddUserID adds u to the "user_id" field.
|
|
func (luo *LibraryUpdateOne) AddUserID(u int64) *LibraryUpdateOne {
|
|
luo.mutation.AddUserID(u)
|
|
return luo
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (luo *LibraryUpdateOne) SetCreatedAt(t time.Time) *LibraryUpdateOne {
|
|
luo.mutation.SetCreatedAt(t)
|
|
return luo
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (luo *LibraryUpdateOne) SetNillableCreatedAt(t *time.Time) *LibraryUpdateOne {
|
|
if t != nil {
|
|
luo.SetCreatedAt(*t)
|
|
}
|
|
return luo
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (luo *LibraryUpdateOne) SetUpdatedAt(t time.Time) *LibraryUpdateOne {
|
|
luo.mutation.SetUpdatedAt(t)
|
|
return luo
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (luo *LibraryUpdateOne) SetNillableUpdatedAt(t *time.Time) *LibraryUpdateOne {
|
|
if t != nil {
|
|
luo.SetUpdatedAt(*t)
|
|
}
|
|
return luo
|
|
}
|
|
|
|
// Mutation returns the LibraryMutation object of the builder.
|
|
func (luo *LibraryUpdateOne) Mutation() *LibraryMutation {
|
|
return luo.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the LibraryUpdate builder.
|
|
func (luo *LibraryUpdateOne) Where(ps ...predicate.Library) *LibraryUpdateOne {
|
|
luo.mutation.Where(ps...)
|
|
return luo
|
|
}
|
|
|
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
|
// The default is selecting all fields defined in the entity schema.
|
|
func (luo *LibraryUpdateOne) Select(field string, fields ...string) *LibraryUpdateOne {
|
|
luo.fields = append([]string{field}, fields...)
|
|
return luo
|
|
}
|
|
|
|
// Save executes the query and returns the updated Library entity.
|
|
func (luo *LibraryUpdateOne) Save(ctx context.Context) (*Library, error) {
|
|
return withHooks(ctx, luo.sqlSave, luo.mutation, luo.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (luo *LibraryUpdateOne) SaveX(ctx context.Context) *Library {
|
|
node, err := luo.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (luo *LibraryUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := luo.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (luo *LibraryUpdateOne) ExecX(ctx context.Context) {
|
|
if err := luo.Exec(ctx); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
|
|
func (luo *LibraryUpdateOne) sqlSave(ctx context.Context) (_node *Library, err error) {
|
|
_spec := sqlgraph.NewUpdateSpec(library.Table, library.Columns, sqlgraph.NewFieldSpec(library.FieldID, field.TypeInt))
|
|
id, ok := luo.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Library.id" for update`)}
|
|
}
|
|
_spec.Node.ID.Value = id
|
|
if fields := luo.fields; len(fields) > 0 {
|
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
|
_spec.Node.Columns = append(_spec.Node.Columns, library.FieldID)
|
|
for _, f := range fields {
|
|
if !library.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != library.FieldID {
|
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
|
}
|
|
}
|
|
}
|
|
if ps := luo.mutation.predicates; len(ps) > 0 {
|
|
_spec.Predicate = func(selector *sql.Selector) {
|
|
for i := range ps {
|
|
ps[i](selector)
|
|
}
|
|
}
|
|
}
|
|
if value, ok := luo.mutation.Name(); ok {
|
|
_spec.SetField(library.FieldName, field.TypeString, value)
|
|
}
|
|
if value, ok := luo.mutation.UserID(); ok {
|
|
_spec.SetField(library.FieldUserID, field.TypeUint64, value)
|
|
}
|
|
if value, ok := luo.mutation.AddedUserID(); ok {
|
|
_spec.AddField(library.FieldUserID, field.TypeUint64, value)
|
|
}
|
|
if value, ok := luo.mutation.CreatedAt(); ok {
|
|
_spec.SetField(library.FieldCreatedAt, field.TypeTime, value)
|
|
}
|
|
if value, ok := luo.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(library.FieldUpdatedAt, field.TypeTime, value)
|
|
}
|
|
_node = &Library{config: luo.config}
|
|
_spec.Assign = _node.assignValues
|
|
_spec.ScanValues = _node.scanValues
|
|
if err = sqlgraph.UpdateNode(ctx, luo.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{library.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
luo.mutation.done = true
|
|
return _node, nil
|
|
}
|