72 lines
3.1 KiB
Go
72 lines
3.1 KiB
Go
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
|
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
|
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
|
|
|
package models
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"quyun/v2/pkg/fields"
|
|
|
|
"go.ipao.vip/gen"
|
|
"go.ipao.vip/gen/types"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
const TableNameUser = "users"
|
|
|
|
// User mapped from table <users>
|
|
type User struct {
|
|
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
|
CreatedAt time.Time `gorm:"column:created_at;type:timestamp without time zone;not null;default:now()" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp without time zone;not null;default:now()" json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp without time zone" json:"deleted_at"`
|
|
Status fields.UserStatus `gorm:"column:status;type:smallint;not null" json:"status"`
|
|
OpenID string `gorm:"column:open_id;type:character varying(128);not null" json:"open_id"`
|
|
Username string `gorm:"column:username;type:character varying(128);not null" json:"username"`
|
|
Avatar string `gorm:"column:avatar;type:text" json:"avatar"`
|
|
Metas types.JSONType[fields.UserMetas] `gorm:"column:metas;type:jsonb;not null;default:{}" json:"metas"`
|
|
AuthToken types.JSONType[fields.UserAuthToken] `gorm:"column:auth_token;type:jsonb;not null;default:{}" json:"auth_token"`
|
|
Balance int64 `gorm:"column:balance;type:bigint;not null" json:"balance"`
|
|
Phone string `gorm:"column:phone;type:character varying(15);not null" json:"phone"`
|
|
}
|
|
|
|
// Quick operations without importing query package
|
|
// Update applies changed fields to the database using the default DB.
|
|
func (m *User) Update(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.User.WithContext(ctx).Updates(m)
|
|
}
|
|
|
|
// Save upserts the model using the default DB.
|
|
func (m *User) Save(ctx context.Context) error { return Q.User.WithContext(ctx).Save(m) }
|
|
|
|
// Create inserts the model using the default DB.
|
|
func (m *User) Create(ctx context.Context) error { return Q.User.WithContext(ctx).Create(m) }
|
|
|
|
// Delete removes the row represented by the model using the default DB.
|
|
func (m *User) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.User.WithContext(ctx).Delete(m)
|
|
}
|
|
|
|
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
|
func (m *User) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.User.WithContext(ctx).Unscoped().Delete(m)
|
|
}
|
|
|
|
// Restore sets deleted_at to NULL for this model's primary key using the default DB.
|
|
func (m *User) Restore(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.User.WithContext(ctx).RestoreByID(m.ID)
|
|
}
|
|
|
|
// Reload reloads the model from database by its primary key and overwrites current fields.
|
|
func (m *User) Reload(ctx context.Context) error {
|
|
fresh, err := Q.User.WithContext(ctx).GetByID(m.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*m = *fresh
|
|
return nil
|
|
}
|