// Code generated by ent, DO NOT EDIT. package ent import ( "encoding/json" "fmt" "polaris/ent/history" "strings" "time" "entgo.io/ent" "entgo.io/ent/dialect/sql" ) // History is the model entity for the History schema. type History struct { config `json:"-"` // ID of the ent. ID int `json:"id,omitempty"` // MediaID holds the value of the "media_id" field. MediaID int `json:"media_id,omitempty"` // EpisodeNums holds the value of the "episode_nums" field. EpisodeNums []int `json:"episode_nums,omitempty"` // SeasonNum holds the value of the "season_num" field. SeasonNum int `json:"season_num,omitempty"` // SourceTitle holds the value of the "source_title" field. SourceTitle string `json:"source_title,omitempty"` // Date holds the value of the "date" field. Date time.Time `json:"date,omitempty"` // TargetDir holds the value of the "target_dir" field. TargetDir string `json:"target_dir,omitempty"` // Size holds the value of the "size" field. Size int `json:"size,omitempty"` // DownloadClientID holds the value of the "download_client_id" field. DownloadClientID int `json:"download_client_id,omitempty"` // IndexerID holds the value of the "indexer_id" field. IndexerID int `json:"indexer_id,omitempty"` // torrent link Link string `json:"link,omitempty"` // torrent hash Hash string `json:"hash,omitempty"` // Status holds the value of the "status" field. Status history.Status `json:"status,omitempty"` // CreateTime holds the value of the "create_time" field. CreateTime time.Time `json:"create_time,omitempty"` selectValues sql.SelectValues } // scanValues returns the types for scanning values from sql.Rows. func (*History) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { case history.FieldEpisodeNums: values[i] = new([]byte) case history.FieldID, history.FieldMediaID, history.FieldSeasonNum, history.FieldSize, history.FieldDownloadClientID, history.FieldIndexerID: values[i] = new(sql.NullInt64) case history.FieldSourceTitle, history.FieldTargetDir, history.FieldLink, history.FieldHash, history.FieldStatus: values[i] = new(sql.NullString) case history.FieldDate, history.FieldCreateTime: values[i] = new(sql.NullTime) default: values[i] = new(sql.UnknownType) } } return values, nil } // assignValues assigns the values that were returned from sql.Rows (after scanning) // to the History fields. func (h *History) assignValues(columns []string, values []any) 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 history.FieldID: value, ok := values[i].(*sql.NullInt64) if !ok { return fmt.Errorf("unexpected type %T for field id", value) } h.ID = int(value.Int64) case history.FieldMediaID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field media_id", values[i]) } else if value.Valid { h.MediaID = int(value.Int64) } case history.FieldEpisodeNums: if value, ok := values[i].(*[]byte); !ok { return fmt.Errorf("unexpected type %T for field episode_nums", values[i]) } else if value != nil && len(*value) > 0 { if err := json.Unmarshal(*value, &h.EpisodeNums); err != nil { return fmt.Errorf("unmarshal field episode_nums: %w", err) } } case history.FieldSeasonNum: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field season_num", values[i]) } else if value.Valid { h.SeasonNum = int(value.Int64) } case history.FieldSourceTitle: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field source_title", values[i]) } else if value.Valid { h.SourceTitle = value.String } case history.FieldDate: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field date", values[i]) } else if value.Valid { h.Date = value.Time } case history.FieldTargetDir: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field target_dir", values[i]) } else if value.Valid { h.TargetDir = value.String } case history.FieldSize: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field size", values[i]) } else if value.Valid { h.Size = int(value.Int64) } case history.FieldDownloadClientID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field download_client_id", values[i]) } else if value.Valid { h.DownloadClientID = int(value.Int64) } case history.FieldIndexerID: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field indexer_id", values[i]) } else if value.Valid { h.IndexerID = int(value.Int64) } case history.FieldLink: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field link", values[i]) } else if value.Valid { h.Link = value.String } case history.FieldHash: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field hash", values[i]) } else if value.Valid { h.Hash = value.String } case history.FieldStatus: if value, ok := values[i].(*sql.NullString); !ok { return fmt.Errorf("unexpected type %T for field status", values[i]) } else if value.Valid { h.Status = history.Status(value.String) } case history.FieldCreateTime: if value, ok := values[i].(*sql.NullTime); !ok { return fmt.Errorf("unexpected type %T for field create_time", values[i]) } else if value.Valid { h.CreateTime = value.Time } default: h.selectValues.Set(columns[i], values[i]) } } return nil } // Value returns the ent.Value that was dynamically selected and assigned to the History. // This includes values selected through modifiers, order, etc. func (h *History) Value(name string) (ent.Value, error) { return h.selectValues.Get(name) } // Update returns a builder for updating this History. // Note that you need to call History.Unwrap() before calling this method if this History // was returned from a transaction, and the transaction was committed or rolled back. func (h *History) Update() *HistoryUpdateOne { return NewHistoryClient(h.config).UpdateOne(h) } // Unwrap unwraps the History 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 (h *History) Unwrap() *History { _tx, ok := h.config.driver.(*txDriver) if !ok { panic("ent: History is not a transactional entity") } h.config.driver = _tx.drv return h } // String implements the fmt.Stringer. func (h *History) String() string { var builder strings.Builder builder.WriteString("History(") builder.WriteString(fmt.Sprintf("id=%v, ", h.ID)) builder.WriteString("media_id=") builder.WriteString(fmt.Sprintf("%v", h.MediaID)) builder.WriteString(", ") builder.WriteString("episode_nums=") builder.WriteString(fmt.Sprintf("%v", h.EpisodeNums)) builder.WriteString(", ") builder.WriteString("season_num=") builder.WriteString(fmt.Sprintf("%v", h.SeasonNum)) builder.WriteString(", ") builder.WriteString("source_title=") builder.WriteString(h.SourceTitle) builder.WriteString(", ") builder.WriteString("date=") builder.WriteString(h.Date.Format(time.ANSIC)) builder.WriteString(", ") builder.WriteString("target_dir=") builder.WriteString(h.TargetDir) builder.WriteString(", ") builder.WriteString("size=") builder.WriteString(fmt.Sprintf("%v", h.Size)) builder.WriteString(", ") builder.WriteString("download_client_id=") builder.WriteString(fmt.Sprintf("%v", h.DownloadClientID)) builder.WriteString(", ") builder.WriteString("indexer_id=") builder.WriteString(fmt.Sprintf("%v", h.IndexerID)) builder.WriteString(", ") builder.WriteString("link=") builder.WriteString(h.Link) builder.WriteString(", ") builder.WriteString("hash=") builder.WriteString(h.Hash) builder.WriteString(", ") builder.WriteString("status=") builder.WriteString(fmt.Sprintf("%v", h.Status)) builder.WriteString(", ") builder.WriteString("create_time=") builder.WriteString(h.CreateTime.Format(time.ANSIC)) builder.WriteByte(')') return builder.String() } // Histories is a parsable slice of History. type Histories []*History