github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/file.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/file"
    12  	"github.com/ngocphuongnb/tetua/packages/entrepository/ent/user"
    13  )
    14  
    15  // File is the model entity for the File schema.
    16  type File struct {
    17  	config `json:"-"`
    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  	// Disk holds the value of the "disk" field.
    27  	Disk string `json:"disk,omitempty"`
    28  	// Path holds the value of the "path" field.
    29  	Path string `json:"path,omitempty"`
    30  	// Type holds the value of the "type" field.
    31  	Type string `json:"type,omitempty"`
    32  	// Size holds the value of the "size" field.
    33  	Size int `json:"size,omitempty"`
    34  	// UserID holds the value of the "user_id" field.
    35  	UserID int `json:"user_id,omitempty"`
    36  	// Edges holds the relations/edges for other nodes in the graph.
    37  	// The values are being populated by the FileQuery when eager-loading is set.
    38  	Edges FileEdges `json:"edges"`
    39  }
    40  
    41  // FileEdges holds the relations/edges for other nodes in the graph.
    42  type FileEdges struct {
    43  	// User holds the value of the user edge.
    44  	User *User `json:"user,omitempty"`
    45  	// Posts holds the value of the posts edge.
    46  	Posts []*Post `json:"posts,omitempty"`
    47  	// Pages holds the value of the pages edge.
    48  	Pages []*Page `json:"pages,omitempty"`
    49  	// UserAvatars holds the value of the user_avatars edge.
    50  	UserAvatars []*User `json:"user_avatars,omitempty"`
    51  	// loadedTypes holds the information for reporting if a
    52  	// type was loaded (or requested) in eager-loading or not.
    53  	loadedTypes [4]bool
    54  }
    55  
    56  // UserOrErr returns the User value or an error if the edge
    57  // was not loaded in eager-loading, or loaded but was not found.
    58  func (e FileEdges) UserOrErr() (*User, error) {
    59  	if e.loadedTypes[0] {
    60  		if e.User == nil {
    61  			// The edge user was loaded in eager-loading,
    62  			// but was not found.
    63  			return nil, &NotFoundError{label: user.Label}
    64  		}
    65  		return e.User, nil
    66  	}
    67  	return nil, &NotLoadedError{edge: "user"}
    68  }
    69  
    70  // PostsOrErr returns the Posts value or an error if the edge
    71  // was not loaded in eager-loading.
    72  func (e FileEdges) PostsOrErr() ([]*Post, error) {
    73  	if e.loadedTypes[1] {
    74  		return e.Posts, nil
    75  	}
    76  	return nil, &NotLoadedError{edge: "posts"}
    77  }
    78  
    79  // PagesOrErr returns the Pages value or an error if the edge
    80  // was not loaded in eager-loading.
    81  func (e FileEdges) PagesOrErr() ([]*Page, error) {
    82  	if e.loadedTypes[2] {
    83  		return e.Pages, nil
    84  	}
    85  	return nil, &NotLoadedError{edge: "pages"}
    86  }
    87  
    88  // UserAvatarsOrErr returns the UserAvatars value or an error if the edge
    89  // was not loaded in eager-loading.
    90  func (e FileEdges) UserAvatarsOrErr() ([]*User, error) {
    91  	if e.loadedTypes[3] {
    92  		return e.UserAvatars, nil
    93  	}
    94  	return nil, &NotLoadedError{edge: "user_avatars"}
    95  }
    96  
    97  // scanValues returns the types for scanning values from sql.Rows.
    98  func (*File) scanValues(columns []string) ([]interface{}, error) {
    99  	values := make([]interface{}, len(columns))
   100  	for i := range columns {
   101  		switch columns[i] {
   102  		case file.FieldID, file.FieldSize, file.FieldUserID:
   103  			values[i] = new(sql.NullInt64)
   104  		case file.FieldDisk, file.FieldPath, file.FieldType:
   105  			values[i] = new(sql.NullString)
   106  		case file.FieldCreatedAt, file.FieldUpdatedAt, file.FieldDeletedAt:
   107  			values[i] = new(sql.NullTime)
   108  		default:
   109  			return nil, fmt.Errorf("unexpected column %q for type File", columns[i])
   110  		}
   111  	}
   112  	return values, nil
   113  }
   114  
   115  // assignValues assigns the values that were returned from sql.Rows (after scanning)
   116  // to the File fields.
   117  func (f *File) assignValues(columns []string, values []interface{}) error {
   118  	if m, n := len(values), len(columns); m < n {
   119  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
   120  	}
   121  	for i := range columns {
   122  		switch columns[i] {
   123  		case file.FieldID:
   124  			value, ok := values[i].(*sql.NullInt64)
   125  			if !ok {
   126  				return fmt.Errorf("unexpected type %T for field id", value)
   127  			}
   128  			f.ID = int(value.Int64)
   129  		case file.FieldCreatedAt:
   130  			if value, ok := values[i].(*sql.NullTime); !ok {
   131  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
   132  			} else if value.Valid {
   133  				f.CreatedAt = value.Time
   134  			}
   135  		case file.FieldUpdatedAt:
   136  			if value, ok := values[i].(*sql.NullTime); !ok {
   137  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
   138  			} else if value.Valid {
   139  				f.UpdatedAt = value.Time
   140  			}
   141  		case file.FieldDeletedAt:
   142  			if value, ok := values[i].(*sql.NullTime); !ok {
   143  				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
   144  			} else if value.Valid {
   145  				f.DeletedAt = value.Time
   146  			}
   147  		case file.FieldDisk:
   148  			if value, ok := values[i].(*sql.NullString); !ok {
   149  				return fmt.Errorf("unexpected type %T for field disk", values[i])
   150  			} else if value.Valid {
   151  				f.Disk = value.String
   152  			}
   153  		case file.FieldPath:
   154  			if value, ok := values[i].(*sql.NullString); !ok {
   155  				return fmt.Errorf("unexpected type %T for field path", values[i])
   156  			} else if value.Valid {
   157  				f.Path = value.String
   158  			}
   159  		case file.FieldType:
   160  			if value, ok := values[i].(*sql.NullString); !ok {
   161  				return fmt.Errorf("unexpected type %T for field type", values[i])
   162  			} else if value.Valid {
   163  				f.Type = value.String
   164  			}
   165  		case file.FieldSize:
   166  			if value, ok := values[i].(*sql.NullInt64); !ok {
   167  				return fmt.Errorf("unexpected type %T for field size", values[i])
   168  			} else if value.Valid {
   169  				f.Size = int(value.Int64)
   170  			}
   171  		case file.FieldUserID:
   172  			if value, ok := values[i].(*sql.NullInt64); !ok {
   173  				return fmt.Errorf("unexpected type %T for field user_id", values[i])
   174  			} else if value.Valid {
   175  				f.UserID = int(value.Int64)
   176  			}
   177  		}
   178  	}
   179  	return nil
   180  }
   181  
   182  // QueryUser queries the "user" edge of the File entity.
   183  func (f *File) QueryUser() *UserQuery {
   184  	return (&FileClient{config: f.config}).QueryUser(f)
   185  }
   186  
   187  // QueryPosts queries the "posts" edge of the File entity.
   188  func (f *File) QueryPosts() *PostQuery {
   189  	return (&FileClient{config: f.config}).QueryPosts(f)
   190  }
   191  
   192  // QueryPages queries the "pages" edge of the File entity.
   193  func (f *File) QueryPages() *PageQuery {
   194  	return (&FileClient{config: f.config}).QueryPages(f)
   195  }
   196  
   197  // QueryUserAvatars queries the "user_avatars" edge of the File entity.
   198  func (f *File) QueryUserAvatars() *UserQuery {
   199  	return (&FileClient{config: f.config}).QueryUserAvatars(f)
   200  }
   201  
   202  // Update returns a builder for updating this File.
   203  // Note that you need to call File.Unwrap() before calling this method if this File
   204  // was returned from a transaction, and the transaction was committed or rolled back.
   205  func (f *File) Update() *FileUpdateOne {
   206  	return (&FileClient{config: f.config}).UpdateOne(f)
   207  }
   208  
   209  // Unwrap unwraps the File entity that was returned from a transaction after it was closed,
   210  // so that all future queries will be executed through the driver which created the transaction.
   211  func (f *File) Unwrap() *File {
   212  	tx, ok := f.config.driver.(*txDriver)
   213  	if !ok {
   214  		panic("ent: File is not a transactional entity")
   215  	}
   216  	f.config.driver = tx.drv
   217  	return f
   218  }
   219  
   220  // String implements the fmt.Stringer.
   221  func (f *File) String() string {
   222  	var builder strings.Builder
   223  	builder.WriteString("File(")
   224  	builder.WriteString(fmt.Sprintf("id=%v", f.ID))
   225  	builder.WriteString(", created_at=")
   226  	builder.WriteString(f.CreatedAt.Format(time.ANSIC))
   227  	builder.WriteString(", updated_at=")
   228  	builder.WriteString(f.UpdatedAt.Format(time.ANSIC))
   229  	builder.WriteString(", deleted_at=")
   230  	builder.WriteString(f.DeletedAt.Format(time.ANSIC))
   231  	builder.WriteString(", disk=")
   232  	builder.WriteString(f.Disk)
   233  	builder.WriteString(", path=")
   234  	builder.WriteString(f.Path)
   235  	builder.WriteString(", type=")
   236  	builder.WriteString(f.Type)
   237  	builder.WriteString(", size=")
   238  	builder.WriteString(fmt.Sprintf("%v", f.Size))
   239  	builder.WriteString(", user_id=")
   240  	builder.WriteString(fmt.Sprintf("%v", f.UserID))
   241  	builder.WriteByte(')')
   242  	return builder.String()
   243  }
   244  
   245  // Files is a parsable slice of File.
   246  type Files []*File
   247  
   248  func (f Files) config(cfg config) {
   249  	for _i := range f {
   250  		f[_i].config = cfg
   251  	}
   252  }