pcmt/ent/hibp.go

329 lines
12 KiB
Go
Raw Normal View History

2023-04-21 13:57:32 +02:00
// Code generated by ent, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
2023-08-07 21:31:46 +02:00
"entgo.io/ent"
2023-04-21 13:57:32 +02:00
"entgo.io/ent/dialect/sql"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
2023-04-21 13:57:32 +02:00
"github.com/google/uuid"
)
// HIBP is the model entity for the HIBP schema.
type HIBP struct {
config `json:"-"`
// ID of the ent.
ID uuid.UUID `json:"id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Title holds the value of the "title" field.
Title string `json:"title,omitempty"`
2023-04-21 13:57:32 +02:00
// Domain holds the value of the "domain" field.
Domain string `json:"domain,omitempty"`
// BreachDate holds the value of the "breach_date" field.
BreachDate time.Time `json:"breach_date,omitempty"`
// AddedDate holds the value of the "added_date" field.
AddedDate time.Time `json:"added_date,omitempty"`
// ModifiedDate holds the value of the "modified_date" field.
ModifiedDate time.Time `json:"modified_date,omitempty"`
// PwnCount holds the value of the "pwn_count" field.
PwnCount int `json:"pwn_count,omitempty"`
// Description holds the value of the "description" field.
Description *string `json:"description,omitempty"`
2023-04-21 13:57:32 +02:00
// Dataclasses holds the value of the "dataclasses" field.
Dataclasses []string `json:"dataclasses,omitempty"`
// IsVerified holds the value of the "is_verified" field.
IsVerified bool `json:"is_verified,omitempty"`
// IsFabricated holds the value of the "is_fabricated" field.
IsFabricated bool `json:"is_fabricated,omitempty"`
// IsSensitive holds the value of the "is_sensitive" field.
IsSensitive bool `json:"is_sensitive,omitempty"`
// IsRetired holds the value of the "is_retired" field.
IsRetired bool `json:"is_retired,omitempty"`
// IsSpamList holds the value of the "is_spamList" field.
IsSpamList bool `json:"is_spamList,omitempty"`
// IsMalware holds the value of the "is_malware" field.
IsMalware bool `json:"is_malware,omitempty"`
// LogoPath holds the value of the "logo_path" field.
LogoPath *string `json:"logo_path,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the HIBPQuery when eager-loading is set.
Edges HIBPEdges `json:"edges"`
tracked_breaches_hibp *uuid.UUID
selectValues sql.SelectValues
}
// HIBPEdges holds the relations/edges for other nodes in the graph.
type HIBPEdges struct {
// TrackedBreaches holds the value of the tracked_breaches edge.
TrackedBreaches *TrackedBreaches `json:"tracked_breaches,omitempty"`
// loadedTypes holds the information for reporting if a
// type was loaded (or requested) in eager-loading or not.
loadedTypes [1]bool
}
// TrackedBreachesOrErr returns the TrackedBreaches value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e HIBPEdges) TrackedBreachesOrErr() (*TrackedBreaches, error) {
if e.loadedTypes[0] {
if e.TrackedBreaches == nil {
// Edge was loaded but was not found.
return nil, &NotFoundError{label: trackedbreaches.Label}
}
return e.TrackedBreaches, nil
}
return nil, &NotLoadedError{edge: "tracked_breaches"}
2023-04-21 13:57:32 +02:00
}
// scanValues returns the types for scanning values from sql.Rows.
func (*HIBP) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case hibp.FieldDataclasses:
values[i] = new([]byte)
case hibp.FieldIsVerified, hibp.FieldIsFabricated, hibp.FieldIsSensitive, hibp.FieldIsRetired, hibp.FieldIsSpamList, hibp.FieldIsMalware:
values[i] = new(sql.NullBool)
case hibp.FieldPwnCount:
values[i] = new(sql.NullInt64)
case hibp.FieldName, hibp.FieldTitle, hibp.FieldDomain, hibp.FieldDescription, hibp.FieldLogoPath:
2023-04-21 13:57:32 +02:00
values[i] = new(sql.NullString)
case hibp.FieldBreachDate, hibp.FieldAddedDate, hibp.FieldModifiedDate:
values[i] = new(sql.NullTime)
case hibp.FieldID:
values[i] = new(uuid.UUID)
case hibp.ForeignKeys[0]: // tracked_breaches_hibp
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
2023-04-21 13:57:32 +02:00
default:
2023-08-07 21:31:46 +02:00
values[i] = new(sql.UnknownType)
2023-04-21 13:57:32 +02:00
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the HIBP fields.
func (h *HIBP) 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 hibp.FieldID:
if value, ok := values[i].(*uuid.UUID); !ok {
return fmt.Errorf("unexpected type %T for field id", values[i])
} else if value != nil {
h.ID = *value
}
case hibp.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
h.Name = value.String
}
case hibp.FieldTitle:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field title", values[i])
} else if value.Valid {
h.Title = value.String
}
2023-04-21 13:57:32 +02:00
case hibp.FieldDomain:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field domain", values[i])
} else if value.Valid {
h.Domain = value.String
}
case hibp.FieldBreachDate:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field breach_date", values[i])
} else if value.Valid {
h.BreachDate = value.Time
}
case hibp.FieldAddedDate:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field added_date", values[i])
} else if value.Valid {
h.AddedDate = value.Time
}
case hibp.FieldModifiedDate:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field modified_date", values[i])
} else if value.Valid {
h.ModifiedDate = value.Time
}
case hibp.FieldPwnCount:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field pwn_count", values[i])
} else if value.Valid {
h.PwnCount = int(value.Int64)
}
case hibp.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
h.Description = new(string)
*h.Description = value.String
2023-04-21 13:57:32 +02:00
}
case hibp.FieldDataclasses:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field dataclasses", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &h.Dataclasses); err != nil {
return fmt.Errorf("unmarshal field dataclasses: %w", err)
}
}
case hibp.FieldIsVerified:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_verified", values[i])
} else if value.Valid {
h.IsVerified = value.Bool
}
case hibp.FieldIsFabricated:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_fabricated", values[i])
} else if value.Valid {
h.IsFabricated = value.Bool
}
case hibp.FieldIsSensitive:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_sensitive", values[i])
} else if value.Valid {
h.IsSensitive = value.Bool
}
case hibp.FieldIsRetired:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_retired", values[i])
} else if value.Valid {
h.IsRetired = value.Bool
}
case hibp.FieldIsSpamList:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_spamList", values[i])
} else if value.Valid {
h.IsSpamList = value.Bool
}
case hibp.FieldIsMalware:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_malware", values[i])
} else if value.Valid {
h.IsMalware = value.Bool
}
case hibp.FieldLogoPath:
2023-04-21 13:57:32 +02:00
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field logo_path", values[i])
2023-04-21 13:57:32 +02:00
} else if value.Valid {
h.LogoPath = new(string)
*h.LogoPath = value.String
}
case hibp.ForeignKeys[0]:
if value, ok := values[i].(*sql.NullScanner); !ok {
return fmt.Errorf("unexpected type %T for field tracked_breaches_hibp", values[i])
} else if value.Valid {
h.tracked_breaches_hibp = new(uuid.UUID)
*h.tracked_breaches_hibp = *value.S.(*uuid.UUID)
2023-04-21 13:57:32 +02:00
}
2023-08-07 21:31:46 +02:00
default:
h.selectValues.Set(columns[i], values[i])
2023-04-21 13:57:32 +02:00
}
}
return nil
}
2023-08-07 21:31:46 +02:00
// Value returns the ent.Value that was dynamically selected and assigned to the HIBP.
// This includes values selected through modifiers, order, etc.
func (h *HIBP) Value(name string) (ent.Value, error) {
return h.selectValues.Get(name)
}
// QueryTrackedBreaches queries the "tracked_breaches" edge of the HIBP entity.
func (h *HIBP) QueryTrackedBreaches() *TrackedBreachesQuery {
return NewHIBPClient(h.config).QueryTrackedBreaches(h)
}
2023-04-21 13:57:32 +02:00
// Update returns a builder for updating this HIBP.
// Note that you need to call HIBP.Unwrap() before calling this method if this HIBP
// was returned from a transaction, and the transaction was committed or rolled back.
func (h *HIBP) Update() *HIBPUpdateOne {
return NewHIBPClient(h.config).UpdateOne(h)
}
// Unwrap unwraps the HIBP 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 *HIBP) Unwrap() *HIBP {
_tx, ok := h.config.driver.(*txDriver)
if !ok {
panic("ent: HIBP is not a transactional entity")
}
h.config.driver = _tx.drv
return h
}
// String implements the fmt.Stringer.
func (h *HIBP) String() string {
var builder strings.Builder
builder.WriteString("HIBP(")
builder.WriteString(fmt.Sprintf("id=%v, ", h.ID))
builder.WriteString("name=")
builder.WriteString(h.Name)
builder.WriteString(", ")
builder.WriteString("title=")
builder.WriteString(h.Title)
builder.WriteString(", ")
2023-04-21 13:57:32 +02:00
builder.WriteString("domain=")
builder.WriteString(h.Domain)
builder.WriteString(", ")
builder.WriteString("breach_date=")
builder.WriteString(h.BreachDate.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("added_date=")
builder.WriteString(h.AddedDate.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("modified_date=")
builder.WriteString(h.ModifiedDate.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("pwn_count=")
builder.WriteString(fmt.Sprintf("%v", h.PwnCount))
builder.WriteString(", ")
if v := h.Description; v != nil {
builder.WriteString("description=")
builder.WriteString(*v)
}
2023-04-21 13:57:32 +02:00
builder.WriteString(", ")
builder.WriteString("dataclasses=")
builder.WriteString(fmt.Sprintf("%v", h.Dataclasses))
builder.WriteString(", ")
builder.WriteString("is_verified=")
builder.WriteString(fmt.Sprintf("%v", h.IsVerified))
builder.WriteString(", ")
builder.WriteString("is_fabricated=")
builder.WriteString(fmt.Sprintf("%v", h.IsFabricated))
builder.WriteString(", ")
builder.WriteString("is_sensitive=")
builder.WriteString(fmt.Sprintf("%v", h.IsSensitive))
builder.WriteString(", ")
builder.WriteString("is_retired=")
builder.WriteString(fmt.Sprintf("%v", h.IsRetired))
builder.WriteString(", ")
builder.WriteString("is_spamList=")
builder.WriteString(fmt.Sprintf("%v", h.IsSpamList))
builder.WriteString(", ")
builder.WriteString("is_malware=")
builder.WriteString(fmt.Sprintf("%v", h.IsMalware))
builder.WriteString(", ")
if v := h.LogoPath; v != nil {
builder.WriteString("logo_path=")
builder.WriteString(*v)
}
2023-04-21 13:57:32 +02:00
builder.WriteByte(')')
return builder.String()
}
// HIBPs is a parsable slice of HIBP.
type HIBPs []*HIBP