You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
5.5 KiB
174 lines
5.5 KiB
// Code generated by entc, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"github.com/go-kratos/examples/blog/internal/data/ent/article"
|
|
)
|
|
|
|
// Article is the model entity for the Article schema.
|
|
type Article struct {
|
|
config `json:"-"`
|
|
// ID of the ent.
|
|
ID int64 `json:"id,omitempty"`
|
|
// Title holds the value of the "title" field.
|
|
Title string `json:"title,omitempty"`
|
|
// Content holds the value of the "content" field.
|
|
Content string `json:"content,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 ArticleQuery when eager-loading is set.
|
|
Edges ArticleEdges `json:"edges"`
|
|
}
|
|
|
|
// ArticleEdges holds the relations/edges for other nodes in the graph.
|
|
type ArticleEdges struct {
|
|
// Comments holds the value of the comments edge.
|
|
Comments []*Comment `json:"comments,omitempty"`
|
|
// Tags holds the value of the tags edge.
|
|
Tags []*Tag `json:"tags,omitempty"`
|
|
// loadedTypes holds the information for reporting if a
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
loadedTypes [2]bool
|
|
}
|
|
|
|
// CommentsOrErr returns the Comments value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e ArticleEdges) CommentsOrErr() ([]*Comment, error) {
|
|
if e.loadedTypes[0] {
|
|
return e.Comments, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "comments"}
|
|
}
|
|
|
|
// TagsOrErr returns the Tags value or an error if the edge
|
|
// was not loaded in eager-loading.
|
|
func (e ArticleEdges) TagsOrErr() ([]*Tag, error) {
|
|
if e.loadedTypes[1] {
|
|
return e.Tags, nil
|
|
}
|
|
return nil, &NotLoadedError{edge: "tags"}
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*Article) scanValues(columns []string) ([]interface{}, error) {
|
|
values := make([]interface{}, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case article.FieldID:
|
|
values[i] = &sql.NullInt64{}
|
|
case article.FieldTitle, article.FieldContent:
|
|
values[i] = &sql.NullString{}
|
|
case article.FieldCreatedAt, article.FieldUpdatedAt:
|
|
values[i] = &sql.NullTime{}
|
|
default:
|
|
return nil, fmt.Errorf("unexpected column %q for type Article", columns[i])
|
|
}
|
|
}
|
|
return values, nil
|
|
}
|
|
|
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
// to the Article fields.
|
|
func (a *Article) assignValues(columns []string, values []interface{}) 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 article.FieldID:
|
|
value, ok := values[i].(*sql.NullInt64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field id", value)
|
|
}
|
|
a.ID = int64(value.Int64)
|
|
case article.FieldTitle:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field title", values[i])
|
|
} else if value.Valid {
|
|
a.Title = value.String
|
|
}
|
|
case article.FieldContent:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field content", values[i])
|
|
} else if value.Valid {
|
|
a.Content = value.String
|
|
}
|
|
case article.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 {
|
|
a.CreatedAt = value.Time
|
|
}
|
|
case article.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 {
|
|
a.UpdatedAt = value.Time
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// QueryComments queries the "comments" edge of the Article entity.
|
|
func (a *Article) QueryComments() *CommentQuery {
|
|
return (&ArticleClient{config: a.config}).QueryComments(a)
|
|
}
|
|
|
|
// QueryTags queries the "tags" edge of the Article entity.
|
|
func (a *Article) QueryTags() *TagQuery {
|
|
return (&ArticleClient{config: a.config}).QueryTags(a)
|
|
}
|
|
|
|
// Update returns a builder for updating this Article.
|
|
// Note that you need to call Article.Unwrap() before calling this method if this Article
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (a *Article) Update() *ArticleUpdateOne {
|
|
return (&ArticleClient{config: a.config}).UpdateOne(a)
|
|
}
|
|
|
|
// Unwrap unwraps the Article 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 (a *Article) Unwrap() *Article {
|
|
tx, ok := a.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("ent: Article is not a transactional entity")
|
|
}
|
|
a.config.driver = tx.drv
|
|
return a
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (a *Article) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("Article(")
|
|
builder.WriteString(fmt.Sprintf("id=%v", a.ID))
|
|
builder.WriteString(", title=")
|
|
builder.WriteString(a.Title)
|
|
builder.WriteString(", content=")
|
|
builder.WriteString(a.Content)
|
|
builder.WriteString(", created_at=")
|
|
builder.WriteString(a.CreatedAt.Format(time.ANSIC))
|
|
builder.WriteString(", updated_at=")
|
|
builder.WriteString(a.UpdatedAt.Format(time.ANSIC))
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// Articles is a parsable slice of Article.
|
|
type Articles []*Article
|
|
|
|
func (a Articles) config(cfg config) {
|
|
for _i := range a {
|
|
a[_i].config = cfg
|
|
}
|
|
}
|
|
|