diff --git a/ent/client.go b/ent/client.go index 83e67a1d..ecd0cf05 100644 --- a/ent/client.go +++ b/ent/client.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "log" + "reflect" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/migrate" @@ -59,9 +60,7 @@ type Client struct { // NewClient creates a new client configured with the given options. func NewClient(opts ...Option) *Client { - cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} - cfg.options(opts...) - client := &Client{config: cfg} + client := &Client{config: newConfig(opts...)} client.init() return client } @@ -99,6 +98,13 @@ type ( Option func(*config) ) +// newConfig creates a new config for the client. +func newConfig(opts ...Option) config { + cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}} + cfg.options(opts...) + return cfg +} + // options applies the options on the config object. func (c *config) options(opts ...Option) { for _, opt := range opts { @@ -146,11 +152,14 @@ func Open(driverName, dataSourceName string, options ...Option) (*Client, error) } } +// ErrTxStarted is returned when trying to start a new transaction from a transactional client. +var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction") + // Tx returns a new transactional client. The provided context // is used until the transaction is committed or rolled back. func (c *Client) Tx(ctx context.Context) (*Tx, error) { if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") + return nil, ErrTxStarted } tx, err := newTx(ctx, c.driver) if err != nil { @@ -312,6 +321,21 @@ func (c *CommentClient) CreateBulk(builders ...*CommentCreate) *CommentCreateBul return &CommentCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *CommentClient) MapCreateBulk(slice any, setFunc func(*CommentCreate, int)) *CommentCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &CommentCreateBulk{err: fmt.Errorf("calling to CommentClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*CommentCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &CommentCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Comment. func (c *CommentClient) Update() *CommentUpdate { mutation := newCommentMutation(c.config, OpUpdate) @@ -462,6 +486,21 @@ func (c *FileClient) CreateBulk(builders ...*FileCreate) *FileCreateBulk { return &FileCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *FileClient) MapCreateBulk(slice any, setFunc func(*FileCreate, int)) *FileCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &FileCreateBulk{err: fmt.Errorf("calling to FileClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*FileCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &FileCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for File. func (c *FileClient) Update() *FileUpdate { mutation := newFileMutation(c.config, OpUpdate) @@ -612,6 +651,21 @@ func (c *GroupClient) CreateBulk(builders ...*GroupCreate) *GroupCreateBulk { return &GroupCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GroupClient) MapCreateBulk(slice any, setFunc func(*GroupCreate, int)) *GroupCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GroupCreateBulk{err: fmt.Errorf("calling to GroupClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GroupCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GroupCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Group. func (c *GroupClient) Update() *GroupUpdate { mutation := newGroupMutation(c.config, OpUpdate) @@ -794,6 +848,21 @@ func (c *GroupBudgetClient) CreateBulk(builders ...*GroupBudgetCreate) *GroupBud return &GroupBudgetCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *GroupBudgetClient) MapCreateBulk(slice any, setFunc func(*GroupBudgetCreate, int)) *GroupBudgetCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &GroupBudgetCreateBulk{err: fmt.Errorf("calling to GroupBudgetClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*GroupBudgetCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &GroupBudgetCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for GroupBudget. func (c *GroupBudgetClient) Update() *GroupBudgetUpdate { mutation := newGroupBudgetMutation(c.config, OpUpdate) @@ -944,6 +1013,21 @@ func (c *RequestClient) CreateBulk(builders ...*RequestCreate) *RequestCreateBul return &RequestCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *RequestClient) MapCreateBulk(slice any, setFunc func(*RequestCreate, int)) *RequestCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &RequestCreateBulk{err: fmt.Errorf("calling to RequestClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*RequestCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &RequestCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Request. func (c *RequestClient) Update() *RequestUpdate { mutation := newRequestMutation(c.config, OpUpdate) @@ -1190,6 +1274,21 @@ func (c *RequestStatusClient) CreateBulk(builders ...*RequestStatusCreate) *Requ return &RequestStatusCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *RequestStatusClient) MapCreateBulk(slice any, setFunc func(*RequestStatusCreate, int)) *RequestStatusCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &RequestStatusCreateBulk{err: fmt.Errorf("calling to RequestStatusClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*RequestStatusCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &RequestStatusCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for RequestStatus. func (c *RequestStatusClient) Update() *RequestStatusUpdate { mutation := newRequestStatusMutation(c.config, OpUpdate) @@ -1340,6 +1439,21 @@ func (c *RequestTargetClient) CreateBulk(builders ...*RequestTargetCreate) *Requ return &RequestTargetCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *RequestTargetClient) MapCreateBulk(slice any, setFunc func(*RequestTargetCreate, int)) *RequestTargetCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &RequestTargetCreateBulk{err: fmt.Errorf("calling to RequestTargetClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*RequestTargetCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &RequestTargetCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for RequestTarget. func (c *RequestTargetClient) Update() *RequestTargetUpdate { mutation := newRequestTargetMutation(c.config, OpUpdate) @@ -1490,6 +1604,21 @@ func (c *TagClient) CreateBulk(builders ...*TagCreate) *TagCreateBulk { return &TagCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TagClient) MapCreateBulk(slice any, setFunc func(*TagCreate, int)) *TagCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TagCreateBulk{err: fmt.Errorf("calling to TagClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TagCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TagCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Tag. func (c *TagClient) Update() *TagUpdate { mutation := newTagMutation(c.config, OpUpdate) @@ -1640,6 +1769,21 @@ func (c *TransactionClient) CreateBulk(builders ...*TransactionCreate) *Transact return &TransactionCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TransactionClient) MapCreateBulk(slice any, setFunc func(*TransactionCreate, int)) *TransactionCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TransactionCreateBulk{err: fmt.Errorf("calling to TransactionClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TransactionCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TransactionCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for Transaction. func (c *TransactionClient) Update() *TransactionUpdate { mutation := newTransactionMutation(c.config, OpUpdate) @@ -1822,6 +1966,21 @@ func (c *TransactionDetailClient) CreateBulk(builders ...*TransactionDetailCreat return &TransactionDetailCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *TransactionDetailClient) MapCreateBulk(slice any, setFunc func(*TransactionDetailCreate, int)) *TransactionDetailCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &TransactionDetailCreateBulk{err: fmt.Errorf("calling to TransactionDetailClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*TransactionDetailCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &TransactionDetailCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for TransactionDetail. func (c *TransactionDetailClient) Update() *TransactionDetailUpdate { mutation := newTransactionDetailMutation(c.config, OpUpdate) @@ -1956,6 +2115,21 @@ func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk { return &UserCreateBulk{config: c.config, builders: builders} } +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*UserCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &UserCreateBulk{config: c.config, builders: builders} +} + // Update returns an update builder for User. func (c *UserClient) Update() *UserUpdate { mutation := newUserMutation(c.config, OpUpdate) diff --git a/ent/comment.go b/ent/comment.go index 707f5a9c..818af558 100644 --- a/ent/comment.go +++ b/ent/comment.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/comment" @@ -32,6 +33,7 @@ type Comment struct { Edges CommentEdges `json:"edges"` comment_user *uuid.UUID request_comment *uuid.UUID + selectValues sql.SelectValues } // CommentEdges holds the relations/edges for other nodes in the graph. @@ -48,12 +50,10 @@ type CommentEdges struct { // RequestOrErr returns the Request value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e CommentEdges) RequestOrErr() (*Request, error) { - if e.loadedTypes[0] { - if e.Request == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: request.Label} - } + if e.Request != nil { return e.Request, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: request.Label} } return nil, &NotLoadedError{edge: "request"} } @@ -61,12 +61,10 @@ func (e CommentEdges) RequestOrErr() (*Request, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e CommentEdges) UserOrErr() (*User, error) { - if e.loadedTypes[1] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -87,7 +85,7 @@ func (*Comment) scanValues(columns []string) ([]any, error) { case comment.ForeignKeys[1]: // request_comment values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type Comment", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -146,11 +144,19 @@ func (c *Comment) assignValues(columns []string, values []any) error { c.request_comment = new(uuid.UUID) *c.request_comment = *value.S.(*uuid.UUID) } + default: + c.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Comment. +// This includes values selected through modifiers, order, etc. +func (c *Comment) Value(name string) (ent.Value, error) { + return c.selectValues.Get(name) +} + // QueryRequest queries the "request" edge of the Comment entity. func (c *Comment) QueryRequest() *RequestQuery { return NewCommentClient(c.config).QueryRequest(c) diff --git a/ent/comment/comment.go b/ent/comment/comment.go index 5e1bbc56..45ed22d6 100644 --- a/ent/comment/comment.go +++ b/ent/comment/comment.go @@ -5,6 +5,8 @@ package comment import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -84,3 +86,59 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Comment queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByComment orders the results by the comment field. +func ByComment(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldComment, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByRequestField orders the results by request field. +func ByRequestField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), sql.OrderByField(field, opts...)) + } +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), + ) +} diff --git a/ent/comment/where.go b/ent/comment/where.go index 4ddde755..cbf57f6c 100644 --- a/ent/comment/where.go +++ b/ent/comment/where.go @@ -285,11 +285,7 @@ func HasRequest() predicate.Comment { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.Comment { return predicate.Comment(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -312,11 +308,7 @@ func HasUser() predicate.Comment { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.Comment { return predicate.Comment(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -327,32 +319,15 @@ func HasUserWith(preds ...predicate.User) predicate.Comment { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Comment) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Comment(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Comment) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Comment(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Comment) predicate.Comment { - return predicate.Comment(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Comment(sql.NotPredicates(p)) } diff --git a/ent/comment_create.go b/ent/comment_create.go index 58522acc..eabdec9e 100644 --- a/ent/comment_create.go +++ b/ent/comment_create.go @@ -115,7 +115,7 @@ func (cc *CommentCreate) Mutation() *CommentMutation { // Save creates the Comment in the database. func (cc *CommentCreate) Save(ctx context.Context) (*Comment, error) { cc.defaults() - return withHooks[*Comment, CommentMutation](ctx, cc.sqlSave, cc.mutation, cc.hooks) + return withHooks(ctx, cc.sqlSave, cc.mutation, cc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -167,10 +167,10 @@ func (cc *CommentCreate) check() error { if _, ok := cc.mutation.UpdatedAt(); !ok { return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Comment.updated_at"`)} } - if _, ok := cc.mutation.RequestID(); !ok { + if len(cc.mutation.RequestIDs()) == 0 { return &ValidationError{Name: "request", err: errors.New(`ent: missing required edge "Comment.request"`)} } - if _, ok := cc.mutation.UserID(); !ok { + if len(cc.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "Comment.user"`)} } return nil @@ -232,10 +232,7 @@ func (cc *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) { Columns: []string{comment.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -252,10 +249,7 @@ func (cc *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) { Columns: []string{comment.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -270,11 +264,15 @@ func (cc *CommentCreate) createSpec() (*Comment, *sqlgraph.CreateSpec) { // CommentCreateBulk is the builder for creating many Comment entities in bulk. type CommentCreateBulk struct { config + err error builders []*CommentCreate } // Save creates the Comment entities in the database. func (ccb *CommentCreateBulk) Save(ctx context.Context) ([]*Comment, error) { + if ccb.err != nil { + return nil, ccb.err + } specs := make([]*sqlgraph.CreateSpec, len(ccb.builders)) nodes := make([]*Comment, len(ccb.builders)) mutators := make([]Mutator, len(ccb.builders)) @@ -291,8 +289,8 @@ func (ccb *CommentCreateBulk) Save(ctx context.Context) ([]*Comment, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, ccb.builders[i+1].mutation) } else { diff --git a/ent/comment_delete.go b/ent/comment_delete.go index de823842..4836b072 100644 --- a/ent/comment_delete.go +++ b/ent/comment_delete.go @@ -27,7 +27,7 @@ func (cd *CommentDelete) Where(ps ...predicate.Comment) *CommentDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (cd *CommentDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, CommentMutation](ctx, cd.sqlExec, cd.mutation, cd.hooks) + return withHooks(ctx, cd.sqlExec, cd.mutation, cd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/comment_query.go b/ent/comment_query.go index 813d9542..95fe65b0 100644 --- a/ent/comment_query.go +++ b/ent/comment_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -21,7 +22,7 @@ import ( type CommentQuery struct { config ctx *QueryContext - order []OrderFunc + order []comment.OrderOption inters []Interceptor predicates []predicate.Comment withRequest *RequestQuery @@ -58,7 +59,7 @@ func (cq *CommentQuery) Unique(unique bool) *CommentQuery { } // Order specifies how the records should be ordered. -func (cq *CommentQuery) Order(o ...OrderFunc) *CommentQuery { +func (cq *CommentQuery) Order(o ...comment.OrderOption) *CommentQuery { cq.order = append(cq.order, o...) return cq } @@ -110,7 +111,7 @@ func (cq *CommentQuery) QueryUser() *UserQuery { // First returns the first Comment entity from the query. // Returns a *NotFoundError when no Comment was found. func (cq *CommentQuery) First(ctx context.Context) (*Comment, error) { - nodes, err := cq.Limit(1).All(setContextOp(ctx, cq.ctx, "First")) + nodes, err := cq.Limit(1).All(setContextOp(ctx, cq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (cq *CommentQuery) FirstX(ctx context.Context) *Comment { // Returns a *NotFoundError when no Comment ID was found. func (cq *CommentQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = cq.Limit(1).IDs(setContextOp(ctx, cq.ctx, "FirstID")); err != nil { + if ids, err = cq.Limit(1).IDs(setContextOp(ctx, cq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (cq *CommentQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Comment entity is found. // Returns a *NotFoundError when no Comment entities are found. func (cq *CommentQuery) Only(ctx context.Context) (*Comment, error) { - nodes, err := cq.Limit(2).All(setContextOp(ctx, cq.ctx, "Only")) + nodes, err := cq.Limit(2).All(setContextOp(ctx, cq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (cq *CommentQuery) OnlyX(ctx context.Context) *Comment { // Returns a *NotFoundError when no entities are found. func (cq *CommentQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = cq.Limit(2).IDs(setContextOp(ctx, cq.ctx, "OnlyID")); err != nil { + if ids, err = cq.Limit(2).IDs(setContextOp(ctx, cq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (cq *CommentQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Comments. func (cq *CommentQuery) All(ctx context.Context) ([]*Comment, error) { - ctx = setContextOp(ctx, cq.ctx, "All") + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryAll) if err := cq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (cq *CommentQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if cq.ctx.Unique == nil && cq.path != nil { cq.Unique(true) } - ctx = setContextOp(ctx, cq.ctx, "IDs") + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryIDs) if err = cq.Select(comment.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (cq *CommentQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (cq *CommentQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, cq.ctx, "Count") + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryCount) if err := cq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (cq *CommentQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (cq *CommentQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, cq.ctx, "Exist") + ctx = setContextOp(ctx, cq.ctx, ent.OpQueryExist) switch _, err := cq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,7 +297,7 @@ func (cq *CommentQuery) Clone() *CommentQuery { return &CommentQuery{ config: cq.config, ctx: cq.ctx.Clone(), - order: append([]OrderFunc{}, cq.order...), + order: append([]comment.OrderOption{}, cq.order...), inters: append([]Interceptor{}, cq.inters...), predicates: append([]predicate.Comment{}, cq.predicates...), withRequest: cq.withRequest.Clone(), @@ -612,7 +613,7 @@ func (cgb *CommentGroupBy) Aggregate(fns ...AggregateFunc) *CommentGroupBy { // Scan applies the selector query and scans the result into the given value. func (cgb *CommentGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, cgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, cgb.build.ctx, ent.OpQueryGroupBy) if err := cgb.build.prepareQuery(ctx); err != nil { return err } @@ -660,7 +661,7 @@ func (cs *CommentSelect) Aggregate(fns ...AggregateFunc) *CommentSelect { // Scan applies the selector query and scans the result into the given value. func (cs *CommentSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, cs.ctx, "Select") + ctx = setContextOp(ctx, cs.ctx, ent.OpQuerySelect) if err := cs.prepareQuery(ctx); err != nil { return err } diff --git a/ent/comment_update.go b/ent/comment_update.go index 3e09796d..81033aad 100644 --- a/ent/comment_update.go +++ b/ent/comment_update.go @@ -37,6 +37,14 @@ func (cu *CommentUpdate) SetComment(s string) *CommentUpdate { return cu } +// SetNillableComment sets the "comment" field if the given value is not nil. +func (cu *CommentUpdate) SetNillableComment(s *string) *CommentUpdate { + if s != nil { + cu.SetComment(*s) + } + return cu +} + // SetCreatedAt sets the "created_at" field. func (cu *CommentUpdate) SetCreatedAt(t time.Time) *CommentUpdate { cu.mutation.SetCreatedAt(t) @@ -119,7 +127,7 @@ func (cu *CommentUpdate) ClearUser() *CommentUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (cu *CommentUpdate) Save(ctx context.Context) (int, error) { cu.defaults() - return withHooks[int, CommentMutation](ctx, cu.sqlSave, cu.mutation, cu.hooks) + return withHooks(ctx, cu.sqlSave, cu.mutation, cu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -154,10 +162,10 @@ func (cu *CommentUpdate) defaults() { // check runs all checks and user-defined validators on the builder. func (cu *CommentUpdate) check() error { - if _, ok := cu.mutation.RequestID(); cu.mutation.RequestCleared() && !ok { + if cu.mutation.RequestCleared() && len(cu.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Comment.request"`) } - if _, ok := cu.mutation.UserID(); cu.mutation.UserCleared() && !ok { + if cu.mutation.UserCleared() && len(cu.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Comment.user"`) } return nil @@ -198,10 +206,7 @@ func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{comment.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -214,10 +219,7 @@ func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{comment.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -233,10 +235,7 @@ func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{comment.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -249,10 +248,7 @@ func (cu *CommentUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{comment.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -286,6 +282,14 @@ func (cuo *CommentUpdateOne) SetComment(s string) *CommentUpdateOne { return cuo } +// SetNillableComment sets the "comment" field if the given value is not nil. +func (cuo *CommentUpdateOne) SetNillableComment(s *string) *CommentUpdateOne { + if s != nil { + cuo.SetComment(*s) + } + return cuo +} + // SetCreatedAt sets the "created_at" field. func (cuo *CommentUpdateOne) SetCreatedAt(t time.Time) *CommentUpdateOne { cuo.mutation.SetCreatedAt(t) @@ -381,7 +385,7 @@ func (cuo *CommentUpdateOne) Select(field string, fields ...string) *CommentUpda // Save executes the query and returns the updated Comment entity. func (cuo *CommentUpdateOne) Save(ctx context.Context) (*Comment, error) { cuo.defaults() - return withHooks[*Comment, CommentMutation](ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) + return withHooks(ctx, cuo.sqlSave, cuo.mutation, cuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -416,10 +420,10 @@ func (cuo *CommentUpdateOne) defaults() { // check runs all checks and user-defined validators on the builder. func (cuo *CommentUpdateOne) check() error { - if _, ok := cuo.mutation.RequestID(); cuo.mutation.RequestCleared() && !ok { + if cuo.mutation.RequestCleared() && len(cuo.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Comment.request"`) } - if _, ok := cuo.mutation.UserID(); cuo.mutation.UserCleared() && !ok { + if cuo.mutation.UserCleared() && len(cuo.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Comment.user"`) } return nil @@ -477,10 +481,7 @@ func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err e Columns: []string{comment.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -493,10 +494,7 @@ func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err e Columns: []string{comment.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -512,10 +510,7 @@ func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err e Columns: []string{comment.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -528,10 +523,7 @@ func (cuo *CommentUpdateOne) sqlSave(ctx context.Context) (_node *Comment, err e Columns: []string{comment.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/ent.go b/ent/ent.go index 83db7ea2..66cc8996 100644 --- a/ent/ent.go +++ b/ent/ent.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "reflect" + "sync" "entgo.io/ent" "entgo.io/ent/dialect/sql" @@ -70,43 +71,39 @@ func NewTxContext(parent context.Context, tx *Tx) context.Context { } // OrderFunc applies an ordering on the sql selector. +// Deprecated: Use Asc/Desc functions or the package builders instead. type OrderFunc func(*sql.Selector) -// columnChecker returns a function indicates if the column exists in the given column. -func columnChecker(table string) func(string) error { - checks := map[string]func(string) bool{ - comment.Table: comment.ValidColumn, - file.Table: file.ValidColumn, - group.Table: group.ValidColumn, - groupbudget.Table: groupbudget.ValidColumn, - request.Table: request.ValidColumn, - requeststatus.Table: requeststatus.ValidColumn, - requesttarget.Table: requesttarget.ValidColumn, - tag.Table: tag.ValidColumn, - transaction.Table: transaction.ValidColumn, - transactiondetail.Table: transactiondetail.ValidColumn, - user.Table: user.ValidColumn, - } - check, ok := checks[table] - if !ok { - return func(string) error { - return fmt.Errorf("unknown table %q", table) - } - } - return func(column string) error { - if !check(column) { - return fmt.Errorf("unknown column %q for table %q", column, table) - } - return nil - } +var ( + initCheck sync.Once + columnCheck sql.ColumnCheck +) + +// checkColumn checks if the column exists in the given table. +func checkColumn(table, column string) error { + initCheck.Do(func() { + columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ + comment.Table: comment.ValidColumn, + file.Table: file.ValidColumn, + group.Table: group.ValidColumn, + groupbudget.Table: groupbudget.ValidColumn, + request.Table: request.ValidColumn, + requeststatus.Table: requeststatus.ValidColumn, + requesttarget.Table: requesttarget.ValidColumn, + tag.Table: tag.ValidColumn, + transaction.Table: transaction.ValidColumn, + transactiondetail.Table: transactiondetail.ValidColumn, + user.Table: user.ValidColumn, + }) + }) + return columnCheck(table, column) } // Asc applies the given fields in ASC order. -func Asc(fields ...string) OrderFunc { +func Asc(fields ...string) func(*sql.Selector) { return func(s *sql.Selector) { - check := columnChecker(s.TableName()) for _, f := range fields { - if err := check(f); err != nil { + if err := checkColumn(s.TableName(), f); err != nil { s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) } s.OrderBy(sql.Asc(s.C(f))) @@ -115,11 +112,10 @@ func Asc(fields ...string) OrderFunc { } // Desc applies the given fields in DESC order. -func Desc(fields ...string) OrderFunc { +func Desc(fields ...string) func(*sql.Selector) { return func(s *sql.Selector) { - check := columnChecker(s.TableName()) for _, f := range fields { - if err := check(f); err != nil { + if err := checkColumn(s.TableName(), f); err != nil { s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) } s.OrderBy(sql.Desc(s.C(f))) @@ -151,8 +147,7 @@ func Count() AggregateFunc { // Max applies the "max" aggregation function on the given field of each group. func Max(field string) AggregateFunc { return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { + if err := checkColumn(s.TableName(), field); err != nil { s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) return "" } @@ -163,8 +158,7 @@ func Max(field string) AggregateFunc { // Mean applies the "mean" aggregation function on the given field of each group. func Mean(field string) AggregateFunc { return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { + if err := checkColumn(s.TableName(), field); err != nil { s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) return "" } @@ -175,8 +169,7 @@ func Mean(field string) AggregateFunc { // Min applies the "min" aggregation function on the given field of each group. func Min(field string) AggregateFunc { return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { + if err := checkColumn(s.TableName(), field); err != nil { s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) return "" } @@ -187,8 +180,7 @@ func Min(field string) AggregateFunc { // Sum applies the "sum" aggregation function on the given field of each group. func Sum(field string) AggregateFunc { return func(s *sql.Selector) string { - check := columnChecker(s.TableName()) - if err := check(field); err != nil { + if err := checkColumn(s.TableName(), field); err != nil { s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) return "" } @@ -525,7 +517,7 @@ func withHooks[V Value, M any, PM interface { return exec(ctx) } var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutationT, ok := m.(PM) + mutationT, ok := any(m).(PM) if !ok { return nil, fmt.Errorf("unexpected mutation type %T", m) } diff --git a/ent/file.go b/ent/file.go index d4594796..40473a12 100644 --- a/ent/file.go +++ b/ent/file.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/file" @@ -32,6 +33,7 @@ type File struct { Edges FileEdges `json:"edges"` file_user *uuid.UUID request_file *uuid.UUID + selectValues sql.SelectValues } // FileEdges holds the relations/edges for other nodes in the graph. @@ -48,12 +50,10 @@ type FileEdges struct { // RequestOrErr returns the Request value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e FileEdges) RequestOrErr() (*Request, error) { - if e.loadedTypes[0] { - if e.Request == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: request.Label} - } + if e.Request != nil { return e.Request, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: request.Label} } return nil, &NotLoadedError{edge: "request"} } @@ -61,12 +61,10 @@ func (e FileEdges) RequestOrErr() (*Request, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e FileEdges) UserOrErr() (*User, error) { - if e.loadedTypes[1] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -87,7 +85,7 @@ func (*File) scanValues(columns []string) ([]any, error) { case file.ForeignKeys[1]: // request_file values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type File", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -146,11 +144,19 @@ func (f *File) assignValues(columns []string, values []any) error { f.request_file = new(uuid.UUID) *f.request_file = *value.S.(*uuid.UUID) } + default: + f.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the File. +// This includes values selected through modifiers, order, etc. +func (f *File) Value(name string) (ent.Value, error) { + return f.selectValues.Get(name) +} + // QueryRequest queries the "request" edge of the File entity. func (f *File) QueryRequest() *RequestQuery { return NewFileClient(f.config).QueryRequest(f) diff --git a/ent/file/file.go b/ent/file/file.go index 70ed49da..afcddad1 100644 --- a/ent/file/file.go +++ b/ent/file/file.go @@ -5,6 +5,8 @@ package file import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -82,3 +84,59 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the File queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByMimeType orders the results by the mime_type field. +func ByMimeType(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldMimeType, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByRequestField orders the results by request field. +func ByRequestField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), sql.OrderByField(field, opts...)) + } +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), + ) +} diff --git a/ent/file/where.go b/ent/file/where.go index e2ae3eba..5f512919 100644 --- a/ent/file/where.go +++ b/ent/file/where.go @@ -310,11 +310,7 @@ func HasRequest() predicate.File { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.File { return predicate.File(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -337,11 +333,7 @@ func HasUser() predicate.File { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.File { return predicate.File(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -352,32 +344,15 @@ func HasUserWith(preds ...predicate.User) predicate.File { // And groups predicates with the AND operator between them. func And(predicates ...predicate.File) predicate.File { - return predicate.File(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.File(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.File) predicate.File { - return predicate.File(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.File(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.File) predicate.File { - return predicate.File(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.File(sql.NotPredicates(p)) } diff --git a/ent/file_create.go b/ent/file_create.go index 13a60867..fcd0b5f1 100644 --- a/ent/file_create.go +++ b/ent/file_create.go @@ -115,7 +115,7 @@ func (fc *FileCreate) Mutation() *FileMutation { // Save creates the File in the database. func (fc *FileCreate) Save(ctx context.Context) (*File, error) { fc.defaults() - return withHooks[*File, FileMutation](ctx, fc.sqlSave, fc.mutation, fc.hooks) + return withHooks(ctx, fc.sqlSave, fc.mutation, fc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -168,7 +168,7 @@ func (fc *FileCreate) check() error { if _, ok := fc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "File.created_at"`)} } - if _, ok := fc.mutation.UserID(); !ok { + if len(fc.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "File.user"`)} } return nil @@ -230,10 +230,7 @@ func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) { Columns: []string{file.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -250,10 +247,7 @@ func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) { Columns: []string{file.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -268,11 +262,15 @@ func (fc *FileCreate) createSpec() (*File, *sqlgraph.CreateSpec) { // FileCreateBulk is the builder for creating many File entities in bulk. type FileCreateBulk struct { config + err error builders []*FileCreate } // Save creates the File entities in the database. func (fcb *FileCreateBulk) Save(ctx context.Context) ([]*File, error) { + if fcb.err != nil { + return nil, fcb.err + } specs := make([]*sqlgraph.CreateSpec, len(fcb.builders)) nodes := make([]*File, len(fcb.builders)) mutators := make([]Mutator, len(fcb.builders)) @@ -289,8 +287,8 @@ func (fcb *FileCreateBulk) Save(ctx context.Context) ([]*File, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, fcb.builders[i+1].mutation) } else { diff --git a/ent/file_delete.go b/ent/file_delete.go index ee248650..d9ac5486 100644 --- a/ent/file_delete.go +++ b/ent/file_delete.go @@ -27,7 +27,7 @@ func (fd *FileDelete) Where(ps ...predicate.File) *FileDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (fd *FileDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, FileMutation](ctx, fd.sqlExec, fd.mutation, fd.hooks) + return withHooks(ctx, fd.sqlExec, fd.mutation, fd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/file_query.go b/ent/file_query.go index 2ee9dc17..8bec1e1a 100644 --- a/ent/file_query.go +++ b/ent/file_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -21,7 +22,7 @@ import ( type FileQuery struct { config ctx *QueryContext - order []OrderFunc + order []file.OrderOption inters []Interceptor predicates []predicate.File withRequest *RequestQuery @@ -58,7 +59,7 @@ func (fq *FileQuery) Unique(unique bool) *FileQuery { } // Order specifies how the records should be ordered. -func (fq *FileQuery) Order(o ...OrderFunc) *FileQuery { +func (fq *FileQuery) Order(o ...file.OrderOption) *FileQuery { fq.order = append(fq.order, o...) return fq } @@ -110,7 +111,7 @@ func (fq *FileQuery) QueryUser() *UserQuery { // First returns the first File entity from the query. // Returns a *NotFoundError when no File was found. func (fq *FileQuery) First(ctx context.Context) (*File, error) { - nodes, err := fq.Limit(1).All(setContextOp(ctx, fq.ctx, "First")) + nodes, err := fq.Limit(1).All(setContextOp(ctx, fq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (fq *FileQuery) FirstX(ctx context.Context) *File { // Returns a *NotFoundError when no File ID was found. func (fq *FileQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = fq.Limit(1).IDs(setContextOp(ctx, fq.ctx, "FirstID")); err != nil { + if ids, err = fq.Limit(1).IDs(setContextOp(ctx, fq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (fq *FileQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one File entity is found. // Returns a *NotFoundError when no File entities are found. func (fq *FileQuery) Only(ctx context.Context) (*File, error) { - nodes, err := fq.Limit(2).All(setContextOp(ctx, fq.ctx, "Only")) + nodes, err := fq.Limit(2).All(setContextOp(ctx, fq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (fq *FileQuery) OnlyX(ctx context.Context) *File { // Returns a *NotFoundError when no entities are found. func (fq *FileQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = fq.Limit(2).IDs(setContextOp(ctx, fq.ctx, "OnlyID")); err != nil { + if ids, err = fq.Limit(2).IDs(setContextOp(ctx, fq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (fq *FileQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Files. func (fq *FileQuery) All(ctx context.Context) ([]*File, error) { - ctx = setContextOp(ctx, fq.ctx, "All") + ctx = setContextOp(ctx, fq.ctx, ent.OpQueryAll) if err := fq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (fq *FileQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if fq.ctx.Unique == nil && fq.path != nil { fq.Unique(true) } - ctx = setContextOp(ctx, fq.ctx, "IDs") + ctx = setContextOp(ctx, fq.ctx, ent.OpQueryIDs) if err = fq.Select(file.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (fq *FileQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (fq *FileQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, fq.ctx, "Count") + ctx = setContextOp(ctx, fq.ctx, ent.OpQueryCount) if err := fq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (fq *FileQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (fq *FileQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, fq.ctx, "Exist") + ctx = setContextOp(ctx, fq.ctx, ent.OpQueryExist) switch _, err := fq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,7 +297,7 @@ func (fq *FileQuery) Clone() *FileQuery { return &FileQuery{ config: fq.config, ctx: fq.ctx.Clone(), - order: append([]OrderFunc{}, fq.order...), + order: append([]file.OrderOption{}, fq.order...), inters: append([]Interceptor{}, fq.inters...), predicates: append([]predicate.File{}, fq.predicates...), withRequest: fq.withRequest.Clone(), @@ -612,7 +613,7 @@ func (fgb *FileGroupBy) Aggregate(fns ...AggregateFunc) *FileGroupBy { // Scan applies the selector query and scans the result into the given value. func (fgb *FileGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, fgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, fgb.build.ctx, ent.OpQueryGroupBy) if err := fgb.build.prepareQuery(ctx); err != nil { return err } @@ -660,7 +661,7 @@ func (fs *FileSelect) Aggregate(fns ...AggregateFunc) *FileSelect { // Scan applies the selector query and scans the result into the given value. func (fs *FileSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, fs.ctx, "Select") + ctx = setContextOp(ctx, fs.ctx, ent.OpQuerySelect) if err := fs.prepareQuery(ctx); err != nil { return err } diff --git a/ent/file_update.go b/ent/file_update.go index 30267e44..ef42d01a 100644 --- a/ent/file_update.go +++ b/ent/file_update.go @@ -37,12 +37,28 @@ func (fu *FileUpdate) SetName(s string) *FileUpdate { return fu } +// SetNillableName sets the "name" field if the given value is not nil. +func (fu *FileUpdate) SetNillableName(s *string) *FileUpdate { + if s != nil { + fu.SetName(*s) + } + return fu +} + // SetMimeType sets the "mime_type" field. func (fu *FileUpdate) SetMimeType(s string) *FileUpdate { fu.mutation.SetMimeType(s) return fu } +// SetNillableMimeType sets the "mime_type" field if the given value is not nil. +func (fu *FileUpdate) SetNillableMimeType(s *string) *FileUpdate { + if s != nil { + fu.SetMimeType(*s) + } + return fu +} + // SetCreatedAt sets the "created_at" field. func (fu *FileUpdate) SetCreatedAt(t time.Time) *FileUpdate { fu.mutation.SetCreatedAt(t) @@ -126,7 +142,7 @@ func (fu *FileUpdate) ClearUser() *FileUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (fu *FileUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, FileMutation](ctx, fu.sqlSave, fu.mutation, fu.hooks) + return withHooks(ctx, fu.sqlSave, fu.mutation, fu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -158,7 +174,7 @@ func (fu *FileUpdate) check() error { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "File.name": %w`, err)} } } - if _, ok := fu.mutation.UserID(); fu.mutation.UserCleared() && !ok { + if fu.mutation.UserCleared() && len(fu.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "File.user"`) } return nil @@ -199,10 +215,7 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{file.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -215,10 +228,7 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{file.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -234,10 +244,7 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{file.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -250,10 +257,7 @@ func (fu *FileUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{file.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -287,12 +291,28 @@ func (fuo *FileUpdateOne) SetName(s string) *FileUpdateOne { return fuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (fuo *FileUpdateOne) SetNillableName(s *string) *FileUpdateOne { + if s != nil { + fuo.SetName(*s) + } + return fuo +} + // SetMimeType sets the "mime_type" field. func (fuo *FileUpdateOne) SetMimeType(s string) *FileUpdateOne { fuo.mutation.SetMimeType(s) return fuo } +// SetNillableMimeType sets the "mime_type" field if the given value is not nil. +func (fuo *FileUpdateOne) SetNillableMimeType(s *string) *FileUpdateOne { + if s != nil { + fuo.SetMimeType(*s) + } + return fuo +} + // SetCreatedAt sets the "created_at" field. func (fuo *FileUpdateOne) SetCreatedAt(t time.Time) *FileUpdateOne { fuo.mutation.SetCreatedAt(t) @@ -389,7 +409,7 @@ func (fuo *FileUpdateOne) Select(field string, fields ...string) *FileUpdateOne // Save executes the query and returns the updated File entity. func (fuo *FileUpdateOne) Save(ctx context.Context) (*File, error) { - return withHooks[*File, FileMutation](ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) + return withHooks(ctx, fuo.sqlSave, fuo.mutation, fuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -421,7 +441,7 @@ func (fuo *FileUpdateOne) check() error { return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "File.name": %w`, err)} } } - if _, ok := fuo.mutation.UserID(); fuo.mutation.UserCleared() && !ok { + if fuo.mutation.UserCleared() && len(fuo.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "File.user"`) } return nil @@ -479,10 +499,7 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) Columns: []string{file.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -495,10 +512,7 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) Columns: []string{file.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -514,10 +528,7 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) Columns: []string{file.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -530,10 +541,7 @@ func (fuo *FileUpdateOne) sqlSave(ctx context.Context) (_node *File, err error) Columns: []string{file.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/group.go b/ent/group.go index 059d8f46..f8d15da2 100644 --- a/ent/group.go +++ b/ent/group.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/group" @@ -31,7 +32,8 @@ type Group struct { DeletedAt *time.Time `json:"deleted_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the GroupQuery when eager-loading is set. - Edges GroupEdges `json:"edges"` + Edges GroupEdges `json:"edges"` + selectValues sql.SelectValues } // GroupEdges holds the relations/edges for other nodes in the graph. @@ -99,7 +101,7 @@ func (*Group) scanValues(columns []string) ([]any, error) { case group.FieldID: values[i] = new(uuid.UUID) default: - return nil, fmt.Errorf("unexpected column %q for type Group", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -157,11 +159,19 @@ func (gr *Group) assignValues(columns []string, values []any) error { gr.DeletedAt = new(time.Time) *gr.DeletedAt = value.Time } + default: + gr.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Group. +// This includes values selected through modifiers, order, etc. +func (gr *Group) Value(name string) (ent.Value, error) { + return gr.selectValues.Get(name) +} + // QueryGroupBudget queries the "group_budget" edge of the Group entity. func (gr *Group) QueryGroupBudget() *GroupBudgetQuery { return NewGroupClient(gr.config).QueryGroupBudget(gr) diff --git a/ent/group/group.go b/ent/group/group.go index 52e5cef3..f836cd5f 100644 --- a/ent/group/group.go +++ b/ent/group/group.go @@ -5,6 +5,8 @@ package group import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -103,3 +105,125 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Group queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByBudget orders the results by the budget field. +func ByBudget(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBudget, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByGroupBudgetCount orders the results by group_budget count. +func ByGroupBudgetCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newGroupBudgetStep(), opts...) + } +} + +// ByGroupBudget orders the results by group_budget terms. +func ByGroupBudget(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupBudgetStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByUserCount orders the results by user count. +func ByUserCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newUserStep(), opts...) + } +} + +// ByUser orders the results by user terms. +func ByUser(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByOwnerCount orders the results by owner count. +func ByOwnerCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newOwnerStep(), opts...) + } +} + +// ByOwner orders the results by owner terms. +func ByOwner(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newOwnerStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByRequestCount orders the results by request count. +func ByRequestCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newRequestStep(), opts...) + } +} + +// ByRequest orders the results by request terms. +func ByRequest(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newGroupBudgetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupBudgetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, GroupBudgetTable, GroupBudgetColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, UserTable, UserPrimaryKey...), + ) +} +func newOwnerStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(OwnerInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, OwnerTable, OwnerPrimaryKey...), + ) +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, RequestTable, RequestColumn), + ) +} diff --git a/ent/group/where.go b/ent/group/where.go index 4eb89bc1..dc7fa48a 100644 --- a/ent/group/where.go +++ b/ent/group/where.go @@ -410,11 +410,7 @@ func HasGroupBudget() predicate.Group { // HasGroupBudgetWith applies the HasEdge predicate on the "group_budget" edge with a given conditions (other predicates). func HasGroupBudgetWith(preds ...predicate.GroupBudget) predicate.Group { return predicate.Group(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupBudgetInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, GroupBudgetTable, GroupBudgetColumn), - ) + step := newGroupBudgetStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -437,11 +433,7 @@ func HasUser() predicate.Group { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.Group { return predicate.Group(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, UserTable, UserPrimaryKey...), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -464,11 +456,7 @@ func HasOwner() predicate.Group { // HasOwnerWith applies the HasEdge predicate on the "owner" edge with a given conditions (other predicates). func HasOwnerWith(preds ...predicate.User) predicate.Group { return predicate.Group(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(OwnerInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, OwnerTable, OwnerPrimaryKey...), - ) + step := newOwnerStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -491,11 +479,7 @@ func HasRequest() predicate.Group { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.Group { return predicate.Group(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -506,32 +490,15 @@ func HasRequestWith(preds ...predicate.Request) predicate.Group { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Group(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Group) predicate.Group { - return predicate.Group(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Group(sql.NotPredicates(p)) } diff --git a/ent/group_create.go b/ent/group_create.go index e739620a..fe6b778c 100644 --- a/ent/group_create.go +++ b/ent/group_create.go @@ -174,7 +174,7 @@ func (gc *GroupCreate) Mutation() *GroupMutation { // Save creates the Group in the database. func (gc *GroupCreate) Save(ctx context.Context) (*Group, error) { gc.defaults() - return withHooks[*Group, GroupMutation](ctx, gc.sqlSave, gc.mutation, gc.hooks) + return withHooks(ctx, gc.sqlSave, gc.mutation, gc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -301,10 +301,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -320,10 +317,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -339,10 +333,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -358,10 +349,7 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -375,11 +363,15 @@ func (gc *GroupCreate) createSpec() (*Group, *sqlgraph.CreateSpec) { // GroupCreateBulk is the builder for creating many Group entities in bulk. type GroupCreateBulk struct { config + err error builders []*GroupCreate } // Save creates the Group entities in the database. func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) { + if gcb.err != nil { + return nil, gcb.err + } specs := make([]*sqlgraph.CreateSpec, len(gcb.builders)) nodes := make([]*Group, len(gcb.builders)) mutators := make([]Mutator, len(gcb.builders)) @@ -396,8 +388,8 @@ func (gcb *GroupCreateBulk) Save(ctx context.Context) ([]*Group, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, gcb.builders[i+1].mutation) } else { diff --git a/ent/group_delete.go b/ent/group_delete.go index 64f73624..50655ab3 100644 --- a/ent/group_delete.go +++ b/ent/group_delete.go @@ -27,7 +27,7 @@ func (gd *GroupDelete) Where(ps ...predicate.Group) *GroupDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (gd *GroupDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, GroupMutation](ctx, gd.sqlExec, gd.mutation, gd.hooks) + return withHooks(ctx, gd.sqlExec, gd.mutation, gd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/group_query.go b/ent/group_query.go index 111f95a2..8765b248 100644 --- a/ent/group_query.go +++ b/ent/group_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -23,7 +24,7 @@ import ( type GroupQuery struct { config ctx *QueryContext - order []OrderFunc + order []group.OrderOption inters []Interceptor predicates []predicate.Group withGroupBudget *GroupBudgetQuery @@ -61,7 +62,7 @@ func (gq *GroupQuery) Unique(unique bool) *GroupQuery { } // Order specifies how the records should be ordered. -func (gq *GroupQuery) Order(o ...OrderFunc) *GroupQuery { +func (gq *GroupQuery) Order(o ...group.OrderOption) *GroupQuery { gq.order = append(gq.order, o...) return gq } @@ -157,7 +158,7 @@ func (gq *GroupQuery) QueryRequest() *RequestQuery { // First returns the first Group entity from the query. // Returns a *NotFoundError when no Group was found. func (gq *GroupQuery) First(ctx context.Context) (*Group, error) { - nodes, err := gq.Limit(1).All(setContextOp(ctx, gq.ctx, "First")) + nodes, err := gq.Limit(1).All(setContextOp(ctx, gq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -180,7 +181,7 @@ func (gq *GroupQuery) FirstX(ctx context.Context) *Group { // Returns a *NotFoundError when no Group ID was found. func (gq *GroupQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gq.Limit(1).IDs(setContextOp(ctx, gq.ctx, "FirstID")); err != nil { + if ids, err = gq.Limit(1).IDs(setContextOp(ctx, gq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -203,7 +204,7 @@ func (gq *GroupQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Group entity is found. // Returns a *NotFoundError when no Group entities are found. func (gq *GroupQuery) Only(ctx context.Context) (*Group, error) { - nodes, err := gq.Limit(2).All(setContextOp(ctx, gq.ctx, "Only")) + nodes, err := gq.Limit(2).All(setContextOp(ctx, gq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -231,7 +232,7 @@ func (gq *GroupQuery) OnlyX(ctx context.Context) *Group { // Returns a *NotFoundError when no entities are found. func (gq *GroupQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gq.Limit(2).IDs(setContextOp(ctx, gq.ctx, "OnlyID")); err != nil { + if ids, err = gq.Limit(2).IDs(setContextOp(ctx, gq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -256,7 +257,7 @@ func (gq *GroupQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Groups. func (gq *GroupQuery) All(ctx context.Context) ([]*Group, error) { - ctx = setContextOp(ctx, gq.ctx, "All") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryAll) if err := gq.prepareQuery(ctx); err != nil { return nil, err } @@ -278,7 +279,7 @@ func (gq *GroupQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if gq.ctx.Unique == nil && gq.path != nil { gq.Unique(true) } - ctx = setContextOp(ctx, gq.ctx, "IDs") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryIDs) if err = gq.Select(group.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -296,7 +297,7 @@ func (gq *GroupQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (gq *GroupQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, gq.ctx, "Count") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryCount) if err := gq.prepareQuery(ctx); err != nil { return 0, err } @@ -314,7 +315,7 @@ func (gq *GroupQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (gq *GroupQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, gq.ctx, "Exist") + ctx = setContextOp(ctx, gq.ctx, ent.OpQueryExist) switch _, err := gq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -343,7 +344,7 @@ func (gq *GroupQuery) Clone() *GroupQuery { return &GroupQuery{ config: gq.config, ctx: gq.ctx.Clone(), - order: append([]OrderFunc{}, gq.order...), + order: append([]group.OrderOption{}, gq.order...), inters: append([]Interceptor{}, gq.inters...), predicates: append([]predicate.Group{}, gq.predicates...), withGroupBudget: gq.withGroupBudget.Clone(), @@ -546,7 +547,7 @@ func (gq *GroupQuery) loadGroupBudget(ctx context.Context, query *GroupBudgetQue } query.withFKs = true query.Where(predicate.GroupBudget(func(s *sql.Selector) { - s.Where(sql.InValues(group.GroupBudgetColumn, fks...)) + s.Where(sql.InValues(s.C(group.GroupBudgetColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -559,7 +560,7 @@ func (gq *GroupQuery) loadGroupBudget(ctx context.Context, query *GroupBudgetQue } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "group_group_budget" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "group_group_budget" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -699,7 +700,7 @@ func (gq *GroupQuery) loadRequest(ctx context.Context, query *RequestQuery, node } query.withFKs = true query.Where(predicate.Request(func(s *sql.Selector) { - s.Where(sql.InValues(group.RequestColumn, fks...)) + s.Where(sql.InValues(s.C(group.RequestColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -712,7 +713,7 @@ func (gq *GroupQuery) loadRequest(ctx context.Context, query *RequestQuery, node } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "group_request" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "group_request" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -814,7 +815,7 @@ func (ggb *GroupGroupBy) Aggregate(fns ...AggregateFunc) *GroupGroupBy { // Scan applies the selector query and scans the result into the given value. func (ggb *GroupGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ggb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, ggb.build.ctx, ent.OpQueryGroupBy) if err := ggb.build.prepareQuery(ctx); err != nil { return err } @@ -862,7 +863,7 @@ func (gs *GroupSelect) Aggregate(fns ...AggregateFunc) *GroupSelect { // Scan applies the selector query and scans the result into the given value. func (gs *GroupSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gs.ctx, "Select") + ctx = setContextOp(ctx, gs.ctx, ent.OpQuerySelect) if err := gs.prepareQuery(ctx); err != nil { return err } diff --git a/ent/group_update.go b/ent/group_update.go index b75e274a..9d7685fc 100644 --- a/ent/group_update.go +++ b/ent/group_update.go @@ -38,12 +38,28 @@ func (gu *GroupUpdate) SetName(s string) *GroupUpdate { return gu } +// SetNillableName sets the "name" field if the given value is not nil. +func (gu *GroupUpdate) SetNillableName(s *string) *GroupUpdate { + if s != nil { + gu.SetName(*s) + } + return gu +} + // SetDescription sets the "description" field. func (gu *GroupUpdate) SetDescription(s string) *GroupUpdate { gu.mutation.SetDescription(s) return gu } +// SetNillableDescription sets the "description" field if the given value is not nil. +func (gu *GroupUpdate) SetNillableDescription(s *string) *GroupUpdate { + if s != nil { + gu.SetDescription(*s) + } + return gu +} + // SetBudget sets the "budget" field. func (gu *GroupUpdate) SetBudget(i int) *GroupUpdate { gu.mutation.ResetBudget() @@ -263,7 +279,7 @@ func (gu *GroupUpdate) RemoveRequest(r ...*Request) *GroupUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (gu *GroupUpdate) Save(ctx context.Context) (int, error) { gu.defaults() - return withHooks[int, GroupMutation](ctx, gu.sqlSave, gu.mutation, gu.hooks) + return withHooks(ctx, gu.sqlSave, gu.mutation, gu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -353,10 +369,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -369,10 +382,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -388,10 +398,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -407,10 +414,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -423,10 +427,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -442,10 +443,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -461,10 +459,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -477,10 +472,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -496,10 +488,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -515,10 +504,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -531,10 +517,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -550,10 +533,7 @@ func (gu *GroupUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -587,12 +567,28 @@ func (guo *GroupUpdateOne) SetName(s string) *GroupUpdateOne { return guo } +// SetNillableName sets the "name" field if the given value is not nil. +func (guo *GroupUpdateOne) SetNillableName(s *string) *GroupUpdateOne { + if s != nil { + guo.SetName(*s) + } + return guo +} + // SetDescription sets the "description" field. func (guo *GroupUpdateOne) SetDescription(s string) *GroupUpdateOne { guo.mutation.SetDescription(s) return guo } +// SetNillableDescription sets the "description" field if the given value is not nil. +func (guo *GroupUpdateOne) SetNillableDescription(s *string) *GroupUpdateOne { + if s != nil { + guo.SetDescription(*s) + } + return guo +} + // SetBudget sets the "budget" field. func (guo *GroupUpdateOne) SetBudget(i int) *GroupUpdateOne { guo.mutation.ResetBudget() @@ -825,7 +821,7 @@ func (guo *GroupUpdateOne) Select(field string, fields ...string) *GroupUpdateOn // Save executes the query and returns the updated Group entity. func (guo *GroupUpdateOne) Save(ctx context.Context) (*Group, error) { guo.defaults() - return withHooks[*Group, GroupMutation](ctx, guo.sqlSave, guo.mutation, guo.hooks) + return withHooks(ctx, guo.sqlSave, guo.mutation, guo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -932,10 +928,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -948,10 +941,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -967,10 +957,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -986,10 +973,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1002,10 +986,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1021,10 +1002,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.UserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1040,10 +1018,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1056,10 +1031,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1075,10 +1047,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: group.OwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1094,10 +1063,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1110,10 +1076,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1129,10 +1092,7 @@ func (guo *GroupUpdateOne) sqlSave(ctx context.Context) (_node *Group, err error Columns: []string{group.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/groupbudget.go b/ent/groupbudget.go index 4d869d05..f373dff0 100644 --- a/ent/groupbudget.go +++ b/ent/groupbudget.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/group" @@ -28,6 +29,7 @@ type GroupBudget struct { // The values are being populated by the GroupBudgetQuery when eager-loading is set. Edges GroupBudgetEdges `json:"edges"` group_group_budget *uuid.UUID + selectValues sql.SelectValues } // GroupBudgetEdges holds the relations/edges for other nodes in the graph. @@ -44,12 +46,10 @@ type GroupBudgetEdges struct { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e GroupBudgetEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[0] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } @@ -79,7 +79,7 @@ func (*GroupBudget) scanValues(columns []string) ([]any, error) { case groupbudget.ForeignKeys[0]: // group_group_budget values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type GroupBudget", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -125,11 +125,19 @@ func (gb *GroupBudget) assignValues(columns []string, values []any) error { gb.group_group_budget = new(uuid.UUID) *gb.group_group_budget = *value.S.(*uuid.UUID) } + default: + gb.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the GroupBudget. +// This includes values selected through modifiers, order, etc. +func (gb *GroupBudget) Value(name string) (ent.Value, error) { + return gb.selectValues.Get(name) +} + // QueryGroup queries the "group" edge of the GroupBudget entity. func (gb *GroupBudget) QueryGroup() *GroupQuery { return NewGroupBudgetClient(gb.config).QueryGroup(gb) diff --git a/ent/groupbudget/groupbudget.go b/ent/groupbudget/groupbudget.go index 2fea902b..12d93201 100644 --- a/ent/groupbudget/groupbudget.go +++ b/ent/groupbudget/groupbudget.go @@ -5,6 +5,8 @@ package groupbudget import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -76,3 +78,61 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the GroupBudget queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByAmount orders the results by the amount field. +func ByAmount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAmount, opts...).ToFunc() +} + +// ByComment orders the results by the comment field. +func ByComment(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldComment, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByGroupField orders the results by group field. +func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...)) + } +} + +// ByTransactionCount orders the results by transaction count. +func ByTransactionCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTransactionStep(), opts...) + } +} + +// ByTransaction orders the results by transaction terms. +func ByTransaction(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTransactionStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newGroupStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), + ) +} +func newTransactionStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TransactionInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, TransactionTable, TransactionColumn), + ) +} diff --git a/ent/groupbudget/where.go b/ent/groupbudget/where.go index 67cc17d2..d2c63277 100644 --- a/ent/groupbudget/where.go +++ b/ent/groupbudget/where.go @@ -240,11 +240,7 @@ func HasGroup() predicate.GroupBudget { // HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates). func HasGroupWith(preds ...predicate.Group) predicate.GroupBudget { return predicate.GroupBudget(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), - ) + step := newGroupStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -267,11 +263,7 @@ func HasTransaction() predicate.GroupBudget { // HasTransactionWith applies the HasEdge predicate on the "transaction" edge with a given conditions (other predicates). func HasTransactionWith(preds ...predicate.Transaction) predicate.GroupBudget { return predicate.GroupBudget(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TransactionInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, TransactionTable, TransactionColumn), - ) + step := newTransactionStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -282,32 +274,15 @@ func HasTransactionWith(preds ...predicate.Transaction) predicate.GroupBudget { // And groups predicates with the AND operator between them. func And(predicates ...predicate.GroupBudget) predicate.GroupBudget { - return predicate.GroupBudget(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.GroupBudget(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.GroupBudget) predicate.GroupBudget { - return predicate.GroupBudget(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.GroupBudget(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.GroupBudget) predicate.GroupBudget { - return predicate.GroupBudget(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.GroupBudget(sql.NotPredicates(p)) } diff --git a/ent/groupbudget_create.go b/ent/groupbudget_create.go index 94f0fa95..fe88b38f 100644 --- a/ent/groupbudget_create.go +++ b/ent/groupbudget_create.go @@ -105,7 +105,7 @@ func (gbc *GroupBudgetCreate) Mutation() *GroupBudgetMutation { // Save creates the GroupBudget in the database. func (gbc *GroupBudgetCreate) Save(ctx context.Context) (*GroupBudget, error) { gbc.defaults() - return withHooks[*GroupBudget, GroupBudgetMutation](ctx, gbc.sqlSave, gbc.mutation, gbc.hooks) + return withHooks(ctx, gbc.sqlSave, gbc.mutation, gbc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -150,7 +150,7 @@ func (gbc *GroupBudgetCreate) check() error { if _, ok := gbc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "GroupBudget.created_at"`)} } - if _, ok := gbc.mutation.GroupID(); !ok { + if len(gbc.mutation.GroupIDs()) == 0 { return &ValidationError{Name: "group", err: errors.New(`ent: missing required edge "GroupBudget.group"`)} } return nil @@ -208,10 +208,7 @@ func (gbc *GroupBudgetCreate) createSpec() (*GroupBudget, *sqlgraph.CreateSpec) Columns: []string{groupbudget.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -228,10 +225,7 @@ func (gbc *GroupBudgetCreate) createSpec() (*GroupBudget, *sqlgraph.CreateSpec) Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -245,11 +239,15 @@ func (gbc *GroupBudgetCreate) createSpec() (*GroupBudget, *sqlgraph.CreateSpec) // GroupBudgetCreateBulk is the builder for creating many GroupBudget entities in bulk. type GroupBudgetCreateBulk struct { config + err error builders []*GroupBudgetCreate } // Save creates the GroupBudget entities in the database. func (gbcb *GroupBudgetCreateBulk) Save(ctx context.Context) ([]*GroupBudget, error) { + if gbcb.err != nil { + return nil, gbcb.err + } specs := make([]*sqlgraph.CreateSpec, len(gbcb.builders)) nodes := make([]*GroupBudget, len(gbcb.builders)) mutators := make([]Mutator, len(gbcb.builders)) @@ -266,8 +264,8 @@ func (gbcb *GroupBudgetCreateBulk) Save(ctx context.Context) ([]*GroupBudget, er return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, gbcb.builders[i+1].mutation) } else { diff --git a/ent/groupbudget_delete.go b/ent/groupbudget_delete.go index 6b95cf18..70842da9 100644 --- a/ent/groupbudget_delete.go +++ b/ent/groupbudget_delete.go @@ -27,7 +27,7 @@ func (gbd *GroupBudgetDelete) Where(ps ...predicate.GroupBudget) *GroupBudgetDel // Exec executes the deletion query and returns how many vertices were deleted. func (gbd *GroupBudgetDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, GroupBudgetMutation](ctx, gbd.sqlExec, gbd.mutation, gbd.hooks) + return withHooks(ctx, gbd.sqlExec, gbd.mutation, gbd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/groupbudget_query.go b/ent/groupbudget_query.go index 8b6e0cb1..dea30497 100644 --- a/ent/groupbudget_query.go +++ b/ent/groupbudget_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -22,7 +23,7 @@ import ( type GroupBudgetQuery struct { config ctx *QueryContext - order []OrderFunc + order []groupbudget.OrderOption inters []Interceptor predicates []predicate.GroupBudget withGroup *GroupQuery @@ -59,7 +60,7 @@ func (gbq *GroupBudgetQuery) Unique(unique bool) *GroupBudgetQuery { } // Order specifies how the records should be ordered. -func (gbq *GroupBudgetQuery) Order(o ...OrderFunc) *GroupBudgetQuery { +func (gbq *GroupBudgetQuery) Order(o ...groupbudget.OrderOption) *GroupBudgetQuery { gbq.order = append(gbq.order, o...) return gbq } @@ -111,7 +112,7 @@ func (gbq *GroupBudgetQuery) QueryTransaction() *TransactionQuery { // First returns the first GroupBudget entity from the query. // Returns a *NotFoundError when no GroupBudget was found. func (gbq *GroupBudgetQuery) First(ctx context.Context) (*GroupBudget, error) { - nodes, err := gbq.Limit(1).All(setContextOp(ctx, gbq.ctx, "First")) + nodes, err := gbq.Limit(1).All(setContextOp(ctx, gbq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -134,7 +135,7 @@ func (gbq *GroupBudgetQuery) FirstX(ctx context.Context) *GroupBudget { // Returns a *NotFoundError when no GroupBudget ID was found. func (gbq *GroupBudgetQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gbq.Limit(1).IDs(setContextOp(ctx, gbq.ctx, "FirstID")); err != nil { + if ids, err = gbq.Limit(1).IDs(setContextOp(ctx, gbq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -157,7 +158,7 @@ func (gbq *GroupBudgetQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one GroupBudget entity is found. // Returns a *NotFoundError when no GroupBudget entities are found. func (gbq *GroupBudgetQuery) Only(ctx context.Context) (*GroupBudget, error) { - nodes, err := gbq.Limit(2).All(setContextOp(ctx, gbq.ctx, "Only")) + nodes, err := gbq.Limit(2).All(setContextOp(ctx, gbq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -185,7 +186,7 @@ func (gbq *GroupBudgetQuery) OnlyX(ctx context.Context) *GroupBudget { // Returns a *NotFoundError when no entities are found. func (gbq *GroupBudgetQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = gbq.Limit(2).IDs(setContextOp(ctx, gbq.ctx, "OnlyID")); err != nil { + if ids, err = gbq.Limit(2).IDs(setContextOp(ctx, gbq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -210,7 +211,7 @@ func (gbq *GroupBudgetQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of GroupBudgets. func (gbq *GroupBudgetQuery) All(ctx context.Context) ([]*GroupBudget, error) { - ctx = setContextOp(ctx, gbq.ctx, "All") + ctx = setContextOp(ctx, gbq.ctx, ent.OpQueryAll) if err := gbq.prepareQuery(ctx); err != nil { return nil, err } @@ -232,7 +233,7 @@ func (gbq *GroupBudgetQuery) IDs(ctx context.Context) (ids []uuid.UUID, err erro if gbq.ctx.Unique == nil && gbq.path != nil { gbq.Unique(true) } - ctx = setContextOp(ctx, gbq.ctx, "IDs") + ctx = setContextOp(ctx, gbq.ctx, ent.OpQueryIDs) if err = gbq.Select(groupbudget.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -250,7 +251,7 @@ func (gbq *GroupBudgetQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (gbq *GroupBudgetQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, gbq.ctx, "Count") + ctx = setContextOp(ctx, gbq.ctx, ent.OpQueryCount) if err := gbq.prepareQuery(ctx); err != nil { return 0, err } @@ -268,7 +269,7 @@ func (gbq *GroupBudgetQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (gbq *GroupBudgetQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, gbq.ctx, "Exist") + ctx = setContextOp(ctx, gbq.ctx, ent.OpQueryExist) switch _, err := gbq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -297,7 +298,7 @@ func (gbq *GroupBudgetQuery) Clone() *GroupBudgetQuery { return &GroupBudgetQuery{ config: gbq.config, ctx: gbq.ctx.Clone(), - order: append([]OrderFunc{}, gbq.order...), + order: append([]groupbudget.OrderOption{}, gbq.order...), inters: append([]Interceptor{}, gbq.inters...), predicates: append([]predicate.GroupBudget{}, gbq.predicates...), withGroup: gbq.withGroup.Clone(), @@ -498,7 +499,7 @@ func (gbq *GroupBudgetQuery) loadTransaction(ctx context.Context, query *Transac } query.withFKs = true query.Where(predicate.Transaction(func(s *sql.Selector) { - s.Where(sql.InValues(groupbudget.TransactionColumn, fks...)) + s.Where(sql.InValues(s.C(groupbudget.TransactionColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -511,7 +512,7 @@ func (gbq *GroupBudgetQuery) loadTransaction(ctx context.Context, query *Transac } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "group_budget_transaction" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "group_budget_transaction" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -613,7 +614,7 @@ func (gbgb *GroupBudgetGroupBy) Aggregate(fns ...AggregateFunc) *GroupBudgetGrou // Scan applies the selector query and scans the result into the given value. func (gbgb *GroupBudgetGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gbgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, gbgb.build.ctx, ent.OpQueryGroupBy) if err := gbgb.build.prepareQuery(ctx); err != nil { return err } @@ -661,7 +662,7 @@ func (gbs *GroupBudgetSelect) Aggregate(fns ...AggregateFunc) *GroupBudgetSelect // Scan applies the selector query and scans the result into the given value. func (gbs *GroupBudgetSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, gbs.ctx, "Select") + ctx = setContextOp(ctx, gbs.ctx, ent.OpQuerySelect) if err := gbs.prepareQuery(ctx); err != nil { return err } diff --git a/ent/groupbudget_update.go b/ent/groupbudget_update.go index 901f1aa3..ef423c5e 100644 --- a/ent/groupbudget_update.go +++ b/ent/groupbudget_update.go @@ -38,6 +38,14 @@ func (gbu *GroupBudgetUpdate) SetAmount(i int) *GroupBudgetUpdate { return gbu } +// SetNillableAmount sets the "amount" field if the given value is not nil. +func (gbu *GroupBudgetUpdate) SetNillableAmount(i *int) *GroupBudgetUpdate { + if i != nil { + gbu.SetAmount(*i) + } + return gbu +} + // AddAmount adds i to the "amount" field. func (gbu *GroupBudgetUpdate) AddAmount(i int) *GroupBudgetUpdate { gbu.mutation.AddAmount(i) @@ -138,7 +146,7 @@ func (gbu *GroupBudgetUpdate) RemoveTransaction(t ...*Transaction) *GroupBudgetU // Save executes the query and returns the number of nodes affected by the update operation. func (gbu *GroupBudgetUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, GroupBudgetMutation](ctx, gbu.sqlSave, gbu.mutation, gbu.hooks) + return withHooks(ctx, gbu.sqlSave, gbu.mutation, gbu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -165,7 +173,7 @@ func (gbu *GroupBudgetUpdate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (gbu *GroupBudgetUpdate) check() error { - if _, ok := gbu.mutation.GroupID(); gbu.mutation.GroupCleared() && !ok { + if gbu.mutation.GroupCleared() && len(gbu.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "GroupBudget.group"`) } return nil @@ -206,10 +214,7 @@ func (gbu *GroupBudgetUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{groupbudget.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -222,10 +227,7 @@ func (gbu *GroupBudgetUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{groupbudget.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -241,10 +243,7 @@ func (gbu *GroupBudgetUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -257,10 +256,7 @@ func (gbu *GroupBudgetUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -276,10 +272,7 @@ func (gbu *GroupBudgetUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -314,6 +307,14 @@ func (gbuo *GroupBudgetUpdateOne) SetAmount(i int) *GroupBudgetUpdateOne { return gbuo } +// SetNillableAmount sets the "amount" field if the given value is not nil. +func (gbuo *GroupBudgetUpdateOne) SetNillableAmount(i *int) *GroupBudgetUpdateOne { + if i != nil { + gbuo.SetAmount(*i) + } + return gbuo +} + // AddAmount adds i to the "amount" field. func (gbuo *GroupBudgetUpdateOne) AddAmount(i int) *GroupBudgetUpdateOne { gbuo.mutation.AddAmount(i) @@ -427,7 +428,7 @@ func (gbuo *GroupBudgetUpdateOne) Select(field string, fields ...string) *GroupB // Save executes the query and returns the updated GroupBudget entity. func (gbuo *GroupBudgetUpdateOne) Save(ctx context.Context) (*GroupBudget, error) { - return withHooks[*GroupBudget, GroupBudgetMutation](ctx, gbuo.sqlSave, gbuo.mutation, gbuo.hooks) + return withHooks(ctx, gbuo.sqlSave, gbuo.mutation, gbuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -454,7 +455,7 @@ func (gbuo *GroupBudgetUpdateOne) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (gbuo *GroupBudgetUpdateOne) check() error { - if _, ok := gbuo.mutation.GroupID(); gbuo.mutation.GroupCleared() && !ok { + if gbuo.mutation.GroupCleared() && len(gbuo.mutation.GroupIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "GroupBudget.group"`) } return nil @@ -512,10 +513,7 @@ func (gbuo *GroupBudgetUpdateOne) sqlSave(ctx context.Context) (_node *GroupBudg Columns: []string{groupbudget.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -528,10 +526,7 @@ func (gbuo *GroupBudgetUpdateOne) sqlSave(ctx context.Context) (_node *GroupBudg Columns: []string{groupbudget.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -547,10 +542,7 @@ func (gbuo *GroupBudgetUpdateOne) sqlSave(ctx context.Context) (_node *GroupBudg Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -563,10 +555,7 @@ func (gbuo *GroupBudgetUpdateOne) sqlSave(ctx context.Context) (_node *GroupBudg Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -582,10 +571,7 @@ func (gbuo *GroupBudgetUpdateOne) sqlSave(ctx context.Context) (_node *GroupBudg Columns: []string{groupbudget.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/request.go b/ent/request.go index cb757486..46c6d442 100644 --- a/ent/request.go +++ b/ent/request.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/group" @@ -32,6 +33,7 @@ type Request struct { Edges RequestEdges `json:"edges"` group_request *uuid.UUID request_user *uuid.UUID + selectValues sql.SelectValues } // RequestEdges holds the relations/edges for other nodes in the graph. @@ -114,12 +116,10 @@ func (e RequestEdges) CommentOrErr() ([]*Comment, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestEdges) UserOrErr() (*User, error) { - if e.loadedTypes[6] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[6] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -127,12 +127,10 @@ func (e RequestEdges) UserOrErr() (*User, error) { // GroupOrErr returns the Group value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestEdges) GroupOrErr() (*Group, error) { - if e.loadedTypes[7] { - if e.Group == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: group.Label} - } + if e.Group != nil { return e.Group, nil + } else if e.loadedTypes[7] { + return nil, &NotFoundError{label: group.Label} } return nil, &NotLoadedError{edge: "group"} } @@ -153,7 +151,7 @@ func (*Request) scanValues(columns []string) ([]any, error) { case request.ForeignKeys[1]: // request_user values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type Request", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -211,11 +209,19 @@ func (r *Request) assignValues(columns []string, values []any) error { r.request_user = new(uuid.UUID) *r.request_user = *value.S.(*uuid.UUID) } + default: + r.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Request. +// This includes values selected through modifiers, order, etc. +func (r *Request) Value(name string) (ent.Value, error) { + return r.selectValues.Get(name) +} + // QueryStatus queries the "status" edge of the Request entity. func (r *Request) QueryStatus() *RequestStatusQuery { return NewRequestClient(r.config).QueryStatus(r) diff --git a/ent/request/request.go b/ent/request/request.go index f8a9146a..00b7d712 100644 --- a/ent/request/request.go +++ b/ent/request/request.go @@ -5,6 +5,8 @@ package request import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -142,3 +144,185 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Request queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByTitle orders the results by the title field. +func ByTitle(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTitle, opts...).ToFunc() +} + +// ByContent orders the results by the content field. +func ByContent(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldContent, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByStatusCount orders the results by status count. +func ByStatusCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newStatusStep(), opts...) + } +} + +// ByStatus orders the results by status terms. +func ByStatus(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newStatusStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByTargetCount orders the results by target count. +func ByTargetCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTargetStep(), opts...) + } +} + +// ByTarget orders the results by target terms. +func ByTarget(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTargetStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByFileCount orders the results by file count. +func ByFileCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newFileStep(), opts...) + } +} + +// ByFile orders the results by file terms. +func ByFile(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newFileStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByTagCount orders the results by tag count. +func ByTagCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTagStep(), opts...) + } +} + +// ByTag orders the results by tag terms. +func ByTag(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTagStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByTransactionCount orders the results by transaction count. +func ByTransactionCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTransactionStep(), opts...) + } +} + +// ByTransaction orders the results by transaction terms. +func ByTransaction(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTransactionStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByCommentCount orders the results by comment count. +func ByCommentCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newCommentStep(), opts...) + } +} + +// ByComment orders the results by comment terms. +func ByComment(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCommentStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} + +// ByGroupField orders the results by group field. +func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...)) + } +} +func newStatusStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(StatusInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, StatusTable, StatusColumn), + ) +} +func newTargetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TargetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, TargetTable, TargetColumn), + ) +} +func newFileStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(FileInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, FileTable, FileColumn), + ) +} +func newTagStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TagInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, TagTable, TagPrimaryKey...), + ) +} +func newTransactionStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TransactionInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, TransactionTable, TransactionColumn), + ) +} +func newCommentStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CommentInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, CommentTable, CommentColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), + ) +} +func newGroupStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), + ) +} diff --git a/ent/request/where.go b/ent/request/where.go index 73ed133b..240fb92b 100644 --- a/ent/request/where.go +++ b/ent/request/where.go @@ -300,11 +300,7 @@ func HasStatus() predicate.Request { // HasStatusWith applies the HasEdge predicate on the "status" edge with a given conditions (other predicates). func HasStatusWith(preds ...predicate.RequestStatus) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(StatusInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, StatusTable, StatusColumn), - ) + step := newStatusStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -327,11 +323,7 @@ func HasTarget() predicate.Request { // HasTargetWith applies the HasEdge predicate on the "target" edge with a given conditions (other predicates). func HasTargetWith(preds ...predicate.RequestTarget) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TargetInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, TargetTable, TargetColumn), - ) + step := newTargetStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -354,11 +346,7 @@ func HasFile() predicate.Request { // HasFileWith applies the HasEdge predicate on the "file" edge with a given conditions (other predicates). func HasFileWith(preds ...predicate.File) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(FileInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, FileTable, FileColumn), - ) + step := newFileStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -381,11 +369,7 @@ func HasTag() predicate.Request { // HasTagWith applies the HasEdge predicate on the "tag" edge with a given conditions (other predicates). func HasTagWith(preds ...predicate.Tag) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TagInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, TagTable, TagPrimaryKey...), - ) + step := newTagStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -408,11 +392,7 @@ func HasTransaction() predicate.Request { // HasTransactionWith applies the HasEdge predicate on the "transaction" edge with a given conditions (other predicates). func HasTransactionWith(preds ...predicate.Transaction) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TransactionInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, TransactionTable, TransactionColumn), - ) + step := newTransactionStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -435,11 +415,7 @@ func HasComment() predicate.Request { // HasCommentWith applies the HasEdge predicate on the "comment" edge with a given conditions (other predicates). func HasCommentWith(preds ...predicate.Comment) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(CommentInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, false, CommentTable, CommentColumn), - ) + step := newCommentStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -462,11 +438,7 @@ func HasUser() predicate.Request { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -489,11 +461,7 @@ func HasGroup() predicate.Request { // HasGroupWith applies the HasEdge predicate on the "group" edge with a given conditions (other predicates). func HasGroupWith(preds ...predicate.Group) predicate.Request { return predicate.Request(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn), - ) + step := newGroupStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -504,32 +472,15 @@ func HasGroupWith(preds ...predicate.Group) predicate.Request { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Request) predicate.Request { - return predicate.Request(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Request(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Request) predicate.Request { - return predicate.Request(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Request(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Request) predicate.Request { - return predicate.Request(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Request(sql.NotPredicates(p)) } diff --git a/ent/request_create.go b/ent/request_create.go index 244bc526..bfb0c57a 100644 --- a/ent/request_create.go +++ b/ent/request_create.go @@ -219,7 +219,7 @@ func (rc *RequestCreate) Mutation() *RequestMutation { // Save creates the Request in the database. func (rc *RequestCreate) Save(ctx context.Context) (*Request, error) { rc.defaults() - return withHooks[*Request, RequestMutation](ctx, rc.sqlSave, rc.mutation, rc.hooks) + return withHooks(ctx, rc.sqlSave, rc.mutation, rc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -333,10 +333,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -352,10 +349,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -371,10 +365,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -390,10 +381,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -409,10 +397,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -428,10 +413,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -447,10 +429,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -467,10 +446,7 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { Columns: []string{request.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -485,11 +461,15 @@ func (rc *RequestCreate) createSpec() (*Request, *sqlgraph.CreateSpec) { // RequestCreateBulk is the builder for creating many Request entities in bulk. type RequestCreateBulk struct { config + err error builders []*RequestCreate } // Save creates the Request entities in the database. func (rcb *RequestCreateBulk) Save(ctx context.Context) ([]*Request, error) { + if rcb.err != nil { + return nil, rcb.err + } specs := make([]*sqlgraph.CreateSpec, len(rcb.builders)) nodes := make([]*Request, len(rcb.builders)) mutators := make([]Mutator, len(rcb.builders)) @@ -506,8 +486,8 @@ func (rcb *RequestCreateBulk) Save(ctx context.Context) ([]*Request, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, rcb.builders[i+1].mutation) } else { diff --git a/ent/request_delete.go b/ent/request_delete.go index f0d5be3c..c49c508f 100644 --- a/ent/request_delete.go +++ b/ent/request_delete.go @@ -27,7 +27,7 @@ func (rd *RequestDelete) Where(ps ...predicate.Request) *RequestDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (rd *RequestDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, RequestMutation](ctx, rd.sqlExec, rd.mutation, rd.hooks) + return withHooks(ctx, rd.sqlExec, rd.mutation, rd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/request_query.go b/ent/request_query.go index 6954adba..73d29e75 100644 --- a/ent/request_query.go +++ b/ent/request_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -28,7 +29,7 @@ import ( type RequestQuery struct { config ctx *QueryContext - order []OrderFunc + order []request.OrderOption inters []Interceptor predicates []predicate.Request withStatus *RequestStatusQuery @@ -71,7 +72,7 @@ func (rq *RequestQuery) Unique(unique bool) *RequestQuery { } // Order specifies how the records should be ordered. -func (rq *RequestQuery) Order(o ...OrderFunc) *RequestQuery { +func (rq *RequestQuery) Order(o ...request.OrderOption) *RequestQuery { rq.order = append(rq.order, o...) return rq } @@ -255,7 +256,7 @@ func (rq *RequestQuery) QueryGroup() *GroupQuery { // First returns the first Request entity from the query. // Returns a *NotFoundError when no Request was found. func (rq *RequestQuery) First(ctx context.Context) (*Request, error) { - nodes, err := rq.Limit(1).All(setContextOp(ctx, rq.ctx, "First")) + nodes, err := rq.Limit(1).All(setContextOp(ctx, rq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -278,7 +279,7 @@ func (rq *RequestQuery) FirstX(ctx context.Context) *Request { // Returns a *NotFoundError when no Request ID was found. func (rq *RequestQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rq.Limit(1).IDs(setContextOp(ctx, rq.ctx, "FirstID")); err != nil { + if ids, err = rq.Limit(1).IDs(setContextOp(ctx, rq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -301,7 +302,7 @@ func (rq *RequestQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Request entity is found. // Returns a *NotFoundError when no Request entities are found. func (rq *RequestQuery) Only(ctx context.Context) (*Request, error) { - nodes, err := rq.Limit(2).All(setContextOp(ctx, rq.ctx, "Only")) + nodes, err := rq.Limit(2).All(setContextOp(ctx, rq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -329,7 +330,7 @@ func (rq *RequestQuery) OnlyX(ctx context.Context) *Request { // Returns a *NotFoundError when no entities are found. func (rq *RequestQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rq.Limit(2).IDs(setContextOp(ctx, rq.ctx, "OnlyID")); err != nil { + if ids, err = rq.Limit(2).IDs(setContextOp(ctx, rq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -354,7 +355,7 @@ func (rq *RequestQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Requests. func (rq *RequestQuery) All(ctx context.Context) ([]*Request, error) { - ctx = setContextOp(ctx, rq.ctx, "All") + ctx = setContextOp(ctx, rq.ctx, ent.OpQueryAll) if err := rq.prepareQuery(ctx); err != nil { return nil, err } @@ -376,7 +377,7 @@ func (rq *RequestQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if rq.ctx.Unique == nil && rq.path != nil { rq.Unique(true) } - ctx = setContextOp(ctx, rq.ctx, "IDs") + ctx = setContextOp(ctx, rq.ctx, ent.OpQueryIDs) if err = rq.Select(request.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -394,7 +395,7 @@ func (rq *RequestQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (rq *RequestQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, rq.ctx, "Count") + ctx = setContextOp(ctx, rq.ctx, ent.OpQueryCount) if err := rq.prepareQuery(ctx); err != nil { return 0, err } @@ -412,7 +413,7 @@ func (rq *RequestQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (rq *RequestQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, rq.ctx, "Exist") + ctx = setContextOp(ctx, rq.ctx, ent.OpQueryExist) switch _, err := rq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -441,7 +442,7 @@ func (rq *RequestQuery) Clone() *RequestQuery { return &RequestQuery{ config: rq.config, ctx: rq.ctx.Clone(), - order: append([]OrderFunc{}, rq.order...), + order: append([]request.OrderOption{}, rq.order...), inters: append([]Interceptor{}, rq.inters...), predicates: append([]predicate.Request{}, rq.predicates...), withStatus: rq.withStatus.Clone(), @@ -729,7 +730,7 @@ func (rq *RequestQuery) loadStatus(ctx context.Context, query *RequestStatusQuer } query.withFKs = true query.Where(predicate.RequestStatus(func(s *sql.Selector) { - s.Where(sql.InValues(request.StatusColumn, fks...)) + s.Where(sql.InValues(s.C(request.StatusColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -742,7 +743,7 @@ func (rq *RequestQuery) loadStatus(ctx context.Context, query *RequestStatusQuer } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_status" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_status" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -760,7 +761,7 @@ func (rq *RequestQuery) loadTarget(ctx context.Context, query *RequestTargetQuer } query.withFKs = true query.Where(predicate.RequestTarget(func(s *sql.Selector) { - s.Where(sql.InValues(request.TargetColumn, fks...)) + s.Where(sql.InValues(s.C(request.TargetColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -773,7 +774,7 @@ func (rq *RequestQuery) loadTarget(ctx context.Context, query *RequestTargetQuer } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_target" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_target" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -791,7 +792,7 @@ func (rq *RequestQuery) loadFile(ctx context.Context, query *FileQuery, nodes [] } query.withFKs = true query.Where(predicate.File(func(s *sql.Selector) { - s.Where(sql.InValues(request.FileColumn, fks...)) + s.Where(sql.InValues(s.C(request.FileColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -804,7 +805,7 @@ func (rq *RequestQuery) loadFile(ctx context.Context, query *FileQuery, nodes [] } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_file" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_file" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -883,7 +884,7 @@ func (rq *RequestQuery) loadTransaction(ctx context.Context, query *TransactionQ } query.withFKs = true query.Where(predicate.Transaction(func(s *sql.Selector) { - s.Where(sql.InValues(request.TransactionColumn, fks...)) + s.Where(sql.InValues(s.C(request.TransactionColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -896,7 +897,7 @@ func (rq *RequestQuery) loadTransaction(ctx context.Context, query *TransactionQ } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_transaction" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_transaction" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -914,7 +915,7 @@ func (rq *RequestQuery) loadComment(ctx context.Context, query *CommentQuery, no } query.withFKs = true query.Where(predicate.Comment(func(s *sql.Selector) { - s.Where(sql.InValues(request.CommentColumn, fks...)) + s.Where(sql.InValues(s.C(request.CommentColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -927,7 +928,7 @@ func (rq *RequestQuery) loadComment(ctx context.Context, query *CommentQuery, no } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_comment" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_comment" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -1093,7 +1094,7 @@ func (rgb *RequestGroupBy) Aggregate(fns ...AggregateFunc) *RequestGroupBy { // Scan applies the selector query and scans the result into the given value. func (rgb *RequestGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, rgb.build.ctx, ent.OpQueryGroupBy) if err := rgb.build.prepareQuery(ctx); err != nil { return err } @@ -1141,7 +1142,7 @@ func (rs *RequestSelect) Aggregate(fns ...AggregateFunc) *RequestSelect { // Scan applies the selector query and scans the result into the given value. func (rs *RequestSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rs.ctx, "Select") + ctx = setContextOp(ctx, rs.ctx, ent.OpQuerySelect) if err := rs.prepareQuery(ctx); err != nil { return err } diff --git a/ent/request_update.go b/ent/request_update.go index 922211fd..b1453c90 100644 --- a/ent/request_update.go +++ b/ent/request_update.go @@ -43,12 +43,28 @@ func (ru *RequestUpdate) SetTitle(s string) *RequestUpdate { return ru } +// SetNillableTitle sets the "title" field if the given value is not nil. +func (ru *RequestUpdate) SetNillableTitle(s *string) *RequestUpdate { + if s != nil { + ru.SetTitle(*s) + } + return ru +} + // SetContent sets the "content" field. func (ru *RequestUpdate) SetContent(s string) *RequestUpdate { ru.mutation.SetContent(s) return ru } +// SetNillableContent sets the "content" field if the given value is not nil. +func (ru *RequestUpdate) SetNillableContent(s *string) *RequestUpdate { + if s != nil { + ru.SetContent(*s) + } + return ru +} + // SetCreatedAt sets the "created_at" field. func (ru *RequestUpdate) SetCreatedAt(t time.Time) *RequestUpdate { ru.mutation.SetCreatedAt(t) @@ -343,7 +359,7 @@ func (ru *RequestUpdate) ClearGroup() *RequestUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (ru *RequestUpdate) Save(ctx context.Context) (int, error) { ru.defaults() - return withHooks[int, RequestMutation](ctx, ru.sqlSave, ru.mutation, ru.hooks) + return withHooks(ctx, ru.sqlSave, ru.mutation, ru.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -405,10 +421,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -421,10 +434,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -440,10 +450,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -459,10 +466,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -475,10 +479,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -494,10 +495,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -513,10 +511,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -529,10 +524,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -548,10 +540,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -567,10 +556,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -583,10 +569,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -602,10 +585,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -621,10 +601,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -637,10 +614,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -656,10 +630,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -675,10 +646,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -691,10 +659,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -710,10 +675,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -729,10 +691,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -745,10 +704,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -764,10 +720,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -780,10 +733,7 @@ func (ru *RequestUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{request.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -817,12 +767,28 @@ func (ruo *RequestUpdateOne) SetTitle(s string) *RequestUpdateOne { return ruo } +// SetNillableTitle sets the "title" field if the given value is not nil. +func (ruo *RequestUpdateOne) SetNillableTitle(s *string) *RequestUpdateOne { + if s != nil { + ruo.SetTitle(*s) + } + return ruo +} + // SetContent sets the "content" field. func (ruo *RequestUpdateOne) SetContent(s string) *RequestUpdateOne { ruo.mutation.SetContent(s) return ruo } +// SetNillableContent sets the "content" field if the given value is not nil. +func (ruo *RequestUpdateOne) SetNillableContent(s *string) *RequestUpdateOne { + if s != nil { + ruo.SetContent(*s) + } + return ruo +} + // SetCreatedAt sets the "created_at" field. func (ruo *RequestUpdateOne) SetCreatedAt(t time.Time) *RequestUpdateOne { ruo.mutation.SetCreatedAt(t) @@ -1130,7 +1096,7 @@ func (ruo *RequestUpdateOne) Select(field string, fields ...string) *RequestUpda // Save executes the query and returns the updated Request entity. func (ruo *RequestUpdateOne) Save(ctx context.Context) (*Request, error) { ruo.defaults() - return withHooks[*Request, RequestMutation](ctx, ruo.sqlSave, ruo.mutation, ruo.hooks) + return withHooks(ctx, ruo.sqlSave, ruo.mutation, ruo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -1209,10 +1175,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1225,10 +1188,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1244,10 +1204,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.StatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1263,10 +1220,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1279,10 +1233,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1298,10 +1249,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1317,10 +1265,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1333,10 +1278,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1352,10 +1294,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1371,10 +1310,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1387,10 +1323,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1406,10 +1339,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: request.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1425,10 +1355,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1441,10 +1368,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1460,10 +1384,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1479,10 +1400,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1495,10 +1413,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1514,10 +1429,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1533,10 +1445,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1549,10 +1458,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1568,10 +1474,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1584,10 +1487,7 @@ func (ruo *RequestUpdateOne) sqlSave(ctx context.Context) (_node *Request, err e Columns: []string{request.GroupColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/requeststatus.go b/ent/requeststatus.go index a9ae69b5..7988d716 100644 --- a/ent/requeststatus.go +++ b/ent/requeststatus.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/request" @@ -28,6 +29,7 @@ type RequestStatus struct { Edges RequestStatusEdges `json:"edges"` request_status *uuid.UUID request_status_user *uuid.UUID + selectValues sql.SelectValues } // RequestStatusEdges holds the relations/edges for other nodes in the graph. @@ -44,12 +46,10 @@ type RequestStatusEdges struct { // RequestOrErr returns the Request value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestStatusEdges) RequestOrErr() (*Request, error) { - if e.loadedTypes[0] { - if e.Request == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: request.Label} - } + if e.Request != nil { return e.Request, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: request.Label} } return nil, &NotLoadedError{edge: "request"} } @@ -57,12 +57,10 @@ func (e RequestStatusEdges) RequestOrErr() (*Request, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestStatusEdges) UserOrErr() (*User, error) { - if e.loadedTypes[1] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -83,7 +81,7 @@ func (*RequestStatus) scanValues(columns []string) ([]any, error) { case requeststatus.ForeignKeys[1]: // request_status_user values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type RequestStatus", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -129,11 +127,19 @@ func (rs *RequestStatus) assignValues(columns []string, values []any) error { rs.request_status_user = new(uuid.UUID) *rs.request_status_user = *value.S.(*uuid.UUID) } + default: + rs.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the RequestStatus. +// This includes values selected through modifiers, order, etc. +func (rs *RequestStatus) Value(name string) (ent.Value, error) { + return rs.selectValues.Get(name) +} + // QueryRequest queries the "request" edge of the RequestStatus entity. func (rs *RequestStatus) QueryRequest() *RequestQuery { return NewRequestStatusClient(rs.config).QueryRequest(rs) diff --git a/ent/requeststatus/requeststatus.go b/ent/requeststatus/requeststatus.go index 9295ff47..3b766bd6 100644 --- a/ent/requeststatus/requeststatus.go +++ b/ent/requeststatus/requeststatus.go @@ -6,6 +6,8 @@ import ( "fmt" "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -104,3 +106,49 @@ func StatusValidator(s Status) error { return fmt.Errorf("requeststatus: invalid enum value for status field: %q", s) } } + +// OrderOption defines the ordering options for the RequestStatus queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByStatus orders the results by the status field. +func ByStatus(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldStatus, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByRequestField orders the results by request field. +func ByRequestField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), sql.OrderByField(field, opts...)) + } +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), + ) +} diff --git a/ent/requeststatus/where.go b/ent/requeststatus/where.go index d034c0c6..38591a28 100644 --- a/ent/requeststatus/where.go +++ b/ent/requeststatus/where.go @@ -135,11 +135,7 @@ func HasRequest() predicate.RequestStatus { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.RequestStatus { return predicate.RequestStatus(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -162,11 +158,7 @@ func HasUser() predicate.RequestStatus { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.RequestStatus { return predicate.RequestStatus(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -177,32 +169,15 @@ func HasUserWith(preds ...predicate.User) predicate.RequestStatus { // And groups predicates with the AND operator between them. func And(predicates ...predicate.RequestStatus) predicate.RequestStatus { - return predicate.RequestStatus(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.RequestStatus(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.RequestStatus) predicate.RequestStatus { - return predicate.RequestStatus(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.RequestStatus(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.RequestStatus) predicate.RequestStatus { - return predicate.RequestStatus(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.RequestStatus(sql.NotPredicates(p)) } diff --git a/ent/requeststatus_create.go b/ent/requeststatus_create.go index 0b102337..5dc73b6c 100644 --- a/ent/requeststatus_create.go +++ b/ent/requeststatus_create.go @@ -95,7 +95,7 @@ func (rsc *RequestStatusCreate) Mutation() *RequestStatusMutation { // Save creates the RequestStatus in the database. func (rsc *RequestStatusCreate) Save(ctx context.Context) (*RequestStatus, error) { rsc.defaults() - return withHooks[*RequestStatus, RequestStatusMutation](ctx, rsc.sqlSave, rsc.mutation, rsc.hooks) + return withHooks(ctx, rsc.sqlSave, rsc.mutation, rsc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -149,10 +149,10 @@ func (rsc *RequestStatusCreate) check() error { if _, ok := rsc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "RequestStatus.created_at"`)} } - if _, ok := rsc.mutation.RequestID(); !ok { + if len(rsc.mutation.RequestIDs()) == 0 { return &ValidationError{Name: "request", err: errors.New(`ent: missing required edge "RequestStatus.request"`)} } - if _, ok := rsc.mutation.UserID(); !ok { + if len(rsc.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "RequestStatus.user"`)} } return nil @@ -206,10 +206,7 @@ func (rsc *RequestStatusCreate) createSpec() (*RequestStatus, *sqlgraph.CreateSp Columns: []string{requeststatus.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -226,10 +223,7 @@ func (rsc *RequestStatusCreate) createSpec() (*RequestStatus, *sqlgraph.CreateSp Columns: []string{requeststatus.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -244,11 +238,15 @@ func (rsc *RequestStatusCreate) createSpec() (*RequestStatus, *sqlgraph.CreateSp // RequestStatusCreateBulk is the builder for creating many RequestStatus entities in bulk. type RequestStatusCreateBulk struct { config + err error builders []*RequestStatusCreate } // Save creates the RequestStatus entities in the database. func (rscb *RequestStatusCreateBulk) Save(ctx context.Context) ([]*RequestStatus, error) { + if rscb.err != nil { + return nil, rscb.err + } specs := make([]*sqlgraph.CreateSpec, len(rscb.builders)) nodes := make([]*RequestStatus, len(rscb.builders)) mutators := make([]Mutator, len(rscb.builders)) @@ -265,8 +263,8 @@ func (rscb *RequestStatusCreateBulk) Save(ctx context.Context) ([]*RequestStatus return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, rscb.builders[i+1].mutation) } else { diff --git a/ent/requeststatus_delete.go b/ent/requeststatus_delete.go index bf63f8dc..11396686 100644 --- a/ent/requeststatus_delete.go +++ b/ent/requeststatus_delete.go @@ -27,7 +27,7 @@ func (rsd *RequestStatusDelete) Where(ps ...predicate.RequestStatus) *RequestSta // Exec executes the deletion query and returns how many vertices were deleted. func (rsd *RequestStatusDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, RequestStatusMutation](ctx, rsd.sqlExec, rsd.mutation, rsd.hooks) + return withHooks(ctx, rsd.sqlExec, rsd.mutation, rsd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/requeststatus_query.go b/ent/requeststatus_query.go index 7dcef240..0c331734 100644 --- a/ent/requeststatus_query.go +++ b/ent/requeststatus_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -21,7 +22,7 @@ import ( type RequestStatusQuery struct { config ctx *QueryContext - order []OrderFunc + order []requeststatus.OrderOption inters []Interceptor predicates []predicate.RequestStatus withRequest *RequestQuery @@ -58,7 +59,7 @@ func (rsq *RequestStatusQuery) Unique(unique bool) *RequestStatusQuery { } // Order specifies how the records should be ordered. -func (rsq *RequestStatusQuery) Order(o ...OrderFunc) *RequestStatusQuery { +func (rsq *RequestStatusQuery) Order(o ...requeststatus.OrderOption) *RequestStatusQuery { rsq.order = append(rsq.order, o...) return rsq } @@ -110,7 +111,7 @@ func (rsq *RequestStatusQuery) QueryUser() *UserQuery { // First returns the first RequestStatus entity from the query. // Returns a *NotFoundError when no RequestStatus was found. func (rsq *RequestStatusQuery) First(ctx context.Context) (*RequestStatus, error) { - nodes, err := rsq.Limit(1).All(setContextOp(ctx, rsq.ctx, "First")) + nodes, err := rsq.Limit(1).All(setContextOp(ctx, rsq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (rsq *RequestStatusQuery) FirstX(ctx context.Context) *RequestStatus { // Returns a *NotFoundError when no RequestStatus ID was found. func (rsq *RequestStatusQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rsq.Limit(1).IDs(setContextOp(ctx, rsq.ctx, "FirstID")); err != nil { + if ids, err = rsq.Limit(1).IDs(setContextOp(ctx, rsq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (rsq *RequestStatusQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one RequestStatus entity is found. // Returns a *NotFoundError when no RequestStatus entities are found. func (rsq *RequestStatusQuery) Only(ctx context.Context) (*RequestStatus, error) { - nodes, err := rsq.Limit(2).All(setContextOp(ctx, rsq.ctx, "Only")) + nodes, err := rsq.Limit(2).All(setContextOp(ctx, rsq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (rsq *RequestStatusQuery) OnlyX(ctx context.Context) *RequestStatus { // Returns a *NotFoundError when no entities are found. func (rsq *RequestStatusQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rsq.Limit(2).IDs(setContextOp(ctx, rsq.ctx, "OnlyID")); err != nil { + if ids, err = rsq.Limit(2).IDs(setContextOp(ctx, rsq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (rsq *RequestStatusQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of RequestStatusSlice. func (rsq *RequestStatusQuery) All(ctx context.Context) ([]*RequestStatus, error) { - ctx = setContextOp(ctx, rsq.ctx, "All") + ctx = setContextOp(ctx, rsq.ctx, ent.OpQueryAll) if err := rsq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (rsq *RequestStatusQuery) IDs(ctx context.Context) (ids []uuid.UUID, err er if rsq.ctx.Unique == nil && rsq.path != nil { rsq.Unique(true) } - ctx = setContextOp(ctx, rsq.ctx, "IDs") + ctx = setContextOp(ctx, rsq.ctx, ent.OpQueryIDs) if err = rsq.Select(requeststatus.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (rsq *RequestStatusQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (rsq *RequestStatusQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, rsq.ctx, "Count") + ctx = setContextOp(ctx, rsq.ctx, ent.OpQueryCount) if err := rsq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (rsq *RequestStatusQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (rsq *RequestStatusQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, rsq.ctx, "Exist") + ctx = setContextOp(ctx, rsq.ctx, ent.OpQueryExist) switch _, err := rsq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,7 +297,7 @@ func (rsq *RequestStatusQuery) Clone() *RequestStatusQuery { return &RequestStatusQuery{ config: rsq.config, ctx: rsq.ctx.Clone(), - order: append([]OrderFunc{}, rsq.order...), + order: append([]requeststatus.OrderOption{}, rsq.order...), inters: append([]Interceptor{}, rsq.inters...), predicates: append([]predicate.RequestStatus{}, rsq.predicates...), withRequest: rsq.withRequest.Clone(), @@ -612,7 +613,7 @@ func (rsgb *RequestStatusGroupBy) Aggregate(fns ...AggregateFunc) *RequestStatus // Scan applies the selector query and scans the result into the given value. func (rsgb *RequestStatusGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rsgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, rsgb.build.ctx, ent.OpQueryGroupBy) if err := rsgb.build.prepareQuery(ctx); err != nil { return err } @@ -660,7 +661,7 @@ func (rss *RequestStatusSelect) Aggregate(fns ...AggregateFunc) *RequestStatusSe // Scan applies the selector query and scans the result into the given value. func (rss *RequestStatusSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rss.ctx, "Select") + ctx = setContextOp(ctx, rss.ctx, ent.OpQuerySelect) if err := rss.prepareQuery(ctx); err != nil { return err } diff --git a/ent/requeststatus_update.go b/ent/requeststatus_update.go index 891aeded..7c5c35a1 100644 --- a/ent/requeststatus_update.go +++ b/ent/requeststatus_update.go @@ -100,7 +100,7 @@ func (rsu *RequestStatusUpdate) ClearUser() *RequestStatusUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (rsu *RequestStatusUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, RequestStatusMutation](ctx, rsu.sqlSave, rsu.mutation, rsu.hooks) + return withHooks(ctx, rsu.sqlSave, rsu.mutation, rsu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -132,10 +132,10 @@ func (rsu *RequestStatusUpdate) check() error { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "RequestStatus.status": %w`, err)} } } - if _, ok := rsu.mutation.RequestID(); rsu.mutation.RequestCleared() && !ok { + if rsu.mutation.RequestCleared() && len(rsu.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestStatus.request"`) } - if _, ok := rsu.mutation.UserID(); rsu.mutation.UserCleared() && !ok { + if rsu.mutation.UserCleared() && len(rsu.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestStatus.user"`) } return nil @@ -167,10 +167,7 @@ func (rsu *RequestStatusUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requeststatus.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -183,10 +180,7 @@ func (rsu *RequestStatusUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requeststatus.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -202,10 +196,7 @@ func (rsu *RequestStatusUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requeststatus.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -218,10 +209,7 @@ func (rsu *RequestStatusUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requeststatus.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -331,7 +319,7 @@ func (rsuo *RequestStatusUpdateOne) Select(field string, fields ...string) *Requ // Save executes the query and returns the updated RequestStatus entity. func (rsuo *RequestStatusUpdateOne) Save(ctx context.Context) (*RequestStatus, error) { - return withHooks[*RequestStatus, RequestStatusMutation](ctx, rsuo.sqlSave, rsuo.mutation, rsuo.hooks) + return withHooks(ctx, rsuo.sqlSave, rsuo.mutation, rsuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -363,10 +351,10 @@ func (rsuo *RequestStatusUpdateOne) check() error { return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "RequestStatus.status": %w`, err)} } } - if _, ok := rsuo.mutation.RequestID(); rsuo.mutation.RequestCleared() && !ok { + if rsuo.mutation.RequestCleared() && len(rsuo.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestStatus.request"`) } - if _, ok := rsuo.mutation.UserID(); rsuo.mutation.UserCleared() && !ok { + if rsuo.mutation.UserCleared() && len(rsuo.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestStatus.user"`) } return nil @@ -415,10 +403,7 @@ func (rsuo *RequestStatusUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requeststatus.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -431,10 +416,7 @@ func (rsuo *RequestStatusUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requeststatus.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -450,10 +432,7 @@ func (rsuo *RequestStatusUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requeststatus.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -466,10 +445,7 @@ func (rsuo *RequestStatusUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requeststatus.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/requesttarget.go b/ent/requesttarget.go index bb54e6ef..9b4324c1 100644 --- a/ent/requesttarget.go +++ b/ent/requesttarget.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/request" @@ -30,6 +31,7 @@ type RequestTarget struct { Edges RequestTargetEdges `json:"edges"` request_target *uuid.UUID request_target_user *uuid.UUID + selectValues sql.SelectValues } // RequestTargetEdges holds the relations/edges for other nodes in the graph. @@ -46,12 +48,10 @@ type RequestTargetEdges struct { // RequestOrErr returns the Request value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestTargetEdges) RequestOrErr() (*Request, error) { - if e.loadedTypes[0] { - if e.Request == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: request.Label} - } + if e.Request != nil { return e.Request, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: request.Label} } return nil, &NotLoadedError{edge: "request"} } @@ -59,12 +59,10 @@ func (e RequestTargetEdges) RequestOrErr() (*Request, error) { // UserOrErr returns the User value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e RequestTargetEdges) UserOrErr() (*User, error) { - if e.loadedTypes[1] { - if e.User == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: user.Label} - } + if e.User != nil { return e.User, nil + } else if e.loadedTypes[1] { + return nil, &NotFoundError{label: user.Label} } return nil, &NotLoadedError{edge: "user"} } @@ -85,7 +83,7 @@ func (*RequestTarget) scanValues(columns []string) ([]any, error) { case requesttarget.ForeignKeys[1]: // request_target_user values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type RequestTarget", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -138,11 +136,19 @@ func (rt *RequestTarget) assignValues(columns []string, values []any) error { rt.request_target_user = new(uuid.UUID) *rt.request_target_user = *value.S.(*uuid.UUID) } + default: + rt.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the RequestTarget. +// This includes values selected through modifiers, order, etc. +func (rt *RequestTarget) Value(name string) (ent.Value, error) { + return rt.selectValues.Get(name) +} + // QueryRequest queries the "request" edge of the RequestTarget entity. func (rt *RequestTarget) QueryRequest() *RequestQuery { return NewRequestTargetClient(rt.config).QueryRequest(rt) diff --git a/ent/requesttarget/requesttarget.go b/ent/requesttarget/requesttarget.go index 45398815..0473493c 100644 --- a/ent/requesttarget/requesttarget.go +++ b/ent/requesttarget/requesttarget.go @@ -5,6 +5,8 @@ package requesttarget import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -77,3 +79,54 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the RequestTarget queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByAmount orders the results by the amount field. +func ByAmount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAmount, opts...).ToFunc() +} + +// ByPaidAt orders the results by the paid_at field. +func ByPaidAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPaidAt, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByRequestField orders the results by request field. +func ByRequestField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), sql.OrderByField(field, opts...)) + } +} + +// ByUserField orders the results by user field. +func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...)) + } +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), + ) +} +func newUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(UserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), + ) +} diff --git a/ent/requesttarget/where.go b/ent/requesttarget/where.go index 0f96a624..31b8ffd5 100644 --- a/ent/requesttarget/where.go +++ b/ent/requesttarget/where.go @@ -215,11 +215,7 @@ func HasRequest() predicate.RequestTarget { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.RequestTarget { return predicate.RequestTarget(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -242,11 +238,7 @@ func HasUser() predicate.RequestTarget { // HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates). func HasUserWith(preds ...predicate.User) predicate.RequestTarget { return predicate.RequestTarget(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(UserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, false, UserTable, UserColumn), - ) + step := newUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -257,32 +249,15 @@ func HasUserWith(preds ...predicate.User) predicate.RequestTarget { // And groups predicates with the AND operator between them. func And(predicates ...predicate.RequestTarget) predicate.RequestTarget { - return predicate.RequestTarget(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.RequestTarget(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.RequestTarget) predicate.RequestTarget { - return predicate.RequestTarget(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.RequestTarget(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.RequestTarget) predicate.RequestTarget { - return predicate.RequestTarget(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.RequestTarget(sql.NotPredicates(p)) } diff --git a/ent/requesttarget_create.go b/ent/requesttarget_create.go index 1702e3ae..d991ee39 100644 --- a/ent/requesttarget_create.go +++ b/ent/requesttarget_create.go @@ -101,7 +101,7 @@ func (rtc *RequestTargetCreate) Mutation() *RequestTargetMutation { // Save creates the RequestTarget in the database. func (rtc *RequestTargetCreate) Save(ctx context.Context) (*RequestTarget, error) { rtc.defaults() - return withHooks[*RequestTarget, RequestTargetMutation](ctx, rtc.sqlSave, rtc.mutation, rtc.hooks) + return withHooks(ctx, rtc.sqlSave, rtc.mutation, rtc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -146,10 +146,10 @@ func (rtc *RequestTargetCreate) check() error { if _, ok := rtc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "RequestTarget.created_at"`)} } - if _, ok := rtc.mutation.RequestID(); !ok { + if len(rtc.mutation.RequestIDs()) == 0 { return &ValidationError{Name: "request", err: errors.New(`ent: missing required edge "RequestTarget.request"`)} } - if _, ok := rtc.mutation.UserID(); !ok { + if len(rtc.mutation.UserIDs()) == 0 { return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "RequestTarget.user"`)} } return nil @@ -207,10 +207,7 @@ func (rtc *RequestTargetCreate) createSpec() (*RequestTarget, *sqlgraph.CreateSp Columns: []string{requesttarget.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -227,10 +224,7 @@ func (rtc *RequestTargetCreate) createSpec() (*RequestTarget, *sqlgraph.CreateSp Columns: []string{requesttarget.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -245,11 +239,15 @@ func (rtc *RequestTargetCreate) createSpec() (*RequestTarget, *sqlgraph.CreateSp // RequestTargetCreateBulk is the builder for creating many RequestTarget entities in bulk. type RequestTargetCreateBulk struct { config + err error builders []*RequestTargetCreate } // Save creates the RequestTarget entities in the database. func (rtcb *RequestTargetCreateBulk) Save(ctx context.Context) ([]*RequestTarget, error) { + if rtcb.err != nil { + return nil, rtcb.err + } specs := make([]*sqlgraph.CreateSpec, len(rtcb.builders)) nodes := make([]*RequestTarget, len(rtcb.builders)) mutators := make([]Mutator, len(rtcb.builders)) @@ -266,8 +264,8 @@ func (rtcb *RequestTargetCreateBulk) Save(ctx context.Context) ([]*RequestTarget return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, rtcb.builders[i+1].mutation) } else { diff --git a/ent/requesttarget_delete.go b/ent/requesttarget_delete.go index 6018e83d..8e8fd257 100644 --- a/ent/requesttarget_delete.go +++ b/ent/requesttarget_delete.go @@ -27,7 +27,7 @@ func (rtd *RequestTargetDelete) Where(ps ...predicate.RequestTarget) *RequestTar // Exec executes the deletion query and returns how many vertices were deleted. func (rtd *RequestTargetDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, RequestTargetMutation](ctx, rtd.sqlExec, rtd.mutation, rtd.hooks) + return withHooks(ctx, rtd.sqlExec, rtd.mutation, rtd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/requesttarget_query.go b/ent/requesttarget_query.go index eba23543..8ed19a27 100644 --- a/ent/requesttarget_query.go +++ b/ent/requesttarget_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -21,7 +22,7 @@ import ( type RequestTargetQuery struct { config ctx *QueryContext - order []OrderFunc + order []requesttarget.OrderOption inters []Interceptor predicates []predicate.RequestTarget withRequest *RequestQuery @@ -58,7 +59,7 @@ func (rtq *RequestTargetQuery) Unique(unique bool) *RequestTargetQuery { } // Order specifies how the records should be ordered. -func (rtq *RequestTargetQuery) Order(o ...OrderFunc) *RequestTargetQuery { +func (rtq *RequestTargetQuery) Order(o ...requesttarget.OrderOption) *RequestTargetQuery { rtq.order = append(rtq.order, o...) return rtq } @@ -110,7 +111,7 @@ func (rtq *RequestTargetQuery) QueryUser() *UserQuery { // First returns the first RequestTarget entity from the query. // Returns a *NotFoundError when no RequestTarget was found. func (rtq *RequestTargetQuery) First(ctx context.Context) (*RequestTarget, error) { - nodes, err := rtq.Limit(1).All(setContextOp(ctx, rtq.ctx, "First")) + nodes, err := rtq.Limit(1).All(setContextOp(ctx, rtq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (rtq *RequestTargetQuery) FirstX(ctx context.Context) *RequestTarget { // Returns a *NotFoundError when no RequestTarget ID was found. func (rtq *RequestTargetQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rtq.Limit(1).IDs(setContextOp(ctx, rtq.ctx, "FirstID")); err != nil { + if ids, err = rtq.Limit(1).IDs(setContextOp(ctx, rtq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (rtq *RequestTargetQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one RequestTarget entity is found. // Returns a *NotFoundError when no RequestTarget entities are found. func (rtq *RequestTargetQuery) Only(ctx context.Context) (*RequestTarget, error) { - nodes, err := rtq.Limit(2).All(setContextOp(ctx, rtq.ctx, "Only")) + nodes, err := rtq.Limit(2).All(setContextOp(ctx, rtq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (rtq *RequestTargetQuery) OnlyX(ctx context.Context) *RequestTarget { // Returns a *NotFoundError when no entities are found. func (rtq *RequestTargetQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = rtq.Limit(2).IDs(setContextOp(ctx, rtq.ctx, "OnlyID")); err != nil { + if ids, err = rtq.Limit(2).IDs(setContextOp(ctx, rtq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (rtq *RequestTargetQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of RequestTargets. func (rtq *RequestTargetQuery) All(ctx context.Context) ([]*RequestTarget, error) { - ctx = setContextOp(ctx, rtq.ctx, "All") + ctx = setContextOp(ctx, rtq.ctx, ent.OpQueryAll) if err := rtq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (rtq *RequestTargetQuery) IDs(ctx context.Context) (ids []uuid.UUID, err er if rtq.ctx.Unique == nil && rtq.path != nil { rtq.Unique(true) } - ctx = setContextOp(ctx, rtq.ctx, "IDs") + ctx = setContextOp(ctx, rtq.ctx, ent.OpQueryIDs) if err = rtq.Select(requesttarget.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (rtq *RequestTargetQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (rtq *RequestTargetQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, rtq.ctx, "Count") + ctx = setContextOp(ctx, rtq.ctx, ent.OpQueryCount) if err := rtq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (rtq *RequestTargetQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (rtq *RequestTargetQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, rtq.ctx, "Exist") + ctx = setContextOp(ctx, rtq.ctx, ent.OpQueryExist) switch _, err := rtq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,7 +297,7 @@ func (rtq *RequestTargetQuery) Clone() *RequestTargetQuery { return &RequestTargetQuery{ config: rtq.config, ctx: rtq.ctx.Clone(), - order: append([]OrderFunc{}, rtq.order...), + order: append([]requesttarget.OrderOption{}, rtq.order...), inters: append([]Interceptor{}, rtq.inters...), predicates: append([]predicate.RequestTarget{}, rtq.predicates...), withRequest: rtq.withRequest.Clone(), @@ -612,7 +613,7 @@ func (rtgb *RequestTargetGroupBy) Aggregate(fns ...AggregateFunc) *RequestTarget // Scan applies the selector query and scans the result into the given value. func (rtgb *RequestTargetGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rtgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, rtgb.build.ctx, ent.OpQueryGroupBy) if err := rtgb.build.prepareQuery(ctx); err != nil { return err } @@ -660,7 +661,7 @@ func (rts *RequestTargetSelect) Aggregate(fns ...AggregateFunc) *RequestTargetSe // Scan applies the selector query and scans the result into the given value. func (rts *RequestTargetSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, rts.ctx, "Select") + ctx = setContextOp(ctx, rts.ctx, ent.OpQuerySelect) if err := rts.prepareQuery(ctx); err != nil { return err } diff --git a/ent/requesttarget_update.go b/ent/requesttarget_update.go index 4ab9744b..ad261abb 100644 --- a/ent/requesttarget_update.go +++ b/ent/requesttarget_update.go @@ -38,6 +38,14 @@ func (rtu *RequestTargetUpdate) SetAmount(i int) *RequestTargetUpdate { return rtu } +// SetNillableAmount sets the "amount" field if the given value is not nil. +func (rtu *RequestTargetUpdate) SetNillableAmount(i *int) *RequestTargetUpdate { + if i != nil { + rtu.SetAmount(*i) + } + return rtu +} + // AddAmount adds i to the "amount" field. func (rtu *RequestTargetUpdate) AddAmount(i int) *RequestTargetUpdate { rtu.mutation.AddAmount(i) @@ -119,7 +127,7 @@ func (rtu *RequestTargetUpdate) ClearUser() *RequestTargetUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (rtu *RequestTargetUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, RequestTargetMutation](ctx, rtu.sqlSave, rtu.mutation, rtu.hooks) + return withHooks(ctx, rtu.sqlSave, rtu.mutation, rtu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -146,10 +154,10 @@ func (rtu *RequestTargetUpdate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (rtu *RequestTargetUpdate) check() error { - if _, ok := rtu.mutation.RequestID(); rtu.mutation.RequestCleared() && !ok { + if rtu.mutation.RequestCleared() && len(rtu.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestTarget.request"`) } - if _, ok := rtu.mutation.UserID(); rtu.mutation.UserCleared() && !ok { + if rtu.mutation.UserCleared() && len(rtu.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestTarget.user"`) } return nil @@ -190,10 +198,7 @@ func (rtu *RequestTargetUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requesttarget.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -206,10 +211,7 @@ func (rtu *RequestTargetUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requesttarget.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -225,10 +227,7 @@ func (rtu *RequestTargetUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requesttarget.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -241,10 +240,7 @@ func (rtu *RequestTargetUpdate) sqlSave(ctx context.Context) (n int, err error) Columns: []string{requesttarget.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -279,6 +275,14 @@ func (rtuo *RequestTargetUpdateOne) SetAmount(i int) *RequestTargetUpdateOne { return rtuo } +// SetNillableAmount sets the "amount" field if the given value is not nil. +func (rtuo *RequestTargetUpdateOne) SetNillableAmount(i *int) *RequestTargetUpdateOne { + if i != nil { + rtuo.SetAmount(*i) + } + return rtuo +} + // AddAmount adds i to the "amount" field. func (rtuo *RequestTargetUpdateOne) AddAmount(i int) *RequestTargetUpdateOne { rtuo.mutation.AddAmount(i) @@ -373,7 +377,7 @@ func (rtuo *RequestTargetUpdateOne) Select(field string, fields ...string) *Requ // Save executes the query and returns the updated RequestTarget entity. func (rtuo *RequestTargetUpdateOne) Save(ctx context.Context) (*RequestTarget, error) { - return withHooks[*RequestTarget, RequestTargetMutation](ctx, rtuo.sqlSave, rtuo.mutation, rtuo.hooks) + return withHooks(ctx, rtuo.sqlSave, rtuo.mutation, rtuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -400,10 +404,10 @@ func (rtuo *RequestTargetUpdateOne) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (rtuo *RequestTargetUpdateOne) check() error { - if _, ok := rtuo.mutation.RequestID(); rtuo.mutation.RequestCleared() && !ok { + if rtuo.mutation.RequestCleared() && len(rtuo.mutation.RequestIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestTarget.request"`) } - if _, ok := rtuo.mutation.UserID(); rtuo.mutation.UserCleared() && !ok { + if rtuo.mutation.UserCleared() && len(rtuo.mutation.UserIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "RequestTarget.user"`) } return nil @@ -461,10 +465,7 @@ func (rtuo *RequestTargetUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requesttarget.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -477,10 +478,7 @@ func (rtuo *RequestTargetUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requesttarget.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -496,10 +494,7 @@ func (rtuo *RequestTargetUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requesttarget.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -512,10 +507,7 @@ func (rtuo *RequestTargetUpdateOne) sqlSave(ctx context.Context) (_node *Request Columns: []string{requesttarget.UserColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: user.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/runtime/runtime.go b/ent/runtime/runtime.go index 4cc61091..f110b81d 100644 --- a/ent/runtime/runtime.go +++ b/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in github.com/traPtitech/Jomon/ent/runtime.go const ( - Version = "v0.11.9" // Version of ent codegen. - Sum = "h1:dbbCkAiPVTRBIJwoZctiSYjB7zxQIBOzVSU5H9VYIQI=" // Sum of ent codegen. + Version = "v0.14.0" // Version of ent codegen. + Sum = "h1:EO3Z9aZ5bXJatJeGqu/EVdnNr6K4mRq3rWe5owt0MC4=" // Sum of ent codegen. ) diff --git a/ent/tag.go b/ent/tag.go index c90d0374..67a8fd3c 100644 --- a/ent/tag.go +++ b/ent/tag.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/tag" @@ -27,7 +28,8 @@ type Tag struct { DeletedAt *time.Time `json:"deleted_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the TagQuery when eager-loading is set. - Edges TagEdges `json:"edges"` + Edges TagEdges `json:"edges"` + selectValues sql.SelectValues } // TagEdges holds the relations/edges for other nodes in the graph. @@ -71,7 +73,7 @@ func (*Tag) scanValues(columns []string) ([]any, error) { case tag.FieldID: values[i] = new(uuid.UUID) default: - return nil, fmt.Errorf("unexpected column %q for type Tag", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -116,11 +118,19 @@ func (t *Tag) assignValues(columns []string, values []any) error { t.DeletedAt = new(time.Time) *t.DeletedAt = value.Time } + default: + t.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Tag. +// This includes values selected through modifiers, order, etc. +func (t *Tag) Value(name string) (ent.Value, error) { + return t.selectValues.Get(name) +} + // QueryRequest queries the "request" edge of the Tag entity. func (t *Tag) QueryRequest() *RequestQuery { return NewTagClient(t.config).QueryRequest(t) diff --git a/ent/tag/tag.go b/ent/tag/tag.go index cbfb4db6..439afd69 100644 --- a/ent/tag/tag.go +++ b/ent/tag/tag.go @@ -5,6 +5,8 @@ package tag import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -79,3 +81,73 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Tag queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByRequestCount orders the results by request count. +func ByRequestCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newRequestStep(), opts...) + } +} + +// ByRequest orders the results by request terms. +func ByRequest(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByTransactionCount orders the results by transaction count. +func ByTransactionCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTransactionStep(), opts...) + } +} + +// ByTransaction orders the results by transaction terms. +func ByTransaction(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTransactionStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, RequestTable, RequestPrimaryKey...), + ) +} +func newTransactionStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TransactionInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, TransactionTable, TransactionPrimaryKey...), + ) +} diff --git a/ent/tag/where.go b/ent/tag/where.go index 8183c019..73a3d389 100644 --- a/ent/tag/where.go +++ b/ent/tag/where.go @@ -285,11 +285,7 @@ func HasRequest() predicate.Tag { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.Tag { return predicate.Tag(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, RequestTable, RequestPrimaryKey...), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -312,11 +308,7 @@ func HasTransaction() predicate.Tag { // HasTransactionWith applies the HasEdge predicate on the "transaction" edge with a given conditions (other predicates). func HasTransactionWith(preds ...predicate.Transaction) predicate.Tag { return predicate.Tag(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TransactionInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, TransactionTable, TransactionPrimaryKey...), - ) + step := newTransactionStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -327,32 +319,15 @@ func HasTransactionWith(preds ...predicate.Transaction) predicate.Tag { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Tag) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Tag(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Tag) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Tag(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Tag) predicate.Tag { - return predicate.Tag(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Tag(sql.NotPredicates(p)) } diff --git a/ent/tag_create.go b/ent/tag_create.go index 5f1033fb..309c943b 100644 --- a/ent/tag_create.go +++ b/ent/tag_create.go @@ -123,7 +123,7 @@ func (tc *TagCreate) Mutation() *TagMutation { // Save creates the Tag in the database. func (tc *TagCreate) Save(ctx context.Context) (*Tag, error) { tc.defaults() - return withHooks[*Tag, TagMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -239,10 +239,7 @@ func (tc *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -258,10 +255,7 @@ func (tc *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -275,11 +269,15 @@ func (tc *TagCreate) createSpec() (*Tag, *sqlgraph.CreateSpec) { // TagCreateBulk is the builder for creating many Tag entities in bulk. type TagCreateBulk struct { config + err error builders []*TagCreate } // Save creates the Tag entities in the database. func (tcb *TagCreateBulk) Save(ctx context.Context) ([]*Tag, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Tag, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) @@ -296,8 +294,8 @@ func (tcb *TagCreateBulk) Save(ctx context.Context) ([]*Tag, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, tcb.builders[i+1].mutation) } else { diff --git a/ent/tag_delete.go b/ent/tag_delete.go index 78dd69a7..81c4d33a 100644 --- a/ent/tag_delete.go +++ b/ent/tag_delete.go @@ -27,7 +27,7 @@ func (td *TagDelete) Where(ps ...predicate.Tag) *TagDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (td *TagDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TagMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/tag_query.go b/ent/tag_query.go index c6bacabb..46e5b12b 100644 --- a/ent/tag_query.go +++ b/ent/tag_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -22,7 +23,7 @@ import ( type TagQuery struct { config ctx *QueryContext - order []OrderFunc + order []tag.OrderOption inters []Interceptor predicates []predicate.Tag withRequest *RequestQuery @@ -58,7 +59,7 @@ func (tq *TagQuery) Unique(unique bool) *TagQuery { } // Order specifies how the records should be ordered. -func (tq *TagQuery) Order(o ...OrderFunc) *TagQuery { +func (tq *TagQuery) Order(o ...tag.OrderOption) *TagQuery { tq.order = append(tq.order, o...) return tq } @@ -110,7 +111,7 @@ func (tq *TagQuery) QueryTransaction() *TransactionQuery { // First returns the first Tag entity from the query. // Returns a *NotFoundError when no Tag was found. func (tq *TagQuery) First(ctx context.Context) (*Tag, error) { - nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, "First")) + nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -133,7 +134,7 @@ func (tq *TagQuery) FirstX(ctx context.Context) *Tag { // Returns a *NotFoundError when no Tag ID was found. func (tq *TagQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, "FirstID")); err != nil { + if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -156,7 +157,7 @@ func (tq *TagQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Tag entity is found. // Returns a *NotFoundError when no Tag entities are found. func (tq *TagQuery) Only(ctx context.Context) (*Tag, error) { - nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, "Only")) + nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -184,7 +185,7 @@ func (tq *TagQuery) OnlyX(ctx context.Context) *Tag { // Returns a *NotFoundError when no entities are found. func (tq *TagQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, "OnlyID")); err != nil { + if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -209,7 +210,7 @@ func (tq *TagQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Tags. func (tq *TagQuery) All(ctx context.Context) ([]*Tag, error) { - ctx = setContextOp(ctx, tq.ctx, "All") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryAll) if err := tq.prepareQuery(ctx); err != nil { return nil, err } @@ -231,7 +232,7 @@ func (tq *TagQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if tq.ctx.Unique == nil && tq.path != nil { tq.Unique(true) } - ctx = setContextOp(ctx, tq.ctx, "IDs") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryIDs) if err = tq.Select(tag.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -249,7 +250,7 @@ func (tq *TagQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (tq *TagQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, tq.ctx, "Count") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryCount) if err := tq.prepareQuery(ctx); err != nil { return 0, err } @@ -267,7 +268,7 @@ func (tq *TagQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (tq *TagQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, tq.ctx, "Exist") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryExist) switch _, err := tq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -296,7 +297,7 @@ func (tq *TagQuery) Clone() *TagQuery { return &TagQuery{ config: tq.config, ctx: tq.ctx.Clone(), - order: append([]OrderFunc{}, tq.order...), + order: append([]tag.OrderOption{}, tq.order...), inters: append([]Interceptor{}, tq.inters...), predicates: append([]predicate.Tag{}, tq.predicates...), withRequest: tq.withRequest.Clone(), @@ -665,7 +666,7 @@ func (tgb *TagGroupBy) Aggregate(fns ...AggregateFunc) *TagGroupBy { // Scan applies the selector query and scans the result into the given value. func (tgb *TagGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, tgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, tgb.build.ctx, ent.OpQueryGroupBy) if err := tgb.build.prepareQuery(ctx); err != nil { return err } @@ -713,7 +714,7 @@ func (ts *TagSelect) Aggregate(fns ...AggregateFunc) *TagSelect { // Scan applies the selector query and scans the result into the given value. func (ts *TagSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ts.ctx, "Select") + ctx = setContextOp(ctx, ts.ctx, ent.OpQuerySelect) if err := ts.prepareQuery(ctx); err != nil { return err } diff --git a/ent/tag_update.go b/ent/tag_update.go index 367e30d6..38b7f22d 100644 --- a/ent/tag_update.go +++ b/ent/tag_update.go @@ -37,6 +37,14 @@ func (tu *TagUpdate) SetName(s string) *TagUpdate { return tu } +// SetNillableName sets the "name" field if the given value is not nil. +func (tu *TagUpdate) SetNillableName(s *string) *TagUpdate { + if s != nil { + tu.SetName(*s) + } + return tu +} + // SetCreatedAt sets the "created_at" field. func (tu *TagUpdate) SetCreatedAt(t time.Time) *TagUpdate { tu.mutation.SetCreatedAt(t) @@ -157,7 +165,7 @@ func (tu *TagUpdate) RemoveTransaction(t ...*Transaction) *TagUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TagUpdate) Save(ctx context.Context) (int, error) { tu.defaults() - return withHooks[int, TagMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -235,10 +243,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -251,10 +256,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -270,10 +272,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -289,10 +288,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -305,10 +301,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -324,10 +317,7 @@ func (tu *TagUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -361,6 +351,14 @@ func (tuo *TagUpdateOne) SetName(s string) *TagUpdateOne { return tuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (tuo *TagUpdateOne) SetNillableName(s *string) *TagUpdateOne { + if s != nil { + tuo.SetName(*s) + } + return tuo +} + // SetCreatedAt sets the "created_at" field. func (tuo *TagUpdateOne) SetCreatedAt(t time.Time) *TagUpdateOne { tuo.mutation.SetCreatedAt(t) @@ -494,7 +492,7 @@ func (tuo *TagUpdateOne) Select(field string, fields ...string) *TagUpdateOne { // Save executes the query and returns the updated Tag entity. func (tuo *TagUpdateOne) Save(ctx context.Context) (*Tag, error) { tuo.defaults() - return withHooks[*Tag, TagMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -589,10 +587,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -605,10 +600,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -624,10 +616,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.RequestPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -643,10 +632,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -659,10 +645,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -678,10 +661,7 @@ func (tuo *TagUpdateOne) sqlSave(ctx context.Context) (_node *Tag, err error) { Columns: tag.TransactionPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/transaction.go b/ent/transaction.go index 22eaa9f9..a59e68b9 100644 --- a/ent/transaction.go +++ b/ent/transaction.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/groupbudget" @@ -27,6 +28,7 @@ type Transaction struct { Edges TransactionEdges `json:"edges"` group_budget_transaction *uuid.UUID request_transaction *uuid.UUID + selectValues sql.SelectValues } // TransactionEdges holds the relations/edges for other nodes in the graph. @@ -47,12 +49,10 @@ type TransactionEdges struct { // DetailOrErr returns the Detail value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TransactionEdges) DetailOrErr() (*TransactionDetail, error) { - if e.loadedTypes[0] { - if e.Detail == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: transactiondetail.Label} - } + if e.Detail != nil { return e.Detail, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: transactiondetail.Label} } return nil, &NotLoadedError{edge: "detail"} } @@ -69,12 +69,10 @@ func (e TransactionEdges) TagOrErr() ([]*Tag, error) { // GroupBudgetOrErr returns the GroupBudget value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TransactionEdges) GroupBudgetOrErr() (*GroupBudget, error) { - if e.loadedTypes[2] { - if e.GroupBudget == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: groupbudget.Label} - } + if e.GroupBudget != nil { return e.GroupBudget, nil + } else if e.loadedTypes[2] { + return nil, &NotFoundError{label: groupbudget.Label} } return nil, &NotLoadedError{edge: "group_budget"} } @@ -82,12 +80,10 @@ func (e TransactionEdges) GroupBudgetOrErr() (*GroupBudget, error) { // RequestOrErr returns the Request value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TransactionEdges) RequestOrErr() (*Request, error) { - if e.loadedTypes[3] { - if e.Request == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: request.Label} - } + if e.Request != nil { return e.Request, nil + } else if e.loadedTypes[3] { + return nil, &NotFoundError{label: request.Label} } return nil, &NotLoadedError{edge: "request"} } @@ -106,7 +102,7 @@ func (*Transaction) scanValues(columns []string) ([]any, error) { case transaction.ForeignKeys[1]: // request_transaction values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type Transaction", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -146,11 +142,19 @@ func (t *Transaction) assignValues(columns []string, values []any) error { t.request_transaction = new(uuid.UUID) *t.request_transaction = *value.S.(*uuid.UUID) } + default: + t.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Transaction. +// This includes values selected through modifiers, order, etc. +func (t *Transaction) Value(name string) (ent.Value, error) { + return t.selectValues.Get(name) +} + // QueryDetail queries the "detail" edge of the Transaction entity. func (t *Transaction) QueryDetail() *TransactionDetailQuery { return NewTransactionClient(t.config).QueryDetail(t) diff --git a/ent/transaction/transaction.go b/ent/transaction/transaction.go index 0004eebc..413ad964 100644 --- a/ent/transaction/transaction.go +++ b/ent/transaction/transaction.go @@ -5,6 +5,8 @@ package transaction import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -93,3 +95,79 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Transaction queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByDetailField orders the results by detail field. +func ByDetailField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newDetailStep(), sql.OrderByField(field, opts...)) + } +} + +// ByTagCount orders the results by tag count. +func ByTagCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newTagStep(), opts...) + } +} + +// ByTag orders the results by tag terms. +func ByTag(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTagStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByGroupBudgetField orders the results by group_budget field. +func ByGroupBudgetField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupBudgetStep(), sql.OrderByField(field, opts...)) + } +} + +// ByRequestField orders the results by request field. +func ByRequestField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), sql.OrderByField(field, opts...)) + } +} +func newDetailStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(DetailInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2O, false, DetailTable, DetailColumn), + ) +} +func newTagStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TagInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, TagTable, TagPrimaryKey...), + ) +} +func newGroupBudgetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupBudgetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, GroupBudgetTable, GroupBudgetColumn), + ) +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), + ) +} diff --git a/ent/transaction/where.go b/ent/transaction/where.go index 4df8f8b0..e48ba68c 100644 --- a/ent/transaction/where.go +++ b/ent/transaction/where.go @@ -115,11 +115,7 @@ func HasDetail() predicate.Transaction { // HasDetailWith applies the HasEdge predicate on the "detail" edge with a given conditions (other predicates). func HasDetailWith(preds ...predicate.TransactionDetail) predicate.Transaction { return predicate.Transaction(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(DetailInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2O, false, DetailTable, DetailColumn), - ) + step := newDetailStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -142,11 +138,7 @@ func HasTag() predicate.Transaction { // HasTagWith applies the HasEdge predicate on the "tag" edge with a given conditions (other predicates). func HasTagWith(preds ...predicate.Tag) predicate.Transaction { return predicate.Transaction(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TagInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, false, TagTable, TagPrimaryKey...), - ) + step := newTagStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -169,11 +161,7 @@ func HasGroupBudget() predicate.Transaction { // HasGroupBudgetWith applies the HasEdge predicate on the "group_budget" edge with a given conditions (other predicates). func HasGroupBudgetWith(preds ...predicate.GroupBudget) predicate.Transaction { return predicate.Transaction(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupBudgetInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, GroupBudgetTable, GroupBudgetColumn), - ) + step := newGroupBudgetStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -196,11 +184,7 @@ func HasRequest() predicate.Transaction { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.Transaction { return predicate.Transaction(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2O, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -211,32 +195,15 @@ func HasRequestWith(preds ...predicate.Request) predicate.Transaction { // And groups predicates with the AND operator between them. func And(predicates ...predicate.Transaction) predicate.Transaction { - return predicate.Transaction(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Transaction(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.Transaction) predicate.Transaction { - return predicate.Transaction(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.Transaction(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.Transaction) predicate.Transaction { - return predicate.Transaction(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.Transaction(sql.NotPredicates(p)) } diff --git a/ent/transaction_create.go b/ent/transaction_create.go index 2e6f23b0..d196fd07 100644 --- a/ent/transaction_create.go +++ b/ent/transaction_create.go @@ -125,7 +125,7 @@ func (tc *TransactionCreate) Mutation() *TransactionMutation { // Save creates the Transaction in the database. func (tc *TransactionCreate) Save(ctx context.Context) (*Transaction, error) { tc.defaults() - return withHooks[*Transaction, TransactionMutation](ctx, tc.sqlSave, tc.mutation, tc.hooks) + return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -167,7 +167,7 @@ func (tc *TransactionCreate) check() error { if _, ok := tc.mutation.CreatedAt(); !ok { return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Transaction.created_at"`)} } - if _, ok := tc.mutation.DetailID(); !ok { + if len(tc.mutation.DetailIDs()) == 0 { return &ValidationError{Name: "detail", err: errors.New(`ent: missing required edge "Transaction.detail"`)} } return nil @@ -217,10 +217,7 @@ func (tc *TransactionCreate) createSpec() (*Transaction, *sqlgraph.CreateSpec) { Columns: []string{transaction.DetailColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transactiondetail.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transactiondetail.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -236,10 +233,7 @@ func (tc *TransactionCreate) createSpec() (*Transaction, *sqlgraph.CreateSpec) { Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -255,10 +249,7 @@ func (tc *TransactionCreate) createSpec() (*Transaction, *sqlgraph.CreateSpec) { Columns: []string{transaction.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -275,10 +266,7 @@ func (tc *TransactionCreate) createSpec() (*Transaction, *sqlgraph.CreateSpec) { Columns: []string{transaction.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -293,11 +281,15 @@ func (tc *TransactionCreate) createSpec() (*Transaction, *sqlgraph.CreateSpec) { // TransactionCreateBulk is the builder for creating many Transaction entities in bulk. type TransactionCreateBulk struct { config + err error builders []*TransactionCreate } // Save creates the Transaction entities in the database. func (tcb *TransactionCreateBulk) Save(ctx context.Context) ([]*Transaction, error) { + if tcb.err != nil { + return nil, tcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tcb.builders)) nodes := make([]*Transaction, len(tcb.builders)) mutators := make([]Mutator, len(tcb.builders)) @@ -314,8 +306,8 @@ func (tcb *TransactionCreateBulk) Save(ctx context.Context) ([]*Transaction, err return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, tcb.builders[i+1].mutation) } else { diff --git a/ent/transaction_delete.go b/ent/transaction_delete.go index 77ba20e4..882589b4 100644 --- a/ent/transaction_delete.go +++ b/ent/transaction_delete.go @@ -27,7 +27,7 @@ func (td *TransactionDelete) Where(ps ...predicate.Transaction) *TransactionDele // Exec executes the deletion query and returns how many vertices were deleted. func (td *TransactionDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TransactionMutation](ctx, td.sqlExec, td.mutation, td.hooks) + return withHooks(ctx, td.sqlExec, td.mutation, td.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/transaction_query.go b/ent/transaction_query.go index 11a6bfe7..e13f8889 100644 --- a/ent/transaction_query.go +++ b/ent/transaction_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -24,7 +25,7 @@ import ( type TransactionQuery struct { config ctx *QueryContext - order []OrderFunc + order []transaction.OrderOption inters []Interceptor predicates []predicate.Transaction withDetail *TransactionDetailQuery @@ -63,7 +64,7 @@ func (tq *TransactionQuery) Unique(unique bool) *TransactionQuery { } // Order specifies how the records should be ordered. -func (tq *TransactionQuery) Order(o ...OrderFunc) *TransactionQuery { +func (tq *TransactionQuery) Order(o ...transaction.OrderOption) *TransactionQuery { tq.order = append(tq.order, o...) return tq } @@ -159,7 +160,7 @@ func (tq *TransactionQuery) QueryRequest() *RequestQuery { // First returns the first Transaction entity from the query. // Returns a *NotFoundError when no Transaction was found. func (tq *TransactionQuery) First(ctx context.Context) (*Transaction, error) { - nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, "First")) + nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -182,7 +183,7 @@ func (tq *TransactionQuery) FirstX(ctx context.Context) *Transaction { // Returns a *NotFoundError when no Transaction ID was found. func (tq *TransactionQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, "FirstID")); err != nil { + if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -205,7 +206,7 @@ func (tq *TransactionQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one Transaction entity is found. // Returns a *NotFoundError when no Transaction entities are found. func (tq *TransactionQuery) Only(ctx context.Context) (*Transaction, error) { - nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, "Only")) + nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -233,7 +234,7 @@ func (tq *TransactionQuery) OnlyX(ctx context.Context) *Transaction { // Returns a *NotFoundError when no entities are found. func (tq *TransactionQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, "OnlyID")); err != nil { + if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -258,7 +259,7 @@ func (tq *TransactionQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Transactions. func (tq *TransactionQuery) All(ctx context.Context) ([]*Transaction, error) { - ctx = setContextOp(ctx, tq.ctx, "All") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryAll) if err := tq.prepareQuery(ctx); err != nil { return nil, err } @@ -280,7 +281,7 @@ func (tq *TransactionQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error if tq.ctx.Unique == nil && tq.path != nil { tq.Unique(true) } - ctx = setContextOp(ctx, tq.ctx, "IDs") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryIDs) if err = tq.Select(transaction.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -298,7 +299,7 @@ func (tq *TransactionQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (tq *TransactionQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, tq.ctx, "Count") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryCount) if err := tq.prepareQuery(ctx); err != nil { return 0, err } @@ -316,7 +317,7 @@ func (tq *TransactionQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (tq *TransactionQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, tq.ctx, "Exist") + ctx = setContextOp(ctx, tq.ctx, ent.OpQueryExist) switch _, err := tq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -345,7 +346,7 @@ func (tq *TransactionQuery) Clone() *TransactionQuery { return &TransactionQuery{ config: tq.config, ctx: tq.ctx.Clone(), - order: append([]OrderFunc{}, tq.order...), + order: append([]transaction.OrderOption{}, tq.order...), inters: append([]Interceptor{}, tq.inters...), predicates: append([]predicate.Transaction{}, tq.predicates...), withDetail: tq.withDetail.Clone(), @@ -549,7 +550,7 @@ func (tq *TransactionQuery) loadDetail(ctx context.Context, query *TransactionDe } query.withFKs = true query.Where(predicate.TransactionDetail(func(s *sql.Selector) { - s.Where(sql.InValues(transaction.DetailColumn, fks...)) + s.Where(sql.InValues(s.C(transaction.DetailColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -562,7 +563,7 @@ func (tq *TransactionQuery) loadDetail(ctx context.Context, query *TransactionDe } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "transaction_detail" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "transaction_detail" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -789,7 +790,7 @@ func (tgb *TransactionGroupBy) Aggregate(fns ...AggregateFunc) *TransactionGroup // Scan applies the selector query and scans the result into the given value. func (tgb *TransactionGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, tgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, tgb.build.ctx, ent.OpQueryGroupBy) if err := tgb.build.prepareQuery(ctx); err != nil { return err } @@ -837,7 +838,7 @@ func (ts *TransactionSelect) Aggregate(fns ...AggregateFunc) *TransactionSelect // Scan applies the selector query and scans the result into the given value. func (ts *TransactionSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ts.ctx, "Select") + ctx = setContextOp(ctx, ts.ctx, ent.OpQuerySelect) if err := ts.prepareQuery(ctx); err != nil { return err } diff --git a/ent/transaction_update.go b/ent/transaction_update.go index 2dfdaf9f..d877a806 100644 --- a/ent/transaction_update.go +++ b/ent/transaction_update.go @@ -157,7 +157,7 @@ func (tu *TransactionUpdate) ClearRequest() *TransactionUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (tu *TransactionUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, TransactionMutation](ctx, tu.sqlSave, tu.mutation, tu.hooks) + return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -184,7 +184,7 @@ func (tu *TransactionUpdate) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (tu *TransactionUpdate) check() error { - if _, ok := tu.mutation.DetailID(); tu.mutation.DetailCleared() && !ok { + if tu.mutation.DetailCleared() && len(tu.mutation.DetailIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Transaction.detail"`) } return nil @@ -213,10 +213,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.DetailColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transactiondetail.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transactiondetail.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -229,10 +226,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.DetailColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transactiondetail.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transactiondetail.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -248,10 +242,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -264,10 +255,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -283,10 +271,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -302,10 +287,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -318,10 +300,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -337,10 +316,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -353,10 +329,7 @@ func (tu *TransactionUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{transaction.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -521,7 +494,7 @@ func (tuo *TransactionUpdateOne) Select(field string, fields ...string) *Transac // Save executes the query and returns the updated Transaction entity. func (tuo *TransactionUpdateOne) Save(ctx context.Context) (*Transaction, error) { - return withHooks[*Transaction, TransactionMutation](ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) + return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -548,7 +521,7 @@ func (tuo *TransactionUpdateOne) ExecX(ctx context.Context) { // check runs all checks and user-defined validators on the builder. func (tuo *TransactionUpdateOne) check() error { - if _, ok := tuo.mutation.DetailID(); tuo.mutation.DetailCleared() && !ok { + if tuo.mutation.DetailCleared() && len(tuo.mutation.DetailIDs()) > 0 { return errors.New(`ent: clearing a required unique edge "Transaction.detail"`) } return nil @@ -594,10 +567,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.DetailColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transactiondetail.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transactiondetail.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -610,10 +580,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.DetailColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transactiondetail.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transactiondetail.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -629,10 +596,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -645,10 +609,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -664,10 +625,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: transaction.TagPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: tag.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(tag.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -683,10 +641,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -699,10 +654,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.GroupBudgetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: groupbudget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(groupbudget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -718,10 +670,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -734,10 +683,7 @@ func (tuo *TransactionUpdateOne) sqlSave(ctx context.Context) (_node *Transactio Columns: []string{transaction.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/transactiondetail.go b/ent/transactiondetail.go index 50f156ab..fe3095f2 100644 --- a/ent/transactiondetail.go +++ b/ent/transactiondetail.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/transaction" @@ -30,6 +31,7 @@ type TransactionDetail struct { // The values are being populated by the TransactionDetailQuery when eager-loading is set. Edges TransactionDetailEdges `json:"edges"` transaction_detail *uuid.UUID + selectValues sql.SelectValues } // TransactionDetailEdges holds the relations/edges for other nodes in the graph. @@ -44,12 +46,10 @@ type TransactionDetailEdges struct { // TransactionOrErr returns the Transaction value or an error if the edge // was not loaded in eager-loading, or loaded but was not found. func (e TransactionDetailEdges) TransactionOrErr() (*Transaction, error) { - if e.loadedTypes[0] { - if e.Transaction == nil { - // Edge was loaded but was not found. - return nil, &NotFoundError{label: transaction.Label} - } + if e.Transaction != nil { return e.Transaction, nil + } else if e.loadedTypes[0] { + return nil, &NotFoundError{label: transaction.Label} } return nil, &NotLoadedError{edge: "transaction"} } @@ -70,7 +70,7 @@ func (*TransactionDetail) scanValues(columns []string) ([]any, error) { case transactiondetail.ForeignKeys[0]: // transaction_detail values[i] = &sql.NullScanner{S: new(uuid.UUID)} default: - return nil, fmt.Errorf("unexpected column %q for type TransactionDetail", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -121,11 +121,19 @@ func (td *TransactionDetail) assignValues(columns []string, values []any) error td.transaction_detail = new(uuid.UUID) *td.transaction_detail = *value.S.(*uuid.UUID) } + default: + td.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the TransactionDetail. +// This includes values selected through modifiers, order, etc. +func (td *TransactionDetail) Value(name string) (ent.Value, error) { + return td.selectValues.Get(name) +} + // QueryTransaction queries the "transaction" edge of the TransactionDetail entity. func (td *TransactionDetail) QueryTransaction() *TransactionQuery { return NewTransactionDetailClient(td.config).QueryTransaction(td) diff --git a/ent/transactiondetail/transactiondetail.go b/ent/transactiondetail/transactiondetail.go index d4cb01d2..7929c68c 100644 --- a/ent/transactiondetail/transactiondetail.go +++ b/ent/transactiondetail/transactiondetail.go @@ -5,6 +5,8 @@ package transactiondetail import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -78,3 +80,45 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the TransactionDetail queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByAmount orders the results by the amount field. +func ByAmount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAmount, opts...).ToFunc() +} + +// ByTarget orders the results by the target field. +func ByTarget(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldTarget, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByTransactionField orders the results by transaction field. +func ByTransactionField(field string, opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newTransactionStep(), sql.OrderByField(field, opts...)) + } +} +func newTransactionStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(TransactionInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2O, true, TransactionTable, TransactionColumn), + ) +} diff --git a/ent/transactiondetail/where.go b/ent/transactiondetail/where.go index 836f2812..60d337fe 100644 --- a/ent/transactiondetail/where.go +++ b/ent/transactiondetail/where.go @@ -275,11 +275,7 @@ func HasTransaction() predicate.TransactionDetail { // HasTransactionWith applies the HasEdge predicate on the "transaction" edge with a given conditions (other predicates). func HasTransactionWith(preds ...predicate.Transaction) predicate.TransactionDetail { return predicate.TransactionDetail(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(TransactionInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2O, true, TransactionTable, TransactionColumn), - ) + step := newTransactionStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -290,32 +286,15 @@ func HasTransactionWith(preds ...predicate.Transaction) predicate.TransactionDet // And groups predicates with the AND operator between them. func And(predicates ...predicate.TransactionDetail) predicate.TransactionDetail { - return predicate.TransactionDetail(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.TransactionDetail(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.TransactionDetail) predicate.TransactionDetail { - return predicate.TransactionDetail(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.TransactionDetail(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.TransactionDetail) predicate.TransactionDetail { - return predicate.TransactionDetail(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.TransactionDetail(sql.NotPredicates(p)) } diff --git a/ent/transactiondetail_create.go b/ent/transactiondetail_create.go index ddefb40a..25cd01b6 100644 --- a/ent/transactiondetail_create.go +++ b/ent/transactiondetail_create.go @@ -119,7 +119,7 @@ func (tdc *TransactionDetailCreate) Mutation() *TransactionDetailMutation { // Save creates the TransactionDetail in the database. func (tdc *TransactionDetailCreate) Save(ctx context.Context) (*TransactionDetail, error) { tdc.defaults() - return withHooks[*TransactionDetail, TransactionDetailMutation](ctx, tdc.sqlSave, tdc.mutation, tdc.hooks) + return withHooks(ctx, tdc.sqlSave, tdc.mutation, tdc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -241,10 +241,7 @@ func (tdc *TransactionDetailCreate) createSpec() (*TransactionDetail, *sqlgraph. Columns: []string{transactiondetail.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -259,11 +256,15 @@ func (tdc *TransactionDetailCreate) createSpec() (*TransactionDetail, *sqlgraph. // TransactionDetailCreateBulk is the builder for creating many TransactionDetail entities in bulk. type TransactionDetailCreateBulk struct { config + err error builders []*TransactionDetailCreate } // Save creates the TransactionDetail entities in the database. func (tdcb *TransactionDetailCreateBulk) Save(ctx context.Context) ([]*TransactionDetail, error) { + if tdcb.err != nil { + return nil, tdcb.err + } specs := make([]*sqlgraph.CreateSpec, len(tdcb.builders)) nodes := make([]*TransactionDetail, len(tdcb.builders)) mutators := make([]Mutator, len(tdcb.builders)) @@ -280,8 +281,8 @@ func (tdcb *TransactionDetailCreateBulk) Save(ctx context.Context) ([]*Transacti return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, tdcb.builders[i+1].mutation) } else { diff --git a/ent/transactiondetail_delete.go b/ent/transactiondetail_delete.go index 60dfaa0c..733ff8aa 100644 --- a/ent/transactiondetail_delete.go +++ b/ent/transactiondetail_delete.go @@ -27,7 +27,7 @@ func (tdd *TransactionDetailDelete) Where(ps ...predicate.TransactionDetail) *Tr // Exec executes the deletion query and returns how many vertices were deleted. func (tdd *TransactionDetailDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, TransactionDetailMutation](ctx, tdd.sqlExec, tdd.mutation, tdd.hooks) + return withHooks(ctx, tdd.sqlExec, tdd.mutation, tdd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/transactiondetail_query.go b/ent/transactiondetail_query.go index 0d7714d3..e2dfe2a9 100644 --- a/ent/transactiondetail_query.go +++ b/ent/transactiondetail_query.go @@ -7,6 +7,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -20,7 +21,7 @@ import ( type TransactionDetailQuery struct { config ctx *QueryContext - order []OrderFunc + order []transactiondetail.OrderOption inters []Interceptor predicates []predicate.TransactionDetail withTransaction *TransactionQuery @@ -56,7 +57,7 @@ func (tdq *TransactionDetailQuery) Unique(unique bool) *TransactionDetailQuery { } // Order specifies how the records should be ordered. -func (tdq *TransactionDetailQuery) Order(o ...OrderFunc) *TransactionDetailQuery { +func (tdq *TransactionDetailQuery) Order(o ...transactiondetail.OrderOption) *TransactionDetailQuery { tdq.order = append(tdq.order, o...) return tdq } @@ -86,7 +87,7 @@ func (tdq *TransactionDetailQuery) QueryTransaction() *TransactionQuery { // First returns the first TransactionDetail entity from the query. // Returns a *NotFoundError when no TransactionDetail was found. func (tdq *TransactionDetailQuery) First(ctx context.Context) (*TransactionDetail, error) { - nodes, err := tdq.Limit(1).All(setContextOp(ctx, tdq.ctx, "First")) + nodes, err := tdq.Limit(1).All(setContextOp(ctx, tdq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -109,7 +110,7 @@ func (tdq *TransactionDetailQuery) FirstX(ctx context.Context) *TransactionDetai // Returns a *NotFoundError when no TransactionDetail ID was found. func (tdq *TransactionDetailQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tdq.Limit(1).IDs(setContextOp(ctx, tdq.ctx, "FirstID")); err != nil { + if ids, err = tdq.Limit(1).IDs(setContextOp(ctx, tdq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -132,7 +133,7 @@ func (tdq *TransactionDetailQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one TransactionDetail entity is found. // Returns a *NotFoundError when no TransactionDetail entities are found. func (tdq *TransactionDetailQuery) Only(ctx context.Context) (*TransactionDetail, error) { - nodes, err := tdq.Limit(2).All(setContextOp(ctx, tdq.ctx, "Only")) + nodes, err := tdq.Limit(2).All(setContextOp(ctx, tdq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -160,7 +161,7 @@ func (tdq *TransactionDetailQuery) OnlyX(ctx context.Context) *TransactionDetail // Returns a *NotFoundError when no entities are found. func (tdq *TransactionDetailQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = tdq.Limit(2).IDs(setContextOp(ctx, tdq.ctx, "OnlyID")); err != nil { + if ids, err = tdq.Limit(2).IDs(setContextOp(ctx, tdq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -185,7 +186,7 @@ func (tdq *TransactionDetailQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of TransactionDetails. func (tdq *TransactionDetailQuery) All(ctx context.Context) ([]*TransactionDetail, error) { - ctx = setContextOp(ctx, tdq.ctx, "All") + ctx = setContextOp(ctx, tdq.ctx, ent.OpQueryAll) if err := tdq.prepareQuery(ctx); err != nil { return nil, err } @@ -207,7 +208,7 @@ func (tdq *TransactionDetailQuery) IDs(ctx context.Context) (ids []uuid.UUID, er if tdq.ctx.Unique == nil && tdq.path != nil { tdq.Unique(true) } - ctx = setContextOp(ctx, tdq.ctx, "IDs") + ctx = setContextOp(ctx, tdq.ctx, ent.OpQueryIDs) if err = tdq.Select(transactiondetail.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -225,7 +226,7 @@ func (tdq *TransactionDetailQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (tdq *TransactionDetailQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, tdq.ctx, "Count") + ctx = setContextOp(ctx, tdq.ctx, ent.OpQueryCount) if err := tdq.prepareQuery(ctx); err != nil { return 0, err } @@ -243,7 +244,7 @@ func (tdq *TransactionDetailQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (tdq *TransactionDetailQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, tdq.ctx, "Exist") + ctx = setContextOp(ctx, tdq.ctx, ent.OpQueryExist) switch _, err := tdq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -272,7 +273,7 @@ func (tdq *TransactionDetailQuery) Clone() *TransactionDetailQuery { return &TransactionDetailQuery{ config: tdq.config, ctx: tdq.ctx.Clone(), - order: append([]OrderFunc{}, tdq.order...), + order: append([]transactiondetail.OrderOption{}, tdq.order...), inters: append([]Interceptor{}, tdq.inters...), predicates: append([]predicate.TransactionDetail{}, tdq.predicates...), withTransaction: tdq.withTransaction.Clone(), @@ -537,7 +538,7 @@ func (tdgb *TransactionDetailGroupBy) Aggregate(fns ...AggregateFunc) *Transacti // Scan applies the selector query and scans the result into the given value. func (tdgb *TransactionDetailGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, tdgb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, tdgb.build.ctx, ent.OpQueryGroupBy) if err := tdgb.build.prepareQuery(ctx); err != nil { return err } @@ -585,7 +586,7 @@ func (tds *TransactionDetailSelect) Aggregate(fns ...AggregateFunc) *Transaction // Scan applies the selector query and scans the result into the given value. func (tds *TransactionDetailSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, tds.ctx, "Select") + ctx = setContextOp(ctx, tds.ctx, ent.OpQuerySelect) if err := tds.prepareQuery(ctx); err != nil { return err } diff --git a/ent/transactiondetail_update.go b/ent/transactiondetail_update.go index 0583e60a..418fd1b9 100644 --- a/ent/transactiondetail_update.go +++ b/ent/transactiondetail_update.go @@ -118,7 +118,7 @@ func (tdu *TransactionDetailUpdate) ClearTransaction() *TransactionDetailUpdate // Save executes the query and returns the number of nodes affected by the update operation. func (tdu *TransactionDetailUpdate) Save(ctx context.Context) (int, error) { tdu.defaults() - return withHooks[int, TransactionDetailMutation](ctx, tdu.sqlSave, tdu.mutation, tdu.hooks) + return withHooks(ctx, tdu.sqlSave, tdu.mutation, tdu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -183,10 +183,7 @@ func (tdu *TransactionDetailUpdate) sqlSave(ctx context.Context) (n int, err err Columns: []string{transactiondetail.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -199,10 +196,7 @@ func (tdu *TransactionDetailUpdate) sqlSave(ctx context.Context) (n int, err err Columns: []string{transactiondetail.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -331,7 +325,7 @@ func (tduo *TransactionDetailUpdateOne) Select(field string, fields ...string) * // Save executes the query and returns the updated TransactionDetail entity. func (tduo *TransactionDetailUpdateOne) Save(ctx context.Context) (*TransactionDetail, error) { tduo.defaults() - return withHooks[*TransactionDetail, TransactionDetailMutation](ctx, tduo.sqlSave, tduo.mutation, tduo.hooks) + return withHooks(ctx, tduo.sqlSave, tduo.mutation, tduo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -413,10 +407,7 @@ func (tduo *TransactionDetailUpdateOne) sqlSave(ctx context.Context) (_node *Tra Columns: []string{transactiondetail.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -429,10 +420,7 @@ func (tduo *TransactionDetailUpdateOne) sqlSave(ctx context.Context) (_node *Tra Columns: []string{transactiondetail.TransactionColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: transaction.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(transaction.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/ent/user.go b/ent/user.go index 234e549b..ee2a0486 100644 --- a/ent/user.go +++ b/ent/user.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "github.com/google/uuid" "github.com/traPtitech/Jomon/ent/user" @@ -31,7 +32,8 @@ type User struct { DeletedAt *time.Time `json:"deleted_at,omitempty"` // Edges holds the relations/edges for other nodes in the graph. // The values are being populated by the UserQuery when eager-loading is set. - Edges UserEdges `json:"edges"` + Edges UserEdges `json:"edges"` + selectValues sql.SelectValues } // UserEdges holds the relations/edges for other nodes in the graph. @@ -132,7 +134,7 @@ func (*User) scanValues(columns []string) ([]any, error) { case user.FieldID: values[i] = new(uuid.UUID) default: - return nil, fmt.Errorf("unexpected column %q for type User", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -189,11 +191,19 @@ func (u *User) assignValues(columns []string, values []any) error { u.DeletedAt = new(time.Time) *u.DeletedAt = value.Time } + default: + u.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the User. +// This includes values selected through modifiers, order, etc. +func (u *User) Value(name string) (ent.Value, error) { + return u.selectValues.Get(name) +} + // QueryGroupUser queries the "group_user" edge of the User entity. func (u *User) QueryGroupUser() *GroupQuery { return NewUserClient(u.config).QueryGroupUser(u) diff --git a/ent/user/user.go b/ent/user/user.go index 1f18ab6f..43f58af7 100644 --- a/ent/user/user.go +++ b/ent/user/user.go @@ -5,6 +5,8 @@ package user import ( "time" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" "github.com/google/uuid" ) @@ -132,3 +134,188 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the User queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByDisplayName orders the results by the display_name field. +func ByDisplayName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDisplayName, opts...).ToFunc() +} + +// ByAdmin orders the results by the admin field. +func ByAdmin(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAdmin, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} + +// ByUpdatedAt orders the results by the updated_at field. +func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc() +} + +// ByDeletedAt orders the results by the deleted_at field. +func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDeletedAt, opts...).ToFunc() +} + +// ByGroupUserCount orders the results by group_user count. +func ByGroupUserCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newGroupUserStep(), opts...) + } +} + +// ByGroupUser orders the results by group_user terms. +func ByGroupUser(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupUserStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByGroupOwnerCount orders the results by group_owner count. +func ByGroupOwnerCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newGroupOwnerStep(), opts...) + } +} + +// ByGroupOwner orders the results by group_owner terms. +func ByGroupOwner(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newGroupOwnerStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByCommentCount orders the results by comment count. +func ByCommentCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newCommentStep(), opts...) + } +} + +// ByComment orders the results by comment terms. +func ByComment(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newCommentStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByRequestStatusCount orders the results by request_status count. +func ByRequestStatusCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newRequestStatusStep(), opts...) + } +} + +// ByRequestStatus orders the results by request_status terms. +func ByRequestStatus(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStatusStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByRequestCount orders the results by request count. +func ByRequestCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newRequestStep(), opts...) + } +} + +// ByRequest orders the results by request terms. +func ByRequest(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByFileCount orders the results by file count. +func ByFileCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newFileStep(), opts...) + } +} + +// ByFile orders the results by file terms. +func ByFile(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newFileStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} + +// ByRequestTargetCount orders the results by request_target count. +func ByRequestTargetCount(opts ...sql.OrderTermOption) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborsCount(s, newRequestTargetStep(), opts...) + } +} + +// ByRequestTarget orders the results by request_target terms. +func ByRequestTarget(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption { + return func(s *sql.Selector) { + sqlgraph.OrderByNeighborTerms(s, newRequestTargetStep(), append([]sql.OrderTerm{term}, terms...)...) + } +} +func newGroupUserStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupUserInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, GroupUserTable, GroupUserPrimaryKey...), + ) +} +func newGroupOwnerStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(GroupOwnerInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, GroupOwnerTable, GroupOwnerPrimaryKey...), + ) +} +func newCommentStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(CommentInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, CommentTable, CommentColumn), + ) +} +func newRequestStatusStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestStatusInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, RequestStatusTable, RequestStatusColumn), + ) +} +func newRequestStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, RequestTable, RequestColumn), + ) +} +func newFileStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(FileInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, FileTable, FileColumn), + ) +} +func newRequestTargetStep() *sqlgraph.Step { + return sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(RequestTargetInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, true, RequestTargetTable, RequestTargetColumn), + ) +} diff --git a/ent/user/where.go b/ent/user/where.go index bf322de3..97d1d1aa 100644 --- a/ent/user/where.go +++ b/ent/user/where.go @@ -370,11 +370,7 @@ func HasGroupUser() predicate.User { // HasGroupUserWith applies the HasEdge predicate on the "group_user" edge with a given conditions (other predicates). func HasGroupUserWith(preds ...predicate.Group) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupUserInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, GroupUserTable, GroupUserPrimaryKey...), - ) + step := newGroupUserStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -397,11 +393,7 @@ func HasGroupOwner() predicate.User { // HasGroupOwnerWith applies the HasEdge predicate on the "group_owner" edge with a given conditions (other predicates). func HasGroupOwnerWith(preds ...predicate.Group) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(GroupOwnerInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.M2M, true, GroupOwnerTable, GroupOwnerPrimaryKey...), - ) + step := newGroupOwnerStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -424,11 +416,7 @@ func HasComment() predicate.User { // HasCommentWith applies the HasEdge predicate on the "comment" edge with a given conditions (other predicates). func HasCommentWith(preds ...predicate.Comment) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(CommentInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, CommentTable, CommentColumn), - ) + step := newCommentStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -451,11 +439,7 @@ func HasRequestStatus() predicate.User { // HasRequestStatusWith applies the HasEdge predicate on the "request_status" edge with a given conditions (other predicates). func HasRequestStatusWith(preds ...predicate.RequestStatus) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestStatusInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, RequestStatusTable, RequestStatusColumn), - ) + step := newRequestStatusStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -478,11 +462,7 @@ func HasRequest() predicate.User { // HasRequestWith applies the HasEdge predicate on the "request" edge with a given conditions (other predicates). func HasRequestWith(preds ...predicate.Request) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, RequestTable, RequestColumn), - ) + step := newRequestStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -505,11 +485,7 @@ func HasFile() predicate.User { // HasFileWith applies the HasEdge predicate on the "file" edge with a given conditions (other predicates). func HasFileWith(preds ...predicate.File) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(FileInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, FileTable, FileColumn), - ) + step := newFileStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -532,11 +508,7 @@ func HasRequestTarget() predicate.User { // HasRequestTargetWith applies the HasEdge predicate on the "request_target" edge with a given conditions (other predicates). func HasRequestTargetWith(preds ...predicate.RequestTarget) predicate.User { return predicate.User(func(s *sql.Selector) { - step := sqlgraph.NewStep( - sqlgraph.From(Table, FieldID), - sqlgraph.To(RequestTargetInverseTable, FieldID), - sqlgraph.Edge(sqlgraph.O2M, true, RequestTargetTable, RequestTargetColumn), - ) + step := newRequestTargetStep() sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { for _, p := range preds { p(s) @@ -547,32 +519,15 @@ func HasRequestTargetWith(preds ...predicate.RequestTarget) predicate.User { // And groups predicates with the AND operator between them. func And(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for _, p := range predicates { - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.AndPredicates(predicates...)) } // Or groups predicates with the OR operator between them. func Or(predicates ...predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - s1 := s.Clone().SetP(nil) - for i, p := range predicates { - if i > 0 { - s1.Or() - } - p(s1) - } - s.Where(s1.P()) - }) + return predicate.User(sql.OrPredicates(predicates...)) } // Not applies the not operator on the given predicate. func Not(p predicate.User) predicate.User { - return predicate.User(func(s *sql.Selector) { - p(s.Not()) - }) + return predicate.User(sql.NotPredicates(p)) } diff --git a/ent/user_create.go b/ent/user_create.go index 68e1224f..9fbcd3ef 100644 --- a/ent/user_create.go +++ b/ent/user_create.go @@ -222,7 +222,7 @@ func (uc *UserCreate) Mutation() *UserMutation { // Save creates the User in the database. func (uc *UserCreate) Save(ctx context.Context) (*User, error) { uc.defaults() - return withHooks[*User, UserMutation](ctx, uc.sqlSave, uc.mutation, uc.hooks) + return withHooks(ctx, uc.sqlSave, uc.mutation, uc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -356,10 +356,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -375,10 +372,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -394,10 +388,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -413,10 +404,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -432,10 +420,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -451,10 +436,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -470,10 +452,7 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -487,11 +466,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) { // UserCreateBulk is the builder for creating many User entities in bulk. type UserCreateBulk struct { config + err error builders []*UserCreate } // Save creates the User entities in the database. func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { + if ucb.err != nil { + return nil, ucb.err + } specs := make([]*sqlgraph.CreateSpec, len(ucb.builders)) nodes := make([]*User, len(ucb.builders)) mutators := make([]Mutator, len(ucb.builders)) @@ -508,8 +491,8 @@ func (ucb *UserCreateBulk) Save(ctx context.Context) ([]*User, error) { return nil, err } builder.mutation = mutation - nodes[i], specs[i] = builder.createSpec() var err error + nodes[i], specs[i] = builder.createSpec() if i < len(mutators)-1 { _, err = mutators[i+1].Mutate(root, ucb.builders[i+1].mutation) } else { diff --git a/ent/user_delete.go b/ent/user_delete.go index 9e0915a1..56efc0a6 100644 --- a/ent/user_delete.go +++ b/ent/user_delete.go @@ -27,7 +27,7 @@ func (ud *UserDelete) Where(ps ...predicate.User) *UserDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (ud *UserDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, UserMutation](ctx, ud.sqlExec, ud.mutation, ud.hooks) + return withHooks(ctx, ud.sqlExec, ud.mutation, ud.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/user_query.go b/ent/user_query.go index 84d6ee6b..5e6b3fe6 100644 --- a/ent/user_query.go +++ b/ent/user_query.go @@ -8,6 +8,7 @@ import ( "fmt" "math" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql/sqlgraph" "entgo.io/ent/schema/field" @@ -26,7 +27,7 @@ import ( type UserQuery struct { config ctx *QueryContext - order []OrderFunc + order []user.OrderOption inters []Interceptor predicates []predicate.User withGroupUser *GroupQuery @@ -67,7 +68,7 @@ func (uq *UserQuery) Unique(unique bool) *UserQuery { } // Order specifies how the records should be ordered. -func (uq *UserQuery) Order(o ...OrderFunc) *UserQuery { +func (uq *UserQuery) Order(o ...user.OrderOption) *UserQuery { uq.order = append(uq.order, o...) return uq } @@ -229,7 +230,7 @@ func (uq *UserQuery) QueryRequestTarget() *RequestTargetQuery { // First returns the first User entity from the query. // Returns a *NotFoundError when no User was found. func (uq *UserQuery) First(ctx context.Context) (*User, error) { - nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, "First")) + nodes, err := uq.Limit(1).All(setContextOp(ctx, uq.ctx, ent.OpQueryFirst)) if err != nil { return nil, err } @@ -252,7 +253,7 @@ func (uq *UserQuery) FirstX(ctx context.Context) *User { // Returns a *NotFoundError when no User ID was found. func (uq *UserQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, "FirstID")); err != nil { + if ids, err = uq.Limit(1).IDs(setContextOp(ctx, uq.ctx, ent.OpQueryFirstID)); err != nil { return } if len(ids) == 0 { @@ -275,7 +276,7 @@ func (uq *UserQuery) FirstIDX(ctx context.Context) uuid.UUID { // Returns a *NotSingularError when more than one User entity is found. // Returns a *NotFoundError when no User entities are found. func (uq *UserQuery) Only(ctx context.Context) (*User, error) { - nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, "Only")) + nodes, err := uq.Limit(2).All(setContextOp(ctx, uq.ctx, ent.OpQueryOnly)) if err != nil { return nil, err } @@ -303,7 +304,7 @@ func (uq *UserQuery) OnlyX(ctx context.Context) *User { // Returns a *NotFoundError when no entities are found. func (uq *UserQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) { var ids []uuid.UUID - if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, "OnlyID")); err != nil { + if ids, err = uq.Limit(2).IDs(setContextOp(ctx, uq.ctx, ent.OpQueryOnlyID)); err != nil { return } switch len(ids) { @@ -328,7 +329,7 @@ func (uq *UserQuery) OnlyIDX(ctx context.Context) uuid.UUID { // All executes the query and returns a list of Users. func (uq *UserQuery) All(ctx context.Context) ([]*User, error) { - ctx = setContextOp(ctx, uq.ctx, "All") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryAll) if err := uq.prepareQuery(ctx); err != nil { return nil, err } @@ -350,7 +351,7 @@ func (uq *UserQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) { if uq.ctx.Unique == nil && uq.path != nil { uq.Unique(true) } - ctx = setContextOp(ctx, uq.ctx, "IDs") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryIDs) if err = uq.Select(user.FieldID).Scan(ctx, &ids); err != nil { return nil, err } @@ -368,7 +369,7 @@ func (uq *UserQuery) IDsX(ctx context.Context) []uuid.UUID { // Count returns the count of the given query. func (uq *UserQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, uq.ctx, "Count") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryCount) if err := uq.prepareQuery(ctx); err != nil { return 0, err } @@ -386,7 +387,7 @@ func (uq *UserQuery) CountX(ctx context.Context) int { // Exist returns true if the query has elements in the graph. func (uq *UserQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, uq.ctx, "Exist") + ctx = setContextOp(ctx, uq.ctx, ent.OpQueryExist) switch _, err := uq.FirstID(ctx); { case IsNotFound(err): return false, nil @@ -415,7 +416,7 @@ func (uq *UserQuery) Clone() *UserQuery { return &UserQuery{ config: uq.config, ctx: uq.ctx.Clone(), - order: append([]OrderFunc{}, uq.order...), + order: append([]user.OrderOption{}, uq.order...), inters: append([]Interceptor{}, uq.inters...), predicates: append([]predicate.User{}, uq.predicates...), withGroupUser: uq.withGroupUser.Clone(), @@ -800,7 +801,7 @@ func (uq *UserQuery) loadComment(ctx context.Context, query *CommentQuery, nodes } query.withFKs = true query.Where(predicate.Comment(func(s *sql.Selector) { - s.Where(sql.InValues(user.CommentColumn, fks...)) + s.Where(sql.InValues(s.C(user.CommentColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -813,7 +814,7 @@ func (uq *UserQuery) loadComment(ctx context.Context, query *CommentQuery, nodes } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "comment_user" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "comment_user" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -831,7 +832,7 @@ func (uq *UserQuery) loadRequestStatus(ctx context.Context, query *RequestStatus } query.withFKs = true query.Where(predicate.RequestStatus(func(s *sql.Selector) { - s.Where(sql.InValues(user.RequestStatusColumn, fks...)) + s.Where(sql.InValues(s.C(user.RequestStatusColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -844,7 +845,7 @@ func (uq *UserQuery) loadRequestStatus(ctx context.Context, query *RequestStatus } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_status_user" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_status_user" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -862,7 +863,7 @@ func (uq *UserQuery) loadRequest(ctx context.Context, query *RequestQuery, nodes } query.withFKs = true query.Where(predicate.Request(func(s *sql.Selector) { - s.Where(sql.InValues(user.RequestColumn, fks...)) + s.Where(sql.InValues(s.C(user.RequestColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -875,7 +876,7 @@ func (uq *UserQuery) loadRequest(ctx context.Context, query *RequestQuery, nodes } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_user" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_user" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -893,7 +894,7 @@ func (uq *UserQuery) loadFile(ctx context.Context, query *FileQuery, nodes []*Us } query.withFKs = true query.Where(predicate.File(func(s *sql.Selector) { - s.Where(sql.InValues(user.FileColumn, fks...)) + s.Where(sql.InValues(s.C(user.FileColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -906,7 +907,7 @@ func (uq *UserQuery) loadFile(ctx context.Context, query *FileQuery, nodes []*Us } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "file_user" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "file_user" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -924,7 +925,7 @@ func (uq *UserQuery) loadRequestTarget(ctx context.Context, query *RequestTarget } query.withFKs = true query.Where(predicate.RequestTarget(func(s *sql.Selector) { - s.Where(sql.InValues(user.RequestTargetColumn, fks...)) + s.Where(sql.InValues(s.C(user.RequestTargetColumn), fks...)) })) neighbors, err := query.All(ctx) if err != nil { @@ -937,7 +938,7 @@ func (uq *UserQuery) loadRequestTarget(ctx context.Context, query *RequestTarget } node, ok := nodeids[*fk] if !ok { - return fmt.Errorf(`unexpected foreign-key "request_target_user" returned %v for node %v`, *fk, n.ID) + return fmt.Errorf(`unexpected referenced foreign-key "request_target_user" returned %v for node %v`, *fk, n.ID) } assign(node, n) } @@ -1039,7 +1040,7 @@ func (ugb *UserGroupBy) Aggregate(fns ...AggregateFunc) *UserGroupBy { // Scan applies the selector query and scans the result into the given value. func (ugb *UserGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, ugb.build.ctx, "GroupBy") + ctx = setContextOp(ctx, ugb.build.ctx, ent.OpQueryGroupBy) if err := ugb.build.prepareQuery(ctx); err != nil { return err } @@ -1087,7 +1088,7 @@ func (us *UserSelect) Aggregate(fns ...AggregateFunc) *UserSelect { // Scan applies the selector query and scans the result into the given value. func (us *UserSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, us.ctx, "Select") + ctx = setContextOp(ctx, us.ctx, ent.OpQuerySelect) if err := us.prepareQuery(ctx); err != nil { return err } diff --git a/ent/user_update.go b/ent/user_update.go index 1d8fcf75..5da8cafb 100644 --- a/ent/user_update.go +++ b/ent/user_update.go @@ -41,12 +41,28 @@ func (uu *UserUpdate) SetName(s string) *UserUpdate { return uu } +// SetNillableName sets the "name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableName(s *string) *UserUpdate { + if s != nil { + uu.SetName(*s) + } + return uu +} + // SetDisplayName sets the "display_name" field. func (uu *UserUpdate) SetDisplayName(s string) *UserUpdate { uu.mutation.SetDisplayName(s) return uu } +// SetNillableDisplayName sets the "display_name" field if the given value is not nil. +func (uu *UserUpdate) SetNillableDisplayName(s *string) *UserUpdate { + if s != nil { + uu.SetDisplayName(*s) + } + return uu +} + // SetAdmin sets the "admin" field. func (uu *UserUpdate) SetAdmin(b bool) *UserUpdate { uu.mutation.SetAdmin(b) @@ -361,7 +377,7 @@ func (uu *UserUpdate) RemoveRequestTarget(r ...*RequestTarget) *UserUpdate { // Save executes the query and returns the number of nodes affected by the update operation. func (uu *UserUpdate) Save(ctx context.Context) (int, error) { uu.defaults() - return withHooks[int, UserMutation](ctx, uu.sqlSave, uu.mutation, uu.hooks) + return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -445,10 +461,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -461,10 +474,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -480,10 +490,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -499,10 +506,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -515,10 +519,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -534,10 +535,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -553,10 +551,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -569,10 +564,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -588,10 +580,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -607,10 +596,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -623,10 +609,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -642,10 +625,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -661,10 +641,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -677,10 +654,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -696,10 +670,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -715,10 +686,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -731,10 +699,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -750,10 +715,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -769,10 +731,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -785,10 +744,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -804,10 +760,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) { Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -841,12 +794,28 @@ func (uuo *UserUpdateOne) SetName(s string) *UserUpdateOne { return uuo } +// SetNillableName sets the "name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetName(*s) + } + return uuo +} + // SetDisplayName sets the "display_name" field. func (uuo *UserUpdateOne) SetDisplayName(s string) *UserUpdateOne { uuo.mutation.SetDisplayName(s) return uuo } +// SetNillableDisplayName sets the "display_name" field if the given value is not nil. +func (uuo *UserUpdateOne) SetNillableDisplayName(s *string) *UserUpdateOne { + if s != nil { + uuo.SetDisplayName(*s) + } + return uuo +} + // SetAdmin sets the "admin" field. func (uuo *UserUpdateOne) SetAdmin(b bool) *UserUpdateOne { uuo.mutation.SetAdmin(b) @@ -1174,7 +1143,7 @@ func (uuo *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne // Save executes the query and returns the updated User entity. func (uuo *UserUpdateOne) Save(ctx context.Context) (*User, error) { uuo.defaults() - return withHooks[*User, UserMutation](ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) + return withHooks(ctx, uuo.sqlSave, uuo.mutation, uuo.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -1275,10 +1244,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1291,10 +1257,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1310,10 +1273,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupUserPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1329,10 +1289,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1345,10 +1302,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1364,10 +1318,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: user.GroupOwnerPrimaryKey, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: group.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(group.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1383,10 +1334,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1399,10 +1347,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1418,10 +1363,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.CommentColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: comment.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(comment.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1437,10 +1379,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1453,10 +1392,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1472,10 +1408,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestStatusColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requeststatus.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requeststatus.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1491,10 +1424,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1507,10 +1437,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1526,10 +1453,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: request.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(request.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1545,10 +1469,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1561,10 +1482,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1580,10 +1498,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.FileColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: file.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(file.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1599,10 +1514,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } _spec.Edges.Clear = append(_spec.Edges.Clear, edge) @@ -1615,10 +1527,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { @@ -1634,10 +1543,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) Columns: []string{user.RequestTargetColumn}, Bidi: false, Target: &sqlgraph.EdgeTarget{ - IDSpec: &sqlgraph.FieldSpec{ - Type: field.TypeUUID, - Column: requesttarget.FieldID, - }, + IDSpec: sqlgraph.NewFieldSpec(requesttarget.FieldID, field.TypeUUID), }, } for _, k := range nodes { diff --git a/go.mod b/go.mod index 640e5cfb..66cc102e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/traPtitech/Jomon go 1.22.3 require ( - entgo.io/ent v0.13.1 + entgo.io/ent v0.14.0 github.com/go-sql-driver/mysql v1.8.1 github.com/golang/mock v1.6.0 github.com/google/uuid v1.6.0 @@ -11,6 +11,7 @@ require ( github.com/labstack/echo-contrib v0.17.1 github.com/labstack/echo/v4 v4.12.0 github.com/ncw/swift v1.0.53 + github.com/samber/lo v1.42.0 github.com/stretchr/testify v1.9.0 go.uber.org/zap v1.27.0 ) @@ -32,7 +33,6 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/samber/lo v1.42.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect github.com/zclconf/go-cty v1.11.0 // indirect diff --git a/go.sum b/go.sum index a93073bd..d1cc9f9a 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 h1:GwdJbXydHCYPedeeLt4x/lrlIISQ4JTH1mRWuE5ZZ14= ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43/go.mod h1:uj3pm+hUTVN/X5yfdBexHlZv+1Xu5u5ZbZx7+CDavNU= -entgo.io/ent v0.13.1 h1:uD8QwN1h6SNphdCCzmkMN3feSUzNnVvV/WIkHKMbzOE= -entgo.io/ent v0.13.1/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A= +entgo.io/ent v0.14.0 h1:EO3Z9aZ5bXJatJeGqu/EVdnNr6K4mRq3rWe5owt0MC4= +entgo.io/ent v0.14.0/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A= filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= @@ -87,8 +87,6 @@ golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+ golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM= golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= -golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -110,8 +108,6 @@ golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=