github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/permission.go (about)

     1  // Code generated by entc, DO NOT EDIT.
     2  
     3  package ent
     4  
     5  import (
     6  	"fmt"
     7  	"strings"
     8  	"time"
     9  
    10  	"entgo.io/ent/dialect/sql"
    11  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/permission"
    12  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/role"
    13  )
    14  
    15  // Permission is the model entity for the Permission schema.
    16  type Permission struct {
    17  	config `json:"-" validate:"-"`
    18  	// ID of the ent.
    19  	ID int `json:"id,omitempty"`
    20  	// CreatedAt holds the value of the "created_at" field.
    21  	CreatedAt time.Time `json:"omitempty"`
    22  	// UpdatedAt holds the value of the "updated_at" field.
    23  	UpdatedAt time.Time `json:"omitempty"`
    24  	// DeletedAt holds the value of the "deleted_at" field.
    25  	DeletedAt time.Time `json:"omitempty"`
    26  	// RoleID holds the value of the "role_id" field.
    27  	RoleID int `json:"role_id,omitempty"`
    28  	// Action holds the value of the "action" field.
    29  	Action string `json:"action,omitempty" validate:"max=255"`
    30  	// Value holds the value of the "value" field.
    31  	// all | own | none
    32  	Value string `json:"value,omitempty"`
    33  	// Edges holds the relations/edges for other nodes in the graph.
    34  	// The values are being populated by the PermissionQuery when eager-loading is set.
    35  	Edges PermissionEdges `json:"edges"`
    36  }
    37  
    38  // PermissionEdges holds the relations/edges for other nodes in the graph.
    39  type PermissionEdges struct {
    40  	// Role holds the value of the role edge.
    41  	Role *Role `json:"role,omitempty"`
    42  	// loadedTypes holds the information for reporting if a
    43  	// type was loaded (or requested) in eager-loading or not.
    44  	loadedTypes [1]bool
    45  }
    46  
    47  // RoleOrErr returns the Role value or an error if the edge
    48  // was not loaded in eager-loading, or loaded but was not found.
    49  func (e PermissionEdges) RoleOrErr() (*Role, error) {
    50  	if e.loadedTypes[0] {
    51  		if e.Role == nil {
    52  			// The edge role was loaded in eager-loading,
    53  			// but was not found.
    54  			return nil, &NotFoundError{label: role.Label}
    55  		}
    56  		return e.Role, nil
    57  	}
    58  	return nil, &NotLoadedError{edge: "role"}
    59  }
    60  
    61  // scanValues returns the types for scanning values from sql.Rows.
    62  func (*Permission) scanValues(columns []string) ([]interface{}, error) {
    63  	values := make([]interface{}, len(columns))
    64  	for i := range columns {
    65  		switch columns[i] {
    66  		case permission.FieldID, permission.FieldRoleID:
    67  			values[i] = new(sql.NullInt64)
    68  		case permission.FieldAction, permission.FieldValue:
    69  			values[i] = new(sql.NullString)
    70  		case permission.FieldCreatedAt, permission.FieldUpdatedAt, permission.FieldDeletedAt:
    71  			values[i] = new(sql.NullTime)
    72  		default:
    73  			return nil, fmt.Errorf("unexpected column %q for type Permission", columns[i])
    74  		}
    75  	}
    76  	return values, nil
    77  }
    78  
    79  // assignValues assigns the values that were returned from sql.Rows (after scanning)
    80  // to the Permission fields.
    81  func (pe *Permission) assignValues(columns []string, values []interface{}) error {
    82  	if m, n := len(values), len(columns); m < n {
    83  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
    84  	}
    85  	for i := range columns {
    86  		switch columns[i] {
    87  		case permission.FieldID:
    88  			value, ok := values[i].(*sql.NullInt64)
    89  			if !ok {
    90  				return fmt.Errorf("unexpected type %T for field id", value)
    91  			}
    92  			pe.ID = int(value.Int64)
    93  		case permission.FieldCreatedAt:
    94  			if value, ok := values[i].(*sql.NullTime); !ok {
    95  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
    96  			} else if value.Valid {
    97  				pe.CreatedAt = value.Time
    98  			}
    99  		case permission.FieldUpdatedAt:
   100  			if value, ok := values[i].(*sql.NullTime); !ok {
   101  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
   102  			} else if value.Valid {
   103  				pe.UpdatedAt = value.Time
   104  			}
   105  		case permission.FieldDeletedAt:
   106  			if value, ok := values[i].(*sql.NullTime); !ok {
   107  				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
   108  			} else if value.Valid {
   109  				pe.DeletedAt = value.Time
   110  			}
   111  		case permission.FieldRoleID:
   112  			if value, ok := values[i].(*sql.NullInt64); !ok {
   113  				return fmt.Errorf("unexpected type %T for field role_id", values[i])
   114  			} else if value.Valid {
   115  				pe.RoleID = int(value.Int64)
   116  			}
   117  		case permission.FieldAction:
   118  			if value, ok := values[i].(*sql.NullString); !ok {
   119  				return fmt.Errorf("unexpected type %T for field action", values[i])
   120  			} else if value.Valid {
   121  				pe.Action = value.String
   122  			}
   123  		case permission.FieldValue:
   124  			if value, ok := values[i].(*sql.NullString); !ok {
   125  				return fmt.Errorf("unexpected type %T for field value", values[i])
   126  			} else if value.Valid {
   127  				pe.Value = value.String
   128  			}
   129  		}
   130  	}
   131  	return nil
   132  }
   133  
   134  // QueryRole queries the "role" edge of the Permission entity.
   135  func (pe *Permission) QueryRole() *RoleQuery {
   136  	return (&PermissionClient{config: pe.config}).QueryRole(pe)
   137  }
   138  
   139  // Update returns a builder for updating this Permission.
   140  // Note that you need to call Permission.Unwrap() before calling this method if this Permission
   141  // was returned from a transaction, and the transaction was committed or rolled back.
   142  func (pe *Permission) Update() *PermissionUpdateOne {
   143  	return (&PermissionClient{config: pe.config}).UpdateOne(pe)
   144  }
   145  
   146  // Unwrap unwraps the Permission entity that was returned from a transaction after it was closed,
   147  // so that all future queries will be executed through the driver which created the transaction.
   148  func (pe *Permission) Unwrap() *Permission {
   149  	tx, ok := pe.config.driver.(*txDriver)
   150  	if !ok {
   151  		panic("ent: Permission is not a transactional entity")
   152  	}
   153  	pe.config.driver = tx.drv
   154  	return pe
   155  }
   156  
   157  // String implements the fmt.Stringer.
   158  func (pe *Permission) String() string {
   159  	var builder strings.Builder
   160  	builder.WriteString("Permission(")
   161  	builder.WriteString(fmt.Sprintf("id=%v", pe.ID))
   162  	builder.WriteString(", created_at=")
   163  	builder.WriteString(pe.CreatedAt.Format(time.ANSIC))
   164  	builder.WriteString(", updated_at=")
   165  	builder.WriteString(pe.UpdatedAt.Format(time.ANSIC))
   166  	builder.WriteString(", deleted_at=")
   167  	builder.WriteString(pe.DeletedAt.Format(time.ANSIC))
   168  	builder.WriteString(", role_id=")
   169  	builder.WriteString(fmt.Sprintf("%v", pe.RoleID))
   170  	builder.WriteString(", action=")
   171  	builder.WriteString(pe.Action)
   172  	builder.WriteString(", value=")
   173  	builder.WriteString(pe.Value)
   174  	builder.WriteByte(')')
   175  	return builder.String()
   176  }
   177  
   178  // Permissions is a parsable slice of Permission.
   179  type Permissions []*Permission
   180  
   181  func (pe Permissions) config(cfg config) {
   182  	for _i := range pe {
   183  		pe[_i].config = cfg
   184  	}
   185  }