From 50e759667298569684eb2830f843acdc4116b233 Mon Sep 17 00:00:00 2001 From: surtur Date: Mon, 7 Aug 2023 21:31:46 +0200 Subject: [PATCH] chore(ent): re-run go generate --- ent/ent.go | 58 +++++++++++++----------------- ent/hibp.go | 14 ++++++-- ent/hibp/hibp.go | 82 ++++++++++++++++++++++++++++++++++++++++++ ent/hibp_create.go | 4 +-- ent/hibp_delete.go | 2 +- ent/hibp_query.go | 6 ++-- ent/hibp_update.go | 4 +-- ent/runtime/runtime.go | 4 +-- ent/setup.go | 14 ++++++-- ent/setup/setup.go | 14 ++++++++ ent/setup_create.go | 4 +-- ent/setup_delete.go | 2 +- ent/setup_query.go | 6 ++-- ent/setup_update.go | 4 +-- ent/user.go | 14 ++++++-- ent/user/user.go | 39 ++++++++++++++++++++ ent/user_create.go | 4 +-- ent/user_delete.go | 2 +- ent/user_query.go | 6 ++-- ent/user_update.go | 4 +-- 20 files changed, 222 insertions(+), 65 deletions(-) diff --git a/ent/ent.go b/ent/ent.go index 211f5d9..be95a75 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" @@ -62,35 +63,31 @@ 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{ - hibp.Table: hibp.ValidColumn, - setup.Table: setup.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 +) + +// columnChecker 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{ + hibp.Table: hibp.ValidColumn, + setup.Table: setup.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))) @@ -99,11 +96,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))) @@ -135,8 +131,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 "" } @@ -147,8 +142,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 "" } @@ -159,8 +153,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 "" } @@ -171,8 +164,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 "" } diff --git a/ent/hibp.go b/ent/hibp.go index b490379..fbf4501 100644 --- a/ent/hibp.go +++ b/ent/hibp.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "git.dotya.ml/mirre-mt/pcmt/ent/hibp" "github.com/google/uuid" @@ -47,7 +48,8 @@ type HIBP struct { // IsMalware holds the value of the "is_malware" field. IsMalware bool `json:"is_malware,omitempty"` // Always in PNG format - Logo string `json:"logo,omitempty"` + Logo string `json:"logo,omitempty"` + selectValues sql.SelectValues } // scanValues returns the types for scanning values from sql.Rows. @@ -68,7 +70,7 @@ func (*HIBP) scanValues(columns []string) ([]any, error) { case hibp.FieldID: values[i] = new(uuid.UUID) default: - return nil, fmt.Errorf("unexpected column %q for type HIBP", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -180,11 +182,19 @@ func (h *HIBP) assignValues(columns []string, values []any) error { } else if value.Valid { h.Logo = value.String } + default: + h.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the HIBP. +// This includes values selected through modifiers, order, etc. +func (h *HIBP) Value(name string) (ent.Value, error) { + return h.selectValues.Get(name) +} + // Update returns a builder for updating this HIBP. // Note that you need to call HIBP.Unwrap() before calling this method if this HIBP // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/ent/hibp/hibp.go b/ent/hibp/hibp.go index c58e576..49c19ac 100644 --- a/ent/hibp/hibp.go +++ b/ent/hibp/hibp.go @@ -2,6 +2,10 @@ package hibp +import ( + "entgo.io/ent/dialect/sql" +) + const ( // Label holds the string label denoting the hibp type in the database. Label = "hibp" @@ -85,3 +89,81 @@ var ( // DefaultIsMalware holds the default value on creation for the "is_malware" field. DefaultIsMalware bool ) + +// OrderOption defines the ordering options for the HIBP 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() +} + +// ByDomain orders the results by the domain field. +func ByDomain(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDomain, opts...).ToFunc() +} + +// ByBreachDate orders the results by the breach_date field. +func ByBreachDate(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldBreachDate, opts...).ToFunc() +} + +// ByAddedDate orders the results by the added_date field. +func ByAddedDate(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldAddedDate, opts...).ToFunc() +} + +// ByModifiedDate orders the results by the modified_date field. +func ByModifiedDate(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldModifiedDate, opts...).ToFunc() +} + +// ByPwnCount orders the results by the pwn_count field. +func ByPwnCount(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPwnCount, opts...).ToFunc() +} + +// ByDescription orders the results by the description field. +func ByDescription(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDescription, opts...).ToFunc() +} + +// ByIsVerified orders the results by the is_verified field. +func ByIsVerified(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIsVerified, opts...).ToFunc() +} + +// ByIsFabricated orders the results by the is_fabricated field. +func ByIsFabricated(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIsFabricated, opts...).ToFunc() +} + +// ByIsSensitive orders the results by the is_sensitive field. +func ByIsSensitive(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIsSensitive, opts...).ToFunc() +} + +// ByIsRetired orders the results by the is_retired field. +func ByIsRetired(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIsRetired, opts...).ToFunc() +} + +// ByIsSpamList orders the results by the is_spamList field. +func ByIsSpamList(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIsSpamList, opts...).ToFunc() +} + +// ByIsMalware orders the results by the is_malware field. +func ByIsMalware(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIsMalware, opts...).ToFunc() +} + +// ByLogo orders the results by the logo field. +func ByLogo(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLogo, opts...).ToFunc() +} diff --git a/ent/hibp_create.go b/ent/hibp_create.go index 44f6204..c95a443 100644 --- a/ent/hibp_create.go +++ b/ent/hibp_create.go @@ -173,7 +173,7 @@ func (hc *HIBPCreate) Mutation() *HIBPMutation { // Save creates the HIBP in the database. func (hc *HIBPCreate) Save(ctx context.Context) (*HIBP, error) { hc.defaults() - return withHooks[*HIBP, HIBPMutation](ctx, hc.sqlSave, hc.mutation, hc.hooks) + return withHooks(ctx, hc.sqlSave, hc.mutation, hc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -395,8 +395,8 @@ func (hcb *HIBPCreateBulk) Save(ctx context.Context) ([]*HIBP, 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, hcb.builders[i+1].mutation) } else { diff --git a/ent/hibp_delete.go b/ent/hibp_delete.go index f99a8cf..2ec16f0 100644 --- a/ent/hibp_delete.go +++ b/ent/hibp_delete.go @@ -27,7 +27,7 @@ func (hd *HIBPDelete) Where(ps ...predicate.HIBP) *HIBPDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (hd *HIBPDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, HIBPMutation](ctx, hd.sqlExec, hd.mutation, hd.hooks) + return withHooks(ctx, hd.sqlExec, hd.mutation, hd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/hibp_query.go b/ent/hibp_query.go index 45dfc88..8b151da 100644 --- a/ent/hibp_query.go +++ b/ent/hibp_query.go @@ -19,7 +19,7 @@ import ( type HIBPQuery struct { config ctx *QueryContext - order []OrderFunc + order []hibp.OrderOption inters []Interceptor predicates []predicate.HIBP // intermediate query (i.e. traversal path). @@ -53,7 +53,7 @@ func (hq *HIBPQuery) Unique(unique bool) *HIBPQuery { } // Order specifies how the records should be ordered. -func (hq *HIBPQuery) Order(o ...OrderFunc) *HIBPQuery { +func (hq *HIBPQuery) Order(o ...hibp.OrderOption) *HIBPQuery { hq.order = append(hq.order, o...) return hq } @@ -247,7 +247,7 @@ func (hq *HIBPQuery) Clone() *HIBPQuery { return &HIBPQuery{ config: hq.config, ctx: hq.ctx.Clone(), - order: append([]OrderFunc{}, hq.order...), + order: append([]hibp.OrderOption{}, hq.order...), inters: append([]Interceptor{}, hq.inters...), predicates: append([]predicate.HIBP{}, hq.predicates...), // clone intermediate query. diff --git a/ent/hibp_update.go b/ent/hibp_update.go index 8fbbbf0..85947c3 100644 --- a/ent/hibp_update.go +++ b/ent/hibp_update.go @@ -181,7 +181,7 @@ func (hu *HIBPUpdate) Mutation() *HIBPMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (hu *HIBPUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, HIBPMutation](ctx, hu.sqlSave, hu.mutation, hu.hooks) + return withHooks(ctx, hu.sqlSave, hu.mutation, hu.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -450,7 +450,7 @@ func (huo *HIBPUpdateOne) Select(field string, fields ...string) *HIBPUpdateOne // Save executes the query and returns the updated HIBP entity. func (huo *HIBPUpdateOne) Save(ctx context.Context) (*HIBP, error) { - return withHooks[*HIBP, HIBPMutation](ctx, huo.sqlSave, huo.mutation, huo.hooks) + return withHooks(ctx, huo.sqlSave, huo.mutation, huo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/ent/runtime/runtime.go b/ent/runtime/runtime.go index 76f5fa3..a577e99 100644 --- a/ent/runtime/runtime.go +++ b/ent/runtime/runtime.go @@ -5,6 +5,6 @@ package runtime // The schema-stitching logic is generated in git.dotya.ml/mirre-mt/pcmt/ent/runtime.go const ( - Version = "v0.11.10" // Version of ent codegen. - Sum = "h1:iqn32ybY5HRW3xSAyMNdNKpZhKgMf1Zunsej9yPKUI8=" // Sum of ent codegen. + Version = "v0.12.3" // Version of ent codegen. + Sum = "h1:N5lO2EOrHpCH5HYfiMOCHYbo+oh5M8GjT0/cx5x6xkk=" // Sum of ent codegen. ) diff --git a/ent/setup.go b/ent/setup.go index d8f0c7a..8566d84 100644 --- a/ent/setup.go +++ b/ent/setup.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "git.dotya.ml/mirre-mt/pcmt/ent/setup" "github.com/google/uuid" @@ -18,7 +19,8 @@ type Setup struct { // ID of the ent. ID uuid.UUID `json:"id,omitempty"` // SetUpAt holds the value of the "set_up_at" field. - SetUpAt time.Time `json:"set_up_at,omitempty"` + SetUpAt time.Time `json:"set_up_at,omitempty"` + selectValues sql.SelectValues } // scanValues returns the types for scanning values from sql.Rows. @@ -31,7 +33,7 @@ func (*Setup) scanValues(columns []string) ([]any, error) { case setup.FieldID: values[i] = new(uuid.UUID) default: - return nil, fmt.Errorf("unexpected column %q for type Setup", columns[i]) + values[i] = new(sql.UnknownType) } } return values, nil @@ -57,11 +59,19 @@ func (s *Setup) assignValues(columns []string, values []any) error { } else if value.Valid { s.SetUpAt = value.Time } + default: + s.selectValues.Set(columns[i], values[i]) } } return nil } +// Value returns the ent.Value that was dynamically selected and assigned to the Setup. +// This includes values selected through modifiers, order, etc. +func (s *Setup) Value(name string) (ent.Value, error) { + return s.selectValues.Get(name) +} + // Update returns a builder for updating this Setup. // Note that you need to call Setup.Unwrap() before calling this method if this Setup // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/ent/setup/setup.go b/ent/setup/setup.go index fe87ea4..8c78eae 100644 --- a/ent/setup/setup.go +++ b/ent/setup/setup.go @@ -5,6 +5,7 @@ package setup import ( "time" + "entgo.io/ent/dialect/sql" "github.com/google/uuid" ) @@ -41,3 +42,16 @@ var ( // DefaultID holds the default value on creation for the "id" field. DefaultID func() uuid.UUID ) + +// OrderOption defines the ordering options for the Setup 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() +} + +// BySetUpAt orders the results by the set_up_at field. +func BySetUpAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldSetUpAt, opts...).ToFunc() +} diff --git a/ent/setup_create.go b/ent/setup_create.go index 88a798a..4b7b5e7 100644 --- a/ent/setup_create.go +++ b/ent/setup_create.go @@ -57,7 +57,7 @@ func (sc *SetupCreate) Mutation() *SetupMutation { // Save creates the Setup in the database. func (sc *SetupCreate) Save(ctx context.Context) (*Setup, error) { sc.defaults() - return withHooks[*Setup, SetupMutation](ctx, sc.sqlSave, sc.mutation, sc.hooks) + return withHooks(ctx, sc.sqlSave, sc.mutation, sc.hooks) } // SaveX calls Save and panics if Save returns an error. @@ -165,8 +165,8 @@ func (scb *SetupCreateBulk) Save(ctx context.Context) ([]*Setup, 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, scb.builders[i+1].mutation) } else { diff --git a/ent/setup_delete.go b/ent/setup_delete.go index fa65483..dfd7813 100644 --- a/ent/setup_delete.go +++ b/ent/setup_delete.go @@ -27,7 +27,7 @@ func (sd *SetupDelete) Where(ps ...predicate.Setup) *SetupDelete { // Exec executes the deletion query and returns how many vertices were deleted. func (sd *SetupDelete) Exec(ctx context.Context) (int, error) { - return withHooks[int, SetupMutation](ctx, sd.sqlExec, sd.mutation, sd.hooks) + return withHooks(ctx, sd.sqlExec, sd.mutation, sd.hooks) } // ExecX is like Exec, but panics if an error occurs. diff --git a/ent/setup_query.go b/ent/setup_query.go index 7d5f2eb..9069c90 100644 --- a/ent/setup_query.go +++ b/ent/setup_query.go @@ -19,7 +19,7 @@ import ( type SetupQuery struct { config ctx *QueryContext - order []OrderFunc + order []setup.OrderOption inters []Interceptor predicates []predicate.Setup // intermediate query (i.e. traversal path). @@ -53,7 +53,7 @@ func (sq *SetupQuery) Unique(unique bool) *SetupQuery { } // Order specifies how the records should be ordered. -func (sq *SetupQuery) Order(o ...OrderFunc) *SetupQuery { +func (sq *SetupQuery) Order(o ...setup.OrderOption) *SetupQuery { sq.order = append(sq.order, o...) return sq } @@ -247,7 +247,7 @@ func (sq *SetupQuery) Clone() *SetupQuery { return &SetupQuery{ config: sq.config, ctx: sq.ctx.Clone(), - order: append([]OrderFunc{}, sq.order...), + order: append([]setup.OrderOption{}, sq.order...), inters: append([]Interceptor{}, sq.inters...), predicates: append([]predicate.Setup{}, sq.predicates...), // clone intermediate query. diff --git a/ent/setup_update.go b/ent/setup_update.go index e35c8a1..11c5817 100644 --- a/ent/setup_update.go +++ b/ent/setup_update.go @@ -34,7 +34,7 @@ func (su *SetupUpdate) Mutation() *SetupMutation { // Save executes the query and returns the number of nodes affected by the update operation. func (su *SetupUpdate) Save(ctx context.Context) (int, error) { - return withHooks[int, SetupMutation](ctx, su.sqlSave, su.mutation, su.hooks) + return withHooks(ctx, su.sqlSave, su.mutation, su.hooks) } // SaveX is like Save, but panics if an error occurs. @@ -108,7 +108,7 @@ func (suo *SetupUpdateOne) Select(field string, fields ...string) *SetupUpdateOn // Save executes the query and returns the updated Setup entity. func (suo *SetupUpdateOne) Save(ctx context.Context) (*Setup, error) { - return withHooks[*Setup, SetupMutation](ctx, suo.sqlSave, suo.mutation, suo.hooks) + return withHooks(ctx, suo.sqlSave, suo.mutation, suo.hooks) } // SaveX is like Save, but panics if an error occurs. diff --git a/ent/user.go b/ent/user.go index 108c0fb..103a6f8 100644 --- a/ent/user.go +++ b/ent/user.go @@ -7,6 +7,7 @@ import ( "strings" "time" + "entgo.io/ent" "entgo.io/ent/dialect/sql" "git.dotya.ml/mirre-mt/pcmt/ent/user" "github.com/google/uuid" @@ -30,7 +31,8 @@ type User struct { // CreatedAt holds the value of the "created_at" field. CreatedAt time.Time `json:"created_at,omitempty"` // UpdatedAt holds the value of the "updated_at" field. - UpdatedAt time.Time `json:"updated_at,omitempty"` + UpdatedAt time.Time `json:"updated_at,omitempty"` + selectValues sql.SelectValues } // scanValues returns the types for scanning values from sql.Rows. @@ -49,7 +51,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 @@ -111,11 +113,19 @@ func (u *User) assignValues(columns []string, values []any) error { } else if value.Valid { u.UpdatedAt = 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) +} + // Update returns a builder for updating this User. // Note that you need to call User.Unwrap() before calling this method if this User // was returned from a transaction, and the transaction was committed or rolled back. diff --git a/ent/user/user.go b/ent/user/user.go index 85bc6ac..4c4dcb6 100644 --- a/ent/user/user.go +++ b/ent/user/user.go @@ -5,6 +5,7 @@ package user import ( "time" + "entgo.io/ent/dialect/sql" "github.com/google/uuid" ) @@ -73,3 +74,41 @@ 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() +} + +// ByUsername orders the results by the username field. +func ByUsername(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldUsername, opts...).ToFunc() +} + +// ByEmail orders the results by the email field. +func ByEmail(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEmail, opts...).ToFunc() +} + +// ByIsAdmin orders the results by the is_admin field. +func ByIsAdmin(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIsAdmin, opts...).ToFunc() +} + +// ByIsActive orders the results by the is_active field. +func ByIsActive(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIsActive, 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() +} diff --git a/ent/user_create.go b/ent/user_create.go index 4e6c53b..cb06520 100644 --- a/ent/user_create.go +++ b/ent/user_create.go @@ -117,7 +117,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. @@ -294,8 +294,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 b419477..6c69220 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 7187b25..c86273e 100644 --- a/ent/user_query.go +++ b/ent/user_query.go @@ -19,7 +19,7 @@ import ( type UserQuery struct { config ctx *QueryContext - order []OrderFunc + order []user.OrderOption inters []Interceptor predicates []predicate.User // intermediate query (i.e. traversal path). @@ -53,7 +53,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 } @@ -247,7 +247,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...), // clone intermediate query. diff --git a/ent/user_update.go b/ent/user_update.go index 2411d0f..cdaedb3 100644 --- a/ent/user_update.go +++ b/ent/user_update.go @@ -88,7 +88,7 @@ func (uu *UserUpdate) Mutation() *UserMutation { // 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. @@ -264,7 +264,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.