You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
212 lines
6.7 KiB
Go
212 lines
6.7 KiB
Go
1 year ago
|
// Code generated by ent, DO NOT EDIT.
|
||
|
|
||
|
package ent
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
"time"
|
||
|
|
||
|
"entgo.io/ent"
|
||
|
"entgo.io/ent/dialect/sql"
|
||
|
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/role"
|
||
|
"git.noahlan.cn/noahlan/ntool-biz/core/orm/nent/types"
|
||
|
)
|
||
|
|
||
|
// 系统角色表
|
||
|
type Role struct {
|
||
|
config `json:"-"`
|
||
|
// ID of the ent.
|
||
|
// Primary Key | 主键
|
||
|
ID int64 `json:"id,omitempty"`
|
||
|
// 创建时间
|
||
|
CreatedAt time.Time `json:"created_at,omitempty"`
|
||
|
// 更新时间
|
||
|
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||
|
// optimistic lock | 乐观锁
|
||
|
Version int64 `json:"version,omitempty"`
|
||
|
// Status | 状态
|
||
|
Status types.Status `json:"status,omitempty"`
|
||
|
// Soft delete | 软删除(逻辑删除)
|
||
|
DeletedAt time.Time `json:"deleted_at,omitempty"`
|
||
|
// Role Code | 角色编码,可用于权限控制
|
||
|
Code string `json:"code,omitempty"`
|
||
|
// Role Name | 角色名
|
||
|
Name string `json:"name,omitempty"`
|
||
|
// Description | 角色描述
|
||
|
Description string `json:"description,omitempty"`
|
||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||
|
// The values are being populated by the RoleQuery when eager-loading is set.
|
||
|
Edges RoleEdges `json:"edges"`
|
||
|
selectValues sql.SelectValues
|
||
|
}
|
||
|
|
||
|
// RoleEdges holds the relations/edges for other nodes in the graph.
|
||
|
type RoleEdges struct {
|
||
|
// Users holds the value of the users edge.
|
||
|
Users []*User `json:"users,omitempty"`
|
||
|
// loadedTypes holds the information for reporting if a
|
||
|
// type was loaded (or requested) in eager-loading or not.
|
||
|
loadedTypes [1]bool
|
||
|
}
|
||
|
|
||
|
// UsersOrErr returns the Users value or an error if the edge
|
||
|
// was not loaded in eager-loading.
|
||
|
func (e RoleEdges) UsersOrErr() ([]*User, error) {
|
||
|
if e.loadedTypes[0] {
|
||
|
return e.Users, nil
|
||
|
}
|
||
|
return nil, &NotLoadedError{edge: "users"}
|
||
|
}
|
||
|
|
||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||
|
func (*Role) scanValues(columns []string) ([]any, error) {
|
||
|
values := make([]any, len(columns))
|
||
|
for i := range columns {
|
||
|
switch columns[i] {
|
||
|
case role.FieldID, role.FieldVersion:
|
||
|
values[i] = new(sql.NullInt64)
|
||
|
case role.FieldStatus, role.FieldCode, role.FieldName, role.FieldDescription:
|
||
|
values[i] = new(sql.NullString)
|
||
|
case role.FieldCreatedAt, role.FieldUpdatedAt, role.FieldDeletedAt:
|
||
|
values[i] = new(sql.NullTime)
|
||
|
default:
|
||
|
values[i] = new(sql.UnknownType)
|
||
|
}
|
||
|
}
|
||
|
return values, nil
|
||
|
}
|
||
|
|
||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||
|
// to the Role fields.
|
||
|
func (r *Role) assignValues(columns []string, values []any) error {
|
||
|
if m, n := len(values), len(columns); m < n {
|
||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||
|
}
|
||
|
for i := range columns {
|
||
|
switch columns[i] {
|
||
|
case role.FieldID:
|
||
|
value, ok := values[i].(*sql.NullInt64)
|
||
|
if !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||
|
}
|
||
|
r.ID = int64(value.Int64)
|
||
|
case role.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 {
|
||
|
r.CreatedAt = value.Time
|
||
|
}
|
||
|
case role.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 {
|
||
|
r.UpdatedAt = value.Time
|
||
|
}
|
||
|
case role.FieldVersion:
|
||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field version", values[i])
|
||
|
} else if value.Valid {
|
||
|
r.Version = value.Int64
|
||
|
}
|
||
|
case role.FieldStatus:
|
||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
||
|
} else if value.Valid {
|
||
|
r.Status = types.Status(value.String)
|
||
|
}
|
||
|
case role.FieldDeletedAt:
|
||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
|
||
|
} else if value.Valid {
|
||
|
r.DeletedAt = value.Time
|
||
|
}
|
||
|
case role.FieldCode:
|
||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field code", values[i])
|
||
|
} else if value.Valid {
|
||
|
r.Code = value.String
|
||
|
}
|
||
|
case role.FieldName:
|
||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||
|
} else if value.Valid {
|
||
|
r.Name = value.String
|
||
|
}
|
||
|
case role.FieldDescription:
|
||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||
|
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||
|
} else if value.Valid {
|
||
|
r.Description = value.String
|
||
|
}
|
||
|
default:
|
||
|
r.selectValues.Set(columns[i], values[i])
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
// Value returns the ent.Value that was dynamically selected and assigned to the Role.
|
||
|
// This includes values selected through modifiers, order, etc.
|
||
|
func (r *Role) Value(name string) (ent.Value, error) {
|
||
|
return r.selectValues.Get(name)
|
||
|
}
|
||
|
|
||
|
// QueryUsers queries the "users" edge of the Role entity.
|
||
|
func (r *Role) QueryUsers() *UserQuery {
|
||
|
return NewRoleClient(r.config).QueryUsers(r)
|
||
|
}
|
||
|
|
||
|
// Update returns a builder for updating this Role.
|
||
|
// Note that you need to call Role.Unwrap() before calling this method if this Role
|
||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||
|
func (r *Role) Update() *RoleUpdateOne {
|
||
|
return NewRoleClient(r.config).UpdateOne(r)
|
||
|
}
|
||
|
|
||
|
// Unwrap unwraps the Role entity that was returned from a transaction after it was closed,
|
||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||
|
func (r *Role) Unwrap() *Role {
|
||
|
_tx, ok := r.config.driver.(*txDriver)
|
||
|
if !ok {
|
||
|
panic("ent: Role is not a transactional entity")
|
||
|
}
|
||
|
r.config.driver = _tx.drv
|
||
|
return r
|
||
|
}
|
||
|
|
||
|
// String implements the fmt.Stringer.
|
||
|
func (r *Role) String() string {
|
||
|
var builder strings.Builder
|
||
|
builder.WriteString("Role(")
|
||
|
builder.WriteString(fmt.Sprintf("id=%v, ", r.ID))
|
||
|
builder.WriteString("created_at=")
|
||
|
builder.WriteString(r.CreatedAt.Format(time.ANSIC))
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("updated_at=")
|
||
|
builder.WriteString(r.UpdatedAt.Format(time.ANSIC))
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("version=")
|
||
|
builder.WriteString(fmt.Sprintf("%v", r.Version))
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("status=")
|
||
|
builder.WriteString(fmt.Sprintf("%v", r.Status))
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("deleted_at=")
|
||
|
builder.WriteString(r.DeletedAt.Format(time.ANSIC))
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("code=")
|
||
|
builder.WriteString(r.Code)
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("name=")
|
||
|
builder.WriteString(r.Name)
|
||
|
builder.WriteString(", ")
|
||
|
builder.WriteString("description=")
|
||
|
builder.WriteString(r.Description)
|
||
|
builder.WriteByte(')')
|
||
|
return builder.String()
|
||
|
}
|
||
|
|
||
|
// Roles is a parsable slice of Role.
|
||
|
type Roles []*Role
|