rag/ent/library_update.go
Twilight df929aa104 改进 swag doc
增加 创建和列出 library
2024-07-15 01:22:40 +08:00

313 lines
8.6 KiB
Go

// 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"
"leafdev.top/leaf/rag/ent/library"
"leafdev.top/leaf/rag/ent/predicate"
)
// 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(s string) *LibraryUpdate {
lu.mutation.SetUserID(s)
return lu
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (lu *LibraryUpdate) SetNillableUserID(s *string) *LibraryUpdate {
if s != nil {
lu.SetUserID(*s)
}
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.TypeString, 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(s string) *LibraryUpdateOne {
luo.mutation.SetUserID(s)
return luo
}
// SetNillableUserID sets the "user_id" field if the given value is not nil.
func (luo *LibraryUpdateOne) SetNillableUserID(s *string) *LibraryUpdateOne {
if s != nil {
luo.SetUserID(*s)
}
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.TypeString, 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
}