From 740a7120ebbb2f6e0660af7165a63f22c47c6793 Mon Sep 17 00:00:00 2001 From: Yvan <8574526@qq,com> Date: Wed, 7 Jan 2026 11:03:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E4=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/data/ent/admin.go | 172 ----- internal/data/ent/admin/admin.go | 116 --- internal/data/ent/admin/where.go | 510 -------------- internal/data/ent/admin_create.go | 859 ----------------------- internal/data/ent/admin_delete.go | 88 --- internal/data/ent/admin_query.go | 527 -------------- internal/data/ent/admin_update.go | 382 ---------- internal/data/ent/client.go | 366 ---------- internal/data/ent/ent.go | 608 ---------------- internal/data/ent/enttest/enttest.go | 84 --- internal/data/ent/generate.go | 3 - internal/data/ent/hook/hook.go | 199 ------ internal/data/ent/migrate/migrate.go | 64 -- internal/data/ent/migrate/schema.go | 35 - internal/data/ent/mutation.go | 684 ------------------ internal/data/ent/predicate/predicate.go | 10 - internal/data/ent/runtime.go | 48 -- internal/data/ent/runtime/runtime.go | 10 - internal/data/ent/schema/admin.go | 27 - internal/data/ent/tx.go | 236 ------- 20 files changed, 5028 deletions(-) delete mode 100644 internal/data/ent/admin.go delete mode 100644 internal/data/ent/admin/admin.go delete mode 100644 internal/data/ent/admin/where.go delete mode 100644 internal/data/ent/admin_create.go delete mode 100644 internal/data/ent/admin_delete.go delete mode 100644 internal/data/ent/admin_query.go delete mode 100644 internal/data/ent/admin_update.go delete mode 100644 internal/data/ent/client.go delete mode 100644 internal/data/ent/ent.go delete mode 100644 internal/data/ent/enttest/enttest.go delete mode 100644 internal/data/ent/generate.go delete mode 100644 internal/data/ent/hook/hook.go delete mode 100644 internal/data/ent/migrate/migrate.go delete mode 100644 internal/data/ent/migrate/schema.go delete mode 100644 internal/data/ent/mutation.go delete mode 100644 internal/data/ent/predicate/predicate.go delete mode 100644 internal/data/ent/runtime.go delete mode 100644 internal/data/ent/runtime/runtime.go delete mode 100644 internal/data/ent/schema/admin.go delete mode 100644 internal/data/ent/tx.go diff --git a/internal/data/ent/admin.go b/internal/data/ent/admin.go deleted file mode 100644 index 3a98dc3..0000000 --- a/internal/data/ent/admin.go +++ /dev/null @@ -1,172 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "fmt" - "strings" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "kra/internal/data/ent/admin" -) - -// Admin is the model entity for the Admin schema. -type Admin struct { - config `json:"-"` - // ID of the ent. - ID int64 `json:"id,omitempty"` - // Name holds the value of the "name" field. - Name string `json:"name,omitempty"` - // Email holds the value of the "email" field. - Email string `json:"email,omitempty"` - // Avatar holds the value of the "avatar" field. - Avatar string `json:"avatar,omitempty"` - // Access holds the value of the "access" field. - Access string `json:"access,omitempty"` - // Password holds the value of the "password" field. - Password string `json:"password,omitempty"` - // CreateTime holds the value of the "create_time" field. - CreateTime time.Time `json:"create_time,omitempty"` - // UpdateTime holds the value of the "update_time" field. - UpdateTime time.Time `json:"update_time,omitempty"` - selectValues sql.SelectValues -} - -// scanValues returns the types for scanning values from sql.Rows. -func (*Admin) scanValues(columns []string) ([]any, error) { - values := make([]any, len(columns)) - for i := range columns { - switch columns[i] { - case admin.FieldID: - values[i] = new(sql.NullInt64) - case admin.FieldName, admin.FieldEmail, admin.FieldAvatar, admin.FieldAccess, admin.FieldPassword: - values[i] = new(sql.NullString) - case admin.FieldCreateTime, admin.FieldUpdateTime: - values[i] = new(sql.NullTime) - default: - values[i] = new(sql.UnknownType) - } - } - return values, nil -} - -// assignValues assigns the values that were returned from sql.Rows (after scanning) -// to the Admin fields. -func (_m *Admin) assignValues(columns []string, values []any) error { - if m, n := len(values), len(columns); m < n { - return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) - } - for i := range columns { - switch columns[i] { - case admin.FieldID: - value, ok := values[i].(*sql.NullInt64) - if !ok { - return fmt.Errorf("unexpected type %T for field id", value) - } - _m.ID = int64(value.Int64) - case admin.FieldName: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field name", values[i]) - } else if value.Valid { - _m.Name = value.String - } - case admin.FieldEmail: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field email", values[i]) - } else if value.Valid { - _m.Email = value.String - } - case admin.FieldAvatar: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field avatar", values[i]) - } else if value.Valid { - _m.Avatar = value.String - } - case admin.FieldAccess: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field access", values[i]) - } else if value.Valid { - _m.Access = value.String - } - case admin.FieldPassword: - if value, ok := values[i].(*sql.NullString); !ok { - return fmt.Errorf("unexpected type %T for field password", values[i]) - } else if value.Valid { - _m.Password = value.String - } - case admin.FieldCreateTime: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field create_time", values[i]) - } else if value.Valid { - _m.CreateTime = value.Time - } - case admin.FieldUpdateTime: - if value, ok := values[i].(*sql.NullTime); !ok { - return fmt.Errorf("unexpected type %T for field update_time", values[i]) - } else if value.Valid { - _m.UpdateTime = value.Time - } - default: - _m.selectValues.Set(columns[i], values[i]) - } - } - return nil -} - -// Value returns the ent.Value that was dynamically selected and assigned to the Admin. -// This includes values selected through modifiers, order, etc. -func (_m *Admin) Value(name string) (ent.Value, error) { - return _m.selectValues.Get(name) -} - -// Update returns a builder for updating this Admin. -// Note that you need to call Admin.Unwrap() before calling this method if this Admin -// was returned from a transaction, and the transaction was committed or rolled back. -func (_m *Admin) Update() *AdminUpdateOne { - return NewAdminClient(_m.config).UpdateOne(_m) -} - -// Unwrap unwraps the Admin entity that was returned from a transaction after it was closed, -// so that all future queries will be executed through the driver which created the transaction. -func (_m *Admin) Unwrap() *Admin { - _tx, ok := _m.config.driver.(*txDriver) - if !ok { - panic("ent: Admin is not a transactional entity") - } - _m.config.driver = _tx.drv - return _m -} - -// String implements the fmt.Stringer. -func (_m *Admin) String() string { - var builder strings.Builder - builder.WriteString("Admin(") - builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) - builder.WriteString("name=") - builder.WriteString(_m.Name) - builder.WriteString(", ") - builder.WriteString("email=") - builder.WriteString(_m.Email) - builder.WriteString(", ") - builder.WriteString("avatar=") - builder.WriteString(_m.Avatar) - builder.WriteString(", ") - builder.WriteString("access=") - builder.WriteString(_m.Access) - builder.WriteString(", ") - builder.WriteString("password=") - builder.WriteString(_m.Password) - builder.WriteString(", ") - builder.WriteString("create_time=") - builder.WriteString(_m.CreateTime.Format(time.ANSIC)) - builder.WriteString(", ") - builder.WriteString("update_time=") - builder.WriteString(_m.UpdateTime.Format(time.ANSIC)) - builder.WriteByte(')') - return builder.String() -} - -// Admins is a parsable slice of Admin. -type Admins []*Admin diff --git a/internal/data/ent/admin/admin.go b/internal/data/ent/admin/admin.go deleted file mode 100644 index 767c0ee..0000000 --- a/internal/data/ent/admin/admin.go +++ /dev/null @@ -1,116 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package admin - -import ( - "time" - - "entgo.io/ent/dialect/sql" -) - -const ( - // Label holds the string label denoting the admin type in the database. - Label = "admin" - // FieldID holds the string denoting the id field in the database. - FieldID = "id" - // FieldName holds the string denoting the name field in the database. - FieldName = "name" - // FieldEmail holds the string denoting the email field in the database. - FieldEmail = "email" - // FieldAvatar holds the string denoting the avatar field in the database. - FieldAvatar = "avatar" - // FieldAccess holds the string denoting the access field in the database. - FieldAccess = "access" - // FieldPassword holds the string denoting the password field in the database. - FieldPassword = "password" - // FieldCreateTime holds the string denoting the create_time field in the database. - FieldCreateTime = "create_time" - // FieldUpdateTime holds the string denoting the update_time field in the database. - FieldUpdateTime = "update_time" - // Table holds the table name of the admin in the database. - Table = "admins" -) - -// Columns holds all SQL columns for admin fields. -var Columns = []string{ - FieldID, - FieldName, - FieldEmail, - FieldAvatar, - FieldAccess, - FieldPassword, - FieldCreateTime, - FieldUpdateTime, -} - -// ValidColumn reports if the column name is valid (part of the table columns). -func ValidColumn(column string) bool { - for i := range Columns { - if column == Columns[i] { - return true - } - } - return false -} - -var ( - // DefaultName holds the default value on creation for the "name" field. - DefaultName string - // DefaultEmail holds the default value on creation for the "email" field. - DefaultEmail string - // DefaultAvatar holds the default value on creation for the "avatar" field. - DefaultAvatar string - // DefaultAccess holds the default value on creation for the "access" field. - DefaultAccess string - // DefaultPassword holds the default value on creation for the "password" field. - DefaultPassword string - // DefaultCreateTime holds the default value on creation for the "create_time" field. - DefaultCreateTime func() time.Time - // DefaultUpdateTime holds the default value on creation for the "update_time" field. - DefaultUpdateTime func() time.Time - // UpdateDefaultUpdateTime holds the default value on update for the "update_time" field. - UpdateDefaultUpdateTime func() time.Time -) - -// OrderOption defines the ordering options for the Admin 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() -} - -// ByEmail orders the results by the email field. -func ByEmail(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldEmail, opts...).ToFunc() -} - -// ByAvatar orders the results by the avatar field. -func ByAvatar(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldAvatar, opts...).ToFunc() -} - -// ByAccess orders the results by the access field. -func ByAccess(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldAccess, opts...).ToFunc() -} - -// ByPassword orders the results by the password field. -func ByPassword(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldPassword, opts...).ToFunc() -} - -// ByCreateTime orders the results by the create_time field. -func ByCreateTime(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldCreateTime, opts...).ToFunc() -} - -// ByUpdateTime orders the results by the update_time field. -func ByUpdateTime(opts ...sql.OrderTermOption) OrderOption { - return sql.OrderByField(FieldUpdateTime, opts...).ToFunc() -} diff --git a/internal/data/ent/admin/where.go b/internal/data/ent/admin/where.go deleted file mode 100644 index 42c98e2..0000000 --- a/internal/data/ent/admin/where.go +++ /dev/null @@ -1,510 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package admin - -import ( - "time" - - "entgo.io/ent/dialect/sql" - "kra/internal/data/ent/predicate" -) - -// ID filters vertices based on their ID field. -func ID(id int64) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldID, id)) -} - -// IDEQ applies the EQ predicate on the ID field. -func IDEQ(id int64) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldID, id)) -} - -// IDNEQ applies the NEQ predicate on the ID field. -func IDNEQ(id int64) predicate.Admin { - return predicate.Admin(sql.FieldNEQ(FieldID, id)) -} - -// IDIn applies the In predicate on the ID field. -func IDIn(ids ...int64) predicate.Admin { - return predicate.Admin(sql.FieldIn(FieldID, ids...)) -} - -// IDNotIn applies the NotIn predicate on the ID field. -func IDNotIn(ids ...int64) predicate.Admin { - return predicate.Admin(sql.FieldNotIn(FieldID, ids...)) -} - -// IDGT applies the GT predicate on the ID field. -func IDGT(id int64) predicate.Admin { - return predicate.Admin(sql.FieldGT(FieldID, id)) -} - -// IDGTE applies the GTE predicate on the ID field. -func IDGTE(id int64) predicate.Admin { - return predicate.Admin(sql.FieldGTE(FieldID, id)) -} - -// IDLT applies the LT predicate on the ID field. -func IDLT(id int64) predicate.Admin { - return predicate.Admin(sql.FieldLT(FieldID, id)) -} - -// IDLTE applies the LTE predicate on the ID field. -func IDLTE(id int64) predicate.Admin { - return predicate.Admin(sql.FieldLTE(FieldID, id)) -} - -// Name applies equality check predicate on the "name" field. It's identical to NameEQ. -func Name(v string) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldName, v)) -} - -// Email applies equality check predicate on the "email" field. It's identical to EmailEQ. -func Email(v string) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldEmail, v)) -} - -// Avatar applies equality check predicate on the "avatar" field. It's identical to AvatarEQ. -func Avatar(v string) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldAvatar, v)) -} - -// Access applies equality check predicate on the "access" field. It's identical to AccessEQ. -func Access(v string) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldAccess, v)) -} - -// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ. -func Password(v string) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldPassword, v)) -} - -// CreateTime applies equality check predicate on the "create_time" field. It's identical to CreateTimeEQ. -func CreateTime(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldCreateTime, v)) -} - -// UpdateTime applies equality check predicate on the "update_time" field. It's identical to UpdateTimeEQ. -func UpdateTime(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldUpdateTime, v)) -} - -// NameEQ applies the EQ predicate on the "name" field. -func NameEQ(v string) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldName, v)) -} - -// NameNEQ applies the NEQ predicate on the "name" field. -func NameNEQ(v string) predicate.Admin { - return predicate.Admin(sql.FieldNEQ(FieldName, v)) -} - -// NameIn applies the In predicate on the "name" field. -func NameIn(vs ...string) predicate.Admin { - return predicate.Admin(sql.FieldIn(FieldName, vs...)) -} - -// NameNotIn applies the NotIn predicate on the "name" field. -func NameNotIn(vs ...string) predicate.Admin { - return predicate.Admin(sql.FieldNotIn(FieldName, vs...)) -} - -// NameGT applies the GT predicate on the "name" field. -func NameGT(v string) predicate.Admin { - return predicate.Admin(sql.FieldGT(FieldName, v)) -} - -// NameGTE applies the GTE predicate on the "name" field. -func NameGTE(v string) predicate.Admin { - return predicate.Admin(sql.FieldGTE(FieldName, v)) -} - -// NameLT applies the LT predicate on the "name" field. -func NameLT(v string) predicate.Admin { - return predicate.Admin(sql.FieldLT(FieldName, v)) -} - -// NameLTE applies the LTE predicate on the "name" field. -func NameLTE(v string) predicate.Admin { - return predicate.Admin(sql.FieldLTE(FieldName, v)) -} - -// NameContains applies the Contains predicate on the "name" field. -func NameContains(v string) predicate.Admin { - return predicate.Admin(sql.FieldContains(FieldName, v)) -} - -// NameHasPrefix applies the HasPrefix predicate on the "name" field. -func NameHasPrefix(v string) predicate.Admin { - return predicate.Admin(sql.FieldHasPrefix(FieldName, v)) -} - -// NameHasSuffix applies the HasSuffix predicate on the "name" field. -func NameHasSuffix(v string) predicate.Admin { - return predicate.Admin(sql.FieldHasSuffix(FieldName, v)) -} - -// NameEqualFold applies the EqualFold predicate on the "name" field. -func NameEqualFold(v string) predicate.Admin { - return predicate.Admin(sql.FieldEqualFold(FieldName, v)) -} - -// NameContainsFold applies the ContainsFold predicate on the "name" field. -func NameContainsFold(v string) predicate.Admin { - return predicate.Admin(sql.FieldContainsFold(FieldName, v)) -} - -// EmailEQ applies the EQ predicate on the "email" field. -func EmailEQ(v string) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldEmail, v)) -} - -// EmailNEQ applies the NEQ predicate on the "email" field. -func EmailNEQ(v string) predicate.Admin { - return predicate.Admin(sql.FieldNEQ(FieldEmail, v)) -} - -// EmailIn applies the In predicate on the "email" field. -func EmailIn(vs ...string) predicate.Admin { - return predicate.Admin(sql.FieldIn(FieldEmail, vs...)) -} - -// EmailNotIn applies the NotIn predicate on the "email" field. -func EmailNotIn(vs ...string) predicate.Admin { - return predicate.Admin(sql.FieldNotIn(FieldEmail, vs...)) -} - -// EmailGT applies the GT predicate on the "email" field. -func EmailGT(v string) predicate.Admin { - return predicate.Admin(sql.FieldGT(FieldEmail, v)) -} - -// EmailGTE applies the GTE predicate on the "email" field. -func EmailGTE(v string) predicate.Admin { - return predicate.Admin(sql.FieldGTE(FieldEmail, v)) -} - -// EmailLT applies the LT predicate on the "email" field. -func EmailLT(v string) predicate.Admin { - return predicate.Admin(sql.FieldLT(FieldEmail, v)) -} - -// EmailLTE applies the LTE predicate on the "email" field. -func EmailLTE(v string) predicate.Admin { - return predicate.Admin(sql.FieldLTE(FieldEmail, v)) -} - -// EmailContains applies the Contains predicate on the "email" field. -func EmailContains(v string) predicate.Admin { - return predicate.Admin(sql.FieldContains(FieldEmail, v)) -} - -// EmailHasPrefix applies the HasPrefix predicate on the "email" field. -func EmailHasPrefix(v string) predicate.Admin { - return predicate.Admin(sql.FieldHasPrefix(FieldEmail, v)) -} - -// EmailHasSuffix applies the HasSuffix predicate on the "email" field. -func EmailHasSuffix(v string) predicate.Admin { - return predicate.Admin(sql.FieldHasSuffix(FieldEmail, v)) -} - -// EmailEqualFold applies the EqualFold predicate on the "email" field. -func EmailEqualFold(v string) predicate.Admin { - return predicate.Admin(sql.FieldEqualFold(FieldEmail, v)) -} - -// EmailContainsFold applies the ContainsFold predicate on the "email" field. -func EmailContainsFold(v string) predicate.Admin { - return predicate.Admin(sql.FieldContainsFold(FieldEmail, v)) -} - -// AvatarEQ applies the EQ predicate on the "avatar" field. -func AvatarEQ(v string) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldAvatar, v)) -} - -// AvatarNEQ applies the NEQ predicate on the "avatar" field. -func AvatarNEQ(v string) predicate.Admin { - return predicate.Admin(sql.FieldNEQ(FieldAvatar, v)) -} - -// AvatarIn applies the In predicate on the "avatar" field. -func AvatarIn(vs ...string) predicate.Admin { - return predicate.Admin(sql.FieldIn(FieldAvatar, vs...)) -} - -// AvatarNotIn applies the NotIn predicate on the "avatar" field. -func AvatarNotIn(vs ...string) predicate.Admin { - return predicate.Admin(sql.FieldNotIn(FieldAvatar, vs...)) -} - -// AvatarGT applies the GT predicate on the "avatar" field. -func AvatarGT(v string) predicate.Admin { - return predicate.Admin(sql.FieldGT(FieldAvatar, v)) -} - -// AvatarGTE applies the GTE predicate on the "avatar" field. -func AvatarGTE(v string) predicate.Admin { - return predicate.Admin(sql.FieldGTE(FieldAvatar, v)) -} - -// AvatarLT applies the LT predicate on the "avatar" field. -func AvatarLT(v string) predicate.Admin { - return predicate.Admin(sql.FieldLT(FieldAvatar, v)) -} - -// AvatarLTE applies the LTE predicate on the "avatar" field. -func AvatarLTE(v string) predicate.Admin { - return predicate.Admin(sql.FieldLTE(FieldAvatar, v)) -} - -// AvatarContains applies the Contains predicate on the "avatar" field. -func AvatarContains(v string) predicate.Admin { - return predicate.Admin(sql.FieldContains(FieldAvatar, v)) -} - -// AvatarHasPrefix applies the HasPrefix predicate on the "avatar" field. -func AvatarHasPrefix(v string) predicate.Admin { - return predicate.Admin(sql.FieldHasPrefix(FieldAvatar, v)) -} - -// AvatarHasSuffix applies the HasSuffix predicate on the "avatar" field. -func AvatarHasSuffix(v string) predicate.Admin { - return predicate.Admin(sql.FieldHasSuffix(FieldAvatar, v)) -} - -// AvatarEqualFold applies the EqualFold predicate on the "avatar" field. -func AvatarEqualFold(v string) predicate.Admin { - return predicate.Admin(sql.FieldEqualFold(FieldAvatar, v)) -} - -// AvatarContainsFold applies the ContainsFold predicate on the "avatar" field. -func AvatarContainsFold(v string) predicate.Admin { - return predicate.Admin(sql.FieldContainsFold(FieldAvatar, v)) -} - -// AccessEQ applies the EQ predicate on the "access" field. -func AccessEQ(v string) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldAccess, v)) -} - -// AccessNEQ applies the NEQ predicate on the "access" field. -func AccessNEQ(v string) predicate.Admin { - return predicate.Admin(sql.FieldNEQ(FieldAccess, v)) -} - -// AccessIn applies the In predicate on the "access" field. -func AccessIn(vs ...string) predicate.Admin { - return predicate.Admin(sql.FieldIn(FieldAccess, vs...)) -} - -// AccessNotIn applies the NotIn predicate on the "access" field. -func AccessNotIn(vs ...string) predicate.Admin { - return predicate.Admin(sql.FieldNotIn(FieldAccess, vs...)) -} - -// AccessGT applies the GT predicate on the "access" field. -func AccessGT(v string) predicate.Admin { - return predicate.Admin(sql.FieldGT(FieldAccess, v)) -} - -// AccessGTE applies the GTE predicate on the "access" field. -func AccessGTE(v string) predicate.Admin { - return predicate.Admin(sql.FieldGTE(FieldAccess, v)) -} - -// AccessLT applies the LT predicate on the "access" field. -func AccessLT(v string) predicate.Admin { - return predicate.Admin(sql.FieldLT(FieldAccess, v)) -} - -// AccessLTE applies the LTE predicate on the "access" field. -func AccessLTE(v string) predicate.Admin { - return predicate.Admin(sql.FieldLTE(FieldAccess, v)) -} - -// AccessContains applies the Contains predicate on the "access" field. -func AccessContains(v string) predicate.Admin { - return predicate.Admin(sql.FieldContains(FieldAccess, v)) -} - -// AccessHasPrefix applies the HasPrefix predicate on the "access" field. -func AccessHasPrefix(v string) predicate.Admin { - return predicate.Admin(sql.FieldHasPrefix(FieldAccess, v)) -} - -// AccessHasSuffix applies the HasSuffix predicate on the "access" field. -func AccessHasSuffix(v string) predicate.Admin { - return predicate.Admin(sql.FieldHasSuffix(FieldAccess, v)) -} - -// AccessEqualFold applies the EqualFold predicate on the "access" field. -func AccessEqualFold(v string) predicate.Admin { - return predicate.Admin(sql.FieldEqualFold(FieldAccess, v)) -} - -// AccessContainsFold applies the ContainsFold predicate on the "access" field. -func AccessContainsFold(v string) predicate.Admin { - return predicate.Admin(sql.FieldContainsFold(FieldAccess, v)) -} - -// PasswordEQ applies the EQ predicate on the "password" field. -func PasswordEQ(v string) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldPassword, v)) -} - -// PasswordNEQ applies the NEQ predicate on the "password" field. -func PasswordNEQ(v string) predicate.Admin { - return predicate.Admin(sql.FieldNEQ(FieldPassword, v)) -} - -// PasswordIn applies the In predicate on the "password" field. -func PasswordIn(vs ...string) predicate.Admin { - return predicate.Admin(sql.FieldIn(FieldPassword, vs...)) -} - -// PasswordNotIn applies the NotIn predicate on the "password" field. -func PasswordNotIn(vs ...string) predicate.Admin { - return predicate.Admin(sql.FieldNotIn(FieldPassword, vs...)) -} - -// PasswordGT applies the GT predicate on the "password" field. -func PasswordGT(v string) predicate.Admin { - return predicate.Admin(sql.FieldGT(FieldPassword, v)) -} - -// PasswordGTE applies the GTE predicate on the "password" field. -func PasswordGTE(v string) predicate.Admin { - return predicate.Admin(sql.FieldGTE(FieldPassword, v)) -} - -// PasswordLT applies the LT predicate on the "password" field. -func PasswordLT(v string) predicate.Admin { - return predicate.Admin(sql.FieldLT(FieldPassword, v)) -} - -// PasswordLTE applies the LTE predicate on the "password" field. -func PasswordLTE(v string) predicate.Admin { - return predicate.Admin(sql.FieldLTE(FieldPassword, v)) -} - -// PasswordContains applies the Contains predicate on the "password" field. -func PasswordContains(v string) predicate.Admin { - return predicate.Admin(sql.FieldContains(FieldPassword, v)) -} - -// PasswordHasPrefix applies the HasPrefix predicate on the "password" field. -func PasswordHasPrefix(v string) predicate.Admin { - return predicate.Admin(sql.FieldHasPrefix(FieldPassword, v)) -} - -// PasswordHasSuffix applies the HasSuffix predicate on the "password" field. -func PasswordHasSuffix(v string) predicate.Admin { - return predicate.Admin(sql.FieldHasSuffix(FieldPassword, v)) -} - -// PasswordEqualFold applies the EqualFold predicate on the "password" field. -func PasswordEqualFold(v string) predicate.Admin { - return predicate.Admin(sql.FieldEqualFold(FieldPassword, v)) -} - -// PasswordContainsFold applies the ContainsFold predicate on the "password" field. -func PasswordContainsFold(v string) predicate.Admin { - return predicate.Admin(sql.FieldContainsFold(FieldPassword, v)) -} - -// CreateTimeEQ applies the EQ predicate on the "create_time" field. -func CreateTimeEQ(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldCreateTime, v)) -} - -// CreateTimeNEQ applies the NEQ predicate on the "create_time" field. -func CreateTimeNEQ(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldNEQ(FieldCreateTime, v)) -} - -// CreateTimeIn applies the In predicate on the "create_time" field. -func CreateTimeIn(vs ...time.Time) predicate.Admin { - return predicate.Admin(sql.FieldIn(FieldCreateTime, vs...)) -} - -// CreateTimeNotIn applies the NotIn predicate on the "create_time" field. -func CreateTimeNotIn(vs ...time.Time) predicate.Admin { - return predicate.Admin(sql.FieldNotIn(FieldCreateTime, vs...)) -} - -// CreateTimeGT applies the GT predicate on the "create_time" field. -func CreateTimeGT(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldGT(FieldCreateTime, v)) -} - -// CreateTimeGTE applies the GTE predicate on the "create_time" field. -func CreateTimeGTE(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldGTE(FieldCreateTime, v)) -} - -// CreateTimeLT applies the LT predicate on the "create_time" field. -func CreateTimeLT(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldLT(FieldCreateTime, v)) -} - -// CreateTimeLTE applies the LTE predicate on the "create_time" field. -func CreateTimeLTE(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldLTE(FieldCreateTime, v)) -} - -// UpdateTimeEQ applies the EQ predicate on the "update_time" field. -func UpdateTimeEQ(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldEQ(FieldUpdateTime, v)) -} - -// UpdateTimeNEQ applies the NEQ predicate on the "update_time" field. -func UpdateTimeNEQ(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldNEQ(FieldUpdateTime, v)) -} - -// UpdateTimeIn applies the In predicate on the "update_time" field. -func UpdateTimeIn(vs ...time.Time) predicate.Admin { - return predicate.Admin(sql.FieldIn(FieldUpdateTime, vs...)) -} - -// UpdateTimeNotIn applies the NotIn predicate on the "update_time" field. -func UpdateTimeNotIn(vs ...time.Time) predicate.Admin { - return predicate.Admin(sql.FieldNotIn(FieldUpdateTime, vs...)) -} - -// UpdateTimeGT applies the GT predicate on the "update_time" field. -func UpdateTimeGT(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldGT(FieldUpdateTime, v)) -} - -// UpdateTimeGTE applies the GTE predicate on the "update_time" field. -func UpdateTimeGTE(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldGTE(FieldUpdateTime, v)) -} - -// UpdateTimeLT applies the LT predicate on the "update_time" field. -func UpdateTimeLT(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldLT(FieldUpdateTime, v)) -} - -// UpdateTimeLTE applies the LTE predicate on the "update_time" field. -func UpdateTimeLTE(v time.Time) predicate.Admin { - return predicate.Admin(sql.FieldLTE(FieldUpdateTime, v)) -} - -// And groups predicates with the AND operator between them. -func And(predicates ...predicate.Admin) predicate.Admin { - return predicate.Admin(sql.AndPredicates(predicates...)) -} - -// Or groups predicates with the OR operator between them. -func Or(predicates ...predicate.Admin) predicate.Admin { - return predicate.Admin(sql.OrPredicates(predicates...)) -} - -// Not applies the not operator on the given predicate. -func Not(p predicate.Admin) predicate.Admin { - return predicate.Admin(sql.NotPredicates(p)) -} diff --git a/internal/data/ent/admin_create.go b/internal/data/ent/admin_create.go deleted file mode 100644 index a9fc110..0000000 --- a/internal/data/ent/admin_create.go +++ /dev/null @@ -1,859 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "kra/internal/data/ent/admin" -) - -// AdminCreate is the builder for creating a Admin entity. -type AdminCreate struct { - config - mutation *AdminMutation - hooks []Hook - conflict []sql.ConflictOption -} - -// SetName sets the "name" field. -func (_c *AdminCreate) SetName(v string) *AdminCreate { - _c.mutation.SetName(v) - return _c -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_c *AdminCreate) SetNillableName(v *string) *AdminCreate { - if v != nil { - _c.SetName(*v) - } - return _c -} - -// SetEmail sets the "email" field. -func (_c *AdminCreate) SetEmail(v string) *AdminCreate { - _c.mutation.SetEmail(v) - return _c -} - -// SetNillableEmail sets the "email" field if the given value is not nil. -func (_c *AdminCreate) SetNillableEmail(v *string) *AdminCreate { - if v != nil { - _c.SetEmail(*v) - } - return _c -} - -// SetAvatar sets the "avatar" field. -func (_c *AdminCreate) SetAvatar(v string) *AdminCreate { - _c.mutation.SetAvatar(v) - return _c -} - -// SetNillableAvatar sets the "avatar" field if the given value is not nil. -func (_c *AdminCreate) SetNillableAvatar(v *string) *AdminCreate { - if v != nil { - _c.SetAvatar(*v) - } - return _c -} - -// SetAccess sets the "access" field. -func (_c *AdminCreate) SetAccess(v string) *AdminCreate { - _c.mutation.SetAccess(v) - return _c -} - -// SetNillableAccess sets the "access" field if the given value is not nil. -func (_c *AdminCreate) SetNillableAccess(v *string) *AdminCreate { - if v != nil { - _c.SetAccess(*v) - } - return _c -} - -// SetPassword sets the "password" field. -func (_c *AdminCreate) SetPassword(v string) *AdminCreate { - _c.mutation.SetPassword(v) - return _c -} - -// SetNillablePassword sets the "password" field if the given value is not nil. -func (_c *AdminCreate) SetNillablePassword(v *string) *AdminCreate { - if v != nil { - _c.SetPassword(*v) - } - return _c -} - -// SetCreateTime sets the "create_time" field. -func (_c *AdminCreate) SetCreateTime(v time.Time) *AdminCreate { - _c.mutation.SetCreateTime(v) - return _c -} - -// SetNillableCreateTime sets the "create_time" field if the given value is not nil. -func (_c *AdminCreate) SetNillableCreateTime(v *time.Time) *AdminCreate { - if v != nil { - _c.SetCreateTime(*v) - } - return _c -} - -// SetUpdateTime sets the "update_time" field. -func (_c *AdminCreate) SetUpdateTime(v time.Time) *AdminCreate { - _c.mutation.SetUpdateTime(v) - return _c -} - -// SetNillableUpdateTime sets the "update_time" field if the given value is not nil. -func (_c *AdminCreate) SetNillableUpdateTime(v *time.Time) *AdminCreate { - if v != nil { - _c.SetUpdateTime(*v) - } - return _c -} - -// SetID sets the "id" field. -func (_c *AdminCreate) SetID(v int64) *AdminCreate { - _c.mutation.SetID(v) - return _c -} - -// Mutation returns the AdminMutation object of the builder. -func (_c *AdminCreate) Mutation() *AdminMutation { - return _c.mutation -} - -// Save creates the Admin in the database. -func (_c *AdminCreate) Save(ctx context.Context) (*Admin, error) { - _c.defaults() - return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) -} - -// SaveX calls Save and panics if Save returns an error. -func (_c *AdminCreate) SaveX(ctx context.Context) *Admin { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *AdminCreate) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *AdminCreate) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_c *AdminCreate) defaults() { - if _, ok := _c.mutation.Name(); !ok { - v := admin.DefaultName - _c.mutation.SetName(v) - } - if _, ok := _c.mutation.Email(); !ok { - v := admin.DefaultEmail - _c.mutation.SetEmail(v) - } - if _, ok := _c.mutation.Avatar(); !ok { - v := admin.DefaultAvatar - _c.mutation.SetAvatar(v) - } - if _, ok := _c.mutation.Access(); !ok { - v := admin.DefaultAccess - _c.mutation.SetAccess(v) - } - if _, ok := _c.mutation.Password(); !ok { - v := admin.DefaultPassword - _c.mutation.SetPassword(v) - } - if _, ok := _c.mutation.CreateTime(); !ok { - v := admin.DefaultCreateTime() - _c.mutation.SetCreateTime(v) - } - if _, ok := _c.mutation.UpdateTime(); !ok { - v := admin.DefaultUpdateTime() - _c.mutation.SetUpdateTime(v) - } -} - -// check runs all checks and user-defined validators on the builder. -func (_c *AdminCreate) check() error { - if _, ok := _c.mutation.Name(); !ok { - return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "Admin.name"`)} - } - if _, ok := _c.mutation.Email(); !ok { - return &ValidationError{Name: "email", err: errors.New(`ent: missing required field "Admin.email"`)} - } - if _, ok := _c.mutation.Avatar(); !ok { - return &ValidationError{Name: "avatar", err: errors.New(`ent: missing required field "Admin.avatar"`)} - } - if _, ok := _c.mutation.Access(); !ok { - return &ValidationError{Name: "access", err: errors.New(`ent: missing required field "Admin.access"`)} - } - if _, ok := _c.mutation.Password(); !ok { - return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Admin.password"`)} - } - if _, ok := _c.mutation.CreateTime(); !ok { - return &ValidationError{Name: "create_time", err: errors.New(`ent: missing required field "Admin.create_time"`)} - } - if _, ok := _c.mutation.UpdateTime(); !ok { - return &ValidationError{Name: "update_time", err: errors.New(`ent: missing required field "Admin.update_time"`)} - } - return nil -} - -func (_c *AdminCreate) sqlSave(ctx context.Context) (*Admin, error) { - if err := _c.check(); err != nil { - return nil, err - } - _node, _spec := _c.createSpec() - if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - if _spec.ID.Value != _node.ID { - id := _spec.ID.Value.(int64) - _node.ID = int64(id) - } - _c.mutation.id = &_node.ID - _c.mutation.done = true - return _node, nil -} - -func (_c *AdminCreate) createSpec() (*Admin, *sqlgraph.CreateSpec) { - var ( - _node = &Admin{config: _c.config} - _spec = sqlgraph.NewCreateSpec(admin.Table, sqlgraph.NewFieldSpec(admin.FieldID, field.TypeInt64)) - ) - _spec.OnConflict = _c.conflict - if id, ok := _c.mutation.ID(); ok { - _node.ID = id - _spec.ID.Value = id - } - if value, ok := _c.mutation.Name(); ok { - _spec.SetField(admin.FieldName, field.TypeString, value) - _node.Name = value - } - if value, ok := _c.mutation.Email(); ok { - _spec.SetField(admin.FieldEmail, field.TypeString, value) - _node.Email = value - } - if value, ok := _c.mutation.Avatar(); ok { - _spec.SetField(admin.FieldAvatar, field.TypeString, value) - _node.Avatar = value - } - if value, ok := _c.mutation.Access(); ok { - _spec.SetField(admin.FieldAccess, field.TypeString, value) - _node.Access = value - } - if value, ok := _c.mutation.Password(); ok { - _spec.SetField(admin.FieldPassword, field.TypeString, value) - _node.Password = value - } - if value, ok := _c.mutation.CreateTime(); ok { - _spec.SetField(admin.FieldCreateTime, field.TypeTime, value) - _node.CreateTime = value - } - if value, ok := _c.mutation.UpdateTime(); ok { - _spec.SetField(admin.FieldUpdateTime, field.TypeTime, value) - _node.UpdateTime = value - } - return _node, _spec -} - -// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause -// of the `INSERT` statement. For example: -// -// client.Admin.Create(). -// SetName(v). -// OnConflict( -// // Update the row with the new values -// // the was proposed for insertion. -// sql.ResolveWithNewValues(), -// ). -// // Override some of the fields with custom -// // update values. -// Update(func(u *ent.AdminUpsert) { -// SetName(v+v). -// }). -// Exec(ctx) -func (_c *AdminCreate) OnConflict(opts ...sql.ConflictOption) *AdminUpsertOne { - _c.conflict = opts - return &AdminUpsertOne{ - create: _c, - } -} - -// OnConflictColumns calls `OnConflict` and configures the columns -// as conflict target. Using this option is equivalent to using: -// -// client.Admin.Create(). -// OnConflict(sql.ConflictColumns(columns...)). -// Exec(ctx) -func (_c *AdminCreate) OnConflictColumns(columns ...string) *AdminUpsertOne { - _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) - return &AdminUpsertOne{ - create: _c, - } -} - -type ( - // AdminUpsertOne is the builder for "upsert"-ing - // one Admin node. - AdminUpsertOne struct { - create *AdminCreate - } - - // AdminUpsert is the "OnConflict" setter. - AdminUpsert struct { - *sql.UpdateSet - } -) - -// SetName sets the "name" field. -func (u *AdminUpsert) SetName(v string) *AdminUpsert { - u.Set(admin.FieldName, v) - return u -} - -// UpdateName sets the "name" field to the value that was provided on create. -func (u *AdminUpsert) UpdateName() *AdminUpsert { - u.SetExcluded(admin.FieldName) - return u -} - -// SetEmail sets the "email" field. -func (u *AdminUpsert) SetEmail(v string) *AdminUpsert { - u.Set(admin.FieldEmail, v) - return u -} - -// UpdateEmail sets the "email" field to the value that was provided on create. -func (u *AdminUpsert) UpdateEmail() *AdminUpsert { - u.SetExcluded(admin.FieldEmail) - return u -} - -// SetAvatar sets the "avatar" field. -func (u *AdminUpsert) SetAvatar(v string) *AdminUpsert { - u.Set(admin.FieldAvatar, v) - return u -} - -// UpdateAvatar sets the "avatar" field to the value that was provided on create. -func (u *AdminUpsert) UpdateAvatar() *AdminUpsert { - u.SetExcluded(admin.FieldAvatar) - return u -} - -// SetAccess sets the "access" field. -func (u *AdminUpsert) SetAccess(v string) *AdminUpsert { - u.Set(admin.FieldAccess, v) - return u -} - -// UpdateAccess sets the "access" field to the value that was provided on create. -func (u *AdminUpsert) UpdateAccess() *AdminUpsert { - u.SetExcluded(admin.FieldAccess) - return u -} - -// SetPassword sets the "password" field. -func (u *AdminUpsert) SetPassword(v string) *AdminUpsert { - u.Set(admin.FieldPassword, v) - return u -} - -// UpdatePassword sets the "password" field to the value that was provided on create. -func (u *AdminUpsert) UpdatePassword() *AdminUpsert { - u.SetExcluded(admin.FieldPassword) - return u -} - -// SetUpdateTime sets the "update_time" field. -func (u *AdminUpsert) SetUpdateTime(v time.Time) *AdminUpsert { - u.Set(admin.FieldUpdateTime, v) - return u -} - -// UpdateUpdateTime sets the "update_time" field to the value that was provided on create. -func (u *AdminUpsert) UpdateUpdateTime() *AdminUpsert { - u.SetExcluded(admin.FieldUpdateTime) - return u -} - -// UpdateNewValues updates the mutable fields using the new values that were set on create except the ID field. -// Using this option is equivalent to using: -// -// client.Admin.Create(). -// OnConflict( -// sql.ResolveWithNewValues(), -// sql.ResolveWith(func(u *sql.UpdateSet) { -// u.SetIgnore(admin.FieldID) -// }), -// ). -// Exec(ctx) -func (u *AdminUpsertOne) UpdateNewValues() *AdminUpsertOne { - u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) - u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { - if _, exists := u.create.mutation.ID(); exists { - s.SetIgnore(admin.FieldID) - } - if _, exists := u.create.mutation.CreateTime(); exists { - s.SetIgnore(admin.FieldCreateTime) - } - })) - return u -} - -// Ignore sets each column to itself in case of conflict. -// Using this option is equivalent to using: -// -// client.Admin.Create(). -// OnConflict(sql.ResolveWithIgnore()). -// Exec(ctx) -func (u *AdminUpsertOne) Ignore() *AdminUpsertOne { - u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) - return u -} - -// DoNothing configures the conflict_action to `DO NOTHING`. -// Supported only by SQLite and PostgreSQL. -func (u *AdminUpsertOne) DoNothing() *AdminUpsertOne { - u.create.conflict = append(u.create.conflict, sql.DoNothing()) - return u -} - -// Update allows overriding fields `UPDATE` values. See the AdminCreate.OnConflict -// documentation for more info. -func (u *AdminUpsertOne) Update(set func(*AdminUpsert)) *AdminUpsertOne { - u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { - set(&AdminUpsert{UpdateSet: update}) - })) - return u -} - -// SetName sets the "name" field. -func (u *AdminUpsertOne) SetName(v string) *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.SetName(v) - }) -} - -// UpdateName sets the "name" field to the value that was provided on create. -func (u *AdminUpsertOne) UpdateName() *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.UpdateName() - }) -} - -// SetEmail sets the "email" field. -func (u *AdminUpsertOne) SetEmail(v string) *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.SetEmail(v) - }) -} - -// UpdateEmail sets the "email" field to the value that was provided on create. -func (u *AdminUpsertOne) UpdateEmail() *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.UpdateEmail() - }) -} - -// SetAvatar sets the "avatar" field. -func (u *AdminUpsertOne) SetAvatar(v string) *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.SetAvatar(v) - }) -} - -// UpdateAvatar sets the "avatar" field to the value that was provided on create. -func (u *AdminUpsertOne) UpdateAvatar() *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.UpdateAvatar() - }) -} - -// SetAccess sets the "access" field. -func (u *AdminUpsertOne) SetAccess(v string) *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.SetAccess(v) - }) -} - -// UpdateAccess sets the "access" field to the value that was provided on create. -func (u *AdminUpsertOne) UpdateAccess() *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.UpdateAccess() - }) -} - -// SetPassword sets the "password" field. -func (u *AdminUpsertOne) SetPassword(v string) *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.SetPassword(v) - }) -} - -// UpdatePassword sets the "password" field to the value that was provided on create. -func (u *AdminUpsertOne) UpdatePassword() *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.UpdatePassword() - }) -} - -// SetUpdateTime sets the "update_time" field. -func (u *AdminUpsertOne) SetUpdateTime(v time.Time) *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.SetUpdateTime(v) - }) -} - -// UpdateUpdateTime sets the "update_time" field to the value that was provided on create. -func (u *AdminUpsertOne) UpdateUpdateTime() *AdminUpsertOne { - return u.Update(func(s *AdminUpsert) { - s.UpdateUpdateTime() - }) -} - -// Exec executes the query. -func (u *AdminUpsertOne) Exec(ctx context.Context) error { - if len(u.create.conflict) == 0 { - return errors.New("ent: missing options for AdminCreate.OnConflict") - } - return u.create.Exec(ctx) -} - -// ExecX is like Exec, but panics if an error occurs. -func (u *AdminUpsertOne) ExecX(ctx context.Context) { - if err := u.create.Exec(ctx); err != nil { - panic(err) - } -} - -// Exec executes the UPSERT query and returns the inserted/updated ID. -func (u *AdminUpsertOne) ID(ctx context.Context) (id int64, err error) { - node, err := u.create.Save(ctx) - if err != nil { - return id, err - } - return node.ID, nil -} - -// IDX is like ID, but panics if an error occurs. -func (u *AdminUpsertOne) IDX(ctx context.Context) int64 { - id, err := u.ID(ctx) - if err != nil { - panic(err) - } - return id -} - -// AdminCreateBulk is the builder for creating many Admin entities in bulk. -type AdminCreateBulk struct { - config - err error - builders []*AdminCreate - conflict []sql.ConflictOption -} - -// Save creates the Admin entities in the database. -func (_c *AdminCreateBulk) Save(ctx context.Context) ([]*Admin, error) { - if _c.err != nil { - return nil, _c.err - } - specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) - nodes := make([]*Admin, len(_c.builders)) - mutators := make([]Mutator, len(_c.builders)) - for i := range _c.builders { - func(i int, root context.Context) { - builder := _c.builders[i] - builder.defaults() - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutation, ok := m.(*AdminMutation) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - if err := builder.check(); err != nil { - return nil, err - } - builder.mutation = mutation - var err error - nodes[i], specs[i] = builder.createSpec() - if i < len(mutators)-1 { - _, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation) - } else { - spec := &sqlgraph.BatchCreateSpec{Nodes: specs} - spec.OnConflict = _c.conflict - // Invoke the actual operation on the latest mutation in the chain. - if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil { - if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - } - } - if err != nil { - return nil, err - } - mutation.id = &nodes[i].ID - if specs[i].ID.Value != nil && nodes[i].ID == 0 { - id := specs[i].ID.Value.(int64) - nodes[i].ID = int64(id) - } - mutation.done = true - return nodes[i], nil - }) - for i := len(builder.hooks) - 1; i >= 0; i-- { - mut = builder.hooks[i](mut) - } - mutators[i] = mut - }(i, ctx) - } - if len(mutators) > 0 { - if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil { - return nil, err - } - } - return nodes, nil -} - -// SaveX is like Save, but panics if an error occurs. -func (_c *AdminCreateBulk) SaveX(ctx context.Context) []*Admin { - v, err := _c.Save(ctx) - if err != nil { - panic(err) - } - return v -} - -// Exec executes the query. -func (_c *AdminCreateBulk) Exec(ctx context.Context) error { - _, err := _c.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_c *AdminCreateBulk) ExecX(ctx context.Context) { - if err := _c.Exec(ctx); err != nil { - panic(err) - } -} - -// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause -// of the `INSERT` statement. For example: -// -// client.Admin.CreateBulk(builders...). -// OnConflict( -// // Update the row with the new values -// // the was proposed for insertion. -// sql.ResolveWithNewValues(), -// ). -// // Override some of the fields with custom -// // update values. -// Update(func(u *ent.AdminUpsert) { -// SetName(v+v). -// }). -// Exec(ctx) -func (_c *AdminCreateBulk) OnConflict(opts ...sql.ConflictOption) *AdminUpsertBulk { - _c.conflict = opts - return &AdminUpsertBulk{ - create: _c, - } -} - -// OnConflictColumns calls `OnConflict` and configures the columns -// as conflict target. Using this option is equivalent to using: -// -// client.Admin.Create(). -// OnConflict(sql.ConflictColumns(columns...)). -// Exec(ctx) -func (_c *AdminCreateBulk) OnConflictColumns(columns ...string) *AdminUpsertBulk { - _c.conflict = append(_c.conflict, sql.ConflictColumns(columns...)) - return &AdminUpsertBulk{ - create: _c, - } -} - -// AdminUpsertBulk is the builder for "upsert"-ing -// a bulk of Admin nodes. -type AdminUpsertBulk struct { - create *AdminCreateBulk -} - -// UpdateNewValues updates the mutable fields using the new values that -// were set on create. Using this option is equivalent to using: -// -// client.Admin.Create(). -// OnConflict( -// sql.ResolveWithNewValues(), -// sql.ResolveWith(func(u *sql.UpdateSet) { -// u.SetIgnore(admin.FieldID) -// }), -// ). -// Exec(ctx) -func (u *AdminUpsertBulk) UpdateNewValues() *AdminUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues()) - u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(s *sql.UpdateSet) { - for _, b := range u.create.builders { - if _, exists := b.mutation.ID(); exists { - s.SetIgnore(admin.FieldID) - } - if _, exists := b.mutation.CreateTime(); exists { - s.SetIgnore(admin.FieldCreateTime) - } - } - })) - return u -} - -// Ignore sets each column to itself in case of conflict. -// Using this option is equivalent to using: -// -// client.Admin.Create(). -// OnConflict(sql.ResolveWithIgnore()). -// Exec(ctx) -func (u *AdminUpsertBulk) Ignore() *AdminUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore()) - return u -} - -// DoNothing configures the conflict_action to `DO NOTHING`. -// Supported only by SQLite and PostgreSQL. -func (u *AdminUpsertBulk) DoNothing() *AdminUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.DoNothing()) - return u -} - -// Update allows overriding fields `UPDATE` values. See the AdminCreateBulk.OnConflict -// documentation for more info. -func (u *AdminUpsertBulk) Update(set func(*AdminUpsert)) *AdminUpsertBulk { - u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) { - set(&AdminUpsert{UpdateSet: update}) - })) - return u -} - -// SetName sets the "name" field. -func (u *AdminUpsertBulk) SetName(v string) *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.SetName(v) - }) -} - -// UpdateName sets the "name" field to the value that was provided on create. -func (u *AdminUpsertBulk) UpdateName() *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.UpdateName() - }) -} - -// SetEmail sets the "email" field. -func (u *AdminUpsertBulk) SetEmail(v string) *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.SetEmail(v) - }) -} - -// UpdateEmail sets the "email" field to the value that was provided on create. -func (u *AdminUpsertBulk) UpdateEmail() *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.UpdateEmail() - }) -} - -// SetAvatar sets the "avatar" field. -func (u *AdminUpsertBulk) SetAvatar(v string) *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.SetAvatar(v) - }) -} - -// UpdateAvatar sets the "avatar" field to the value that was provided on create. -func (u *AdminUpsertBulk) UpdateAvatar() *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.UpdateAvatar() - }) -} - -// SetAccess sets the "access" field. -func (u *AdminUpsertBulk) SetAccess(v string) *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.SetAccess(v) - }) -} - -// UpdateAccess sets the "access" field to the value that was provided on create. -func (u *AdminUpsertBulk) UpdateAccess() *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.UpdateAccess() - }) -} - -// SetPassword sets the "password" field. -func (u *AdminUpsertBulk) SetPassword(v string) *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.SetPassword(v) - }) -} - -// UpdatePassword sets the "password" field to the value that was provided on create. -func (u *AdminUpsertBulk) UpdatePassword() *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.UpdatePassword() - }) -} - -// SetUpdateTime sets the "update_time" field. -func (u *AdminUpsertBulk) SetUpdateTime(v time.Time) *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.SetUpdateTime(v) - }) -} - -// UpdateUpdateTime sets the "update_time" field to the value that was provided on create. -func (u *AdminUpsertBulk) UpdateUpdateTime() *AdminUpsertBulk { - return u.Update(func(s *AdminUpsert) { - s.UpdateUpdateTime() - }) -} - -// Exec executes the query. -func (u *AdminUpsertBulk) Exec(ctx context.Context) error { - if u.create.err != nil { - return u.create.err - } - for i, b := range u.create.builders { - if len(b.conflict) != 0 { - return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AdminCreateBulk instead", i) - } - } - if len(u.create.conflict) == 0 { - return errors.New("ent: missing options for AdminCreateBulk.OnConflict") - } - return u.create.Exec(ctx) -} - -// ExecX is like Exec, but panics if an error occurs. -func (u *AdminUpsertBulk) ExecX(ctx context.Context) { - if err := u.create.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/internal/data/ent/admin_delete.go b/internal/data/ent/admin_delete.go deleted file mode 100644 index 881482f..0000000 --- a/internal/data/ent/admin_delete.go +++ /dev/null @@ -1,88 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "kra/internal/data/ent/admin" - "kra/internal/data/ent/predicate" -) - -// AdminDelete is the builder for deleting a Admin entity. -type AdminDelete struct { - config - hooks []Hook - mutation *AdminMutation -} - -// Where appends a list predicates to the AdminDelete builder. -func (_d *AdminDelete) Where(ps ...predicate.Admin) *AdminDelete { - _d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query and returns how many vertices were deleted. -func (_d *AdminDelete) Exec(ctx context.Context) (int, error) { - return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *AdminDelete) ExecX(ctx context.Context) int { - n, err := _d.Exec(ctx) - if err != nil { - panic(err) - } - return n -} - -func (_d *AdminDelete) sqlExec(ctx context.Context) (int, error) { - _spec := sqlgraph.NewDeleteSpec(admin.Table, sqlgraph.NewFieldSpec(admin.FieldID, field.TypeInt64)) - if ps := _d.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) - if err != nil && sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - _d.mutation.done = true - return affected, err -} - -// AdminDeleteOne is the builder for deleting a single Admin entity. -type AdminDeleteOne struct { - _d *AdminDelete -} - -// Where appends a list predicates to the AdminDelete builder. -func (_d *AdminDeleteOne) Where(ps ...predicate.Admin) *AdminDeleteOne { - _d._d.mutation.Where(ps...) - return _d -} - -// Exec executes the deletion query. -func (_d *AdminDeleteOne) Exec(ctx context.Context) error { - n, err := _d._d.Exec(ctx) - switch { - case err != nil: - return err - case n == 0: - return &NotFoundError{admin.Label} - default: - return nil - } -} - -// ExecX is like Exec, but panics if an error occurs. -func (_d *AdminDeleteOne) ExecX(ctx context.Context) { - if err := _d.Exec(ctx); err != nil { - panic(err) - } -} diff --git a/internal/data/ent/admin_query.go b/internal/data/ent/admin_query.go deleted file mode 100644 index 4192c01..0000000 --- a/internal/data/ent/admin_query.go +++ /dev/null @@ -1,527 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "fmt" - "math" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "kra/internal/data/ent/admin" - "kra/internal/data/ent/predicate" -) - -// AdminQuery is the builder for querying Admin entities. -type AdminQuery struct { - config - ctx *QueryContext - order []admin.OrderOption - inters []Interceptor - predicates []predicate.Admin - // intermediate query (i.e. traversal path). - sql *sql.Selector - path func(context.Context) (*sql.Selector, error) -} - -// Where adds a new predicate for the AdminQuery builder. -func (_q *AdminQuery) Where(ps ...predicate.Admin) *AdminQuery { - _q.predicates = append(_q.predicates, ps...) - return _q -} - -// Limit the number of records to be returned by this query. -func (_q *AdminQuery) Limit(limit int) *AdminQuery { - _q.ctx.Limit = &limit - return _q -} - -// Offset to start from. -func (_q *AdminQuery) Offset(offset int) *AdminQuery { - _q.ctx.Offset = &offset - return _q -} - -// Unique configures the query builder to filter duplicate records on query. -// By default, unique is set to true, and can be disabled using this method. -func (_q *AdminQuery) Unique(unique bool) *AdminQuery { - _q.ctx.Unique = &unique - return _q -} - -// Order specifies how the records should be ordered. -func (_q *AdminQuery) Order(o ...admin.OrderOption) *AdminQuery { - _q.order = append(_q.order, o...) - return _q -} - -// First returns the first Admin entity from the query. -// Returns a *NotFoundError when no Admin was found. -func (_q *AdminQuery) First(ctx context.Context) (*Admin, error) { - nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) - if err != nil { - return nil, err - } - if len(nodes) == 0 { - return nil, &NotFoundError{admin.Label} - } - return nodes[0], nil -} - -// FirstX is like First, but panics if an error occurs. -func (_q *AdminQuery) FirstX(ctx context.Context) *Admin { - node, err := _q.First(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return node -} - -// FirstID returns the first Admin ID from the query. -// Returns a *NotFoundError when no Admin ID was found. -func (_q *AdminQuery) FirstID(ctx context.Context) (id int64, err error) { - var ids []int64 - if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { - return - } - if len(ids) == 0 { - err = &NotFoundError{admin.Label} - return - } - return ids[0], nil -} - -// FirstIDX is like FirstID, but panics if an error occurs. -func (_q *AdminQuery) FirstIDX(ctx context.Context) int64 { - id, err := _q.FirstID(ctx) - if err != nil && !IsNotFound(err) { - panic(err) - } - return id -} - -// Only returns a single Admin entity found by the query, ensuring it only returns one. -// Returns a *NotSingularError when more than one Admin entity is found. -// Returns a *NotFoundError when no Admin entities are found. -func (_q *AdminQuery) Only(ctx context.Context) (*Admin, error) { - nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) - if err != nil { - return nil, err - } - switch len(nodes) { - case 1: - return nodes[0], nil - case 0: - return nil, &NotFoundError{admin.Label} - default: - return nil, &NotSingularError{admin.Label} - } -} - -// OnlyX is like Only, but panics if an error occurs. -func (_q *AdminQuery) OnlyX(ctx context.Context) *Admin { - node, err := _q.Only(ctx) - if err != nil { - panic(err) - } - return node -} - -// OnlyID is like Only, but returns the only Admin ID in the query. -// Returns a *NotSingularError when more than one Admin ID is found. -// Returns a *NotFoundError when no entities are found. -func (_q *AdminQuery) OnlyID(ctx context.Context) (id int64, err error) { - var ids []int64 - if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { - return - } - switch len(ids) { - case 1: - id = ids[0] - case 0: - err = &NotFoundError{admin.Label} - default: - err = &NotSingularError{admin.Label} - } - return -} - -// OnlyIDX is like OnlyID, but panics if an error occurs. -func (_q *AdminQuery) OnlyIDX(ctx context.Context) int64 { - id, err := _q.OnlyID(ctx) - if err != nil { - panic(err) - } - return id -} - -// All executes the query and returns a list of Admins. -func (_q *AdminQuery) All(ctx context.Context) ([]*Admin, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) - if err := _q.prepareQuery(ctx); err != nil { - return nil, err - } - qr := querierAll[[]*Admin, *AdminQuery]() - return withInterceptors[[]*Admin](ctx, _q, qr, _q.inters) -} - -// AllX is like All, but panics if an error occurs. -func (_q *AdminQuery) AllX(ctx context.Context) []*Admin { - nodes, err := _q.All(ctx) - if err != nil { - panic(err) - } - return nodes -} - -// IDs executes the query and returns a list of Admin IDs. -func (_q *AdminQuery) IDs(ctx context.Context) (ids []int64, err error) { - if _q.ctx.Unique == nil && _q.path != nil { - _q.Unique(true) - } - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) - if err = _q.Select(admin.FieldID).Scan(ctx, &ids); err != nil { - return nil, err - } - return ids, nil -} - -// IDsX is like IDs, but panics if an error occurs. -func (_q *AdminQuery) IDsX(ctx context.Context) []int64 { - ids, err := _q.IDs(ctx) - if err != nil { - panic(err) - } - return ids -} - -// Count returns the count of the given query. -func (_q *AdminQuery) Count(ctx context.Context) (int, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) - if err := _q.prepareQuery(ctx); err != nil { - return 0, err - } - return withInterceptors[int](ctx, _q, querierCount[*AdminQuery](), _q.inters) -} - -// CountX is like Count, but panics if an error occurs. -func (_q *AdminQuery) CountX(ctx context.Context) int { - count, err := _q.Count(ctx) - if err != nil { - panic(err) - } - return count -} - -// Exist returns true if the query has elements in the graph. -func (_q *AdminQuery) Exist(ctx context.Context) (bool, error) { - ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) - switch _, err := _q.FirstID(ctx); { - case IsNotFound(err): - return false, nil - case err != nil: - return false, fmt.Errorf("ent: check existence: %w", err) - default: - return true, nil - } -} - -// ExistX is like Exist, but panics if an error occurs. -func (_q *AdminQuery) ExistX(ctx context.Context) bool { - exist, err := _q.Exist(ctx) - if err != nil { - panic(err) - } - return exist -} - -// Clone returns a duplicate of the AdminQuery builder, including all associated steps. It can be -// used to prepare common query builders and use them differently after the clone is made. -func (_q *AdminQuery) Clone() *AdminQuery { - if _q == nil { - return nil - } - return &AdminQuery{ - config: _q.config, - ctx: _q.ctx.Clone(), - order: append([]admin.OrderOption{}, _q.order...), - inters: append([]Interceptor{}, _q.inters...), - predicates: append([]predicate.Admin{}, _q.predicates...), - // clone intermediate query. - sql: _q.sql.Clone(), - path: _q.path, - } -} - -// GroupBy is used to group vertices by one or more fields/columns. -// It is often used with aggregate functions, like: count, max, mean, min, sum. -// -// Example: -// -// var v []struct { -// Name string `json:"name,omitempty"` -// Count int `json:"count,omitempty"` -// } -// -// client.Admin.Query(). -// GroupBy(admin.FieldName). -// Aggregate(ent.Count()). -// Scan(ctx, &v) -func (_q *AdminQuery) GroupBy(field string, fields ...string) *AdminGroupBy { - _q.ctx.Fields = append([]string{field}, fields...) - grbuild := &AdminGroupBy{build: _q} - grbuild.flds = &_q.ctx.Fields - grbuild.label = admin.Label - grbuild.scan = grbuild.Scan - return grbuild -} - -// Select allows the selection one or more fields/columns for the given query, -// instead of selecting all fields in the entity. -// -// Example: -// -// var v []struct { -// Name string `json:"name,omitempty"` -// } -// -// client.Admin.Query(). -// Select(admin.FieldName). -// Scan(ctx, &v) -func (_q *AdminQuery) Select(fields ...string) *AdminSelect { - _q.ctx.Fields = append(_q.ctx.Fields, fields...) - sbuild := &AdminSelect{AdminQuery: _q} - sbuild.label = admin.Label - sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan - return sbuild -} - -// Aggregate returns a AdminSelect configured with the given aggregations. -func (_q *AdminQuery) Aggregate(fns ...AggregateFunc) *AdminSelect { - return _q.Select().Aggregate(fns...) -} - -func (_q *AdminQuery) prepareQuery(ctx context.Context) error { - for _, inter := range _q.inters { - if inter == nil { - return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") - } - if trv, ok := inter.(Traverser); ok { - if err := trv.Traverse(ctx, _q); err != nil { - return err - } - } - } - for _, f := range _q.ctx.Fields { - if !admin.ValidColumn(f) { - return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - } - if _q.path != nil { - prev, err := _q.path(ctx) - if err != nil { - return err - } - _q.sql = prev - } - return nil -} - -func (_q *AdminQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Admin, error) { - var ( - nodes = []*Admin{} - _spec = _q.querySpec() - ) - _spec.ScanValues = func(columns []string) ([]any, error) { - return (*Admin).scanValues(nil, columns) - } - _spec.Assign = func(columns []string, values []any) error { - node := &Admin{config: _q.config} - nodes = append(nodes, node) - return node.assignValues(columns, values) - } - for i := range hooks { - hooks[i](ctx, _spec) - } - if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { - return nil, err - } - if len(nodes) == 0 { - return nodes, nil - } - return nodes, nil -} - -func (_q *AdminQuery) sqlCount(ctx context.Context) (int, error) { - _spec := _q.querySpec() - _spec.Node.Columns = _q.ctx.Fields - if len(_q.ctx.Fields) > 0 { - _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique - } - return sqlgraph.CountNodes(ctx, _q.driver, _spec) -} - -func (_q *AdminQuery) querySpec() *sqlgraph.QuerySpec { - _spec := sqlgraph.NewQuerySpec(admin.Table, admin.Columns, sqlgraph.NewFieldSpec(admin.FieldID, field.TypeInt64)) - _spec.From = _q.sql - if unique := _q.ctx.Unique; unique != nil { - _spec.Unique = *unique - } else if _q.path != nil { - _spec.Unique = true - } - if fields := _q.ctx.Fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, admin.FieldID) - for i := range fields { - if fields[i] != admin.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) - } - } - } - if ps := _q.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if limit := _q.ctx.Limit; limit != nil { - _spec.Limit = *limit - } - if offset := _q.ctx.Offset; offset != nil { - _spec.Offset = *offset - } - if ps := _q.order; len(ps) > 0 { - _spec.Order = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - return _spec -} - -func (_q *AdminQuery) sqlQuery(ctx context.Context) *sql.Selector { - builder := sql.Dialect(_q.driver.Dialect()) - t1 := builder.Table(admin.Table) - columns := _q.ctx.Fields - if len(columns) == 0 { - columns = admin.Columns - } - selector := builder.Select(t1.Columns(columns...)...).From(t1) - if _q.sql != nil { - selector = _q.sql - selector.Select(selector.Columns(columns...)...) - } - if _q.ctx.Unique != nil && *_q.ctx.Unique { - selector.Distinct() - } - for _, p := range _q.predicates { - p(selector) - } - for _, p := range _q.order { - p(selector) - } - if offset := _q.ctx.Offset; offset != nil { - // limit is mandatory for offset clause. We start - // with default value, and override it below if needed. - selector.Offset(*offset).Limit(math.MaxInt32) - } - if limit := _q.ctx.Limit; limit != nil { - selector.Limit(*limit) - } - return selector -} - -// AdminGroupBy is the group-by builder for Admin entities. -type AdminGroupBy struct { - selector - build *AdminQuery -} - -// Aggregate adds the given aggregation functions to the group-by query. -func (_g *AdminGroupBy) Aggregate(fns ...AggregateFunc) *AdminGroupBy { - _g.fns = append(_g.fns, fns...) - return _g -} - -// Scan applies the selector query and scans the result into the given value. -func (_g *AdminGroupBy) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) - if err := _g.build.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*AdminQuery, *AdminGroupBy](ctx, _g.build, _g, _g.build.inters, v) -} - -func (_g *AdminGroupBy) sqlScan(ctx context.Context, root *AdminQuery, v any) error { - selector := root.sqlQuery(ctx).Select() - aggregation := make([]string, 0, len(_g.fns)) - for _, fn := range _g.fns { - aggregation = append(aggregation, fn(selector)) - } - if len(selector.SelectedColumns()) == 0 { - columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) - for _, f := range *_g.flds { - columns = append(columns, selector.C(f)) - } - columns = append(columns, aggregation...) - selector.Select(columns...) - } - selector.GroupBy(selector.Columns(*_g.flds...)...) - if err := selector.Err(); err != nil { - return err - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} - -// AdminSelect is the builder for selecting fields of Admin entities. -type AdminSelect struct { - *AdminQuery - selector -} - -// Aggregate adds the given aggregation functions to the selector query. -func (_s *AdminSelect) Aggregate(fns ...AggregateFunc) *AdminSelect { - _s.fns = append(_s.fns, fns...) - return _s -} - -// Scan applies the selector query and scans the result into the given value. -func (_s *AdminSelect) Scan(ctx context.Context, v any) error { - ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) - if err := _s.prepareQuery(ctx); err != nil { - return err - } - return scanWithInterceptors[*AdminQuery, *AdminSelect](ctx, _s.AdminQuery, _s, _s.inters, v) -} - -func (_s *AdminSelect) sqlScan(ctx context.Context, root *AdminQuery, v any) error { - selector := root.sqlQuery(ctx) - aggregation := make([]string, 0, len(_s.fns)) - for _, fn := range _s.fns { - aggregation = append(aggregation, fn(selector)) - } - switch n := len(*_s.selector.flds); { - case n == 0 && len(aggregation) > 0: - selector.Select(aggregation...) - case n != 0 && len(aggregation) > 0: - selector.AppendSelect(aggregation...) - } - rows := &sql.Rows{} - query, args := selector.Query() - if err := _s.driver.Query(ctx, query, args, rows); err != nil { - return err - } - defer rows.Close() - return sql.ScanSlice(rows, v) -} diff --git a/internal/data/ent/admin_update.go b/internal/data/ent/admin_update.go deleted file mode 100644 index ca468b8..0000000 --- a/internal/data/ent/admin_update.go +++ /dev/null @@ -1,382 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "time" - - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "entgo.io/ent/schema/field" - "kra/internal/data/ent/admin" - "kra/internal/data/ent/predicate" -) - -// AdminUpdate is the builder for updating Admin entities. -type AdminUpdate struct { - config - hooks []Hook - mutation *AdminMutation -} - -// Where appends a list predicates to the AdminUpdate builder. -func (_u *AdminUpdate) Where(ps ...predicate.Admin) *AdminUpdate { - _u.mutation.Where(ps...) - return _u -} - -// SetName sets the "name" field. -func (_u *AdminUpdate) SetName(v string) *AdminUpdate { - _u.mutation.SetName(v) - return _u -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_u *AdminUpdate) SetNillableName(v *string) *AdminUpdate { - if v != nil { - _u.SetName(*v) - } - return _u -} - -// SetEmail sets the "email" field. -func (_u *AdminUpdate) SetEmail(v string) *AdminUpdate { - _u.mutation.SetEmail(v) - return _u -} - -// SetNillableEmail sets the "email" field if the given value is not nil. -func (_u *AdminUpdate) SetNillableEmail(v *string) *AdminUpdate { - if v != nil { - _u.SetEmail(*v) - } - return _u -} - -// SetAvatar sets the "avatar" field. -func (_u *AdminUpdate) SetAvatar(v string) *AdminUpdate { - _u.mutation.SetAvatar(v) - return _u -} - -// SetNillableAvatar sets the "avatar" field if the given value is not nil. -func (_u *AdminUpdate) SetNillableAvatar(v *string) *AdminUpdate { - if v != nil { - _u.SetAvatar(*v) - } - return _u -} - -// SetAccess sets the "access" field. -func (_u *AdminUpdate) SetAccess(v string) *AdminUpdate { - _u.mutation.SetAccess(v) - return _u -} - -// SetNillableAccess sets the "access" field if the given value is not nil. -func (_u *AdminUpdate) SetNillableAccess(v *string) *AdminUpdate { - if v != nil { - _u.SetAccess(*v) - } - return _u -} - -// SetPassword sets the "password" field. -func (_u *AdminUpdate) SetPassword(v string) *AdminUpdate { - _u.mutation.SetPassword(v) - return _u -} - -// SetNillablePassword sets the "password" field if the given value is not nil. -func (_u *AdminUpdate) SetNillablePassword(v *string) *AdminUpdate { - if v != nil { - _u.SetPassword(*v) - } - return _u -} - -// SetUpdateTime sets the "update_time" field. -func (_u *AdminUpdate) SetUpdateTime(v time.Time) *AdminUpdate { - _u.mutation.SetUpdateTime(v) - return _u -} - -// Mutation returns the AdminMutation object of the builder. -func (_u *AdminUpdate) Mutation() *AdminMutation { - return _u.mutation -} - -// Save executes the query and returns the number of nodes affected by the update operation. -func (_u *AdminUpdate) Save(ctx context.Context) (int, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *AdminUpdate) SaveX(ctx context.Context) int { - affected, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return affected -} - -// Exec executes the query. -func (_u *AdminUpdate) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *AdminUpdate) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *AdminUpdate) defaults() { - if _, ok := _u.mutation.UpdateTime(); !ok { - v := admin.UpdateDefaultUpdateTime() - _u.mutation.SetUpdateTime(v) - } -} - -func (_u *AdminUpdate) sqlSave(ctx context.Context) (_node int, err error) { - _spec := sqlgraph.NewUpdateSpec(admin.Table, admin.Columns, sqlgraph.NewFieldSpec(admin.FieldID, field.TypeInt64)) - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.Name(); ok { - _spec.SetField(admin.FieldName, field.TypeString, value) - } - if value, ok := _u.mutation.Email(); ok { - _spec.SetField(admin.FieldEmail, field.TypeString, value) - } - if value, ok := _u.mutation.Avatar(); ok { - _spec.SetField(admin.FieldAvatar, field.TypeString, value) - } - if value, ok := _u.mutation.Access(); ok { - _spec.SetField(admin.FieldAccess, field.TypeString, value) - } - if value, ok := _u.mutation.Password(); ok { - _spec.SetField(admin.FieldPassword, field.TypeString, value) - } - if value, ok := _u.mutation.UpdateTime(); ok { - _spec.SetField(admin.FieldUpdateTime, field.TypeTime, value) - } - if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{admin.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return 0, err - } - _u.mutation.done = true - return _node, nil -} - -// AdminUpdateOne is the builder for updating a single Admin entity. -type AdminUpdateOne struct { - config - fields []string - hooks []Hook - mutation *AdminMutation -} - -// SetName sets the "name" field. -func (_u *AdminUpdateOne) SetName(v string) *AdminUpdateOne { - _u.mutation.SetName(v) - return _u -} - -// SetNillableName sets the "name" field if the given value is not nil. -func (_u *AdminUpdateOne) SetNillableName(v *string) *AdminUpdateOne { - if v != nil { - _u.SetName(*v) - } - return _u -} - -// SetEmail sets the "email" field. -func (_u *AdminUpdateOne) SetEmail(v string) *AdminUpdateOne { - _u.mutation.SetEmail(v) - return _u -} - -// SetNillableEmail sets the "email" field if the given value is not nil. -func (_u *AdminUpdateOne) SetNillableEmail(v *string) *AdminUpdateOne { - if v != nil { - _u.SetEmail(*v) - } - return _u -} - -// SetAvatar sets the "avatar" field. -func (_u *AdminUpdateOne) SetAvatar(v string) *AdminUpdateOne { - _u.mutation.SetAvatar(v) - return _u -} - -// SetNillableAvatar sets the "avatar" field if the given value is not nil. -func (_u *AdminUpdateOne) SetNillableAvatar(v *string) *AdminUpdateOne { - if v != nil { - _u.SetAvatar(*v) - } - return _u -} - -// SetAccess sets the "access" field. -func (_u *AdminUpdateOne) SetAccess(v string) *AdminUpdateOne { - _u.mutation.SetAccess(v) - return _u -} - -// SetNillableAccess sets the "access" field if the given value is not nil. -func (_u *AdminUpdateOne) SetNillableAccess(v *string) *AdminUpdateOne { - if v != nil { - _u.SetAccess(*v) - } - return _u -} - -// SetPassword sets the "password" field. -func (_u *AdminUpdateOne) SetPassword(v string) *AdminUpdateOne { - _u.mutation.SetPassword(v) - return _u -} - -// SetNillablePassword sets the "password" field if the given value is not nil. -func (_u *AdminUpdateOne) SetNillablePassword(v *string) *AdminUpdateOne { - if v != nil { - _u.SetPassword(*v) - } - return _u -} - -// SetUpdateTime sets the "update_time" field. -func (_u *AdminUpdateOne) SetUpdateTime(v time.Time) *AdminUpdateOne { - _u.mutation.SetUpdateTime(v) - return _u -} - -// Mutation returns the AdminMutation object of the builder. -func (_u *AdminUpdateOne) Mutation() *AdminMutation { - return _u.mutation -} - -// Where appends a list predicates to the AdminUpdate builder. -func (_u *AdminUpdateOne) Where(ps ...predicate.Admin) *AdminUpdateOne { - _u.mutation.Where(ps...) - return _u -} - -// Select allows selecting one or more fields (columns) of the returned entity. -// The default is selecting all fields defined in the entity schema. -func (_u *AdminUpdateOne) Select(field string, fields ...string) *AdminUpdateOne { - _u.fields = append([]string{field}, fields...) - return _u -} - -// Save executes the query and returns the updated Admin entity. -func (_u *AdminUpdateOne) Save(ctx context.Context) (*Admin, error) { - _u.defaults() - return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) -} - -// SaveX is like Save, but panics if an error occurs. -func (_u *AdminUpdateOne) SaveX(ctx context.Context) *Admin { - node, err := _u.Save(ctx) - if err != nil { - panic(err) - } - return node -} - -// Exec executes the query on the entity. -func (_u *AdminUpdateOne) Exec(ctx context.Context) error { - _, err := _u.Save(ctx) - return err -} - -// ExecX is like Exec, but panics if an error occurs. -func (_u *AdminUpdateOne) ExecX(ctx context.Context) { - if err := _u.Exec(ctx); err != nil { - panic(err) - } -} - -// defaults sets the default values of the builder before save. -func (_u *AdminUpdateOne) defaults() { - if _, ok := _u.mutation.UpdateTime(); !ok { - v := admin.UpdateDefaultUpdateTime() - _u.mutation.SetUpdateTime(v) - } -} - -func (_u *AdminUpdateOne) sqlSave(ctx context.Context) (_node *Admin, err error) { - _spec := sqlgraph.NewUpdateSpec(admin.Table, admin.Columns, sqlgraph.NewFieldSpec(admin.FieldID, field.TypeInt64)) - id, ok := _u.mutation.ID() - if !ok { - return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Admin.id" for update`)} - } - _spec.Node.ID.Value = id - if fields := _u.fields; len(fields) > 0 { - _spec.Node.Columns = make([]string, 0, len(fields)) - _spec.Node.Columns = append(_spec.Node.Columns, admin.FieldID) - for _, f := range fields { - if !admin.ValidColumn(f) { - return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} - } - if f != admin.FieldID { - _spec.Node.Columns = append(_spec.Node.Columns, f) - } - } - } - if ps := _u.mutation.predicates; len(ps) > 0 { - _spec.Predicate = func(selector *sql.Selector) { - for i := range ps { - ps[i](selector) - } - } - } - if value, ok := _u.mutation.Name(); ok { - _spec.SetField(admin.FieldName, field.TypeString, value) - } - if value, ok := _u.mutation.Email(); ok { - _spec.SetField(admin.FieldEmail, field.TypeString, value) - } - if value, ok := _u.mutation.Avatar(); ok { - _spec.SetField(admin.FieldAvatar, field.TypeString, value) - } - if value, ok := _u.mutation.Access(); ok { - _spec.SetField(admin.FieldAccess, field.TypeString, value) - } - if value, ok := _u.mutation.Password(); ok { - _spec.SetField(admin.FieldPassword, field.TypeString, value) - } - if value, ok := _u.mutation.UpdateTime(); ok { - _spec.SetField(admin.FieldUpdateTime, field.TypeTime, value) - } - _node = &Admin{config: _u.config} - _spec.Assign = _node.assignValues - _spec.ScanValues = _node.scanValues - if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil { - if _, ok := err.(*sqlgraph.NotFoundError); ok { - err = &NotFoundError{admin.Label} - } else if sqlgraph.IsConstraintError(err) { - err = &ConstraintError{msg: err.Error(), wrap: err} - } - return nil, err - } - _u.mutation.done = true - return _node, nil -} diff --git a/internal/data/ent/client.go b/internal/data/ent/client.go deleted file mode 100644 index a363e2d..0000000 --- a/internal/data/ent/client.go +++ /dev/null @@ -1,366 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "log" - "reflect" - - "kra/internal/data/ent/migrate" - - "entgo.io/ent" - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql" - "kra/internal/data/ent/admin" - - stdsql "database/sql" -) - -// Client is the client that holds all ent builders. -type Client struct { - config - // Schema is the client for creating, migrating and dropping schema. - Schema *migrate.Schema - // Admin is the client for interacting with the Admin builders. - Admin *AdminClient -} - -// NewClient creates a new client configured with the given options. -func NewClient(opts ...Option) *Client { - client := &Client{config: newConfig(opts...)} - client.init() - return client -} - -func (c *Client) init() { - c.Schema = migrate.NewSchema(c.driver) - c.Admin = NewAdminClient(c.config) -} - -type ( - // config is the configuration for the client and its builder. - config struct { - // driver used for executing database requests. - driver dialect.Driver - // debug enable a debug logging. - debug bool - // log used for logging on debug mode. - log func(...any) - // hooks to execute on mutations. - hooks *hooks - // interceptors to execute on queries. - inters *inters - } - // Option function to configure the client. - 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 { - opt(c) - } - if c.debug { - c.driver = dialect.Debug(c.driver, c.log) - } -} - -// Debug enables debug logging on the ent.Driver. -func Debug() Option { - return func(c *config) { - c.debug = true - } -} - -// Log sets the logging function for debug mode. -func Log(fn func(...any)) Option { - return func(c *config) { - c.log = fn - } -} - -// Driver configures the client driver. -func Driver(driver dialect.Driver) Option { - return func(c *config) { - c.driver = driver - } -} - -// Open opens a database/sql.DB specified by the driver name and -// the data source name, and returns a new client attached to it. -// Optional parameters can be added for configuring the client. -func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { - switch driverName { - case dialect.MySQL, dialect.Postgres, dialect.SQLite: - drv, err := sql.Open(driverName, dataSourceName) - if err != nil { - return nil, err - } - return NewClient(append(options, Driver(drv))...), nil - default: - return nil, fmt.Errorf("unsupported driver: %q", driverName) - } -} - -// 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, ErrTxStarted - } - tx, err := newTx(ctx, c.driver) - if err != nil { - return nil, fmt.Errorf("ent: starting a transaction: %w", err) - } - cfg := c.config - cfg.driver = tx - return &Tx{ - ctx: ctx, - config: cfg, - Admin: NewAdminClient(cfg), - }, nil -} - -// BeginTx returns a transactional client with specified options. -func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { - if _, ok := c.driver.(*txDriver); ok { - return nil, errors.New("ent: cannot start a transaction within a transaction") - } - tx, err := c.driver.(interface { - BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) - }).BeginTx(ctx, opts) - if err != nil { - return nil, fmt.Errorf("ent: starting a transaction: %w", err) - } - cfg := c.config - cfg.driver = &txDriver{tx: tx, drv: c.driver} - return &Tx{ - ctx: ctx, - config: cfg, - Admin: NewAdminClient(cfg), - }, nil -} - -// Debug returns a new debug-client. It's used to get verbose logging on specific operations. -// -// client.Debug(). -// Admin. -// Query(). -// Count(ctx) -func (c *Client) Debug() *Client { - if c.debug { - return c - } - cfg := c.config - cfg.driver = dialect.Debug(c.driver, c.log) - client := &Client{config: cfg} - client.init() - return client -} - -// Close closes the database connection and prevents new queries from starting. -func (c *Client) Close() error { - return c.driver.Close() -} - -// Use adds the mutation hooks to all the entity clients. -// In order to add hooks to a specific client, call: `client.Node.Use(...)`. -func (c *Client) Use(hooks ...Hook) { - c.Admin.Use(hooks...) -} - -// Intercept adds the query interceptors to all the entity clients. -// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. -func (c *Client) Intercept(interceptors ...Interceptor) { - c.Admin.Intercept(interceptors...) -} - -// Mutate implements the ent.Mutator interface. -func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { - switch m := m.(type) { - case *AdminMutation: - return c.Admin.mutate(ctx, m) - default: - return nil, fmt.Errorf("ent: unknown mutation type %T", m) - } -} - -// AdminClient is a client for the Admin schema. -type AdminClient struct { - config -} - -// NewAdminClient returns a client for the Admin from the given config. -func NewAdminClient(c config) *AdminClient { - return &AdminClient{config: c} -} - -// Use adds a list of mutation hooks to the hooks stack. -// A call to `Use(f, g, h)` equals to `admin.Hooks(f(g(h())))`. -func (c *AdminClient) Use(hooks ...Hook) { - c.hooks.Admin = append(c.hooks.Admin, hooks...) -} - -// Intercept adds a list of query interceptors to the interceptors stack. -// A call to `Intercept(f, g, h)` equals to `admin.Intercept(f(g(h())))`. -func (c *AdminClient) Intercept(interceptors ...Interceptor) { - c.inters.Admin = append(c.inters.Admin, interceptors...) -} - -// Create returns a builder for creating a Admin entity. -func (c *AdminClient) Create() *AdminCreate { - mutation := newAdminMutation(c.config, OpCreate) - return &AdminCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// CreateBulk returns a builder for creating a bulk of Admin entities. -func (c *AdminClient) CreateBulk(builders ...*AdminCreate) *AdminCreateBulk { - return &AdminCreateBulk{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 *AdminClient) MapCreateBulk(slice any, setFunc func(*AdminCreate, int)) *AdminCreateBulk { - rv := reflect.ValueOf(slice) - if rv.Kind() != reflect.Slice { - return &AdminCreateBulk{err: fmt.Errorf("calling to AdminClient.MapCreateBulk with wrong type %T, need slice", slice)} - } - builders := make([]*AdminCreate, rv.Len()) - for i := 0; i < rv.Len(); i++ { - builders[i] = c.Create() - setFunc(builders[i], i) - } - return &AdminCreateBulk{config: c.config, builders: builders} -} - -// Update returns an update builder for Admin. -func (c *AdminClient) Update() *AdminUpdate { - mutation := newAdminMutation(c.config, OpUpdate) - return &AdminUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOne returns an update builder for the given entity. -func (c *AdminClient) UpdateOne(_m *Admin) *AdminUpdateOne { - mutation := newAdminMutation(c.config, OpUpdateOne, withAdmin(_m)) - return &AdminUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// UpdateOneID returns an update builder for the given id. -func (c *AdminClient) UpdateOneID(id int64) *AdminUpdateOne { - mutation := newAdminMutation(c.config, OpUpdateOne, withAdminID(id)) - return &AdminUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// Delete returns a delete builder for Admin. -func (c *AdminClient) Delete() *AdminDelete { - mutation := newAdminMutation(c.config, OpDelete) - return &AdminDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} -} - -// DeleteOne returns a builder for deleting the given entity. -func (c *AdminClient) DeleteOne(_m *Admin) *AdminDeleteOne { - return c.DeleteOneID(_m.ID) -} - -// DeleteOneID returns a builder for deleting the given entity by its id. -func (c *AdminClient) DeleteOneID(id int64) *AdminDeleteOne { - builder := c.Delete().Where(admin.ID(id)) - builder.mutation.id = &id - builder.mutation.op = OpDeleteOne - return &AdminDeleteOne{builder} -} - -// Query returns a query builder for Admin. -func (c *AdminClient) Query() *AdminQuery { - return &AdminQuery{ - config: c.config, - ctx: &QueryContext{Type: TypeAdmin}, - inters: c.Interceptors(), - } -} - -// Get returns a Admin entity by its id. -func (c *AdminClient) Get(ctx context.Context, id int64) (*Admin, error) { - return c.Query().Where(admin.ID(id)).Only(ctx) -} - -// GetX is like Get, but panics if an error occurs. -func (c *AdminClient) GetX(ctx context.Context, id int64) *Admin { - obj, err := c.Get(ctx, id) - if err != nil { - panic(err) - } - return obj -} - -// Hooks returns the client hooks. -func (c *AdminClient) Hooks() []Hook { - return c.hooks.Admin -} - -// Interceptors returns the client interceptors. -func (c *AdminClient) Interceptors() []Interceptor { - return c.inters.Admin -} - -func (c *AdminClient) mutate(ctx context.Context, m *AdminMutation) (Value, error) { - switch m.Op() { - case OpCreate: - return (&AdminCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdate: - return (&AdminUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpUpdateOne: - return (&AdminUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) - case OpDelete, OpDeleteOne: - return (&AdminDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) - default: - return nil, fmt.Errorf("ent: unknown Admin mutation op: %q", m.Op()) - } -} - -// hooks and interceptors per client, for fast access. -type ( - hooks struct { - Admin []ent.Hook - } - inters struct { - Admin []ent.Interceptor - } -) - -// ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it. -// See, database/sql#DB.ExecContext for more information. -func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) { - ex, ok := c.driver.(interface { - ExecContext(context.Context, string, ...any) (stdsql.Result, error) - }) - if !ok { - return nil, fmt.Errorf("Driver.ExecContext is not supported") - } - return ex.ExecContext(ctx, query, args...) -} - -// QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it. -// See, database/sql#DB.QueryContext for more information. -func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) { - q, ok := c.driver.(interface { - QueryContext(context.Context, string, ...any) (*stdsql.Rows, error) - }) - if !ok { - return nil, fmt.Errorf("Driver.QueryContext is not supported") - } - return q.QueryContext(ctx, query, args...) -} diff --git a/internal/data/ent/ent.go b/internal/data/ent/ent.go deleted file mode 100644 index 1976d56..0000000 --- a/internal/data/ent/ent.go +++ /dev/null @@ -1,608 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "reflect" - "sync" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "entgo.io/ent/dialect/sql/sqlgraph" - "kra/internal/data/ent/admin" -) - -// ent aliases to avoid import conflicts in user's code. -type ( - Op = ent.Op - Hook = ent.Hook - Value = ent.Value - Query = ent.Query - QueryContext = ent.QueryContext - Querier = ent.Querier - QuerierFunc = ent.QuerierFunc - Interceptor = ent.Interceptor - InterceptFunc = ent.InterceptFunc - Traverser = ent.Traverser - TraverseFunc = ent.TraverseFunc - Policy = ent.Policy - Mutator = ent.Mutator - Mutation = ent.Mutation - MutateFunc = ent.MutateFunc -) - -type clientCtxKey struct{} - -// FromContext returns a Client stored inside a context, or nil if there isn't one. -func FromContext(ctx context.Context) *Client { - c, _ := ctx.Value(clientCtxKey{}).(*Client) - return c -} - -// NewContext returns a new context with the given Client attached. -func NewContext(parent context.Context, c *Client) context.Context { - return context.WithValue(parent, clientCtxKey{}, c) -} - -type txCtxKey struct{} - -// TxFromContext returns a Tx stored inside a context, or nil if there isn't one. -func TxFromContext(ctx context.Context) *Tx { - tx, _ := ctx.Value(txCtxKey{}).(*Tx) - return tx -} - -// NewTxContext returns a new context with the given Tx attached. -func NewTxContext(parent context.Context, tx *Tx) context.Context { - return context.WithValue(parent, txCtxKey{}, tx) -} - -// OrderFunc applies an ordering on the sql selector. -// Deprecated: Use Asc/Desc functions or the package builders instead. -type OrderFunc func(*sql.Selector) - -var ( - initCheck sync.Once - columnCheck sql.ColumnCheck -) - -// checkColumn checks if the column exists in the given table. -func checkColumn(t, c string) error { - initCheck.Do(func() { - columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ - admin.Table: admin.ValidColumn, - }) - }) - return columnCheck(t, c) -} - -// Asc applies the given fields in ASC order. -func Asc(fields ...string) func(*sql.Selector) { - return func(s *sql.Selector) { - for _, f := range fields { - 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))) - } - } -} - -// Desc applies the given fields in DESC order. -func Desc(fields ...string) func(*sql.Selector) { - return func(s *sql.Selector) { - for _, f := range fields { - 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))) - } - } -} - -// AggregateFunc applies an aggregation step on the group-by traversal/selector. -type AggregateFunc func(*sql.Selector) string - -// As is a pseudo aggregation function for renaming another other functions with custom names. For example: -// -// GroupBy(field1, field2). -// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")). -// Scan(ctx, &v) -func As(fn AggregateFunc, end string) AggregateFunc { - return func(s *sql.Selector) string { - return sql.As(fn(s), end) - } -} - -// Count applies the "count" aggregation function on each group. -func Count() AggregateFunc { - return func(s *sql.Selector) string { - return sql.Count("*") - } -} - -// Max applies the "max" aggregation function on the given field of each group. -func Max(field string) AggregateFunc { - return func(s *sql.Selector) string { - if err := checkColumn(s.TableName(), field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Max(s.C(field)) - } -} - -// Mean applies the "mean" aggregation function on the given field of each group. -func Mean(field string) AggregateFunc { - return func(s *sql.Selector) string { - if err := checkColumn(s.TableName(), field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Avg(s.C(field)) - } -} - -// Min applies the "min" aggregation function on the given field of each group. -func Min(field string) AggregateFunc { - return func(s *sql.Selector) string { - if err := checkColumn(s.TableName(), field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Min(s.C(field)) - } -} - -// Sum applies the "sum" aggregation function on the given field of each group. -func Sum(field string) AggregateFunc { - return func(s *sql.Selector) string { - if err := checkColumn(s.TableName(), field); err != nil { - s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) - return "" - } - return sql.Sum(s.C(field)) - } -} - -// ValidationError returns when validating a field or edge fails. -type ValidationError struct { - Name string // Field or edge name. - err error -} - -// Error implements the error interface. -func (e *ValidationError) Error() string { - return e.err.Error() -} - -// Unwrap implements the errors.Wrapper interface. -func (e *ValidationError) Unwrap() error { - return e.err -} - -// IsValidationError returns a boolean indicating whether the error is a validation error. -func IsValidationError(err error) bool { - if err == nil { - return false - } - var e *ValidationError - return errors.As(err, &e) -} - -// NotFoundError returns when trying to fetch a specific entity and it was not found in the database. -type NotFoundError struct { - label string -} - -// Error implements the error interface. -func (e *NotFoundError) Error() string { - return "ent: " + e.label + " not found" -} - -// IsNotFound returns a boolean indicating whether the error is a not found error. -func IsNotFound(err error) bool { - if err == nil { - return false - } - var e *NotFoundError - return errors.As(err, &e) -} - -// MaskNotFound masks not found error. -func MaskNotFound(err error) error { - if IsNotFound(err) { - return nil - } - return err -} - -// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database. -type NotSingularError struct { - label string -} - -// Error implements the error interface. -func (e *NotSingularError) Error() string { - return "ent: " + e.label + " not singular" -} - -// IsNotSingular returns a boolean indicating whether the error is a not singular error. -func IsNotSingular(err error) bool { - if err == nil { - return false - } - var e *NotSingularError - return errors.As(err, &e) -} - -// NotLoadedError returns when trying to get a node that was not loaded by the query. -type NotLoadedError struct { - edge string -} - -// Error implements the error interface. -func (e *NotLoadedError) Error() string { - return "ent: " + e.edge + " edge was not loaded" -} - -// IsNotLoaded returns a boolean indicating whether the error is a not loaded error. -func IsNotLoaded(err error) bool { - if err == nil { - return false - } - var e *NotLoadedError - return errors.As(err, &e) -} - -// ConstraintError returns when trying to create/update one or more entities and -// one or more of their constraints failed. For example, violation of edge or -// field uniqueness. -type ConstraintError struct { - msg string - wrap error -} - -// Error implements the error interface. -func (e ConstraintError) Error() string { - return "ent: constraint failed: " + e.msg -} - -// Unwrap implements the errors.Wrapper interface. -func (e *ConstraintError) Unwrap() error { - return e.wrap -} - -// IsConstraintError returns a boolean indicating whether the error is a constraint failure. -func IsConstraintError(err error) bool { - if err == nil { - return false - } - var e *ConstraintError - return errors.As(err, &e) -} - -// selector embedded by the different Select/GroupBy builders. -type selector struct { - label string - flds *[]string - fns []AggregateFunc - scan func(context.Context, any) error -} - -// ScanX is like Scan, but panics if an error occurs. -func (s *selector) ScanX(ctx context.Context, v any) { - if err := s.scan(ctx, v); err != nil { - panic(err) - } -} - -// Strings returns list of strings from a selector. It is only allowed when selecting one field. -func (s *selector) Strings(ctx context.Context) ([]string, error) { - if len(*s.flds) > 1 { - return nil, errors.New("ent: Strings is not achievable when selecting more than 1 field") - } - var v []string - if err := s.scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// StringsX is like Strings, but panics if an error occurs. -func (s *selector) StringsX(ctx context.Context) []string { - v, err := s.Strings(ctx) - if err != nil { - panic(err) - } - return v -} - -// String returns a single string from a selector. It is only allowed when selecting one field. -func (s *selector) String(ctx context.Context) (_ string, err error) { - var v []string - if v, err = s.Strings(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{s.label} - default: - err = fmt.Errorf("ent: Strings returned %d results when one was expected", len(v)) - } - return -} - -// StringX is like String, but panics if an error occurs. -func (s *selector) StringX(ctx context.Context) string { - v, err := s.String(ctx) - if err != nil { - panic(err) - } - return v -} - -// Ints returns list of ints from a selector. It is only allowed when selecting one field. -func (s *selector) Ints(ctx context.Context) ([]int, error) { - if len(*s.flds) > 1 { - return nil, errors.New("ent: Ints is not achievable when selecting more than 1 field") - } - var v []int - if err := s.scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// IntsX is like Ints, but panics if an error occurs. -func (s *selector) IntsX(ctx context.Context) []int { - v, err := s.Ints(ctx) - if err != nil { - panic(err) - } - return v -} - -// Int returns a single int from a selector. It is only allowed when selecting one field. -func (s *selector) Int(ctx context.Context) (_ int, err error) { - var v []int - if v, err = s.Ints(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{s.label} - default: - err = fmt.Errorf("ent: Ints returned %d results when one was expected", len(v)) - } - return -} - -// IntX is like Int, but panics if an error occurs. -func (s *selector) IntX(ctx context.Context) int { - v, err := s.Int(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. -func (s *selector) Float64s(ctx context.Context) ([]float64, error) { - if len(*s.flds) > 1 { - return nil, errors.New("ent: Float64s is not achievable when selecting more than 1 field") - } - var v []float64 - if err := s.scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// Float64sX is like Float64s, but panics if an error occurs. -func (s *selector) Float64sX(ctx context.Context) []float64 { - v, err := s.Float64s(ctx) - if err != nil { - panic(err) - } - return v -} - -// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. -func (s *selector) Float64(ctx context.Context) (_ float64, err error) { - var v []float64 - if v, err = s.Float64s(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{s.label} - default: - err = fmt.Errorf("ent: Float64s returned %d results when one was expected", len(v)) - } - return -} - -// Float64X is like Float64, but panics if an error occurs. -func (s *selector) Float64X(ctx context.Context) float64 { - v, err := s.Float64(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bools returns list of bools from a selector. It is only allowed when selecting one field. -func (s *selector) Bools(ctx context.Context) ([]bool, error) { - if len(*s.flds) > 1 { - return nil, errors.New("ent: Bools is not achievable when selecting more than 1 field") - } - var v []bool - if err := s.scan(ctx, &v); err != nil { - return nil, err - } - return v, nil -} - -// BoolsX is like Bools, but panics if an error occurs. -func (s *selector) BoolsX(ctx context.Context) []bool { - v, err := s.Bools(ctx) - if err != nil { - panic(err) - } - return v -} - -// Bool returns a single bool from a selector. It is only allowed when selecting one field. -func (s *selector) Bool(ctx context.Context) (_ bool, err error) { - var v []bool - if v, err = s.Bools(ctx); err != nil { - return - } - switch len(v) { - case 1: - return v[0], nil - case 0: - err = &NotFoundError{s.label} - default: - err = fmt.Errorf("ent: Bools returned %d results when one was expected", len(v)) - } - return -} - -// BoolX is like Bool, but panics if an error occurs. -func (s *selector) BoolX(ctx context.Context) bool { - v, err := s.Bool(ctx) - if err != nil { - panic(err) - } - return v -} - -// withHooks invokes the builder operation with the given hooks, if any. -func withHooks[V Value, M any, PM interface { - *M - Mutation -}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) { - if len(hooks) == 0 { - return exec(ctx) - } - var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { - mutationT, ok := any(m).(PM) - if !ok { - return nil, fmt.Errorf("unexpected mutation type %T", m) - } - // Set the mutation to the builder. - *mutation = *mutationT - return exec(ctx) - }) - for i := len(hooks) - 1; i >= 0; i-- { - if hooks[i] == nil { - return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") - } - mut = hooks[i](mut) - } - v, err := mut.Mutate(ctx, mutation) - if err != nil { - return value, err - } - nv, ok := v.(V) - if !ok { - return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation) - } - return nv, nil -} - -// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist. -func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context { - if ent.QueryFromContext(ctx) == nil { - qc.Op = op - ctx = ent.NewQueryContext(ctx, qc) - } - return ctx -} - -func querierAll[V Value, Q interface { - sqlAll(context.Context, ...queryHook) (V, error) -}]() Querier { - return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - query, ok := q.(Q) - if !ok { - return nil, fmt.Errorf("unexpected query type %T", q) - } - return query.sqlAll(ctx) - }) -} - -func querierCount[Q interface { - sqlCount(context.Context) (int, error) -}]() Querier { - return QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - query, ok := q.(Q) - if !ok { - return nil, fmt.Errorf("unexpected query type %T", q) - } - return query.sqlCount(ctx) - }) -} - -func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) { - for i := len(inters) - 1; i >= 0; i-- { - qr = inters[i].Intercept(qr) - } - rv, err := qr.Query(ctx, q) - if err != nil { - return v, err - } - vt, ok := rv.(V) - if !ok { - return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v) - } - return vt, nil -} - -func scanWithInterceptors[Q1 ent.Query, Q2 interface { - sqlScan(context.Context, Q1, any) error -}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error { - rv := reflect.ValueOf(v) - var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) { - query, ok := q.(Q1) - if !ok { - return nil, fmt.Errorf("unexpected query type %T", q) - } - if err := selectOrGroup.sqlScan(ctx, query, v); err != nil { - return nil, err - } - if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() { - return rv.Elem().Interface(), nil - } - return v, nil - }) - for i := len(inters) - 1; i >= 0; i-- { - qr = inters[i].Intercept(qr) - } - vv, err := qr.Query(ctx, rootQuery) - if err != nil { - return err - } - switch rv2 := reflect.ValueOf(vv); { - case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer: - case rv.Type() == rv2.Type(): - rv.Elem().Set(rv2.Elem()) - case rv.Elem().Type() == rv2.Type(): - rv.Elem().Set(rv2) - } - return nil -} - -// queryHook describes an internal hook for the different sqlAll methods. -type queryHook func(context.Context, *sqlgraph.QuerySpec) diff --git a/internal/data/ent/enttest/enttest.go b/internal/data/ent/enttest/enttest.go deleted file mode 100644 index 6b9daaf..0000000 --- a/internal/data/ent/enttest/enttest.go +++ /dev/null @@ -1,84 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package enttest - -import ( - "context" - - "kra/internal/data/ent" - // required by schema hooks. - _ "kra/internal/data/ent/runtime" - - "entgo.io/ent/dialect/sql/schema" - "kra/internal/data/ent/migrate" -) - -type ( - // TestingT is the interface that is shared between - // testing.T and testing.B and used by enttest. - TestingT interface { - FailNow() - Error(...any) - } - - // Option configures client creation. - Option func(*options) - - options struct { - opts []ent.Option - migrateOpts []schema.MigrateOption - } -) - -// WithOptions forwards options to client creation. -func WithOptions(opts ...ent.Option) Option { - return func(o *options) { - o.opts = append(o.opts, opts...) - } -} - -// WithMigrateOptions forwards options to auto migration. -func WithMigrateOptions(opts ...schema.MigrateOption) Option { - return func(o *options) { - o.migrateOpts = append(o.migrateOpts, opts...) - } -} - -func newOptions(opts []Option) *options { - o := &options{} - for _, opt := range opts { - opt(o) - } - return o -} - -// Open calls ent.Open and auto-run migration. -func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client { - o := newOptions(opts) - c, err := ent.Open(driverName, dataSourceName, o.opts...) - if err != nil { - t.Error(err) - t.FailNow() - } - migrateSchema(t, c, o) - return c -} - -// NewClient calls ent.NewClient and auto-run migration. -func NewClient(t TestingT, opts ...Option) *ent.Client { - o := newOptions(opts) - c := ent.NewClient(o.opts...) - migrateSchema(t, c, o) - return c -} -func migrateSchema(t TestingT, c *ent.Client, o *options) { - tables, err := schema.CopyTables(migrate.Tables) - if err != nil { - t.Error(err) - t.FailNow() - } - if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil { - t.Error(err) - t.FailNow() - } -} diff --git a/internal/data/ent/generate.go b/internal/data/ent/generate.go deleted file mode 100644 index 67985fa..0000000 --- a/internal/data/ent/generate.go +++ /dev/null @@ -1,3 +0,0 @@ -package ent - -//go:generate go run -mod=mod entgo.io/ent/cmd/ent generate ./schema --feature sql/execquery --feature sql/upsert diff --git a/internal/data/ent/hook/hook.go b/internal/data/ent/hook/hook.go deleted file mode 100644 index cb9a040..0000000 --- a/internal/data/ent/hook/hook.go +++ /dev/null @@ -1,199 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package hook - -import ( - "context" - "fmt" - - "kra/internal/data/ent" -) - -// The AdminFunc type is an adapter to allow the use of ordinary -// function as Admin mutator. -type AdminFunc func(context.Context, *ent.AdminMutation) (ent.Value, error) - -// Mutate calls f(ctx, m). -func (f AdminFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if mv, ok := m.(*ent.AdminMutation); ok { - return f(ctx, mv) - } - return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AdminMutation", m) -} - -// Condition is a hook condition function. -type Condition func(context.Context, ent.Mutation) bool - -// And groups conditions with the AND operator. -func And(first, second Condition, rest ...Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - if !first(ctx, m) || !second(ctx, m) { - return false - } - for _, cond := range rest { - if !cond(ctx, m) { - return false - } - } - return true - } -} - -// Or groups conditions with the OR operator. -func Or(first, second Condition, rest ...Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - if first(ctx, m) || second(ctx, m) { - return true - } - for _, cond := range rest { - if cond(ctx, m) { - return true - } - } - return false - } -} - -// Not negates a given condition. -func Not(cond Condition) Condition { - return func(ctx context.Context, m ent.Mutation) bool { - return !cond(ctx, m) - } -} - -// HasOp is a condition testing mutation operation. -func HasOp(op ent.Op) Condition { - return func(_ context.Context, m ent.Mutation) bool { - return m.Op().Is(op) - } -} - -// HasAddedFields is a condition validating `.AddedField` on fields. -func HasAddedFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if _, exists := m.AddedField(field); !exists { - return false - } - for _, field := range fields { - if _, exists := m.AddedField(field); !exists { - return false - } - } - return true - } -} - -// HasClearedFields is a condition validating `.FieldCleared` on fields. -func HasClearedFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if exists := m.FieldCleared(field); !exists { - return false - } - for _, field := range fields { - if exists := m.FieldCleared(field); !exists { - return false - } - } - return true - } -} - -// HasFields is a condition validating `.Field` on fields. -func HasFields(field string, fields ...string) Condition { - return func(_ context.Context, m ent.Mutation) bool { - if _, exists := m.Field(field); !exists { - return false - } - for _, field := range fields { - if _, exists := m.Field(field); !exists { - return false - } - } - return true - } -} - -// If executes the given hook under condition. -// -// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...))) -func If(hk ent.Hook, cond Condition) ent.Hook { - return func(next ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { - if cond(ctx, m) { - return hk(next).Mutate(ctx, m) - } - return next.Mutate(ctx, m) - }) - } -} - -// On executes the given hook only for the given operation. -// -// hook.On(Log, ent.Delete|ent.Create) -func On(hk ent.Hook, op ent.Op) ent.Hook { - return If(hk, HasOp(op)) -} - -// Unless skips the given hook only for the given operation. -// -// hook.Unless(Log, ent.Update|ent.UpdateOne) -func Unless(hk ent.Hook, op ent.Op) ent.Hook { - return If(hk, Not(HasOp(op))) -} - -// FixedError is a hook returning a fixed error. -func FixedError(err error) ent.Hook { - return func(ent.Mutator) ent.Mutator { - return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { - return nil, err - }) - } -} - -// Reject returns a hook that rejects all operations that match op. -// -// func (T) Hooks() []ent.Hook { -// return []ent.Hook{ -// Reject(ent.Delete|ent.Update), -// } -// } -func Reject(op ent.Op) ent.Hook { - hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) - return On(hk, op) -} - -// Chain acts as a list of hooks and is effectively immutable. -// Once created, it will always hold the same set of hooks in the same order. -type Chain struct { - hooks []ent.Hook -} - -// NewChain creates a new chain of hooks. -func NewChain(hooks ...ent.Hook) Chain { - return Chain{append([]ent.Hook(nil), hooks...)} -} - -// Hook chains the list of hooks and returns the final hook. -func (c Chain) Hook() ent.Hook { - return func(mutator ent.Mutator) ent.Mutator { - for i := len(c.hooks) - 1; i >= 0; i-- { - mutator = c.hooks[i](mutator) - } - return mutator - } -} - -// Append extends a chain, adding the specified hook -// as the last ones in the mutation flow. -func (c Chain) Append(hooks ...ent.Hook) Chain { - newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks)) - newHooks = append(newHooks, c.hooks...) - newHooks = append(newHooks, hooks...) - return Chain{newHooks} -} - -// Extend extends a chain, adding the specified chain -// as the last ones in the mutation flow. -func (c Chain) Extend(chain Chain) Chain { - return c.Append(chain.hooks...) -} diff --git a/internal/data/ent/migrate/migrate.go b/internal/data/ent/migrate/migrate.go deleted file mode 100644 index 1956a6b..0000000 --- a/internal/data/ent/migrate/migrate.go +++ /dev/null @@ -1,64 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package migrate - -import ( - "context" - "fmt" - "io" - - "entgo.io/ent/dialect" - "entgo.io/ent/dialect/sql/schema" -) - -var ( - // WithGlobalUniqueID sets the universal ids options to the migration. - // If this option is enabled, ent migration will allocate a 1<<32 range - // for the ids of each entity (table). - // Note that this option cannot be applied on tables that already exist. - WithGlobalUniqueID = schema.WithGlobalUniqueID - // WithDropColumn sets the drop column option to the migration. - // If this option is enabled, ent migration will drop old columns - // that were used for both fields and edges. This defaults to false. - WithDropColumn = schema.WithDropColumn - // WithDropIndex sets the drop index option to the migration. - // If this option is enabled, ent migration will drop old indexes - // that were defined in the schema. This defaults to false. - // Note that unique constraints are defined using `UNIQUE INDEX`, - // and therefore, it's recommended to enable this option to get more - // flexibility in the schema changes. - WithDropIndex = schema.WithDropIndex - // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. - WithForeignKeys = schema.WithForeignKeys -) - -// Schema is the API for creating, migrating and dropping a schema. -type Schema struct { - drv dialect.Driver -} - -// NewSchema creates a new schema client. -func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } - -// Create creates all schema resources. -func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { - return Create(ctx, s, Tables, opts...) -} - -// Create creates all table resources using the given schema driver. -func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error { - migrate, err := schema.NewMigrate(s.drv, opts...) - if err != nil { - return fmt.Errorf("ent/migrate: %w", err) - } - return migrate.Create(ctx, tables...) -} - -// WriteTo writes the schema changes to w instead of running them against the database. -// -// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { -// log.Fatal(err) -// } -func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { - return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...) -} diff --git a/internal/data/ent/migrate/schema.go b/internal/data/ent/migrate/schema.go deleted file mode 100644 index c140ea5..0000000 --- a/internal/data/ent/migrate/schema.go +++ /dev/null @@ -1,35 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package migrate - -import ( - "entgo.io/ent/dialect/sql/schema" - "entgo.io/ent/schema/field" -) - -var ( - // AdminsColumns holds the columns for the "admins" table. - AdminsColumns = []*schema.Column{ - {Name: "id", Type: field.TypeInt64, Increment: true}, - {Name: "name", Type: field.TypeString, Default: ""}, - {Name: "email", Type: field.TypeString, Default: ""}, - {Name: "avatar", Type: field.TypeString, Default: ""}, - {Name: "access", Type: field.TypeString, Default: ""}, - {Name: "password", Type: field.TypeString, Default: ""}, - {Name: "create_time", Type: field.TypeTime}, - {Name: "update_time", Type: field.TypeTime}, - } - // AdminsTable holds the schema information for the "admins" table. - AdminsTable = &schema.Table{ - Name: "admins", - Columns: AdminsColumns, - PrimaryKey: []*schema.Column{AdminsColumns[0]}, - } - // Tables holds all the tables in the schema. - Tables = []*schema.Table{ - AdminsTable, - } -) - -func init() { -} diff --git a/internal/data/ent/mutation.go b/internal/data/ent/mutation.go deleted file mode 100644 index 9ee90fa..0000000 --- a/internal/data/ent/mutation.go +++ /dev/null @@ -1,684 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - "errors" - "fmt" - "sync" - "time" - - "entgo.io/ent" - "entgo.io/ent/dialect/sql" - "kra/internal/data/ent/admin" - "kra/internal/data/ent/predicate" -) - -const ( - // Operation types. - OpCreate = ent.OpCreate - OpDelete = ent.OpDelete - OpDeleteOne = ent.OpDeleteOne - OpUpdate = ent.OpUpdate - OpUpdateOne = ent.OpUpdateOne - - // Node types. - TypeAdmin = "Admin" -) - -// AdminMutation represents an operation that mutates the Admin nodes in the graph. -type AdminMutation struct { - config - op Op - typ string - id *int64 - name *string - email *string - avatar *string - access *string - password *string - create_time *time.Time - update_time *time.Time - clearedFields map[string]struct{} - done bool - oldValue func(context.Context) (*Admin, error) - predicates []predicate.Admin -} - -var _ ent.Mutation = (*AdminMutation)(nil) - -// adminOption allows management of the mutation configuration using functional options. -type adminOption func(*AdminMutation) - -// newAdminMutation creates new mutation for the Admin entity. -func newAdminMutation(c config, op Op, opts ...adminOption) *AdminMutation { - m := &AdminMutation{ - config: c, - op: op, - typ: TypeAdmin, - clearedFields: make(map[string]struct{}), - } - for _, opt := range opts { - opt(m) - } - return m -} - -// withAdminID sets the ID field of the mutation. -func withAdminID(id int64) adminOption { - return func(m *AdminMutation) { - var ( - err error - once sync.Once - value *Admin - ) - m.oldValue = func(ctx context.Context) (*Admin, error) { - once.Do(func() { - if m.done { - err = errors.New("querying old values post mutation is not allowed") - } else { - value, err = m.Client().Admin.Get(ctx, id) - } - }) - return value, err - } - m.id = &id - } -} - -// withAdmin sets the old Admin of the mutation. -func withAdmin(node *Admin) adminOption { - return func(m *AdminMutation) { - m.oldValue = func(context.Context) (*Admin, error) { - return node, nil - } - m.id = &node.ID - } -} - -// Client returns a new `ent.Client` from the mutation. If the mutation was -// executed in a transaction (ent.Tx), a transactional client is returned. -func (m AdminMutation) Client() *Client { - client := &Client{config: m.config} - client.init() - return client -} - -// Tx returns an `ent.Tx` for mutations that were executed in transactions; -// it returns an error otherwise. -func (m AdminMutation) Tx() (*Tx, error) { - if _, ok := m.driver.(*txDriver); !ok { - return nil, errors.New("ent: mutation is not running in a transaction") - } - tx := &Tx{config: m.config} - tx.init() - return tx, nil -} - -// SetID sets the value of the id field. Note that this -// operation is only accepted on creation of Admin entities. -func (m *AdminMutation) SetID(id int64) { - m.id = &id -} - -// ID returns the ID value in the mutation. Note that the ID is only available -// if it was provided to the builder or after it was returned from the database. -func (m *AdminMutation) ID() (id int64, exists bool) { - if m.id == nil { - return - } - return *m.id, true -} - -// IDs queries the database and returns the entity ids that match the mutation's predicate. -// That means, if the mutation is applied within a transaction with an isolation level such -// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated -// or updated by the mutation. -func (m *AdminMutation) IDs(ctx context.Context) ([]int64, error) { - switch { - case m.op.Is(OpUpdateOne | OpDeleteOne): - id, exists := m.ID() - if exists { - return []int64{id}, nil - } - fallthrough - case m.op.Is(OpUpdate | OpDelete): - return m.Client().Admin.Query().Where(m.predicates...).IDs(ctx) - default: - return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) - } -} - -// SetName sets the "name" field. -func (m *AdminMutation) SetName(s string) { - m.name = &s -} - -// Name returns the value of the "name" field in the mutation. -func (m *AdminMutation) Name() (r string, exists bool) { - v := m.name - if v == nil { - return - } - return *v, true -} - -// OldName returns the old "name" field's value of the Admin entity. -// If the Admin object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *AdminMutation) OldName(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldName is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldName requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldName: %w", err) - } - return oldValue.Name, nil -} - -// ResetName resets all changes to the "name" field. -func (m *AdminMutation) ResetName() { - m.name = nil -} - -// SetEmail sets the "email" field. -func (m *AdminMutation) SetEmail(s string) { - m.email = &s -} - -// Email returns the value of the "email" field in the mutation. -func (m *AdminMutation) Email() (r string, exists bool) { - v := m.email - if v == nil { - return - } - return *v, true -} - -// OldEmail returns the old "email" field's value of the Admin entity. -// If the Admin object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *AdminMutation) OldEmail(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldEmail is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldEmail requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldEmail: %w", err) - } - return oldValue.Email, nil -} - -// ResetEmail resets all changes to the "email" field. -func (m *AdminMutation) ResetEmail() { - m.email = nil -} - -// SetAvatar sets the "avatar" field. -func (m *AdminMutation) SetAvatar(s string) { - m.avatar = &s -} - -// Avatar returns the value of the "avatar" field in the mutation. -func (m *AdminMutation) Avatar() (r string, exists bool) { - v := m.avatar - if v == nil { - return - } - return *v, true -} - -// OldAvatar returns the old "avatar" field's value of the Admin entity. -// If the Admin object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *AdminMutation) OldAvatar(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAvatar is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAvatar requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldAvatar: %w", err) - } - return oldValue.Avatar, nil -} - -// ResetAvatar resets all changes to the "avatar" field. -func (m *AdminMutation) ResetAvatar() { - m.avatar = nil -} - -// SetAccess sets the "access" field. -func (m *AdminMutation) SetAccess(s string) { - m.access = &s -} - -// Access returns the value of the "access" field in the mutation. -func (m *AdminMutation) Access() (r string, exists bool) { - v := m.access - if v == nil { - return - } - return *v, true -} - -// OldAccess returns the old "access" field's value of the Admin entity. -// If the Admin object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *AdminMutation) OldAccess(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldAccess is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldAccess requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldAccess: %w", err) - } - return oldValue.Access, nil -} - -// ResetAccess resets all changes to the "access" field. -func (m *AdminMutation) ResetAccess() { - m.access = nil -} - -// SetPassword sets the "password" field. -func (m *AdminMutation) SetPassword(s string) { - m.password = &s -} - -// Password returns the value of the "password" field in the mutation. -func (m *AdminMutation) Password() (r string, exists bool) { - v := m.password - if v == nil { - return - } - return *v, true -} - -// OldPassword returns the old "password" field's value of the Admin entity. -// If the Admin object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *AdminMutation) OldPassword(ctx context.Context) (v string, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldPassword is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldPassword requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldPassword: %w", err) - } - return oldValue.Password, nil -} - -// ResetPassword resets all changes to the "password" field. -func (m *AdminMutation) ResetPassword() { - m.password = nil -} - -// SetCreateTime sets the "create_time" field. -func (m *AdminMutation) SetCreateTime(t time.Time) { - m.create_time = &t -} - -// CreateTime returns the value of the "create_time" field in the mutation. -func (m *AdminMutation) CreateTime() (r time.Time, exists bool) { - v := m.create_time - if v == nil { - return - } - return *v, true -} - -// OldCreateTime returns the old "create_time" field's value of the Admin entity. -// If the Admin object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *AdminMutation) OldCreateTime(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldCreateTime is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldCreateTime requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldCreateTime: %w", err) - } - return oldValue.CreateTime, nil -} - -// ResetCreateTime resets all changes to the "create_time" field. -func (m *AdminMutation) ResetCreateTime() { - m.create_time = nil -} - -// SetUpdateTime sets the "update_time" field. -func (m *AdminMutation) SetUpdateTime(t time.Time) { - m.update_time = &t -} - -// UpdateTime returns the value of the "update_time" field in the mutation. -func (m *AdminMutation) UpdateTime() (r time.Time, exists bool) { - v := m.update_time - if v == nil { - return - } - return *v, true -} - -// OldUpdateTime returns the old "update_time" field's value of the Admin entity. -// If the Admin object wasn't provided to the builder, the object is fetched from the database. -// An error is returned if the mutation operation is not UpdateOne, or the database query fails. -func (m *AdminMutation) OldUpdateTime(ctx context.Context) (v time.Time, err error) { - if !m.op.Is(OpUpdateOne) { - return v, errors.New("OldUpdateTime is only allowed on UpdateOne operations") - } - if m.id == nil || m.oldValue == nil { - return v, errors.New("OldUpdateTime requires an ID field in the mutation") - } - oldValue, err := m.oldValue(ctx) - if err != nil { - return v, fmt.Errorf("querying old value for OldUpdateTime: %w", err) - } - return oldValue.UpdateTime, nil -} - -// ResetUpdateTime resets all changes to the "update_time" field. -func (m *AdminMutation) ResetUpdateTime() { - m.update_time = nil -} - -// Where appends a list predicates to the AdminMutation builder. -func (m *AdminMutation) Where(ps ...predicate.Admin) { - m.predicates = append(m.predicates, ps...) -} - -// WhereP appends storage-level predicates to the AdminMutation builder. Using this method, -// users can use type-assertion to append predicates that do not depend on any generated package. -func (m *AdminMutation) WhereP(ps ...func(*sql.Selector)) { - p := make([]predicate.Admin, len(ps)) - for i := range ps { - p[i] = ps[i] - } - m.Where(p...) -} - -// Op returns the operation name. -func (m *AdminMutation) Op() Op { - return m.op -} - -// SetOp allows setting the mutation operation. -func (m *AdminMutation) SetOp(op Op) { - m.op = op -} - -// Type returns the node type of this mutation (Admin). -func (m *AdminMutation) Type() string { - return m.typ -} - -// Fields returns all fields that were changed during this mutation. Note that in -// order to get all numeric fields that were incremented/decremented, call -// AddedFields(). -func (m *AdminMutation) Fields() []string { - fields := make([]string, 0, 7) - if m.name != nil { - fields = append(fields, admin.FieldName) - } - if m.email != nil { - fields = append(fields, admin.FieldEmail) - } - if m.avatar != nil { - fields = append(fields, admin.FieldAvatar) - } - if m.access != nil { - fields = append(fields, admin.FieldAccess) - } - if m.password != nil { - fields = append(fields, admin.FieldPassword) - } - if m.create_time != nil { - fields = append(fields, admin.FieldCreateTime) - } - if m.update_time != nil { - fields = append(fields, admin.FieldUpdateTime) - } - return fields -} - -// Field returns the value of a field with the given name. The second boolean -// return value indicates that this field was not set, or was not defined in the -// schema. -func (m *AdminMutation) Field(name string) (ent.Value, bool) { - switch name { - case admin.FieldName: - return m.Name() - case admin.FieldEmail: - return m.Email() - case admin.FieldAvatar: - return m.Avatar() - case admin.FieldAccess: - return m.Access() - case admin.FieldPassword: - return m.Password() - case admin.FieldCreateTime: - return m.CreateTime() - case admin.FieldUpdateTime: - return m.UpdateTime() - } - return nil, false -} - -// OldField returns the old value of the field from the database. An error is -// returned if the mutation operation is not UpdateOne, or the query to the -// database failed. -func (m *AdminMutation) OldField(ctx context.Context, name string) (ent.Value, error) { - switch name { - case admin.FieldName: - return m.OldName(ctx) - case admin.FieldEmail: - return m.OldEmail(ctx) - case admin.FieldAvatar: - return m.OldAvatar(ctx) - case admin.FieldAccess: - return m.OldAccess(ctx) - case admin.FieldPassword: - return m.OldPassword(ctx) - case admin.FieldCreateTime: - return m.OldCreateTime(ctx) - case admin.FieldUpdateTime: - return m.OldUpdateTime(ctx) - } - return nil, fmt.Errorf("unknown Admin field %s", name) -} - -// SetField sets the value of a field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *AdminMutation) SetField(name string, value ent.Value) error { - switch name { - case admin.FieldName: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetName(v) - return nil - case admin.FieldEmail: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetEmail(v) - return nil - case admin.FieldAvatar: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAvatar(v) - return nil - case admin.FieldAccess: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetAccess(v) - return nil - case admin.FieldPassword: - v, ok := value.(string) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetPassword(v) - return nil - case admin.FieldCreateTime: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetCreateTime(v) - return nil - case admin.FieldUpdateTime: - v, ok := value.(time.Time) - if !ok { - return fmt.Errorf("unexpected type %T for field %s", value, name) - } - m.SetUpdateTime(v) - return nil - } - return fmt.Errorf("unknown Admin field %s", name) -} - -// AddedFields returns all numeric fields that were incremented/decremented during -// this mutation. -func (m *AdminMutation) AddedFields() []string { - return nil -} - -// AddedField returns the numeric value that was incremented/decremented on a field -// with the given name. The second boolean return value indicates that this field -// was not set, or was not defined in the schema. -func (m *AdminMutation) AddedField(name string) (ent.Value, bool) { - return nil, false -} - -// AddField adds the value to the field with the given name. It returns an error if -// the field is not defined in the schema, or if the type mismatched the field -// type. -func (m *AdminMutation) AddField(name string, value ent.Value) error { - switch name { - } - return fmt.Errorf("unknown Admin numeric field %s", name) -} - -// ClearedFields returns all nullable fields that were cleared during this -// mutation. -func (m *AdminMutation) ClearedFields() []string { - return nil -} - -// FieldCleared returns a boolean indicating if a field with the given name was -// cleared in this mutation. -func (m *AdminMutation) FieldCleared(name string) bool { - _, ok := m.clearedFields[name] - return ok -} - -// ClearField clears the value of the field with the given name. It returns an -// error if the field is not defined in the schema. -func (m *AdminMutation) ClearField(name string) error { - return fmt.Errorf("unknown Admin nullable field %s", name) -} - -// ResetField resets all changes in the mutation for the field with the given name. -// It returns an error if the field is not defined in the schema. -func (m *AdminMutation) ResetField(name string) error { - switch name { - case admin.FieldName: - m.ResetName() - return nil - case admin.FieldEmail: - m.ResetEmail() - return nil - case admin.FieldAvatar: - m.ResetAvatar() - return nil - case admin.FieldAccess: - m.ResetAccess() - return nil - case admin.FieldPassword: - m.ResetPassword() - return nil - case admin.FieldCreateTime: - m.ResetCreateTime() - return nil - case admin.FieldUpdateTime: - m.ResetUpdateTime() - return nil - } - return fmt.Errorf("unknown Admin field %s", name) -} - -// AddedEdges returns all edge names that were set/added in this mutation. -func (m *AdminMutation) AddedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// AddedIDs returns all IDs (to other nodes) that were added for the given edge -// name in this mutation. -func (m *AdminMutation) AddedIDs(name string) []ent.Value { - return nil -} - -// RemovedEdges returns all edge names that were removed in this mutation. -func (m *AdminMutation) RemovedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with -// the given name in this mutation. -func (m *AdminMutation) RemovedIDs(name string) []ent.Value { - return nil -} - -// ClearedEdges returns all edge names that were cleared in this mutation. -func (m *AdminMutation) ClearedEdges() []string { - edges := make([]string, 0, 0) - return edges -} - -// EdgeCleared returns a boolean which indicates if the edge with the given name -// was cleared in this mutation. -func (m *AdminMutation) EdgeCleared(name string) bool { - return false -} - -// ClearEdge clears the value of the edge with the given name. It returns an error -// if that edge is not defined in the schema. -func (m *AdminMutation) ClearEdge(name string) error { - return fmt.Errorf("unknown Admin unique edge %s", name) -} - -// ResetEdge resets all changes to the edge with the given name in this mutation. -// It returns an error if the edge is not defined in the schema. -func (m *AdminMutation) ResetEdge(name string) error { - return fmt.Errorf("unknown Admin edge %s", name) -} diff --git a/internal/data/ent/predicate/predicate.go b/internal/data/ent/predicate/predicate.go deleted file mode 100644 index 1c3f480..0000000 --- a/internal/data/ent/predicate/predicate.go +++ /dev/null @@ -1,10 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package predicate - -import ( - "entgo.io/ent/dialect/sql" -) - -// Admin is the predicate function for admin builders. -type Admin func(*sql.Selector) diff --git a/internal/data/ent/runtime.go b/internal/data/ent/runtime.go deleted file mode 100644 index 82d5dc5..0000000 --- a/internal/data/ent/runtime.go +++ /dev/null @@ -1,48 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "time" - - "kra/internal/data/ent/admin" - "kra/internal/data/ent/schema" -) - -// The init function reads all schema descriptors with runtime code -// (default values, validators, hooks and policies) and stitches it -// to their package variables. -func init() { - adminFields := schema.Admin{}.Fields() - _ = adminFields - // adminDescName is the schema descriptor for name field. - adminDescName := adminFields[1].Descriptor() - // admin.DefaultName holds the default value on creation for the name field. - admin.DefaultName = adminDescName.Default.(string) - // adminDescEmail is the schema descriptor for email field. - adminDescEmail := adminFields[2].Descriptor() - // admin.DefaultEmail holds the default value on creation for the email field. - admin.DefaultEmail = adminDescEmail.Default.(string) - // adminDescAvatar is the schema descriptor for avatar field. - adminDescAvatar := adminFields[3].Descriptor() - // admin.DefaultAvatar holds the default value on creation for the avatar field. - admin.DefaultAvatar = adminDescAvatar.Default.(string) - // adminDescAccess is the schema descriptor for access field. - adminDescAccess := adminFields[4].Descriptor() - // admin.DefaultAccess holds the default value on creation for the access field. - admin.DefaultAccess = adminDescAccess.Default.(string) - // adminDescPassword is the schema descriptor for password field. - adminDescPassword := adminFields[5].Descriptor() - // admin.DefaultPassword holds the default value on creation for the password field. - admin.DefaultPassword = adminDescPassword.Default.(string) - // adminDescCreateTime is the schema descriptor for create_time field. - adminDescCreateTime := adminFields[6].Descriptor() - // admin.DefaultCreateTime holds the default value on creation for the create_time field. - admin.DefaultCreateTime = adminDescCreateTime.Default.(func() time.Time) - // adminDescUpdateTime is the schema descriptor for update_time field. - adminDescUpdateTime := adminFields[7].Descriptor() - // admin.DefaultUpdateTime holds the default value on creation for the update_time field. - admin.DefaultUpdateTime = adminDescUpdateTime.Default.(func() time.Time) - // admin.UpdateDefaultUpdateTime holds the default value on update for the update_time field. - admin.UpdateDefaultUpdateTime = adminDescUpdateTime.UpdateDefault.(func() time.Time) -} diff --git a/internal/data/ent/runtime/runtime.go b/internal/data/ent/runtime/runtime.go deleted file mode 100644 index 3f91d65..0000000 --- a/internal/data/ent/runtime/runtime.go +++ /dev/null @@ -1,10 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package runtime - -// The schema-stitching logic is generated in kra/internal/data/ent/runtime.go - -const ( - Version = "v0.14.5" // Version of ent codegen. - Sum = "h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4=" // Sum of ent codegen. -) diff --git a/internal/data/ent/schema/admin.go b/internal/data/ent/schema/admin.go deleted file mode 100644 index ad07e95..0000000 --- a/internal/data/ent/schema/admin.go +++ /dev/null @@ -1,27 +0,0 @@ -package schema - -import ( - "time" - - "entgo.io/ent" - "entgo.io/ent/schema/field" -) - -// Admin holds the schema definition for the Admin entity. -type Admin struct { - ent.Schema -} - -// Fields of the Admin. -func (Admin) Fields() []ent.Field { - return []ent.Field{ - field.Int64("id").Unique().Immutable(), - field.String("name").Default(""), - field.String("email").Default(""), - field.String("avatar").Default(""), - field.String("access").Default(""), - field.String("password").Default(""), - field.Time("create_time").Default(time.Now).Immutable(), - field.Time("update_time").Default(time.Now).UpdateDefault(time.Now), - } -} diff --git a/internal/data/ent/tx.go b/internal/data/ent/tx.go deleted file mode 100644 index 2789ff3..0000000 --- a/internal/data/ent/tx.go +++ /dev/null @@ -1,236 +0,0 @@ -// Code generated by ent, DO NOT EDIT. - -package ent - -import ( - "context" - stdsql "database/sql" - "fmt" - "sync" - - "entgo.io/ent/dialect" -) - -// Tx is a transactional client that is created by calling Client.Tx(). -type Tx struct { - config - // Admin is the client for interacting with the Admin builders. - Admin *AdminClient - - // lazily loaded. - client *Client - clientOnce sync.Once - // ctx lives for the life of the transaction. It is - // the same context used by the underlying connection. - ctx context.Context -} - -type ( - // Committer is the interface that wraps the Commit method. - Committer interface { - Commit(context.Context, *Tx) error - } - - // The CommitFunc type is an adapter to allow the use of ordinary - // function as a Committer. If f is a function with the appropriate - // signature, CommitFunc(f) is a Committer that calls f. - CommitFunc func(context.Context, *Tx) error - - // CommitHook defines the "commit middleware". A function that gets a Committer - // and returns a Committer. For example: - // - // hook := func(next ent.Committer) ent.Committer { - // return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error { - // // Do some stuff before. - // if err := next.Commit(ctx, tx); err != nil { - // return err - // } - // // Do some stuff after. - // return nil - // }) - // } - // - CommitHook func(Committer) Committer -) - -// Commit calls f(ctx, m). -func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { - return f(ctx, tx) -} - -// Commit commits the transaction. -func (tx *Tx) Commit() error { - txDriver := tx.config.driver.(*txDriver) - var fn Committer = CommitFunc(func(context.Context, *Tx) error { - return txDriver.tx.Commit() - }) - txDriver.mu.Lock() - hooks := append([]CommitHook(nil), txDriver.onCommit...) - txDriver.mu.Unlock() - for i := len(hooks) - 1; i >= 0; i-- { - fn = hooks[i](fn) - } - return fn.Commit(tx.ctx, tx) -} - -// OnCommit adds a hook to call on commit. -func (tx *Tx) OnCommit(f CommitHook) { - txDriver := tx.config.driver.(*txDriver) - txDriver.mu.Lock() - txDriver.onCommit = append(txDriver.onCommit, f) - txDriver.mu.Unlock() -} - -type ( - // Rollbacker is the interface that wraps the Rollback method. - Rollbacker interface { - Rollback(context.Context, *Tx) error - } - - // The RollbackFunc type is an adapter to allow the use of ordinary - // function as a Rollbacker. If f is a function with the appropriate - // signature, RollbackFunc(f) is a Rollbacker that calls f. - RollbackFunc func(context.Context, *Tx) error - - // RollbackHook defines the "rollback middleware". A function that gets a Rollbacker - // and returns a Rollbacker. For example: - // - // hook := func(next ent.Rollbacker) ent.Rollbacker { - // return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error { - // // Do some stuff before. - // if err := next.Rollback(ctx, tx); err != nil { - // return err - // } - // // Do some stuff after. - // return nil - // }) - // } - // - RollbackHook func(Rollbacker) Rollbacker -) - -// Rollback calls f(ctx, m). -func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { - return f(ctx, tx) -} - -// Rollback rollbacks the transaction. -func (tx *Tx) Rollback() error { - txDriver := tx.config.driver.(*txDriver) - var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { - return txDriver.tx.Rollback() - }) - txDriver.mu.Lock() - hooks := append([]RollbackHook(nil), txDriver.onRollback...) - txDriver.mu.Unlock() - for i := len(hooks) - 1; i >= 0; i-- { - fn = hooks[i](fn) - } - return fn.Rollback(tx.ctx, tx) -} - -// OnRollback adds a hook to call on rollback. -func (tx *Tx) OnRollback(f RollbackHook) { - txDriver := tx.config.driver.(*txDriver) - txDriver.mu.Lock() - txDriver.onRollback = append(txDriver.onRollback, f) - txDriver.mu.Unlock() -} - -// Client returns a Client that binds to current transaction. -func (tx *Tx) Client() *Client { - tx.clientOnce.Do(func() { - tx.client = &Client{config: tx.config} - tx.client.init() - }) - return tx.client -} - -func (tx *Tx) init() { - tx.Admin = NewAdminClient(tx.config) -} - -// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. -// The idea is to support transactions without adding any extra code to the builders. -// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. -// Commit and Rollback are nop for the internal builders and the user must call one -// of them in order to commit or rollback the transaction. -// -// If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: Admin.QueryXXX(), the query will be executed -// through the driver which created this transaction. -// -// Note that txDriver is not goroutine safe. -type txDriver struct { - // the driver we started the transaction from. - drv dialect.Driver - // tx is the underlying transaction. - tx dialect.Tx - // completion hooks. - mu sync.Mutex - onCommit []CommitHook - onRollback []RollbackHook -} - -// newTx creates a new transactional driver. -func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { - tx, err := drv.Tx(ctx) - if err != nil { - return nil, err - } - return &txDriver{tx: tx, drv: drv}, nil -} - -// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls -// from the internal builders. Should be called only by the internal builders. -func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } - -// Dialect returns the dialect of the driver we started the transaction from. -func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } - -// Close is a nop close. -func (*txDriver) Close() error { return nil } - -// Commit is a nop commit for the internal builders. -// User must call `Tx.Commit` in order to commit the transaction. -func (*txDriver) Commit() error { return nil } - -// Rollback is a nop rollback for the internal builders. -// User must call `Tx.Rollback` in order to rollback the transaction. -func (*txDriver) Rollback() error { return nil } - -// Exec calls tx.Exec. -func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error { - return tx.tx.Exec(ctx, query, args, v) -} - -// Query calls tx.Query. -func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error { - return tx.tx.Query(ctx, query, args, v) -} - -var _ dialect.Driver = (*txDriver)(nil) - -// ExecContext allows calling the underlying ExecContext method of the transaction if it is supported by it. -// See, database/sql#Tx.ExecContext for more information. -func (tx *txDriver) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) { - ex, ok := tx.tx.(interface { - ExecContext(context.Context, string, ...any) (stdsql.Result, error) - }) - if !ok { - return nil, fmt.Errorf("Tx.ExecContext is not supported") - } - return ex.ExecContext(ctx, query, args...) -} - -// QueryContext allows calling the underlying QueryContext method of the transaction if it is supported by it. -// See, database/sql#Tx.QueryContext for more information. -func (tx *txDriver) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) { - q, ok := tx.tx.(interface { - QueryContext(context.Context, string, ...any) (*stdsql.Rows, error) - }) - if !ok { - return nil, fmt.Errorf("Tx.QueryContext is not supported") - } - return q.QueryContext(ctx, query, args...) -}