github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/post.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/post" 13 "github.com/ngocphuongnb/tetua/packages/entrepository/ent/user" 14 ) 15 16 // Post is the model entity for the Post schema. 17 type Post struct { 18 config `json:"-" validate:"-"` 19 // ID of the ent. 20 ID int `json:"id,omitempty"` 21 // CreatedAt holds the value of the "created_at" field. 22 CreatedAt time.Time `json:"omitempty"` 23 // UpdatedAt holds the value of the "updated_at" field. 24 UpdatedAt time.Time `json:"omitempty"` 25 // DeletedAt holds the value of the "deleted_at" field. 26 DeletedAt time.Time `json:"omitempty"` 27 // Name holds the value of the "name" field. 28 Name string `json:"name,omitempty"` 29 // Slug holds the value of the "slug" field. 30 Slug string `json:"slug,omitempty"` 31 // Description holds the value of the "description" field. 32 Description string `json:"description,omitempty" validate:"max=255"` 33 // Content holds the value of the "content" field. 34 Content string `json:"content,omitempty" validate:"required"` 35 // ContentHTML holds the value of the "content_html" field. 36 ContentHTML string `json:"content_html,omitempty"` 37 // ViewCount holds the value of the "view_count" field. 38 ViewCount int64 `json:"view_count,omitempty"` 39 // CommentCount holds the value of the "comment_count" field. 40 CommentCount int64 `json:"comment_count,omitempty"` 41 // RatingCount holds the value of the "rating_count" field. 42 RatingCount int64 `json:"rating_count,omitempty"` 43 // RatingTotal holds the value of the "rating_total" field. 44 RatingTotal int64 `json:"rating_total,omitempty"` 45 // Draft holds the value of the "draft" field. 46 Draft bool `json:"draft,omitempty"` 47 // Approved holds the value of the "approved" field. 48 Approved bool `json:"approved,omitempty"` 49 // FeaturedImageID holds the value of the "featured_image_id" field. 50 FeaturedImageID int `json:"featured_image_id,omitempty"` 51 // UserID holds the value of the "user_id" field. 52 UserID int `json:"user_id,omitempty"` 53 // Edges holds the relations/edges for other nodes in the graph. 54 // The values are being populated by the PostQuery when eager-loading is set. 55 Edges PostEdges `json:"edges"` 56 } 57 58 // PostEdges holds the relations/edges for other nodes in the graph. 59 type PostEdges struct { 60 // User holds the value of the user edge. 61 User *User `json:"user,omitempty"` 62 // Topics holds the value of the topics edge. 63 Topics []*Topic `json:"topics,omitempty"` 64 // FeaturedImage holds the value of the featured_image edge. 65 FeaturedImage *File `json:"featured_image,omitempty"` 66 // Comments holds the value of the comments edge. 67 Comments []*Comment `json:"comments,omitempty"` 68 // loadedTypes holds the information for reporting if a 69 // type was loaded (or requested) in eager-loading or not. 70 loadedTypes [4]bool 71 } 72 73 // UserOrErr returns the User value or an error if the edge 74 // was not loaded in eager-loading, or loaded but was not found. 75 func (e PostEdges) UserOrErr() (*User, error) { 76 if e.loadedTypes[0] { 77 if e.User == nil { 78 // The edge user was loaded in eager-loading, 79 // but was not found. 80 return nil, &NotFoundError{label: user.Label} 81 } 82 return e.User, nil 83 } 84 return nil, &NotLoadedError{edge: "user"} 85 } 86 87 // TopicsOrErr returns the Topics value or an error if the edge 88 // was not loaded in eager-loading. 89 func (e PostEdges) TopicsOrErr() ([]*Topic, error) { 90 if e.loadedTypes[1] { 91 return e.Topics, nil 92 } 93 return nil, &NotLoadedError{edge: "topics"} 94 } 95 96 // FeaturedImageOrErr returns the FeaturedImage value or an error if the edge 97 // was not loaded in eager-loading, or loaded but was not found. 98 func (e PostEdges) FeaturedImageOrErr() (*File, error) { 99 if e.loadedTypes[2] { 100 if e.FeaturedImage == nil { 101 // The edge featured_image was loaded in eager-loading, 102 // but was not found. 103 return nil, &NotFoundError{label: file.Label} 104 } 105 return e.FeaturedImage, nil 106 } 107 return nil, &NotLoadedError{edge: "featured_image"} 108 } 109 110 // CommentsOrErr returns the Comments value or an error if the edge 111 // was not loaded in eager-loading. 112 func (e PostEdges) CommentsOrErr() ([]*Comment, error) { 113 if e.loadedTypes[3] { 114 return e.Comments, nil 115 } 116 return nil, &NotLoadedError{edge: "comments"} 117 } 118 119 // scanValues returns the types for scanning values from sql.Rows. 120 func (*Post) scanValues(columns []string) ([]interface{}, error) { 121 values := make([]interface{}, len(columns)) 122 for i := range columns { 123 switch columns[i] { 124 case post.FieldDraft, post.FieldApproved: 125 values[i] = new(sql.NullBool) 126 case post.FieldID, post.FieldViewCount, post.FieldCommentCount, post.FieldRatingCount, post.FieldRatingTotal, post.FieldFeaturedImageID, post.FieldUserID: 127 values[i] = new(sql.NullInt64) 128 case post.FieldName, post.FieldSlug, post.FieldDescription, post.FieldContent, post.FieldContentHTML: 129 values[i] = new(sql.NullString) 130 case post.FieldCreatedAt, post.FieldUpdatedAt, post.FieldDeletedAt: 131 values[i] = new(sql.NullTime) 132 default: 133 return nil, fmt.Errorf("unexpected column %q for type Post", columns[i]) 134 } 135 } 136 return values, nil 137 } 138 139 // assignValues assigns the values that were returned from sql.Rows (after scanning) 140 // to the Post fields. 141 func (po *Post) assignValues(columns []string, values []interface{}) error { 142 if m, n := len(values), len(columns); m < n { 143 return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) 144 } 145 for i := range columns { 146 switch columns[i] { 147 case post.FieldID: 148 value, ok := values[i].(*sql.NullInt64) 149 if !ok { 150 return fmt.Errorf("unexpected type %T for field id", value) 151 } 152 po.ID = int(value.Int64) 153 case post.FieldCreatedAt: 154 if value, ok := values[i].(*sql.NullTime); !ok { 155 return fmt.Errorf("unexpected type %T for field created_at", values[i]) 156 } else if value.Valid { 157 po.CreatedAt = value.Time 158 } 159 case post.FieldUpdatedAt: 160 if value, ok := values[i].(*sql.NullTime); !ok { 161 return fmt.Errorf("unexpected type %T for field updated_at", values[i]) 162 } else if value.Valid { 163 po.UpdatedAt = value.Time 164 } 165 case post.FieldDeletedAt: 166 if value, ok := values[i].(*sql.NullTime); !ok { 167 return fmt.Errorf("unexpected type %T for field deleted_at", values[i]) 168 } else if value.Valid { 169 po.DeletedAt = value.Time 170 } 171 case post.FieldName: 172 if value, ok := values[i].(*sql.NullString); !ok { 173 return fmt.Errorf("unexpected type %T for field name", values[i]) 174 } else if value.Valid { 175 po.Name = value.String 176 } 177 case post.FieldSlug: 178 if value, ok := values[i].(*sql.NullString); !ok { 179 return fmt.Errorf("unexpected type %T for field slug", values[i]) 180 } else if value.Valid { 181 po.Slug = value.String 182 } 183 case post.FieldDescription: 184 if value, ok := values[i].(*sql.NullString); !ok { 185 return fmt.Errorf("unexpected type %T for field description", values[i]) 186 } else if value.Valid { 187 po.Description = value.String 188 } 189 case post.FieldContent: 190 if value, ok := values[i].(*sql.NullString); !ok { 191 return fmt.Errorf("unexpected type %T for field content", values[i]) 192 } else if value.Valid { 193 po.Content = value.String 194 } 195 case post.FieldContentHTML: 196 if value, ok := values[i].(*sql.NullString); !ok { 197 return fmt.Errorf("unexpected type %T for field content_html", values[i]) 198 } else if value.Valid { 199 po.ContentHTML = value.String 200 } 201 case post.FieldViewCount: 202 if value, ok := values[i].(*sql.NullInt64); !ok { 203 return fmt.Errorf("unexpected type %T for field view_count", values[i]) 204 } else if value.Valid { 205 po.ViewCount = value.Int64 206 } 207 case post.FieldCommentCount: 208 if value, ok := values[i].(*sql.NullInt64); !ok { 209 return fmt.Errorf("unexpected type %T for field comment_count", values[i]) 210 } else if value.Valid { 211 po.CommentCount = value.Int64 212 } 213 case post.FieldRatingCount: 214 if value, ok := values[i].(*sql.NullInt64); !ok { 215 return fmt.Errorf("unexpected type %T for field rating_count", values[i]) 216 } else if value.Valid { 217 po.RatingCount = value.Int64 218 } 219 case post.FieldRatingTotal: 220 if value, ok := values[i].(*sql.NullInt64); !ok { 221 return fmt.Errorf("unexpected type %T for field rating_total", values[i]) 222 } else if value.Valid { 223 po.RatingTotal = value.Int64 224 } 225 case post.FieldDraft: 226 if value, ok := values[i].(*sql.NullBool); !ok { 227 return fmt.Errorf("unexpected type %T for field draft", values[i]) 228 } else if value.Valid { 229 po.Draft = value.Bool 230 } 231 case post.FieldApproved: 232 if value, ok := values[i].(*sql.NullBool); !ok { 233 return fmt.Errorf("unexpected type %T for field approved", values[i]) 234 } else if value.Valid { 235 po.Approved = value.Bool 236 } 237 case post.FieldFeaturedImageID: 238 if value, ok := values[i].(*sql.NullInt64); !ok { 239 return fmt.Errorf("unexpected type %T for field featured_image_id", values[i]) 240 } else if value.Valid { 241 po.FeaturedImageID = int(value.Int64) 242 } 243 case post.FieldUserID: 244 if value, ok := values[i].(*sql.NullInt64); !ok { 245 return fmt.Errorf("unexpected type %T for field user_id", values[i]) 246 } else if value.Valid { 247 po.UserID = int(value.Int64) 248 } 249 } 250 } 251 return nil 252 } 253 254 // QueryUser queries the "user" edge of the Post entity. 255 func (po *Post) QueryUser() *UserQuery { 256 return (&PostClient{config: po.config}).QueryUser(po) 257 } 258 259 // QueryTopics queries the "topics" edge of the Post entity. 260 func (po *Post) QueryTopics() *TopicQuery { 261 return (&PostClient{config: po.config}).QueryTopics(po) 262 } 263 264 // QueryFeaturedImage queries the "featured_image" edge of the Post entity. 265 func (po *Post) QueryFeaturedImage() *FileQuery { 266 return (&PostClient{config: po.config}).QueryFeaturedImage(po) 267 } 268 269 // QueryComments queries the "comments" edge of the Post entity. 270 func (po *Post) QueryComments() *CommentQuery { 271 return (&PostClient{config: po.config}).QueryComments(po) 272 } 273 274 // Update returns a builder for updating this Post. 275 // Note that you need to call Post.Unwrap() before calling this method if this Post 276 // was returned from a transaction, and the transaction was committed or rolled back. 277 func (po *Post) Update() *PostUpdateOne { 278 return (&PostClient{config: po.config}).UpdateOne(po) 279 } 280 281 // Unwrap unwraps the Post entity that was returned from a transaction after it was closed, 282 // so that all future queries will be executed through the driver which created the transaction. 283 func (po *Post) Unwrap() *Post { 284 tx, ok := po.config.driver.(*txDriver) 285 if !ok { 286 panic("ent: Post is not a transactional entity") 287 } 288 po.config.driver = tx.drv 289 return po 290 } 291 292 // String implements the fmt.Stringer. 293 func (po *Post) String() string { 294 var builder strings.Builder 295 builder.WriteString("Post(") 296 builder.WriteString(fmt.Sprintf("id=%v", po.ID)) 297 builder.WriteString(", created_at=") 298 builder.WriteString(po.CreatedAt.Format(time.ANSIC)) 299 builder.WriteString(", updated_at=") 300 builder.WriteString(po.UpdatedAt.Format(time.ANSIC)) 301 builder.WriteString(", deleted_at=") 302 builder.WriteString(po.DeletedAt.Format(time.ANSIC)) 303 builder.WriteString(", name=") 304 builder.WriteString(po.Name) 305 builder.WriteString(", slug=") 306 builder.WriteString(po.Slug) 307 builder.WriteString(", description=") 308 builder.WriteString(po.Description) 309 builder.WriteString(", content=") 310 builder.WriteString(po.Content) 311 builder.WriteString(", content_html=") 312 builder.WriteString(po.ContentHTML) 313 builder.WriteString(", view_count=") 314 builder.WriteString(fmt.Sprintf("%v", po.ViewCount)) 315 builder.WriteString(", comment_count=") 316 builder.WriteString(fmt.Sprintf("%v", po.CommentCount)) 317 builder.WriteString(", rating_count=") 318 builder.WriteString(fmt.Sprintf("%v", po.RatingCount)) 319 builder.WriteString(", rating_total=") 320 builder.WriteString(fmt.Sprintf("%v", po.RatingTotal)) 321 builder.WriteString(", draft=") 322 builder.WriteString(fmt.Sprintf("%v", po.Draft)) 323 builder.WriteString(", approved=") 324 builder.WriteString(fmt.Sprintf("%v", po.Approved)) 325 builder.WriteString(", featured_image_id=") 326 builder.WriteString(fmt.Sprintf("%v", po.FeaturedImageID)) 327 builder.WriteString(", user_id=") 328 builder.WriteString(fmt.Sprintf("%v", po.UserID)) 329 builder.WriteByte(')') 330 return builder.String() 331 } 332 333 // Posts is a parsable slice of Post. 334 type Posts []*Post 335 336 func (po Posts) config(cfg config) { 337 for _i := range po { 338 po[_i].config = cfg 339 } 340 }