github.com/ngocphuongnb/tetua@v0.0.7-alpha/packages/entrepository/ent/page.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/page"
    13  )
    14  
    15  // Page is the model entity for the Page schema.
    16  type Page 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  	// Name holds the value of the "name" field.
    27  	Name string `json:"name,omitempty"`
    28  	// Slug holds the value of the "slug" field.
    29  	Slug string `json:"slug,omitempty"`
    30  	// Content holds the value of the "content" field.
    31  	Content string `json:"content,omitempty" validate:"required"`
    32  	// ContentHTML holds the value of the "content_html" field.
    33  	ContentHTML string `json:"content_html,omitempty"`
    34  	// Draft holds the value of the "draft" field.
    35  	Draft bool `json:"draft,omitempty"`
    36  	// FeaturedImageID holds the value of the "featured_image_id" field.
    37  	FeaturedImageID int `json:"featured_image_id,omitempty"`
    38  	// Edges holds the relations/edges for other nodes in the graph.
    39  	// The values are being populated by the PageQuery when eager-loading is set.
    40  	Edges PageEdges `json:"edges"`
    41  }
    42  
    43  // PageEdges holds the relations/edges for other nodes in the graph.
    44  type PageEdges struct {
    45  	// FeaturedImage holds the value of the featured_image edge.
    46  	FeaturedImage *File `json:"featured_image,omitempty"`
    47  	// loadedTypes holds the information for reporting if a
    48  	// type was loaded (or requested) in eager-loading or not.
    49  	loadedTypes [1]bool
    50  }
    51  
    52  // FeaturedImageOrErr returns the FeaturedImage value or an error if the edge
    53  // was not loaded in eager-loading, or loaded but was not found.
    54  func (e PageEdges) FeaturedImageOrErr() (*File, error) {
    55  	if e.loadedTypes[0] {
    56  		if e.FeaturedImage == nil {
    57  			// The edge featured_image was loaded in eager-loading,
    58  			// but was not found.
    59  			return nil, &NotFoundError{label: file.Label}
    60  		}
    61  		return e.FeaturedImage, nil
    62  	}
    63  	return nil, &NotLoadedError{edge: "featured_image"}
    64  }
    65  
    66  // scanValues returns the types for scanning values from sql.Rows.
    67  func (*Page) scanValues(columns []string) ([]interface{}, error) {
    68  	values := make([]interface{}, len(columns))
    69  	for i := range columns {
    70  		switch columns[i] {
    71  		case page.FieldDraft:
    72  			values[i] = new(sql.NullBool)
    73  		case page.FieldID, page.FieldFeaturedImageID:
    74  			values[i] = new(sql.NullInt64)
    75  		case page.FieldName, page.FieldSlug, page.FieldContent, page.FieldContentHTML:
    76  			values[i] = new(sql.NullString)
    77  		case page.FieldCreatedAt, page.FieldUpdatedAt, page.FieldDeletedAt:
    78  			values[i] = new(sql.NullTime)
    79  		default:
    80  			return nil, fmt.Errorf("unexpected column %q for type Page", columns[i])
    81  		}
    82  	}
    83  	return values, nil
    84  }
    85  
    86  // assignValues assigns the values that were returned from sql.Rows (after scanning)
    87  // to the Page fields.
    88  func (pa *Page) assignValues(columns []string, values []interface{}) error {
    89  	if m, n := len(values), len(columns); m < n {
    90  		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
    91  	}
    92  	for i := range columns {
    93  		switch columns[i] {
    94  		case page.FieldID:
    95  			value, ok := values[i].(*sql.NullInt64)
    96  			if !ok {
    97  				return fmt.Errorf("unexpected type %T for field id", value)
    98  			}
    99  			pa.ID = int(value.Int64)
   100  		case page.FieldCreatedAt:
   101  			if value, ok := values[i].(*sql.NullTime); !ok {
   102  				return fmt.Errorf("unexpected type %T for field created_at", values[i])
   103  			} else if value.Valid {
   104  				pa.CreatedAt = value.Time
   105  			}
   106  		case page.FieldUpdatedAt:
   107  			if value, ok := values[i].(*sql.NullTime); !ok {
   108  				return fmt.Errorf("unexpected type %T for field updated_at", values[i])
   109  			} else if value.Valid {
   110  				pa.UpdatedAt = value.Time
   111  			}
   112  		case page.FieldDeletedAt:
   113  			if value, ok := values[i].(*sql.NullTime); !ok {
   114  				return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
   115  			} else if value.Valid {
   116  				pa.DeletedAt = value.Time
   117  			}
   118  		case page.FieldName:
   119  			if value, ok := values[i].(*sql.NullString); !ok {
   120  				return fmt.Errorf("unexpected type %T for field name", values[i])
   121  			} else if value.Valid {
   122  				pa.Name = value.String
   123  			}
   124  		case page.FieldSlug:
   125  			if value, ok := values[i].(*sql.NullString); !ok {
   126  				return fmt.Errorf("unexpected type %T for field slug", values[i])
   127  			} else if value.Valid {
   128  				pa.Slug = value.String
   129  			}
   130  		case page.FieldContent:
   131  			if value, ok := values[i].(*sql.NullString); !ok {
   132  				return fmt.Errorf("unexpected type %T for field content", values[i])
   133  			} else if value.Valid {
   134  				pa.Content = value.String
   135  			}
   136  		case page.FieldContentHTML:
   137  			if value, ok := values[i].(*sql.NullString); !ok {
   138  				return fmt.Errorf("unexpected type %T for field content_html", values[i])
   139  			} else if value.Valid {
   140  				pa.ContentHTML = value.String
   141  			}
   142  		case page.FieldDraft:
   143  			if value, ok := values[i].(*sql.NullBool); !ok {
   144  				return fmt.Errorf("unexpected type %T for field draft", values[i])
   145  			} else if value.Valid {
   146  				pa.Draft = value.Bool
   147  			}
   148  		case page.FieldFeaturedImageID:
   149  			if value, ok := values[i].(*sql.NullInt64); !ok {
   150  				return fmt.Errorf("unexpected type %T for field featured_image_id", values[i])
   151  			} else if value.Valid {
   152  				pa.FeaturedImageID = int(value.Int64)
   153  			}
   154  		}
   155  	}
   156  	return nil
   157  }
   158  
   159  // QueryFeaturedImage queries the "featured_image" edge of the Page entity.
   160  func (pa *Page) QueryFeaturedImage() *FileQuery {
   161  	return (&PageClient{config: pa.config}).QueryFeaturedImage(pa)
   162  }
   163  
   164  // Update returns a builder for updating this Page.
   165  // Note that you need to call Page.Unwrap() before calling this method if this Page
   166  // was returned from a transaction, and the transaction was committed or rolled back.
   167  func (pa *Page) Update() *PageUpdateOne {
   168  	return (&PageClient{config: pa.config}).UpdateOne(pa)
   169  }
   170  
   171  // Unwrap unwraps the Page entity that was returned from a transaction after it was closed,
   172  // so that all future queries will be executed through the driver which created the transaction.
   173  func (pa *Page) Unwrap() *Page {
   174  	tx, ok := pa.config.driver.(*txDriver)
   175  	if !ok {
   176  		panic("ent: Page is not a transactional entity")
   177  	}
   178  	pa.config.driver = tx.drv
   179  	return pa
   180  }
   181  
   182  // String implements the fmt.Stringer.
   183  func (pa *Page) String() string {
   184  	var builder strings.Builder
   185  	builder.WriteString("Page(")
   186  	builder.WriteString(fmt.Sprintf("id=%v", pa.ID))
   187  	builder.WriteString(", created_at=")
   188  	builder.WriteString(pa.CreatedAt.Format(time.ANSIC))
   189  	builder.WriteString(", updated_at=")
   190  	builder.WriteString(pa.UpdatedAt.Format(time.ANSIC))
   191  	builder.WriteString(", deleted_at=")
   192  	builder.WriteString(pa.DeletedAt.Format(time.ANSIC))
   193  	builder.WriteString(", name=")
   194  	builder.WriteString(pa.Name)
   195  	builder.WriteString(", slug=")
   196  	builder.WriteString(pa.Slug)
   197  	builder.WriteString(", content=")
   198  	builder.WriteString(pa.Content)
   199  	builder.WriteString(", content_html=")
   200  	builder.WriteString(pa.ContentHTML)
   201  	builder.WriteString(", draft=")
   202  	builder.WriteString(fmt.Sprintf("%v", pa.Draft))
   203  	builder.WriteString(", featured_image_id=")
   204  	builder.WriteString(fmt.Sprintf("%v", pa.FeaturedImageID))
   205  	builder.WriteByte(')')
   206  	return builder.String()
   207  }
   208  
   209  // Pages is a parsable slice of Page.
   210  type Pages []*Page
   211  
   212  func (pa Pages) config(cfg config) {
   213  	for _i := range pa {
   214  		pa[_i].config = cfg
   215  	}
   216  }