feat(schema): 添加基础混入定义公共时间字段
This commit is contained in:
1 parent
5281459fcb
commit
fe86c081f4
16 files changed
+1715
-14
No files matched your search
+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)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user