tss-rocks/backend/ent/permission.go
CDN 05ddc1f783
Some checks failed
Build Backend / Build Docker Image (push) Successful in 3m33s
Test Backend / test (push) Failing after 31s
[feature] migrate to monorepo
2025-02-21 00:49:20 +08:00

176 lines
5.8 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"fmt"
"strings"
"time"
"tss-rocks-be/ent/permission"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// Permission is the model entity for the Permission schema.
type Permission struct {
config `json:"-"`
// ID of the ent.
ID int `json:"id,omitempty"`
// Resource name, e.g., 'media', 'post'
Resource string `json:"resource,omitempty"`
// Action name, e.g., 'create', 'read', 'update', 'delete'
Action string `json:"action,omitempty"`
// Human readable description of the permission
Description string `json:"description,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"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the PermissionQuery when eager-loading is set.
Edges PermissionEdges `json:"edges"`
selectValues sql.SelectValues
}
// PermissionEdges holds the relations/edges for other nodes in the graph.
type PermissionEdges struct {
// Roles holds the value of the roles edge.
Roles []*Role `json:"roles,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// RolesOrErr returns the Roles value or an error if the edge
// was not loaded in eager-loading.
func (e PermissionEdges) RolesOrErr() ([]*Role, error) {
if e.loadedTypes[0] {
return e.Roles, nil
}
return nil, &NotLoadedError{edge: "roles"}
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Permission) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case permission.FieldID:
values[i] = new(sql.NullInt64)
case permission.FieldResource, permission.FieldAction, permission.FieldDescription:
values[i] = new(sql.NullString)
case permission.FieldCreatedAt, permission.FieldUpdatedAt:
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 Permission fields.
func (pe *Permission) 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 permission.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
pe.ID = int(value.Int64)
case permission.FieldResource:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field resource", values[i])
} else if value.Valid {
pe.Resource = value.String
}
case permission.FieldAction:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field action", values[i])
} else if value.Valid {
pe.Action = value.String
}
case permission.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
pe.Description = value.String
}
case permission.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 {
pe.CreatedAt = value.Time
}
case permission.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 {
pe.UpdatedAt = value.Time
}
default:
pe.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Permission.
// This includes values selected through modifiers, order, etc.
func (pe *Permission) Value(name string) (ent.Value, error) {
return pe.selectValues.Get(name)
}
// QueryRoles queries the "roles" edge of the Permission entity.
func (pe *Permission) QueryRoles() *RoleQuery {
return NewPermissionClient(pe.config).QueryRoles(pe)
}
// Update returns a builder for updating this Permission.
// Note that you need to call Permission.Unwrap() before calling this method if this Permission
// was returned from a transaction, and the transaction was committed or rolled back.
func (pe *Permission) Update() *PermissionUpdateOne {
return NewPermissionClient(pe.config).UpdateOne(pe)
}
// Unwrap unwraps the Permission 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 (pe *Permission) Unwrap() *Permission {
_tx, ok := pe.config.driver.(*txDriver)
if !ok {
panic("ent: Permission is not a transactional entity")
}
pe.config.driver = _tx.drv
return pe
}
// String implements the fmt.Stringer.
func (pe *Permission) String() string {
var builder strings.Builder
builder.WriteString("Permission(")
builder.WriteString(fmt.Sprintf("id=%v, ", pe.ID))
builder.WriteString("resource=")
builder.WriteString(pe.Resource)
builder.WriteString(", ")
builder.WriteString("action=")
builder.WriteString(pe.Action)
builder.WriteString(", ")
builder.WriteString("description=")
builder.WriteString(pe.Description)
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(pe.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(pe.UpdatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// Permissions is a parsable slice of Permission.
type Permissions []*Permission