feat(schema): 添加基础混入定义公共时间字段
This commit is contained in:
1 parent
5281459fcb
commit
fe86c081f4
16 files changed
+1715
-14
No files matched your search
@@ -24,6 +24,11 @@ func Init(driver string, dsn string) error {
|
||||
return fmt.Errorf("打开数据库连接失败 [%s]: %w", driver, err)
|
||||
}
|
||||
|
||||
// 立即 Ping 数据库,验证账号密码及数据库是否存在
|
||||
if err := db.Ping(); err != nil {
|
||||
return fmt.Errorf("无法连接至数据库 [%s],请检查账号密码或数据库是否存在: %w", driver, err)
|
||||
}
|
||||
|
||||
// 连接池设置
|
||||
db.SetMaxIdleConns(10)
|
||||
db.SetMaxOpenConns(100)
|
||||
|
||||
@@ -11,6 +11,13 @@ var (
|
||||
// UsersColumns holds the columns for the "users" table.
|
||||
UsersColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
{Name: "updated_at", Type: field.TypeTime},
|
||||
{Name: "username", Type: field.TypeString, Unique: true},
|
||||
{Name: "password", Type: field.TypeString},
|
||||
{Name: "email", Type: field.TypeString, Nullable: true},
|
||||
{Name: "ip", Type: field.TypeString, Nullable: true},
|
||||
{Name: "addr", Type: field.TypeString, Nullable: true, Size: 500},
|
||||
}
|
||||
// UsersTable holds the schema information for the "users" table.
|
||||
UsersTable = &schema.Table{
|
||||
|
||||
+450
-2
@@ -4,10 +4,12 @@ package ent
|
||||
|
||||
import (
|
||||
"EnGin/internal/ent/predicate"
|
||||
"EnGin/internal/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -31,6 +33,13 @@ type UserMutation struct {
|
||||
op Op
|
||||
typ string
|
||||
id *int
|
||||
created_at *time.Time
|
||||
updated_at *time.Time
|
||||
username *string
|
||||
password *string
|
||||
email *string
|
||||
ip *string
|
||||
addr *string
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
oldValue func(context.Context) (*User, error)
|
||||
@@ -135,6 +144,297 @@ func (m *UserMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (m *UserMutation) SetCreatedAt(t time.Time) {
|
||||
m.created_at = &t
|
||||
}
|
||||
|
||||
// CreatedAt returns the value of the "created_at" field in the mutation.
|
||||
func (m *UserMutation) CreatedAt() (r time.Time, exists bool) {
|
||||
v := m.created_at
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldCreatedAt returns the old "created_at" field's value of the User entity.
|
||||
// If the User 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 *UserMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldCreatedAt requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err)
|
||||
}
|
||||
return oldValue.CreatedAt, nil
|
||||
}
|
||||
|
||||
// ResetCreatedAt resets all changes to the "created_at" field.
|
||||
func (m *UserMutation) ResetCreatedAt() {
|
||||
m.created_at = nil
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (m *UserMutation) SetUpdatedAt(t time.Time) {
|
||||
m.updated_at = &t
|
||||
}
|
||||
|
||||
// UpdatedAt returns the value of the "updated_at" field in the mutation.
|
||||
func (m *UserMutation) UpdatedAt() (r time.Time, exists bool) {
|
||||
v := m.updated_at
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldUpdatedAt returns the old "updated_at" field's value of the User entity.
|
||||
// If the User 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 *UserMutation) OldUpdatedAt(ctx context.Context) (v time.Time, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUpdatedAt is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldUpdatedAt requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUpdatedAt: %w", err)
|
||||
}
|
||||
return oldValue.UpdatedAt, nil
|
||||
}
|
||||
|
||||
// ResetUpdatedAt resets all changes to the "updated_at" field.
|
||||
func (m *UserMutation) ResetUpdatedAt() {
|
||||
m.updated_at = nil
|
||||
}
|
||||
|
||||
// SetUsername sets the "username" field.
|
||||
func (m *UserMutation) SetUsername(s string) {
|
||||
m.username = &s
|
||||
}
|
||||
|
||||
// Username returns the value of the "username" field in the mutation.
|
||||
func (m *UserMutation) Username() (r string, exists bool) {
|
||||
v := m.username
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldUsername returns the old "username" field's value of the User entity.
|
||||
// If the User 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 *UserMutation) OldUsername(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUsername is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldUsername requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUsername: %w", err)
|
||||
}
|
||||
return oldValue.Username, nil
|
||||
}
|
||||
|
||||
// ResetUsername resets all changes to the "username" field.
|
||||
func (m *UserMutation) ResetUsername() {
|
||||
m.username = nil
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (m *UserMutation) SetPassword(s string) {
|
||||
m.password = &s
|
||||
}
|
||||
|
||||
// Password returns the value of the "password" field in the mutation.
|
||||
func (m *UserMutation) 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 User entity.
|
||||
// If the User 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 *UserMutation) 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 *UserMutation) ResetPassword() {
|
||||
m.password = nil
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (m *UserMutation) SetEmail(s string) {
|
||||
m.email = &s
|
||||
}
|
||||
|
||||
// Email returns the value of the "email" field in the mutation.
|
||||
func (m *UserMutation) 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 User entity.
|
||||
// If the User 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 *UserMutation) 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
|
||||
}
|
||||
|
||||
// ClearEmail clears the value of the "email" field.
|
||||
func (m *UserMutation) ClearEmail() {
|
||||
m.email = nil
|
||||
m.clearedFields[user.FieldEmail] = struct{}{}
|
||||
}
|
||||
|
||||
// EmailCleared returns if the "email" field was cleared in this mutation.
|
||||
func (m *UserMutation) EmailCleared() bool {
|
||||
_, ok := m.clearedFields[user.FieldEmail]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetEmail resets all changes to the "email" field.
|
||||
func (m *UserMutation) ResetEmail() {
|
||||
m.email = nil
|
||||
delete(m.clearedFields, user.FieldEmail)
|
||||
}
|
||||
|
||||
// SetIP sets the "ip" field.
|
||||
func (m *UserMutation) SetIP(s string) {
|
||||
m.ip = &s
|
||||
}
|
||||
|
||||
// IP returns the value of the "ip" field in the mutation.
|
||||
func (m *UserMutation) IP() (r string, exists bool) {
|
||||
v := m.ip
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldIP returns the old "ip" field's value of the User entity.
|
||||
// If the User 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 *UserMutation) OldIP(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldIP is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldIP requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldIP: %w", err)
|
||||
}
|
||||
return oldValue.IP, nil
|
||||
}
|
||||
|
||||
// ClearIP clears the value of the "ip" field.
|
||||
func (m *UserMutation) ClearIP() {
|
||||
m.ip = nil
|
||||
m.clearedFields[user.FieldIP] = struct{}{}
|
||||
}
|
||||
|
||||
// IPCleared returns if the "ip" field was cleared in this mutation.
|
||||
func (m *UserMutation) IPCleared() bool {
|
||||
_, ok := m.clearedFields[user.FieldIP]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetIP resets all changes to the "ip" field.
|
||||
func (m *UserMutation) ResetIP() {
|
||||
m.ip = nil
|
||||
delete(m.clearedFields, user.FieldIP)
|
||||
}
|
||||
|
||||
// SetAddr sets the "addr" field.
|
||||
func (m *UserMutation) SetAddr(s string) {
|
||||
m.addr = &s
|
||||
}
|
||||
|
||||
// Addr returns the value of the "addr" field in the mutation.
|
||||
func (m *UserMutation) Addr() (r string, exists bool) {
|
||||
v := m.addr
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldAddr returns the old "addr" field's value of the User entity.
|
||||
// If the User 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 *UserMutation) OldAddr(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldAddr is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldAddr requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldAddr: %w", err)
|
||||
}
|
||||
return oldValue.Addr, nil
|
||||
}
|
||||
|
||||
// ClearAddr clears the value of the "addr" field.
|
||||
func (m *UserMutation) ClearAddr() {
|
||||
m.addr = nil
|
||||
m.clearedFields[user.FieldAddr] = struct{}{}
|
||||
}
|
||||
|
||||
// AddrCleared returns if the "addr" field was cleared in this mutation.
|
||||
func (m *UserMutation) AddrCleared() bool {
|
||||
_, ok := m.clearedFields[user.FieldAddr]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetAddr resets all changes to the "addr" field.
|
||||
func (m *UserMutation) ResetAddr() {
|
||||
m.addr = nil
|
||||
delete(m.clearedFields, user.FieldAddr)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserMutation builder.
|
||||
func (m *UserMutation) Where(ps ...predicate.User) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
@@ -169,7 +469,28 @@ func (m *UserMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *UserMutation) Fields() []string {
|
||||
fields := make([]string, 0, 0)
|
||||
fields := make([]string, 0, 7)
|
||||
if m.created_at != nil {
|
||||
fields = append(fields, user.FieldCreatedAt)
|
||||
}
|
||||
if m.updated_at != nil {
|
||||
fields = append(fields, user.FieldUpdatedAt)
|
||||
}
|
||||
if m.username != nil {
|
||||
fields = append(fields, user.FieldUsername)
|
||||
}
|
||||
if m.password != nil {
|
||||
fields = append(fields, user.FieldPassword)
|
||||
}
|
||||
if m.email != nil {
|
||||
fields = append(fields, user.FieldEmail)
|
||||
}
|
||||
if m.ip != nil {
|
||||
fields = append(fields, user.FieldIP)
|
||||
}
|
||||
if m.addr != nil {
|
||||
fields = append(fields, user.FieldAddr)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
@@ -177,6 +498,22 @@ func (m *UserMutation) Fields() []string {
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *UserMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case user.FieldCreatedAt:
|
||||
return m.CreatedAt()
|
||||
case user.FieldUpdatedAt:
|
||||
return m.UpdatedAt()
|
||||
case user.FieldUsername:
|
||||
return m.Username()
|
||||
case user.FieldPassword:
|
||||
return m.Password()
|
||||
case user.FieldEmail:
|
||||
return m.Email()
|
||||
case user.FieldIP:
|
||||
return m.IP()
|
||||
case user.FieldAddr:
|
||||
return m.Addr()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
@@ -184,6 +521,22 @@ func (m *UserMutation) Field(name string) (ent.Value, bool) {
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case user.FieldCreatedAt:
|
||||
return m.OldCreatedAt(ctx)
|
||||
case user.FieldUpdatedAt:
|
||||
return m.OldUpdatedAt(ctx)
|
||||
case user.FieldUsername:
|
||||
return m.OldUsername(ctx)
|
||||
case user.FieldPassword:
|
||||
return m.OldPassword(ctx)
|
||||
case user.FieldEmail:
|
||||
return m.OldEmail(ctx)
|
||||
case user.FieldIP:
|
||||
return m.OldIP(ctx)
|
||||
case user.FieldAddr:
|
||||
return m.OldAddr(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown User field %s", name)
|
||||
}
|
||||
|
||||
@@ -192,6 +545,55 @@ func (m *UserMutation) OldField(ctx context.Context, name string) (ent.Value, er
|
||||
// type.
|
||||
func (m *UserMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case user.FieldCreatedAt:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetCreatedAt(v)
|
||||
return nil
|
||||
case user.FieldUpdatedAt:
|
||||
v, ok := value.(time.Time)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUpdatedAt(v)
|
||||
return nil
|
||||
case user.FieldUsername:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUsername(v)
|
||||
return nil
|
||||
case user.FieldPassword:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetPassword(v)
|
||||
return nil
|
||||
case user.FieldEmail:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetEmail(v)
|
||||
return nil
|
||||
case user.FieldIP:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetIP(v)
|
||||
return nil
|
||||
case user.FieldAddr:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetAddr(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown User field %s", name)
|
||||
}
|
||||
@@ -213,13 +615,25 @@ func (m *UserMutation) AddedField(name string) (ent.Value, bool) {
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *UserMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown User numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *UserMutation) ClearedFields() []string {
|
||||
return nil
|
||||
var fields []string
|
||||
if m.FieldCleared(user.FieldEmail) {
|
||||
fields = append(fields, user.FieldEmail)
|
||||
}
|
||||
if m.FieldCleared(user.FieldIP) {
|
||||
fields = append(fields, user.FieldIP)
|
||||
}
|
||||
if m.FieldCleared(user.FieldAddr) {
|
||||
fields = append(fields, user.FieldAddr)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
@@ -232,12 +646,46 @@ func (m *UserMutation) FieldCleared(name string) bool {
|
||||
// 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 *UserMutation) ClearField(name string) error {
|
||||
switch name {
|
||||
case user.FieldEmail:
|
||||
m.ClearEmail()
|
||||
return nil
|
||||
case user.FieldIP:
|
||||
m.ClearIP()
|
||||
return nil
|
||||
case user.FieldAddr:
|
||||
m.ClearAddr()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown User 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 *UserMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case user.FieldCreatedAt:
|
||||
m.ResetCreatedAt()
|
||||
return nil
|
||||
case user.FieldUpdatedAt:
|
||||
m.ResetUpdatedAt()
|
||||
return nil
|
||||
case user.FieldUsername:
|
||||
m.ResetUsername()
|
||||
return nil
|
||||
case user.FieldPassword:
|
||||
m.ResetPassword()
|
||||
return nil
|
||||
case user.FieldEmail:
|
||||
m.ResetEmail()
|
||||
return nil
|
||||
case user.FieldIP:
|
||||
m.ResetIP()
|
||||
return nil
|
||||
case user.FieldAddr:
|
||||
m.ResetAddr()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown User field %s", name)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,45 @@
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"EnGin/internal/ent/schema"
|
||||
"EnGin/internal/ent/user"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 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() {
|
||||
userMixin := schema.User{}.Mixin()
|
||||
userMixinFields0 := userMixin[0].Fields()
|
||||
_ = userMixinFields0
|
||||
userFields := schema.User{}.Fields()
|
||||
_ = userFields
|
||||
// userDescCreatedAt is the schema descriptor for created_at field.
|
||||
userDescCreatedAt := userMixinFields0[0].Descriptor()
|
||||
// user.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
user.DefaultCreatedAt = userDescCreatedAt.Default.(func() time.Time)
|
||||
// userDescUpdatedAt is the schema descriptor for updated_at field.
|
||||
userDescUpdatedAt := userMixinFields0[1].Descriptor()
|
||||
// user.DefaultUpdatedAt holds the default value on creation for the updated_at field.
|
||||
user.DefaultUpdatedAt = userDescUpdatedAt.Default.(func() time.Time)
|
||||
// user.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
|
||||
user.UpdateDefaultUpdatedAt = userDescUpdatedAt.UpdateDefault.(func() time.Time)
|
||||
// userDescUsername is the schema descriptor for username field.
|
||||
userDescUsername := userFields[0].Descriptor()
|
||||
// user.UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
||||
user.UsernameValidator = userDescUsername.Validators[0].(func(string) error)
|
||||
// userDescEmail is the schema descriptor for email field.
|
||||
userDescEmail := userFields[2].Descriptor()
|
||||
// user.EmailValidator is a validator for the "email" field. It is called by the builders before save.
|
||||
user.EmailValidator = userDescEmail.Validators[0].(func(string) error)
|
||||
// userDescIP is the schema descriptor for ip field.
|
||||
userDescIP := userFields[3].Descriptor()
|
||||
// user.IPValidator is a validator for the "ip" field. It is called by the builders before save.
|
||||
user.IPValidator = userDescIP.Validators[0].(func(string) error)
|
||||
// userDescAddr is the schema descriptor for addr field.
|
||||
userDescAddr := userFields[4].Descriptor()
|
||||
// user.AddrValidator is a validator for the "addr" field. It is called by the builders before save.
|
||||
user.AddrValidator = userDescAddr.Validators[0].(func(string) error)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/mixin"
|
||||
)
|
||||
|
||||
// BaseMixin 定义公共的基础混入
|
||||
type BaseMixin struct {
|
||||
mixin.Schema
|
||||
}
|
||||
|
||||
// Fields 定义所有表都拥有的公共字段
|
||||
func (BaseMixin) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
// 创建时间:默认当前时间,不可修改(Immutable)
|
||||
field.Time("created_at").
|
||||
Default(time.Now).
|
||||
Immutable(),
|
||||
|
||||
// 更新时间:默认当前时间,并且在每次数据 Update 时自动更新为当前时间
|
||||
field.Time("updated_at").
|
||||
Default(time.Now).
|
||||
UpdateDefault(time.Now),
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,41 @@
|
||||
package schema
|
||||
|
||||
import "entgo.io/ent"
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// User holds the schema definition for the User entity.
|
||||
type User struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
func (User) Mixin() []ent.Mixin {
|
||||
return []ent.Mixin{
|
||||
BaseMixin{},
|
||||
}
|
||||
}
|
||||
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
return nil
|
||||
return []ent.Field{
|
||||
field.String("username").
|
||||
Unique().
|
||||
NotEmpty(),
|
||||
field.String("password").
|
||||
Sensitive(),
|
||||
field.String("email").
|
||||
Optional().
|
||||
Match(regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$`)), // 邮箱格式正则校验
|
||||
field.String("ip").
|
||||
Optional().
|
||||
Match(regexp.MustCompile(`^((25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(25[0-5]|2[0-4]\d|[01]?\d\d?)$|^([\da-fA-F]{1,4}:){7}[\da-fA-F]{1,4}$`)),
|
||||
field.String("addr").
|
||||
Optional().
|
||||
MaxLen(500),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the User.
|
||||
|
||||
+83
-3
@@ -6,6 +6,7 @@ import (
|
||||
"EnGin/internal/ent/user"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@@ -13,9 +14,23 @@ import (
|
||||
|
||||
// User is the model entity for the User schema.
|
||||
type User struct {
|
||||
config
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
ID int `json:"id,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// Username holds the value of the "username" field.
|
||||
Username string `json:"username,omitempty"`
|
||||
// Password holds the value of the "password" field.
|
||||
Password string `json:"-"`
|
||||
// Email holds the value of the "email" field.
|
||||
Email string `json:"email,omitempty"`
|
||||
// IP holds the value of the "ip" field.
|
||||
IP string `json:"ip,omitempty"`
|
||||
// Addr holds the value of the "addr" field.
|
||||
Addr string `json:"addr,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
@@ -26,6 +41,10 @@ func (*User) scanValues(columns []string) ([]any, error) {
|
||||
switch columns[i] {
|
||||
case user.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case user.FieldUsername, user.FieldPassword, user.FieldEmail, user.FieldIP, user.FieldAddr:
|
||||
values[i] = new(sql.NullString)
|
||||
case user.FieldCreatedAt, user.FieldUpdatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
@@ -47,6 +66,48 @@ func (_m *User) assignValues(columns []string, values []any) error {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
_m.ID = int(value.Int64)
|
||||
case user.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.CreatedAt = value.Time
|
||||
}
|
||||
case user.FieldUpdatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UpdatedAt = value.Time
|
||||
}
|
||||
case user.FieldUsername:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field username", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Username = value.String
|
||||
}
|
||||
case user.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 user.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 user.FieldIP:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field ip", values[i])
|
||||
} else if value.Valid {
|
||||
_m.IP = value.String
|
||||
}
|
||||
case user.FieldAddr:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field addr", values[i])
|
||||
} else if value.Valid {
|
||||
_m.Addr = value.String
|
||||
}
|
||||
default:
|
||||
_m.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@@ -82,7 +143,26 @@ func (_m *User) Unwrap() *User {
|
||||
func (_m *User) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("User(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v", _m.ID))
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated_at=")
|
||||
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("username=")
|
||||
builder.WriteString(_m.Username)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("password=<sensitive>")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("email=")
|
||||
builder.WriteString(_m.Email)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("ip=")
|
||||
builder.WriteString(_m.IP)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("addr=")
|
||||
builder.WriteString(_m.Addr)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
@@ -11,6 +13,20 @@ const (
|
||||
Label = "user"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
|
||||
FieldUpdatedAt = "updated_at"
|
||||
// FieldUsername holds the string denoting the username field in the database.
|
||||
FieldUsername = "username"
|
||||
// FieldPassword holds the string denoting the password field in the database.
|
||||
FieldPassword = "password"
|
||||
// FieldEmail holds the string denoting the email field in the database.
|
||||
FieldEmail = "email"
|
||||
// FieldIP holds the string denoting the ip field in the database.
|
||||
FieldIP = "ip"
|
||||
// FieldAddr holds the string denoting the addr field in the database.
|
||||
FieldAddr = "addr"
|
||||
// Table holds the table name of the user in the database.
|
||||
Table = "users"
|
||||
)
|
||||
@@ -18,6 +34,13 @@ const (
|
||||
// Columns holds all SQL columns for user fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldCreatedAt,
|
||||
FieldUpdatedAt,
|
||||
FieldUsername,
|
||||
FieldPassword,
|
||||
FieldEmail,
|
||||
FieldIP,
|
||||
FieldAddr,
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@@ -30,6 +53,23 @@ func ValidColumn(column string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
var (
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt func() time.Time
|
||||
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
|
||||
DefaultUpdatedAt func() time.Time
|
||||
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
|
||||
UpdateDefaultUpdatedAt func() time.Time
|
||||
// UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
||||
UsernameValidator func(string) error
|
||||
// EmailValidator is a validator for the "email" field. It is called by the builders before save.
|
||||
EmailValidator func(string) error
|
||||
// IPValidator is a validator for the "ip" field. It is called by the builders before save.
|
||||
IPValidator func(string) error
|
||||
// AddrValidator is a validator for the "addr" field. It is called by the builders before save.
|
||||
AddrValidator func(string) error
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the User queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
@@ -37,3 +77,38 @@ type OrderOption func(*sql.Selector)
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdatedAt orders the results by the updated_at field.
|
||||
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUsername orders the results by the username field.
|
||||
func ByUsername(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUsername, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByPassword orders the results by the password field.
|
||||
func ByPassword(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldPassword, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByEmail orders the results by the email field.
|
||||
func ByEmail(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldEmail, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByIP orders the results by the ip field.
|
||||
func ByIP(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIP, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAddr orders the results by the addr field.
|
||||
func ByAddr(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldAddr, opts...).ToFunc()
|
||||
}
|
||||
@@ -4,6 +4,7 @@ package user
|
||||
|
||||
import (
|
||||
"EnGin/internal/ent/predicate"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
@@ -53,6 +54,476 @@ func IDLTE(id int) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
|
||||
func UpdatedAt(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// Username applies equality check predicate on the "username" field. It's identical to UsernameEQ.
|
||||
func Username(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldUsername, v))
|
||||
}
|
||||
|
||||
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
|
||||
func Password(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// Email applies equality check predicate on the "email" field. It's identical to EmailEQ.
|
||||
func Email(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldEmail, v))
|
||||
}
|
||||
|
||||
// IP applies equality check predicate on the "ip" field. It's identical to IPEQ.
|
||||
func IP(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldIP, v))
|
||||
}
|
||||
|
||||
// Addr applies equality check predicate on the "addr" field. It's identical to AddrEQ.
|
||||
func Addr(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldAddr, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
|
||||
func UpdatedAtEQ(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
|
||||
func UpdatedAtNEQ(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtIn applies the In predicate on the "updated_at" field.
|
||||
func UpdatedAtIn(vs ...time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
|
||||
func UpdatedAtNotIn(vs ...time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldUpdatedAt, vs...))
|
||||
}
|
||||
|
||||
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
|
||||
func UpdatedAtGT(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
|
||||
func UpdatedAtGTE(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
|
||||
func UpdatedAtLT(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
|
||||
func UpdatedAtLTE(v time.Time) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldUpdatedAt, v))
|
||||
}
|
||||
|
||||
// UsernameEQ applies the EQ predicate on the "username" field.
|
||||
func UsernameEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameNEQ applies the NEQ predicate on the "username" field.
|
||||
func UsernameNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameIn applies the In predicate on the "username" field.
|
||||
func UsernameIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldUsername, vs...))
|
||||
}
|
||||
|
||||
// UsernameNotIn applies the NotIn predicate on the "username" field.
|
||||
func UsernameNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldUsername, vs...))
|
||||
}
|
||||
|
||||
// UsernameGT applies the GT predicate on the "username" field.
|
||||
func UsernameGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameGTE applies the GTE predicate on the "username" field.
|
||||
func UsernameGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameLT applies the LT predicate on the "username" field.
|
||||
func UsernameLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameLTE applies the LTE predicate on the "username" field.
|
||||
func UsernameLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameContains applies the Contains predicate on the "username" field.
|
||||
func UsernameContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameHasPrefix applies the HasPrefix predicate on the "username" field.
|
||||
func UsernameHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameHasSuffix applies the HasSuffix predicate on the "username" field.
|
||||
func UsernameHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameEqualFold applies the EqualFold predicate on the "username" field.
|
||||
func UsernameEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldUsername, v))
|
||||
}
|
||||
|
||||
// UsernameContainsFold applies the ContainsFold predicate on the "username" field.
|
||||
func UsernameContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldUsername, v))
|
||||
}
|
||||
|
||||
// PasswordEQ applies the EQ predicate on the "password" field.
|
||||
func PasswordEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordNEQ applies the NEQ predicate on the "password" field.
|
||||
func PasswordNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordIn applies the In predicate on the "password" field.
|
||||
func PasswordIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldPassword, vs...))
|
||||
}
|
||||
|
||||
// PasswordNotIn applies the NotIn predicate on the "password" field.
|
||||
func PasswordNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldPassword, vs...))
|
||||
}
|
||||
|
||||
// PasswordGT applies the GT predicate on the "password" field.
|
||||
func PasswordGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordGTE applies the GTE predicate on the "password" field.
|
||||
func PasswordGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordLT applies the LT predicate on the "password" field.
|
||||
func PasswordLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordLTE applies the LTE predicate on the "password" field.
|
||||
func PasswordLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordContains applies the Contains predicate on the "password" field.
|
||||
func PasswordContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordHasPrefix applies the HasPrefix predicate on the "password" field.
|
||||
func PasswordHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordHasSuffix applies the HasSuffix predicate on the "password" field.
|
||||
func PasswordHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordEqualFold applies the EqualFold predicate on the "password" field.
|
||||
func PasswordEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldPassword, v))
|
||||
}
|
||||
|
||||
// PasswordContainsFold applies the ContainsFold predicate on the "password" field.
|
||||
func PasswordContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldPassword, v))
|
||||
}
|
||||
|
||||
// EmailEQ applies the EQ predicate on the "email" field.
|
||||
func EmailEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailNEQ applies the NEQ predicate on the "email" field.
|
||||
func EmailNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailIn applies the In predicate on the "email" field.
|
||||
func EmailIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldEmail, vs...))
|
||||
}
|
||||
|
||||
// EmailNotIn applies the NotIn predicate on the "email" field.
|
||||
func EmailNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldEmail, vs...))
|
||||
}
|
||||
|
||||
// EmailGT applies the GT predicate on the "email" field.
|
||||
func EmailGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailGTE applies the GTE predicate on the "email" field.
|
||||
func EmailGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailLT applies the LT predicate on the "email" field.
|
||||
func EmailLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailLTE applies the LTE predicate on the "email" field.
|
||||
func EmailLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailContains applies the Contains predicate on the "email" field.
|
||||
func EmailContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailHasPrefix applies the HasPrefix predicate on the "email" field.
|
||||
func EmailHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailHasSuffix applies the HasSuffix predicate on the "email" field.
|
||||
func EmailHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailIsNil applies the IsNil predicate on the "email" field.
|
||||
func EmailIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldEmail))
|
||||
}
|
||||
|
||||
// EmailNotNil applies the NotNil predicate on the "email" field.
|
||||
func EmailNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldEmail))
|
||||
}
|
||||
|
||||
// EmailEqualFold applies the EqualFold predicate on the "email" field.
|
||||
func EmailEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldEmail, v))
|
||||
}
|
||||
|
||||
// EmailContainsFold applies the ContainsFold predicate on the "email" field.
|
||||
func EmailContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldEmail, v))
|
||||
}
|
||||
|
||||
// IPEQ applies the EQ predicate on the "ip" field.
|
||||
func IPEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldIP, v))
|
||||
}
|
||||
|
||||
// IPNEQ applies the NEQ predicate on the "ip" field.
|
||||
func IPNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldIP, v))
|
||||
}
|
||||
|
||||
// IPIn applies the In predicate on the "ip" field.
|
||||
func IPIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldIP, vs...))
|
||||
}
|
||||
|
||||
// IPNotIn applies the NotIn predicate on the "ip" field.
|
||||
func IPNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldIP, vs...))
|
||||
}
|
||||
|
||||
// IPGT applies the GT predicate on the "ip" field.
|
||||
func IPGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldIP, v))
|
||||
}
|
||||
|
||||
// IPGTE applies the GTE predicate on the "ip" field.
|
||||
func IPGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldIP, v))
|
||||
}
|
||||
|
||||
// IPLT applies the LT predicate on the "ip" field.
|
||||
func IPLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldIP, v))
|
||||
}
|
||||
|
||||
// IPLTE applies the LTE predicate on the "ip" field.
|
||||
func IPLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldIP, v))
|
||||
}
|
||||
|
||||
// IPContains applies the Contains predicate on the "ip" field.
|
||||
func IPContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldIP, v))
|
||||
}
|
||||
|
||||
// IPHasPrefix applies the HasPrefix predicate on the "ip" field.
|
||||
func IPHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldIP, v))
|
||||
}
|
||||
|
||||
// IPHasSuffix applies the HasSuffix predicate on the "ip" field.
|
||||
func IPHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldIP, v))
|
||||
}
|
||||
|
||||
// IPIsNil applies the IsNil predicate on the "ip" field.
|
||||
func IPIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldIP))
|
||||
}
|
||||
|
||||
// IPNotNil applies the NotNil predicate on the "ip" field.
|
||||
func IPNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldIP))
|
||||
}
|
||||
|
||||
// IPEqualFold applies the EqualFold predicate on the "ip" field.
|
||||
func IPEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldIP, v))
|
||||
}
|
||||
|
||||
// IPContainsFold applies the ContainsFold predicate on the "ip" field.
|
||||
func IPContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldIP, v))
|
||||
}
|
||||
|
||||
// AddrEQ applies the EQ predicate on the "addr" field.
|
||||
func AddrEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEQ(FieldAddr, v))
|
||||
}
|
||||
|
||||
// AddrNEQ applies the NEQ predicate on the "addr" field.
|
||||
func AddrNEQ(v string) predicate.User {
|
||||
return predicate.User(sql.FieldNEQ(FieldAddr, v))
|
||||
}
|
||||
|
||||
// AddrIn applies the In predicate on the "addr" field.
|
||||
func AddrIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldIn(FieldAddr, vs...))
|
||||
}
|
||||
|
||||
// AddrNotIn applies the NotIn predicate on the "addr" field.
|
||||
func AddrNotIn(vs ...string) predicate.User {
|
||||
return predicate.User(sql.FieldNotIn(FieldAddr, vs...))
|
||||
}
|
||||
|
||||
// AddrGT applies the GT predicate on the "addr" field.
|
||||
func AddrGT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGT(FieldAddr, v))
|
||||
}
|
||||
|
||||
// AddrGTE applies the GTE predicate on the "addr" field.
|
||||
func AddrGTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldGTE(FieldAddr, v))
|
||||
}
|
||||
|
||||
// AddrLT applies the LT predicate on the "addr" field.
|
||||
func AddrLT(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLT(FieldAddr, v))
|
||||
}
|
||||
|
||||
// AddrLTE applies the LTE predicate on the "addr" field.
|
||||
func AddrLTE(v string) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldAddr, v))
|
||||
}
|
||||
|
||||
// AddrContains applies the Contains predicate on the "addr" field.
|
||||
func AddrContains(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContains(FieldAddr, v))
|
||||
}
|
||||
|
||||
// AddrHasPrefix applies the HasPrefix predicate on the "addr" field.
|
||||
func AddrHasPrefix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasPrefix(FieldAddr, v))
|
||||
}
|
||||
|
||||
// AddrHasSuffix applies the HasSuffix predicate on the "addr" field.
|
||||
func AddrHasSuffix(v string) predicate.User {
|
||||
return predicate.User(sql.FieldHasSuffix(FieldAddr, v))
|
||||
}
|
||||
|
||||
// AddrIsNil applies the IsNil predicate on the "addr" field.
|
||||
func AddrIsNil() predicate.User {
|
||||
return predicate.User(sql.FieldIsNull(FieldAddr))
|
||||
}
|
||||
|
||||
// AddrNotNil applies the NotNil predicate on the "addr" field.
|
||||
func AddrNotNil() predicate.User {
|
||||
return predicate.User(sql.FieldNotNull(FieldAddr))
|
||||
}
|
||||
|
||||
// AddrEqualFold applies the EqualFold predicate on the "addr" field.
|
||||
func AddrEqualFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldEqualFold(FieldAddr, v))
|
||||
}
|
||||
|
||||
// AddrContainsFold applies the ContainsFold predicate on the "addr" field.
|
||||
func AddrContainsFold(v string) predicate.User {
|
||||
return predicate.User(sql.FieldContainsFold(FieldAddr, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(sql.AndPredicates(predicates...))
|
||||
|
||||
@@ -5,7 +5,9 @@ package ent
|
||||
import (
|
||||
"EnGin/internal/ent/user"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
@@ -18,6 +20,88 @@ type UserCreate struct {
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *UserCreate) SetCreatedAt(v time.Time) *UserCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableCreatedAt(v *time.Time) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_c *UserCreate) SetUpdatedAt(v time.Time) *UserCreate {
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableUpdatedAt(v *time.Time) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetUpdatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUsername sets the "username" field.
|
||||
func (_c *UserCreate) SetUsername(v string) *UserCreate {
|
||||
_c.mutation.SetUsername(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (_c *UserCreate) SetPassword(v string) *UserCreate {
|
||||
_c.mutation.SetPassword(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (_c *UserCreate) SetEmail(v string) *UserCreate {
|
||||
_c.mutation.SetEmail(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableEmail(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetEmail(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetIP sets the "ip" field.
|
||||
func (_c *UserCreate) SetIP(v string) *UserCreate {
|
||||
_c.mutation.SetIP(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableIP sets the "ip" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableIP(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetIP(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAddr sets the "addr" field.
|
||||
func (_c *UserCreate) SetAddr(v string) *UserCreate {
|
||||
_c.mutation.SetAddr(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAddr sets the "addr" field if the given value is not nil.
|
||||
func (_c *UserCreate) SetNillableAddr(v *string) *UserCreate {
|
||||
if v != nil {
|
||||
_c.SetAddr(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (_c *UserCreate) Mutation() *UserMutation {
|
||||
return _c.mutation
|
||||
@@ -25,6 +109,7 @@ func (_c *UserCreate) Mutation() *UserMutation {
|
||||
|
||||
// Save creates the User in the database.
|
||||
func (_c *UserCreate) Save(ctx context.Context) (*User, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
@@ -50,8 +135,52 @@ func (_c *UserCreate) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *UserCreate) defaults() {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := user.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
v := user.DefaultUpdatedAt()
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *UserCreate) check() error {
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "User.created_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "User.updated_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Username(); !ok {
|
||||
return &ValidationError{Name: "username", err: errors.New(`ent: missing required field "User.username"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Username(); ok {
|
||||
if err := user.UsernameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Password(); !ok {
|
||||
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "User.password"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Email(); ok {
|
||||
if err := user.EmailValidator(v); err != nil {
|
||||
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _c.mutation.IP(); ok {
|
||||
if err := user.IPValidator(v); err != nil {
|
||||
return &ValidationError{Name: "ip", err: fmt.Errorf(`ent: validator failed for field "User.ip": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _c.mutation.Addr(); ok {
|
||||
if err := user.AddrValidator(v); err != nil {
|
||||
return &ValidationError{Name: "addr", err: fmt.Errorf(`ent: validator failed for field "User.addr": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -78,6 +207,34 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||
_node = &User{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(user.Table, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(user.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.Username(); ok {
|
||||
_spec.SetField(user.FieldUsername, field.TypeString, value)
|
||||
_node.Username = value
|
||||
}
|
||||
if value, ok := _c.mutation.Password(); ok {
|
||||
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
||||
_node.Password = value
|
||||
}
|
||||
if value, ok := _c.mutation.Email(); ok {
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
_node.Email = value
|
||||
}
|
||||
if value, ok := _c.mutation.IP(); ok {
|
||||
_spec.SetField(user.FieldIP, field.TypeString, value)
|
||||
_node.IP = value
|
||||
}
|
||||
if value, ok := _c.mutation.Addr(); ok {
|
||||
_spec.SetField(user.FieldAddr, field.TypeString, value)
|
||||
_node.Addr = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
@@ -99,6 +256,7 @@ func (_c *UserCreateBulk) Save(ctx context.Context) ([]*User, error) {
|
||||
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.(*UserMutation)
|
||||
if !ok {
|
||||
|
||||
@@ -258,6 +258,18 @@ func (_q *UserQuery) Clone() *UserQuery {
|
||||
|
||||
// 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 {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.User.Query().
|
||||
// GroupBy(user.FieldCreatedAt).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
_q.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &UserGroupBy{build: _q}
|
||||
@@ -269,6 +281,16 @@ func (_q *UserQuery) GroupBy(field string, fields ...string) *UserGroupBy {
|
||||
|
||||
// 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 {
|
||||
// CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.User.Query().
|
||||
// Select(user.FieldCreatedAt).
|
||||
// Scan(ctx, &v)
|
||||
func (_q *UserQuery) Select(fields ...string) *UserSelect {
|
||||
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
|
||||
sbuild := &UserSelect{UserQuery: _q}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
@@ -27,6 +28,100 @@ func (_u *UserUpdate) Where(ps ...predicate.User) *UserUpdate {
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *UserUpdate) SetUpdatedAt(v time.Time) *UserUpdate {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUsername sets the "username" field.
|
||||
func (_u *UserUpdate) SetUsername(v string) *UserUpdate {
|
||||
_u.mutation.SetUsername(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUsername sets the "username" field if the given value is not nil.
|
||||
func (_u *UserUpdate) SetNillableUsername(v *string) *UserUpdate {
|
||||
if v != nil {
|
||||
_u.SetUsername(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (_u *UserUpdate) SetPassword(v string) *UserUpdate {
|
||||
_u.mutation.SetPassword(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (_u *UserUpdate) SetNillablePassword(v *string) *UserUpdate {
|
||||
if v != nil {
|
||||
_u.SetPassword(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (_u *UserUpdate) SetEmail(v string) *UserUpdate {
|
||||
_u.mutation.SetEmail(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (_u *UserUpdate) SetNillableEmail(v *string) *UserUpdate {
|
||||
if v != nil {
|
||||
_u.SetEmail(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearEmail clears the value of the "email" field.
|
||||
func (_u *UserUpdate) ClearEmail() *UserUpdate {
|
||||
_u.mutation.ClearEmail()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetIP sets the "ip" field.
|
||||
func (_u *UserUpdate) SetIP(v string) *UserUpdate {
|
||||
_u.mutation.SetIP(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableIP sets the "ip" field if the given value is not nil.
|
||||
func (_u *UserUpdate) SetNillableIP(v *string) *UserUpdate {
|
||||
if v != nil {
|
||||
_u.SetIP(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearIP clears the value of the "ip" field.
|
||||
func (_u *UserUpdate) ClearIP() *UserUpdate {
|
||||
_u.mutation.ClearIP()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAddr sets the "addr" field.
|
||||
func (_u *UserUpdate) SetAddr(v string) *UserUpdate {
|
||||
_u.mutation.SetAddr(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAddr sets the "addr" field if the given value is not nil.
|
||||
func (_u *UserUpdate) SetNillableAddr(v *string) *UserUpdate {
|
||||
if v != nil {
|
||||
_u.SetAddr(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearAddr clears the value of the "addr" field.
|
||||
func (_u *UserUpdate) ClearAddr() *UserUpdate {
|
||||
_u.mutation.ClearAddr()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (_u *UserUpdate) Mutation() *UserMutation {
|
||||
return _u.mutation
|
||||
@@ -34,6 +129,7 @@ func (_u *UserUpdate) Mutation() *UserMutation {
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *UserUpdate) Save(ctx context.Context) (int, error) {
|
||||
_u.defaults()
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
@@ -59,7 +155,43 @@ func (_u *UserUpdate) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_u *UserUpdate) defaults() {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
v := user.UpdateDefaultUpdatedAt()
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *UserUpdate) check() error {
|
||||
if v, ok := _u.mutation.Username(); ok {
|
||||
if err := user.UsernameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Email(); ok {
|
||||
if err := user.EmailValidator(v); err != nil {
|
||||
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.IP(); ok {
|
||||
if err := user.IPValidator(v); err != nil {
|
||||
return &ValidationError{Name: "ip", err: fmt.Errorf(`ent: validator failed for field "User.ip": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Addr(); ok {
|
||||
if err := user.AddrValidator(v); err != nil {
|
||||
return &ValidationError{Name: "addr", err: fmt.Errorf(`ent: validator failed for field "User.addr": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
@@ -68,6 +200,33 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Username(); ok {
|
||||
_spec.SetField(user.FieldUsername, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Password(); ok {
|
||||
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Email(); ok {
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.EmailCleared() {
|
||||
_spec.ClearField(user.FieldEmail, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.IP(); ok {
|
||||
_spec.SetField(user.FieldIP, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.IPCleared() {
|
||||
_spec.ClearField(user.FieldIP, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Addr(); ok {
|
||||
_spec.SetField(user.FieldAddr, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.AddrCleared() {
|
||||
_spec.ClearField(user.FieldAddr, field.TypeString)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{user.Label}
|
||||
@@ -88,6 +247,100 @@ type UserUpdateOne struct {
|
||||
mutation *UserMutation
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *UserUpdateOne) SetUpdatedAt(v time.Time) *UserUpdateOne {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUsername sets the "username" field.
|
||||
func (_u *UserUpdateOne) SetUsername(v string) *UserUpdateOne {
|
||||
_u.mutation.SetUsername(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUsername sets the "username" field if the given value is not nil.
|
||||
func (_u *UserUpdateOne) SetNillableUsername(v *string) *UserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUsername(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetPassword sets the "password" field.
|
||||
func (_u *UserUpdateOne) SetPassword(v string) *UserUpdateOne {
|
||||
_u.mutation.SetPassword(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillablePassword sets the "password" field if the given value is not nil.
|
||||
func (_u *UserUpdateOne) SetNillablePassword(v *string) *UserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetPassword(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetEmail sets the "email" field.
|
||||
func (_u *UserUpdateOne) SetEmail(v string) *UserUpdateOne {
|
||||
_u.mutation.SetEmail(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableEmail sets the "email" field if the given value is not nil.
|
||||
func (_u *UserUpdateOne) SetNillableEmail(v *string) *UserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetEmail(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearEmail clears the value of the "email" field.
|
||||
func (_u *UserUpdateOne) ClearEmail() *UserUpdateOne {
|
||||
_u.mutation.ClearEmail()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetIP sets the "ip" field.
|
||||
func (_u *UserUpdateOne) SetIP(v string) *UserUpdateOne {
|
||||
_u.mutation.SetIP(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableIP sets the "ip" field if the given value is not nil.
|
||||
func (_u *UserUpdateOne) SetNillableIP(v *string) *UserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetIP(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearIP clears the value of the "ip" field.
|
||||
func (_u *UserUpdateOne) ClearIP() *UserUpdateOne {
|
||||
_u.mutation.ClearIP()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetAddr sets the "addr" field.
|
||||
func (_u *UserUpdateOne) SetAddr(v string) *UserUpdateOne {
|
||||
_u.mutation.SetAddr(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableAddr sets the "addr" field if the given value is not nil.
|
||||
func (_u *UserUpdateOne) SetNillableAddr(v *string) *UserUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetAddr(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearAddr clears the value of the "addr" field.
|
||||
func (_u *UserUpdateOne) ClearAddr() *UserUpdateOne {
|
||||
_u.mutation.ClearAddr()
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (_u *UserUpdateOne) Mutation() *UserMutation {
|
||||
return _u.mutation
|
||||
@@ -108,6 +361,7 @@ func (_u *UserUpdateOne) Select(field string, fields ...string) *UserUpdateOne {
|
||||
|
||||
// Save executes the query and returns the updated User entity.
|
||||
func (_u *UserUpdateOne) Save(ctx context.Context) (*User, error) {
|
||||
_u.defaults()
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
@@ -133,7 +387,43 @@ func (_u *UserUpdateOne) ExecX(ctx context.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_u *UserUpdateOne) defaults() {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
v := user.UpdateDefaultUpdatedAt()
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *UserUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.Username(); ok {
|
||||
if err := user.UsernameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "username", err: fmt.Errorf(`ent: validator failed for field "User.username": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Email(); ok {
|
||||
if err := user.EmailValidator(v); err != nil {
|
||||
return &ValidationError{Name: "email", err: fmt.Errorf(`ent: validator failed for field "User.email": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.IP(); ok {
|
||||
if err := user.IPValidator(v); err != nil {
|
||||
return &ValidationError{Name: "ip", err: fmt.Errorf(`ent: validator failed for field "User.ip": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Addr(); ok {
|
||||
if err := user.AddrValidator(v); err != nil {
|
||||
return &ValidationError{Name: "addr", err: fmt.Errorf(`ent: validator failed for field "User.addr": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(user.Table, user.Columns, sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
@@ -159,6 +449,33 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(user.FieldUpdatedAt, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Username(); ok {
|
||||
_spec.SetField(user.FieldUsername, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Password(); ok {
|
||||
_spec.SetField(user.FieldPassword, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Email(); ok {
|
||||
_spec.SetField(user.FieldEmail, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.EmailCleared() {
|
||||
_spec.ClearField(user.FieldEmail, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.IP(); ok {
|
||||
_spec.SetField(user.FieldIP, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.IPCleared() {
|
||||
_spec.ClearField(user.FieldIP, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Addr(); ok {
|
||||
_spec.SetField(user.FieldAddr, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.AddrCleared() {
|
||||
_spec.ClearField(user.FieldAddr, field.TypeString)
|
||||
}
|
||||
_node = &User{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
||||
Reference in new issue
Block a user