ent: add HIBP model
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-04-21 13:57:32 +02:00
parent 555bc65502
commit e58c15f1c9
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
16 changed files with 4020 additions and 4 deletions

@ -14,6 +14,7 @@ import (
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"git.dotya.ml/mirre-mt/pcmt/ent/user"
)
@ -22,6 +23,8 @@ type Client struct {
config
// Schema is the client for creating, migrating and dropping schema.
Schema *migrate.Schema
// HIBP is the client for interacting with the HIBP builders.
HIBP *HIBPClient
// User is the client for interacting with the User builders.
User *UserClient
}
@ -37,6 +40,7 @@ func NewClient(opts ...Option) *Client {
func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.HIBP = NewHIBPClient(c.config)
c.User = NewUserClient(c.config)
}
@ -120,6 +124,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
return &Tx{
ctx: ctx,
config: cfg,
HIBP: NewHIBPClient(cfg),
User: NewUserClient(cfg),
}, nil
}
@ -140,6 +145,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
return &Tx{
ctx: ctx,
config: cfg,
HIBP: NewHIBPClient(cfg),
User: NewUserClient(cfg),
}, nil
}
@ -147,7 +153,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// User.
// HIBP.
// Query().
// Count(ctx)
func (c *Client) Debug() *Client {
@ -169,18 +175,22 @@ func (c *Client) Close() error {
// Use adds the mutation hooks to all the entity clients.
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
c.HIBP.Use(hooks...)
c.User.Use(hooks...)
}
// Intercept adds the query interceptors to all the entity clients.
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func (c *Client) Intercept(interceptors ...Interceptor) {
c.HIBP.Intercept(interceptors...)
c.User.Intercept(interceptors...)
}
// Mutate implements the ent.Mutator interface.
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
switch m := m.(type) {
case *HIBPMutation:
return c.HIBP.mutate(ctx, m)
case *UserMutation:
return c.User.mutate(ctx, m)
default:
@ -188,6 +198,124 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
}
}
// HIBPClient is a client for the HIBP schema.
type HIBPClient struct {
config
}
// NewHIBPClient returns a client for the HIBP from the given config.
func NewHIBPClient(c config) *HIBPClient {
return &HIBPClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `hibp.Hooks(f(g(h())))`.
func (c *HIBPClient) Use(hooks ...Hook) {
c.hooks.HIBP = append(c.hooks.HIBP, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `hibp.Intercept(f(g(h())))`.
func (c *HIBPClient) Intercept(interceptors ...Interceptor) {
c.inters.HIBP = append(c.inters.HIBP, interceptors...)
}
// Create returns a builder for creating a HIBP entity.
func (c *HIBPClient) Create() *HIBPCreate {
mutation := newHIBPMutation(c.config, OpCreate)
return &HIBPCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of HIBP entities.
func (c *HIBPClient) CreateBulk(builders ...*HIBPCreate) *HIBPCreateBulk {
return &HIBPCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for HIBP.
func (c *HIBPClient) Update() *HIBPUpdate {
mutation := newHIBPMutation(c.config, OpUpdate)
return &HIBPUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *HIBPClient) UpdateOne(h *HIBP) *HIBPUpdateOne {
mutation := newHIBPMutation(c.config, OpUpdateOne, withHIBP(h))
return &HIBPUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *HIBPClient) UpdateOneID(id uuid.UUID) *HIBPUpdateOne {
mutation := newHIBPMutation(c.config, OpUpdateOne, withHIBPID(id))
return &HIBPUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for HIBP.
func (c *HIBPClient) Delete() *HIBPDelete {
mutation := newHIBPMutation(c.config, OpDelete)
return &HIBPDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *HIBPClient) DeleteOne(h *HIBP) *HIBPDeleteOne {
return c.DeleteOneID(h.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *HIBPClient) DeleteOneID(id uuid.UUID) *HIBPDeleteOne {
builder := c.Delete().Where(hibp.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &HIBPDeleteOne{builder}
}
// Query returns a query builder for HIBP.
func (c *HIBPClient) Query() *HIBPQuery {
return &HIBPQuery{
config: c.config,
ctx: &QueryContext{Type: TypeHIBP},
inters: c.Interceptors(),
}
}
// Get returns a HIBP entity by its id.
func (c *HIBPClient) Get(ctx context.Context, id uuid.UUID) (*HIBP, error) {
return c.Query().Where(hibp.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *HIBPClient) GetX(ctx context.Context, id uuid.UUID) *HIBP {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *HIBPClient) Hooks() []Hook {
return c.hooks.HIBP
}
// Interceptors returns the client interceptors.
func (c *HIBPClient) Interceptors() []Interceptor {
return c.inters.HIBP
}
func (c *HIBPClient) mutate(ctx context.Context, m *HIBPMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&HIBPCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&HIBPUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&HIBPUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&HIBPDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown HIBP mutation op: %q", m.Op())
}
}
// UserClient is a client for the User schema.
type UserClient struct {
config
@ -309,9 +437,9 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error)
// hooks and interceptors per client, for fast access.
type (
hooks struct {
User []ent.Hook
HIBP, User []ent.Hook
}
inters struct {
User []ent.Interceptor
HIBP, User []ent.Interceptor
}
)

@ -11,6 +11,7 @@ import (
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"git.dotya.ml/mirre-mt/pcmt/ent/user"
)
@ -65,6 +66,7 @@ type OrderFunc func(*sql.Selector)
// columnChecker returns a function indicates if the column exists in the given column.
func columnChecker(table string) func(string) error {
checks := map[string]func(string) bool{
hibp.Table: hibp.ValidColumn,
user.Table: user.ValidColumn,
}
check, ok := checks[table]

260
ent/hibp.go Normal file

@ -0,0 +1,260 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent/dialect/sql"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"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"`
// 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"`
// May contain HTML markup
Description string `json:"description,omitempty"`
// 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"`
// Always in PNG format
Logo string `json:"logo,omitempty"`
}
// 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.FieldDomain, hibp.FieldDescription, hibp.FieldLogo:
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)
default:
return nil, fmt.Errorf("unexpected column %q for type HIBP", columns[i])
}
}
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.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 = value.String
}
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.FieldLogo:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field logo", values[i])
} else if value.Valid {
h.Logo = value.String
}
}
}
return nil
}
// 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("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(", ")
builder.WriteString("description=")
builder.WriteString(h.Description)
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(", ")
builder.WriteString("logo=")
builder.WriteString(h.Logo)
builder.WriteByte(')')
return builder.String()
}
// HIBPs is a parsable slice of HIBP.
type HIBPs []*HIBP

87
ent/hibp/hibp.go Normal file

@ -0,0 +1,87 @@
// Code generated by ent, DO NOT EDIT.
package hibp
const (
// Label holds the string label denoting the hibp type in the database.
Label = "hibp"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldDomain holds the string denoting the domain field in the database.
FieldDomain = "domain"
// FieldBreachDate holds the string denoting the breach_date field in the database.
FieldBreachDate = "breach_date"
// FieldAddedDate holds the string denoting the added_date field in the database.
FieldAddedDate = "added_date"
// FieldModifiedDate holds the string denoting the modified_date field in the database.
FieldModifiedDate = "modified_date"
// FieldPwnCount holds the string denoting the pwn_count field in the database.
FieldPwnCount = "pwn_count"
// FieldDescription holds the string denoting the description field in the database.
FieldDescription = "description"
// FieldDataclasses holds the string denoting the dataclasses field in the database.
FieldDataclasses = "dataclasses"
// FieldIsVerified holds the string denoting the is_verified field in the database.
FieldIsVerified = "is_verified"
// FieldIsFabricated holds the string denoting the is_fabricated field in the database.
FieldIsFabricated = "is_fabricated"
// FieldIsSensitive holds the string denoting the is_sensitive field in the database.
FieldIsSensitive = "is_sensitive"
// FieldIsRetired holds the string denoting the is_retired field in the database.
FieldIsRetired = "is_retired"
// FieldIsSpamList holds the string denoting the is_spamlist field in the database.
FieldIsSpamList = "is_spam_list"
// FieldIsMalware holds the string denoting the is_malware field in the database.
FieldIsMalware = "is_malware"
// FieldLogo holds the string denoting the logo field in the database.
FieldLogo = "logo"
// Table holds the table name of the hibp in the database.
Table = "hib_ps"
)
// Columns holds all SQL columns for hibp fields.
var Columns = []string{
FieldID,
FieldName,
FieldDomain,
FieldBreachDate,
FieldAddedDate,
FieldModifiedDate,
FieldPwnCount,
FieldDescription,
FieldDataclasses,
FieldIsVerified,
FieldIsFabricated,
FieldIsSensitive,
FieldIsRetired,
FieldIsSpamList,
FieldIsMalware,
FieldLogo,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultIsVerified holds the default value on creation for the "is_verified" field.
DefaultIsVerified bool
// DefaultIsFabricated holds the default value on creation for the "is_fabricated" field.
DefaultIsFabricated bool
// DefaultIsSensitive holds the default value on creation for the "is_sensitive" field.
DefaultIsSensitive bool
// DefaultIsRetired holds the default value on creation for the "is_retired" field.
DefaultIsRetired bool
// DefaultIsSpamList holds the default value on creation for the "is_spamList" field.
DefaultIsSpamList bool
// DefaultIsMalware holds the default value on creation for the "is_malware" field.
DefaultIsMalware bool
)

638
ent/hibp/where.go Normal file

@ -0,0 +1,638 @@
// Code generated by ent, DO NOT EDIT.
package hibp
import (
"time"
"entgo.io/ent/dialect/sql"
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
"github.com/google/uuid"
)
// ID filters vertices based on their ID field.
func ID(id uuid.UUID) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id uuid.UUID) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id uuid.UUID) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...uuid.UUID) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...uuid.UUID) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id uuid.UUID) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id uuid.UUID) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id uuid.UUID) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id uuid.UUID) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldID, id))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldName, v))
}
// Domain applies equality check predicate on the "domain" field. It's identical to DomainEQ.
func Domain(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldDomain, v))
}
// BreachDate applies equality check predicate on the "breach_date" field. It's identical to BreachDateEQ.
func BreachDate(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldBreachDate, v))
}
// AddedDate applies equality check predicate on the "added_date" field. It's identical to AddedDateEQ.
func AddedDate(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldAddedDate, v))
}
// ModifiedDate applies equality check predicate on the "modified_date" field. It's identical to ModifiedDateEQ.
func ModifiedDate(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldModifiedDate, v))
}
// PwnCount applies equality check predicate on the "pwn_count" field. It's identical to PwnCountEQ.
func PwnCount(v int) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldPwnCount, v))
}
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
func Description(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldDescription, v))
}
// IsVerified applies equality check predicate on the "is_verified" field. It's identical to IsVerifiedEQ.
func IsVerified(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsVerified, v))
}
// IsFabricated applies equality check predicate on the "is_fabricated" field. It's identical to IsFabricatedEQ.
func IsFabricated(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsFabricated, v))
}
// IsSensitive applies equality check predicate on the "is_sensitive" field. It's identical to IsSensitiveEQ.
func IsSensitive(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsSensitive, v))
}
// IsRetired applies equality check predicate on the "is_retired" field. It's identical to IsRetiredEQ.
func IsRetired(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsRetired, v))
}
// IsSpamList applies equality check predicate on the "is_spamList" field. It's identical to IsSpamListEQ.
func IsSpamList(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsSpamList, v))
}
// IsMalware applies equality check predicate on the "is_malware" field. It's identical to IsMalwareEQ.
func IsMalware(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsMalware, v))
}
// Logo applies equality check predicate on the "logo" field. It's identical to LogoEQ.
func Logo(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldLogo, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContainsFold(FieldName, v))
}
// DomainEQ applies the EQ predicate on the "domain" field.
func DomainEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldDomain, v))
}
// DomainNEQ applies the NEQ predicate on the "domain" field.
func DomainNEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldDomain, v))
}
// DomainIn applies the In predicate on the "domain" field.
func DomainIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldDomain, vs...))
}
// DomainNotIn applies the NotIn predicate on the "domain" field.
func DomainNotIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldDomain, vs...))
}
// DomainGT applies the GT predicate on the "domain" field.
func DomainGT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldDomain, v))
}
// DomainGTE applies the GTE predicate on the "domain" field.
func DomainGTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldDomain, v))
}
// DomainLT applies the LT predicate on the "domain" field.
func DomainLT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldDomain, v))
}
// DomainLTE applies the LTE predicate on the "domain" field.
func DomainLTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldDomain, v))
}
// DomainContains applies the Contains predicate on the "domain" field.
func DomainContains(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContains(FieldDomain, v))
}
// DomainHasPrefix applies the HasPrefix predicate on the "domain" field.
func DomainHasPrefix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasPrefix(FieldDomain, v))
}
// DomainHasSuffix applies the HasSuffix predicate on the "domain" field.
func DomainHasSuffix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasSuffix(FieldDomain, v))
}
// DomainEqualFold applies the EqualFold predicate on the "domain" field.
func DomainEqualFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEqualFold(FieldDomain, v))
}
// DomainContainsFold applies the ContainsFold predicate on the "domain" field.
func DomainContainsFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContainsFold(FieldDomain, v))
}
// BreachDateEQ applies the EQ predicate on the "breach_date" field.
func BreachDateEQ(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldBreachDate, v))
}
// BreachDateNEQ applies the NEQ predicate on the "breach_date" field.
func BreachDateNEQ(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldBreachDate, v))
}
// BreachDateIn applies the In predicate on the "breach_date" field.
func BreachDateIn(vs ...time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldBreachDate, vs...))
}
// BreachDateNotIn applies the NotIn predicate on the "breach_date" field.
func BreachDateNotIn(vs ...time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldBreachDate, vs...))
}
// BreachDateGT applies the GT predicate on the "breach_date" field.
func BreachDateGT(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldBreachDate, v))
}
// BreachDateGTE applies the GTE predicate on the "breach_date" field.
func BreachDateGTE(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldBreachDate, v))
}
// BreachDateLT applies the LT predicate on the "breach_date" field.
func BreachDateLT(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldBreachDate, v))
}
// BreachDateLTE applies the LTE predicate on the "breach_date" field.
func BreachDateLTE(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldBreachDate, v))
}
// AddedDateEQ applies the EQ predicate on the "added_date" field.
func AddedDateEQ(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldAddedDate, v))
}
// AddedDateNEQ applies the NEQ predicate on the "added_date" field.
func AddedDateNEQ(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldAddedDate, v))
}
// AddedDateIn applies the In predicate on the "added_date" field.
func AddedDateIn(vs ...time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldAddedDate, vs...))
}
// AddedDateNotIn applies the NotIn predicate on the "added_date" field.
func AddedDateNotIn(vs ...time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldAddedDate, vs...))
}
// AddedDateGT applies the GT predicate on the "added_date" field.
func AddedDateGT(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldAddedDate, v))
}
// AddedDateGTE applies the GTE predicate on the "added_date" field.
func AddedDateGTE(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldAddedDate, v))
}
// AddedDateLT applies the LT predicate on the "added_date" field.
func AddedDateLT(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldAddedDate, v))
}
// AddedDateLTE applies the LTE predicate on the "added_date" field.
func AddedDateLTE(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldAddedDate, v))
}
// ModifiedDateEQ applies the EQ predicate on the "modified_date" field.
func ModifiedDateEQ(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldModifiedDate, v))
}
// ModifiedDateNEQ applies the NEQ predicate on the "modified_date" field.
func ModifiedDateNEQ(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldModifiedDate, v))
}
// ModifiedDateIn applies the In predicate on the "modified_date" field.
func ModifiedDateIn(vs ...time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldModifiedDate, vs...))
}
// ModifiedDateNotIn applies the NotIn predicate on the "modified_date" field.
func ModifiedDateNotIn(vs ...time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldModifiedDate, vs...))
}
// ModifiedDateGT applies the GT predicate on the "modified_date" field.
func ModifiedDateGT(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldModifiedDate, v))
}
// ModifiedDateGTE applies the GTE predicate on the "modified_date" field.
func ModifiedDateGTE(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldModifiedDate, v))
}
// ModifiedDateLT applies the LT predicate on the "modified_date" field.
func ModifiedDateLT(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldModifiedDate, v))
}
// ModifiedDateLTE applies the LTE predicate on the "modified_date" field.
func ModifiedDateLTE(v time.Time) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldModifiedDate, v))
}
// PwnCountEQ applies the EQ predicate on the "pwn_count" field.
func PwnCountEQ(v int) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldPwnCount, v))
}
// PwnCountNEQ applies the NEQ predicate on the "pwn_count" field.
func PwnCountNEQ(v int) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldPwnCount, v))
}
// PwnCountIn applies the In predicate on the "pwn_count" field.
func PwnCountIn(vs ...int) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldPwnCount, vs...))
}
// PwnCountNotIn applies the NotIn predicate on the "pwn_count" field.
func PwnCountNotIn(vs ...int) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldPwnCount, vs...))
}
// PwnCountGT applies the GT predicate on the "pwn_count" field.
func PwnCountGT(v int) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldPwnCount, v))
}
// PwnCountGTE applies the GTE predicate on the "pwn_count" field.
func PwnCountGTE(v int) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldPwnCount, v))
}
// PwnCountLT applies the LT predicate on the "pwn_count" field.
func PwnCountLT(v int) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldPwnCount, v))
}
// PwnCountLTE applies the LTE predicate on the "pwn_count" field.
func PwnCountLTE(v int) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldPwnCount, v))
}
// DescriptionEQ applies the EQ predicate on the "description" field.
func DescriptionEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldDescription, v))
}
// DescriptionNEQ applies the NEQ predicate on the "description" field.
func DescriptionNEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldDescription, v))
}
// DescriptionIn applies the In predicate on the "description" field.
func DescriptionIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldDescription, vs...))
}
// DescriptionNotIn applies the NotIn predicate on the "description" field.
func DescriptionNotIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldDescription, vs...))
}
// DescriptionGT applies the GT predicate on the "description" field.
func DescriptionGT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldDescription, v))
}
// DescriptionGTE applies the GTE predicate on the "description" field.
func DescriptionGTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldDescription, v))
}
// DescriptionLT applies the LT predicate on the "description" field.
func DescriptionLT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldDescription, v))
}
// DescriptionLTE applies the LTE predicate on the "description" field.
func DescriptionLTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldDescription, v))
}
// DescriptionContains applies the Contains predicate on the "description" field.
func DescriptionContains(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContains(FieldDescription, v))
}
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
func DescriptionHasPrefix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasPrefix(FieldDescription, v))
}
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
func DescriptionHasSuffix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasSuffix(FieldDescription, v))
}
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
func DescriptionEqualFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEqualFold(FieldDescription, v))
}
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
func DescriptionContainsFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContainsFold(FieldDescription, v))
}
// IsVerifiedEQ applies the EQ predicate on the "is_verified" field.
func IsVerifiedEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsVerified, v))
}
// IsVerifiedNEQ applies the NEQ predicate on the "is_verified" field.
func IsVerifiedNEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldIsVerified, v))
}
// IsFabricatedEQ applies the EQ predicate on the "is_fabricated" field.
func IsFabricatedEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsFabricated, v))
}
// IsFabricatedNEQ applies the NEQ predicate on the "is_fabricated" field.
func IsFabricatedNEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldIsFabricated, v))
}
// IsSensitiveEQ applies the EQ predicate on the "is_sensitive" field.
func IsSensitiveEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsSensitive, v))
}
// IsSensitiveNEQ applies the NEQ predicate on the "is_sensitive" field.
func IsSensitiveNEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldIsSensitive, v))
}
// IsRetiredEQ applies the EQ predicate on the "is_retired" field.
func IsRetiredEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsRetired, v))
}
// IsRetiredNEQ applies the NEQ predicate on the "is_retired" field.
func IsRetiredNEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldIsRetired, v))
}
// IsSpamListEQ applies the EQ predicate on the "is_spamList" field.
func IsSpamListEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsSpamList, v))
}
// IsSpamListNEQ applies the NEQ predicate on the "is_spamList" field.
func IsSpamListNEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldIsSpamList, v))
}
// IsMalwareEQ applies the EQ predicate on the "is_malware" field.
func IsMalwareEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldIsMalware, v))
}
// IsMalwareNEQ applies the NEQ predicate on the "is_malware" field.
func IsMalwareNEQ(v bool) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldIsMalware, v))
}
// LogoEQ applies the EQ predicate on the "logo" field.
func LogoEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEQ(FieldLogo, v))
}
// LogoNEQ applies the NEQ predicate on the "logo" field.
func LogoNEQ(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldNEQ(FieldLogo, v))
}
// LogoIn applies the In predicate on the "logo" field.
func LogoIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldIn(FieldLogo, vs...))
}
// LogoNotIn applies the NotIn predicate on the "logo" field.
func LogoNotIn(vs ...string) predicate.HIBP {
return predicate.HIBP(sql.FieldNotIn(FieldLogo, vs...))
}
// LogoGT applies the GT predicate on the "logo" field.
func LogoGT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGT(FieldLogo, v))
}
// LogoGTE applies the GTE predicate on the "logo" field.
func LogoGTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldGTE(FieldLogo, v))
}
// LogoLT applies the LT predicate on the "logo" field.
func LogoLT(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLT(FieldLogo, v))
}
// LogoLTE applies the LTE predicate on the "logo" field.
func LogoLTE(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldLTE(FieldLogo, v))
}
// LogoContains applies the Contains predicate on the "logo" field.
func LogoContains(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContains(FieldLogo, v))
}
// LogoHasPrefix applies the HasPrefix predicate on the "logo" field.
func LogoHasPrefix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasPrefix(FieldLogo, v))
}
// LogoHasSuffix applies the HasSuffix predicate on the "logo" field.
func LogoHasSuffix(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldHasSuffix(FieldLogo, v))
}
// LogoEqualFold applies the EqualFold predicate on the "logo" field.
func LogoEqualFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldEqualFold(FieldLogo, v))
}
// LogoContainsFold applies the ContainsFold predicate on the "logo" field.
func LogoContainsFold(v string) predicate.HIBP {
return predicate.HIBP(sql.FieldContainsFold(FieldLogo, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.HIBP) predicate.HIBP {
return predicate.HIBP(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for _, p := range predicates {
p(s1)
}
s.Where(s1.P())
})
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.HIBP) predicate.HIBP {
return predicate.HIBP(func(s *sql.Selector) {
s1 := s.Clone().SetP(nil)
for i, p := range predicates {
if i > 0 {
s1.Or()
}
p(s1)
}
s.Where(s1.P())
})
}
// Not applies the not operator on the given predicate.
func Not(p predicate.HIBP) predicate.HIBP {
return predicate.HIBP(func(s *sql.Selector) {
p(s.Not())
})
}

452
ent/hibp_create.go Normal file

@ -0,0 +1,452 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"github.com/google/uuid"
)
// HIBPCreate is the builder for creating a HIBP entity.
type HIBPCreate struct {
config
mutation *HIBPMutation
hooks []Hook
}
// SetName sets the "name" field.
func (hc *HIBPCreate) SetName(s string) *HIBPCreate {
hc.mutation.SetName(s)
return hc
}
// SetDomain sets the "domain" field.
func (hc *HIBPCreate) SetDomain(s string) *HIBPCreate {
hc.mutation.SetDomain(s)
return hc
}
// SetBreachDate sets the "breach_date" field.
func (hc *HIBPCreate) SetBreachDate(t time.Time) *HIBPCreate {
hc.mutation.SetBreachDate(t)
return hc
}
// SetAddedDate sets the "added_date" field.
func (hc *HIBPCreate) SetAddedDate(t time.Time) *HIBPCreate {
hc.mutation.SetAddedDate(t)
return hc
}
// SetModifiedDate sets the "modified_date" field.
func (hc *HIBPCreate) SetModifiedDate(t time.Time) *HIBPCreate {
hc.mutation.SetModifiedDate(t)
return hc
}
// SetPwnCount sets the "pwn_count" field.
func (hc *HIBPCreate) SetPwnCount(i int) *HIBPCreate {
hc.mutation.SetPwnCount(i)
return hc
}
// SetDescription sets the "description" field.
func (hc *HIBPCreate) SetDescription(s string) *HIBPCreate {
hc.mutation.SetDescription(s)
return hc
}
// SetDataclasses sets the "dataclasses" field.
func (hc *HIBPCreate) SetDataclasses(s []string) *HIBPCreate {
hc.mutation.SetDataclasses(s)
return hc
}
// SetIsVerified sets the "is_verified" field.
func (hc *HIBPCreate) SetIsVerified(b bool) *HIBPCreate {
hc.mutation.SetIsVerified(b)
return hc
}
// SetNillableIsVerified sets the "is_verified" field if the given value is not nil.
func (hc *HIBPCreate) SetNillableIsVerified(b *bool) *HIBPCreate {
if b != nil {
hc.SetIsVerified(*b)
}
return hc
}
// SetIsFabricated sets the "is_fabricated" field.
func (hc *HIBPCreate) SetIsFabricated(b bool) *HIBPCreate {
hc.mutation.SetIsFabricated(b)
return hc
}
// SetNillableIsFabricated sets the "is_fabricated" field if the given value is not nil.
func (hc *HIBPCreate) SetNillableIsFabricated(b *bool) *HIBPCreate {
if b != nil {
hc.SetIsFabricated(*b)
}
return hc
}
// SetIsSensitive sets the "is_sensitive" field.
func (hc *HIBPCreate) SetIsSensitive(b bool) *HIBPCreate {
hc.mutation.SetIsSensitive(b)
return hc
}
// SetNillableIsSensitive sets the "is_sensitive" field if the given value is not nil.
func (hc *HIBPCreate) SetNillableIsSensitive(b *bool) *HIBPCreate {
if b != nil {
hc.SetIsSensitive(*b)
}
return hc
}
// SetIsRetired sets the "is_retired" field.
func (hc *HIBPCreate) SetIsRetired(b bool) *HIBPCreate {
hc.mutation.SetIsRetired(b)
return hc
}
// SetNillableIsRetired sets the "is_retired" field if the given value is not nil.
func (hc *HIBPCreate) SetNillableIsRetired(b *bool) *HIBPCreate {
if b != nil {
hc.SetIsRetired(*b)
}
return hc
}
// SetIsSpamList sets the "is_spamList" field.
func (hc *HIBPCreate) SetIsSpamList(b bool) *HIBPCreate {
hc.mutation.SetIsSpamList(b)
return hc
}
// SetNillableIsSpamList sets the "is_spamList" field if the given value is not nil.
func (hc *HIBPCreate) SetNillableIsSpamList(b *bool) *HIBPCreate {
if b != nil {
hc.SetIsSpamList(*b)
}
return hc
}
// SetIsMalware sets the "is_malware" field.
func (hc *HIBPCreate) SetIsMalware(b bool) *HIBPCreate {
hc.mutation.SetIsMalware(b)
return hc
}
// SetNillableIsMalware sets the "is_malware" field if the given value is not nil.
func (hc *HIBPCreate) SetNillableIsMalware(b *bool) *HIBPCreate {
if b != nil {
hc.SetIsMalware(*b)
}
return hc
}
// SetLogo sets the "logo" field.
func (hc *HIBPCreate) SetLogo(s string) *HIBPCreate {
hc.mutation.SetLogo(s)
return hc
}
// SetID sets the "id" field.
func (hc *HIBPCreate) SetID(u uuid.UUID) *HIBPCreate {
hc.mutation.SetID(u)
return hc
}
// Mutation returns the HIBPMutation object of the builder.
func (hc *HIBPCreate) Mutation() *HIBPMutation {
return hc.mutation
}
// Save creates the HIBP in the database.
func (hc *HIBPCreate) Save(ctx context.Context) (*HIBP, error) {
hc.defaults()
return withHooks[*HIBP, HIBPMutation](ctx, hc.sqlSave, hc.mutation, hc.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (hc *HIBPCreate) SaveX(ctx context.Context) *HIBP {
v, err := hc.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (hc *HIBPCreate) Exec(ctx context.Context) error {
_, err := hc.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (hc *HIBPCreate) ExecX(ctx context.Context) {
if err := hc.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (hc *HIBPCreate) defaults() {
if _, ok := hc.mutation.IsVerified(); !ok {
v := hibp.DefaultIsVerified
hc.mutation.SetIsVerified(v)
}
if _, ok := hc.mutation.IsFabricated(); !ok {
v := hibp.DefaultIsFabricated
hc.mutation.SetIsFabricated(v)
}
if _, ok := hc.mutation.IsSensitive(); !ok {
v := hibp.DefaultIsSensitive
hc.mutation.SetIsSensitive(v)
}
if _, ok := hc.mutation.IsRetired(); !ok {
v := hibp.DefaultIsRetired
hc.mutation.SetIsRetired(v)
}
if _, ok := hc.mutation.IsSpamList(); !ok {
v := hibp.DefaultIsSpamList
hc.mutation.SetIsSpamList(v)
}
if _, ok := hc.mutation.IsMalware(); !ok {
v := hibp.DefaultIsMalware
hc.mutation.SetIsMalware(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (hc *HIBPCreate) check() error {
if _, ok := hc.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "HIBP.name"`)}
}
if _, ok := hc.mutation.Domain(); !ok {
return &ValidationError{Name: "domain", err: errors.New(`ent: missing required field "HIBP.domain"`)}
}
if _, ok := hc.mutation.BreachDate(); !ok {
return &ValidationError{Name: "breach_date", err: errors.New(`ent: missing required field "HIBP.breach_date"`)}
}
if _, ok := hc.mutation.AddedDate(); !ok {
return &ValidationError{Name: "added_date", err: errors.New(`ent: missing required field "HIBP.added_date"`)}
}
if _, ok := hc.mutation.ModifiedDate(); !ok {
return &ValidationError{Name: "modified_date", err: errors.New(`ent: missing required field "HIBP.modified_date"`)}
}
if _, ok := hc.mutation.PwnCount(); !ok {
return &ValidationError{Name: "pwn_count", err: errors.New(`ent: missing required field "HIBP.pwn_count"`)}
}
if _, ok := hc.mutation.Description(); !ok {
return &ValidationError{Name: "description", err: errors.New(`ent: missing required field "HIBP.description"`)}
}
if _, ok := hc.mutation.Dataclasses(); !ok {
return &ValidationError{Name: "dataclasses", err: errors.New(`ent: missing required field "HIBP.dataclasses"`)}
}
if _, ok := hc.mutation.IsVerified(); !ok {
return &ValidationError{Name: "is_verified", err: errors.New(`ent: missing required field "HIBP.is_verified"`)}
}
if _, ok := hc.mutation.IsFabricated(); !ok {
return &ValidationError{Name: "is_fabricated", err: errors.New(`ent: missing required field "HIBP.is_fabricated"`)}
}
if _, ok := hc.mutation.IsSensitive(); !ok {
return &ValidationError{Name: "is_sensitive", err: errors.New(`ent: missing required field "HIBP.is_sensitive"`)}
}
if _, ok := hc.mutation.IsRetired(); !ok {
return &ValidationError{Name: "is_retired", err: errors.New(`ent: missing required field "HIBP.is_retired"`)}
}
if _, ok := hc.mutation.IsSpamList(); !ok {
return &ValidationError{Name: "is_spamList", err: errors.New(`ent: missing required field "HIBP.is_spamList"`)}
}
if _, ok := hc.mutation.IsMalware(); !ok {
return &ValidationError{Name: "is_malware", err: errors.New(`ent: missing required field "HIBP.is_malware"`)}
}
if _, ok := hc.mutation.Logo(); !ok {
return &ValidationError{Name: "logo", err: errors.New(`ent: missing required field "HIBP.logo"`)}
}
return nil
}
func (hc *HIBPCreate) sqlSave(ctx context.Context) (*HIBP, error) {
if err := hc.check(); err != nil {
return nil, err
}
_node, _spec := hc.createSpec()
if err := sqlgraph.CreateNode(ctx, hc.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
if _spec.ID.Value != nil {
if id, ok := _spec.ID.Value.(*uuid.UUID); ok {
_node.ID = *id
} else if err := _node.ID.Scan(_spec.ID.Value); err != nil {
return nil, err
}
}
hc.mutation.id = &_node.ID
hc.mutation.done = true
return _node, nil
}
func (hc *HIBPCreate) createSpec() (*HIBP, *sqlgraph.CreateSpec) {
var (
_node = &HIBP{config: hc.config}
_spec = sqlgraph.NewCreateSpec(hibp.Table, sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID))
)
if id, ok := hc.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = &id
}
if value, ok := hc.mutation.Name(); ok {
_spec.SetField(hibp.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := hc.mutation.Domain(); ok {
_spec.SetField(hibp.FieldDomain, field.TypeString, value)
_node.Domain = value
}
if value, ok := hc.mutation.BreachDate(); ok {
_spec.SetField(hibp.FieldBreachDate, field.TypeTime, value)
_node.BreachDate = value
}
if value, ok := hc.mutation.AddedDate(); ok {
_spec.SetField(hibp.FieldAddedDate, field.TypeTime, value)
_node.AddedDate = value
}
if value, ok := hc.mutation.ModifiedDate(); ok {
_spec.SetField(hibp.FieldModifiedDate, field.TypeTime, value)
_node.ModifiedDate = value
}
if value, ok := hc.mutation.PwnCount(); ok {
_spec.SetField(hibp.FieldPwnCount, field.TypeInt, value)
_node.PwnCount = value
}
if value, ok := hc.mutation.Description(); ok {
_spec.SetField(hibp.FieldDescription, field.TypeString, value)
_node.Description = value
}
if value, ok := hc.mutation.Dataclasses(); ok {
_spec.SetField(hibp.FieldDataclasses, field.TypeJSON, value)
_node.Dataclasses = value
}
if value, ok := hc.mutation.IsVerified(); ok {
_spec.SetField(hibp.FieldIsVerified, field.TypeBool, value)
_node.IsVerified = value
}
if value, ok := hc.mutation.IsFabricated(); ok {
_spec.SetField(hibp.FieldIsFabricated, field.TypeBool, value)
_node.IsFabricated = value
}
if value, ok := hc.mutation.IsSensitive(); ok {
_spec.SetField(hibp.FieldIsSensitive, field.TypeBool, value)
_node.IsSensitive = value
}
if value, ok := hc.mutation.IsRetired(); ok {
_spec.SetField(hibp.FieldIsRetired, field.TypeBool, value)
_node.IsRetired = value
}
if value, ok := hc.mutation.IsSpamList(); ok {
_spec.SetField(hibp.FieldIsSpamList, field.TypeBool, value)
_node.IsSpamList = value
}
if value, ok := hc.mutation.IsMalware(); ok {
_spec.SetField(hibp.FieldIsMalware, field.TypeBool, value)
_node.IsMalware = value
}
if value, ok := hc.mutation.Logo(); ok {
_spec.SetField(hibp.FieldLogo, field.TypeString, value)
_node.Logo = value
}
return _node, _spec
}
// HIBPCreateBulk is the builder for creating many HIBP entities in bulk.
type HIBPCreateBulk struct {
config
builders []*HIBPCreate
}
// Save creates the HIBP entities in the database.
func (hcb *HIBPCreateBulk) Save(ctx context.Context) ([]*HIBP, error) {
specs := make([]*sqlgraph.CreateSpec, len(hcb.builders))
nodes := make([]*HIBP, len(hcb.builders))
mutators := make([]Mutator, len(hcb.builders))
for i := range hcb.builders {
func(i int, root context.Context) {
builder := hcb.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*HIBPMutation)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
if err := builder.check(); err != nil {
return nil, err
}
builder.mutation = mutation
nodes[i], specs[i] = builder.createSpec()
var err error
if i < len(mutators)-1 {
_, err = mutators[i+1].Mutate(root, hcb.builders[i+1].mutation)
} else {
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
// Invoke the actual operation on the latest mutation in the chain.
if err = sqlgraph.BatchCreate(ctx, hcb.driver, spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
}
}
if err != nil {
return nil, err
}
mutation.id = &nodes[i].ID
mutation.done = true
return nodes[i], nil
})
for i := len(builder.hooks) - 1; i >= 0; i-- {
mut = builder.hooks[i](mut)
}
mutators[i] = mut
}(i, ctx)
}
if len(mutators) > 0 {
if _, err := mutators[0].Mutate(ctx, hcb.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (hcb *HIBPCreateBulk) SaveX(ctx context.Context) []*HIBP {
v, err := hcb.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (hcb *HIBPCreateBulk) Exec(ctx context.Context) error {
_, err := hcb.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (hcb *HIBPCreateBulk) ExecX(ctx context.Context) {
if err := hcb.Exec(ctx); err != nil {
panic(err)
}
}

88
ent/hibp_delete.go Normal file

@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
)
// HIBPDelete is the builder for deleting a HIBP entity.
type HIBPDelete struct {
config
hooks []Hook
mutation *HIBPMutation
}
// Where appends a list predicates to the HIBPDelete builder.
func (hd *HIBPDelete) Where(ps ...predicate.HIBP) *HIBPDelete {
hd.mutation.Where(ps...)
return hd
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (hd *HIBPDelete) Exec(ctx context.Context) (int, error) {
return withHooks[int, HIBPMutation](ctx, hd.sqlExec, hd.mutation, hd.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (hd *HIBPDelete) ExecX(ctx context.Context) int {
n, err := hd.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (hd *HIBPDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(hibp.Table, sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID))
if ps := hd.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, hd.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
hd.mutation.done = true
return affected, err
}
// HIBPDeleteOne is the builder for deleting a single HIBP entity.
type HIBPDeleteOne struct {
hd *HIBPDelete
}
// Where appends a list predicates to the HIBPDelete builder.
func (hdo *HIBPDeleteOne) Where(ps ...predicate.HIBP) *HIBPDeleteOne {
hdo.hd.mutation.Where(ps...)
return hdo
}
// Exec executes the deletion query.
func (hdo *HIBPDeleteOne) Exec(ctx context.Context) error {
n, err := hdo.hd.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{hibp.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (hdo *HIBPDeleteOne) ExecX(ctx context.Context) {
if err := hdo.Exec(ctx); err != nil {
panic(err)
}
}

527
ent/hibp_query.go Normal file

@ -0,0 +1,527 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"fmt"
"math"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
"github.com/google/uuid"
)
// HIBPQuery is the builder for querying HIBP entities.
type HIBPQuery struct {
config
ctx *QueryContext
order []OrderFunc
inters []Interceptor
predicates []predicate.HIBP
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the HIBPQuery builder.
func (hq *HIBPQuery) Where(ps ...predicate.HIBP) *HIBPQuery {
hq.predicates = append(hq.predicates, ps...)
return hq
}
// Limit the number of records to be returned by this query.
func (hq *HIBPQuery) Limit(limit int) *HIBPQuery {
hq.ctx.Limit = &limit
return hq
}
// Offset to start from.
func (hq *HIBPQuery) Offset(offset int) *HIBPQuery {
hq.ctx.Offset = &offset
return hq
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func (hq *HIBPQuery) Unique(unique bool) *HIBPQuery {
hq.ctx.Unique = &unique
return hq
}
// Order specifies how the records should be ordered.
func (hq *HIBPQuery) Order(o ...OrderFunc) *HIBPQuery {
hq.order = append(hq.order, o...)
return hq
}
// First returns the first HIBP entity from the query.
// Returns a *NotFoundError when no HIBP was found.
func (hq *HIBPQuery) First(ctx context.Context) (*HIBP, error) {
nodes, err := hq.Limit(1).All(setContextOp(ctx, hq.ctx, "First"))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{hibp.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (hq *HIBPQuery) FirstX(ctx context.Context) *HIBP {
node, err := hq.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first HIBP ID from the query.
// Returns a *NotFoundError when no HIBP ID was found.
func (hq *HIBPQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = hq.Limit(1).IDs(setContextOp(ctx, hq.ctx, "FirstID")); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{hibp.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (hq *HIBPQuery) FirstIDX(ctx context.Context) uuid.UUID {
id, err := hq.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single HIBP entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one HIBP entity is found.
// Returns a *NotFoundError when no HIBP entities are found.
func (hq *HIBPQuery) Only(ctx context.Context) (*HIBP, error) {
nodes, err := hq.Limit(2).All(setContextOp(ctx, hq.ctx, "Only"))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{hibp.Label}
default:
return nil, &NotSingularError{hibp.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (hq *HIBPQuery) OnlyX(ctx context.Context) *HIBP {
node, err := hq.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only HIBP ID in the query.
// Returns a *NotSingularError when more than one HIBP ID is found.
// Returns a *NotFoundError when no entities are found.
func (hq *HIBPQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
var ids []uuid.UUID
if ids, err = hq.Limit(2).IDs(setContextOp(ctx, hq.ctx, "OnlyID")); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{hibp.Label}
default:
err = &NotSingularError{hibp.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (hq *HIBPQuery) OnlyIDX(ctx context.Context) uuid.UUID {
id, err := hq.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of HIBPs.
func (hq *HIBPQuery) All(ctx context.Context) ([]*HIBP, error) {
ctx = setContextOp(ctx, hq.ctx, "All")
if err := hq.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*HIBP, *HIBPQuery]()
return withInterceptors[[]*HIBP](ctx, hq, qr, hq.inters)
}
// AllX is like All, but panics if an error occurs.
func (hq *HIBPQuery) AllX(ctx context.Context) []*HIBP {
nodes, err := hq.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of HIBP IDs.
func (hq *HIBPQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
if hq.ctx.Unique == nil && hq.path != nil {
hq.Unique(true)
}
ctx = setContextOp(ctx, hq.ctx, "IDs")
if err = hq.Select(hibp.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (hq *HIBPQuery) IDsX(ctx context.Context) []uuid.UUID {
ids, err := hq.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (hq *HIBPQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, hq.ctx, "Count")
if err := hq.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, hq, querierCount[*HIBPQuery](), hq.inters)
}
// CountX is like Count, but panics if an error occurs.
func (hq *HIBPQuery) CountX(ctx context.Context) int {
count, err := hq.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (hq *HIBPQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, hq.ctx, "Exist")
switch _, err := hq.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("ent: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (hq *HIBPQuery) ExistX(ctx context.Context) bool {
exist, err := hq.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the HIBPQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (hq *HIBPQuery) Clone() *HIBPQuery {
if hq == nil {
return nil
}
return &HIBPQuery{
config: hq.config,
ctx: hq.ctx.Clone(),
order: append([]OrderFunc{}, hq.order...),
inters: append([]Interceptor{}, hq.inters...),
predicates: append([]predicate.HIBP{}, hq.predicates...),
// clone intermediate query.
sql: hq.sql.Clone(),
path: hq.path,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.HIBP.Query().
// GroupBy(hibp.FieldName).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func (hq *HIBPQuery) GroupBy(field string, fields ...string) *HIBPGroupBy {
hq.ctx.Fields = append([]string{field}, fields...)
grbuild := &HIBPGroupBy{build: hq}
grbuild.flds = &hq.ctx.Fields
grbuild.label = hibp.Label
grbuild.scan = grbuild.Scan
return grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// Name string `json:"name,omitempty"`
// }
//
// client.HIBP.Query().
// Select(hibp.FieldName).
// Scan(ctx, &v)
func (hq *HIBPQuery) Select(fields ...string) *HIBPSelect {
hq.ctx.Fields = append(hq.ctx.Fields, fields...)
sbuild := &HIBPSelect{HIBPQuery: hq}
sbuild.label = hibp.Label
sbuild.flds, sbuild.scan = &hq.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a HIBPSelect configured with the given aggregations.
func (hq *HIBPQuery) Aggregate(fns ...AggregateFunc) *HIBPSelect {
return hq.Select().Aggregate(fns...)
}
func (hq *HIBPQuery) prepareQuery(ctx context.Context) error {
for _, inter := range hq.inters {
if inter == nil {
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, hq); err != nil {
return err
}
}
}
for _, f := range hq.ctx.Fields {
if !hibp.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
}
if hq.path != nil {
prev, err := hq.path(ctx)
if err != nil {
return err
}
hq.sql = prev
}
return nil
}
func (hq *HIBPQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*HIBP, error) {
var (
nodes = []*HIBP{}
_spec = hq.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*HIBP).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &HIBP{config: hq.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, hq.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (hq *HIBPQuery) sqlCount(ctx context.Context) (int, error) {
_spec := hq.querySpec()
_spec.Node.Columns = hq.ctx.Fields
if len(hq.ctx.Fields) > 0 {
_spec.Unique = hq.ctx.Unique != nil && *hq.ctx.Unique
}
return sqlgraph.CountNodes(ctx, hq.driver, _spec)
}
func (hq *HIBPQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(hibp.Table, hibp.Columns, sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID))
_spec.From = hq.sql
if unique := hq.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if hq.path != nil {
_spec.Unique = true
}
if fields := hq.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, hibp.FieldID)
for i := range fields {
if fields[i] != hibp.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := hq.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := hq.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := hq.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := hq.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (hq *HIBPQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(hq.driver.Dialect())
t1 := builder.Table(hibp.Table)
columns := hq.ctx.Fields
if len(columns) == 0 {
columns = hibp.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if hq.sql != nil {
selector = hq.sql
selector.Select(selector.Columns(columns...)...)
}
if hq.ctx.Unique != nil && *hq.ctx.Unique {
selector.Distinct()
}
for _, p := range hq.predicates {
p(selector)
}
for _, p := range hq.order {
p(selector)
}
if offset := hq.ctx.Offset; offset != nil {
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector.Offset(*offset).Limit(math.MaxInt32)
}
if limit := hq.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// HIBPGroupBy is the group-by builder for HIBP entities.
type HIBPGroupBy struct {
selector
build *HIBPQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (hgb *HIBPGroupBy) Aggregate(fns ...AggregateFunc) *HIBPGroupBy {
hgb.fns = append(hgb.fns, fns...)
return hgb
}
// Scan applies the selector query and scans the result into the given value.
func (hgb *HIBPGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, hgb.build.ctx, "GroupBy")
if err := hgb.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*HIBPQuery, *HIBPGroupBy](ctx, hgb.build, hgb, hgb.build.inters, v)
}
func (hgb *HIBPGroupBy) sqlScan(ctx context.Context, root *HIBPQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(hgb.fns))
for _, fn := range hgb.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*hgb.flds)+len(hgb.fns))
for _, f := range *hgb.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*hgb.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := hgb.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// HIBPSelect is the builder for selecting fields of HIBP entities.
type HIBPSelect struct {
*HIBPQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (hs *HIBPSelect) Aggregate(fns ...AggregateFunc) *HIBPSelect {
hs.fns = append(hs.fns, fns...)
return hs
}
// Scan applies the selector query and scans the result into the given value.
func (hs *HIBPSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, hs.ctx, "Select")
if err := hs.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*HIBPQuery, *HIBPSelect](ctx, hs.HIBPQuery, hs, hs.inters, v)
}
func (hs *HIBPSelect) sqlScan(ctx context.Context, root *HIBPQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(hs.fns))
for _, fn := range hs.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*hs.selector.flds); {
case n == 0 && len(aggregation) > 0:
selector.Select(aggregation...)
case n != 0 && len(aggregation) > 0:
selector.AppendSelect(aggregation...)
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := hs.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}

567
ent/hibp_update.go Normal file

@ -0,0 +1,567 @@
// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqljson"
"entgo.io/ent/schema/field"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
)
// HIBPUpdate is the builder for updating HIBP entities.
type HIBPUpdate struct {
config
hooks []Hook
mutation *HIBPMutation
}
// Where appends a list predicates to the HIBPUpdate builder.
func (hu *HIBPUpdate) Where(ps ...predicate.HIBP) *HIBPUpdate {
hu.mutation.Where(ps...)
return hu
}
// SetName sets the "name" field.
func (hu *HIBPUpdate) SetName(s string) *HIBPUpdate {
hu.mutation.SetName(s)
return hu
}
// SetBreachDate sets the "breach_date" field.
func (hu *HIBPUpdate) SetBreachDate(t time.Time) *HIBPUpdate {
hu.mutation.SetBreachDate(t)
return hu
}
// SetAddedDate sets the "added_date" field.
func (hu *HIBPUpdate) SetAddedDate(t time.Time) *HIBPUpdate {
hu.mutation.SetAddedDate(t)
return hu
}
// SetModifiedDate sets the "modified_date" field.
func (hu *HIBPUpdate) SetModifiedDate(t time.Time) *HIBPUpdate {
hu.mutation.SetModifiedDate(t)
return hu
}
// SetPwnCount sets the "pwn_count" field.
func (hu *HIBPUpdate) SetPwnCount(i int) *HIBPUpdate {
hu.mutation.ResetPwnCount()
hu.mutation.SetPwnCount(i)
return hu
}
// AddPwnCount adds i to the "pwn_count" field.
func (hu *HIBPUpdate) AddPwnCount(i int) *HIBPUpdate {
hu.mutation.AddPwnCount(i)
return hu
}
// SetDescription sets the "description" field.
func (hu *HIBPUpdate) SetDescription(s string) *HIBPUpdate {
hu.mutation.SetDescription(s)
return hu
}
// SetDataclasses sets the "dataclasses" field.
func (hu *HIBPUpdate) SetDataclasses(s []string) *HIBPUpdate {
hu.mutation.SetDataclasses(s)
return hu
}
// AppendDataclasses appends s to the "dataclasses" field.
func (hu *HIBPUpdate) AppendDataclasses(s []string) *HIBPUpdate {
hu.mutation.AppendDataclasses(s)
return hu
}
// SetIsVerified sets the "is_verified" field.
func (hu *HIBPUpdate) SetIsVerified(b bool) *HIBPUpdate {
hu.mutation.SetIsVerified(b)
return hu
}
// SetNillableIsVerified sets the "is_verified" field if the given value is not nil.
func (hu *HIBPUpdate) SetNillableIsVerified(b *bool) *HIBPUpdate {
if b != nil {
hu.SetIsVerified(*b)
}
return hu
}
// SetIsFabricated sets the "is_fabricated" field.
func (hu *HIBPUpdate) SetIsFabricated(b bool) *HIBPUpdate {
hu.mutation.SetIsFabricated(b)
return hu
}
// SetNillableIsFabricated sets the "is_fabricated" field if the given value is not nil.
func (hu *HIBPUpdate) SetNillableIsFabricated(b *bool) *HIBPUpdate {
if b != nil {
hu.SetIsFabricated(*b)
}
return hu
}
// SetIsSensitive sets the "is_sensitive" field.
func (hu *HIBPUpdate) SetIsSensitive(b bool) *HIBPUpdate {
hu.mutation.SetIsSensitive(b)
return hu
}
// SetNillableIsSensitive sets the "is_sensitive" field if the given value is not nil.
func (hu *HIBPUpdate) SetNillableIsSensitive(b *bool) *HIBPUpdate {
if b != nil {
hu.SetIsSensitive(*b)
}
return hu
}
// SetIsRetired sets the "is_retired" field.
func (hu *HIBPUpdate) SetIsRetired(b bool) *HIBPUpdate {
hu.mutation.SetIsRetired(b)
return hu
}
// SetNillableIsRetired sets the "is_retired" field if the given value is not nil.
func (hu *HIBPUpdate) SetNillableIsRetired(b *bool) *HIBPUpdate {
if b != nil {
hu.SetIsRetired(*b)
}
return hu
}
// SetIsSpamList sets the "is_spamList" field.
func (hu *HIBPUpdate) SetIsSpamList(b bool) *HIBPUpdate {
hu.mutation.SetIsSpamList(b)
return hu
}
// SetNillableIsSpamList sets the "is_spamList" field if the given value is not nil.
func (hu *HIBPUpdate) SetNillableIsSpamList(b *bool) *HIBPUpdate {
if b != nil {
hu.SetIsSpamList(*b)
}
return hu
}
// SetIsMalware sets the "is_malware" field.
func (hu *HIBPUpdate) SetIsMalware(b bool) *HIBPUpdate {
hu.mutation.SetIsMalware(b)
return hu
}
// SetNillableIsMalware sets the "is_malware" field if the given value is not nil.
func (hu *HIBPUpdate) SetNillableIsMalware(b *bool) *HIBPUpdate {
if b != nil {
hu.SetIsMalware(*b)
}
return hu
}
// SetLogo sets the "logo" field.
func (hu *HIBPUpdate) SetLogo(s string) *HIBPUpdate {
hu.mutation.SetLogo(s)
return hu
}
// Mutation returns the HIBPMutation object of the builder.
func (hu *HIBPUpdate) Mutation() *HIBPMutation {
return hu.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (hu *HIBPUpdate) Save(ctx context.Context) (int, error) {
return withHooks[int, HIBPMutation](ctx, hu.sqlSave, hu.mutation, hu.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (hu *HIBPUpdate) SaveX(ctx context.Context) int {
affected, err := hu.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (hu *HIBPUpdate) Exec(ctx context.Context) error {
_, err := hu.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (hu *HIBPUpdate) ExecX(ctx context.Context) {
if err := hu.Exec(ctx); err != nil {
panic(err)
}
}
func (hu *HIBPUpdate) sqlSave(ctx context.Context) (n int, err error) {
_spec := sqlgraph.NewUpdateSpec(hibp.Table, hibp.Columns, sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID))
if ps := hu.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := hu.mutation.Name(); ok {
_spec.SetField(hibp.FieldName, field.TypeString, value)
}
if value, ok := hu.mutation.BreachDate(); ok {
_spec.SetField(hibp.FieldBreachDate, field.TypeTime, value)
}
if value, ok := hu.mutation.AddedDate(); ok {
_spec.SetField(hibp.FieldAddedDate, field.TypeTime, value)
}
if value, ok := hu.mutation.ModifiedDate(); ok {
_spec.SetField(hibp.FieldModifiedDate, field.TypeTime, value)
}
if value, ok := hu.mutation.PwnCount(); ok {
_spec.SetField(hibp.FieldPwnCount, field.TypeInt, value)
}
if value, ok := hu.mutation.AddedPwnCount(); ok {
_spec.AddField(hibp.FieldPwnCount, field.TypeInt, value)
}
if value, ok := hu.mutation.Description(); ok {
_spec.SetField(hibp.FieldDescription, field.TypeString, value)
}
if value, ok := hu.mutation.Dataclasses(); ok {
_spec.SetField(hibp.FieldDataclasses, field.TypeJSON, value)
}
if value, ok := hu.mutation.AppendedDataclasses(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, hibp.FieldDataclasses, value)
})
}
if value, ok := hu.mutation.IsVerified(); ok {
_spec.SetField(hibp.FieldIsVerified, field.TypeBool, value)
}
if value, ok := hu.mutation.IsFabricated(); ok {
_spec.SetField(hibp.FieldIsFabricated, field.TypeBool, value)
}
if value, ok := hu.mutation.IsSensitive(); ok {
_spec.SetField(hibp.FieldIsSensitive, field.TypeBool, value)
}
if value, ok := hu.mutation.IsRetired(); ok {
_spec.SetField(hibp.FieldIsRetired, field.TypeBool, value)
}
if value, ok := hu.mutation.IsSpamList(); ok {
_spec.SetField(hibp.FieldIsSpamList, field.TypeBool, value)
}
if value, ok := hu.mutation.IsMalware(); ok {
_spec.SetField(hibp.FieldIsMalware, field.TypeBool, value)
}
if value, ok := hu.mutation.Logo(); ok {
_spec.SetField(hibp.FieldLogo, field.TypeString, value)
}
if n, err = sqlgraph.UpdateNodes(ctx, hu.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{hibp.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
hu.mutation.done = true
return n, nil
}
// HIBPUpdateOne is the builder for updating a single HIBP entity.
type HIBPUpdateOne struct {
config
fields []string
hooks []Hook
mutation *HIBPMutation
}
// SetName sets the "name" field.
func (huo *HIBPUpdateOne) SetName(s string) *HIBPUpdateOne {
huo.mutation.SetName(s)
return huo
}
// SetBreachDate sets the "breach_date" field.
func (huo *HIBPUpdateOne) SetBreachDate(t time.Time) *HIBPUpdateOne {
huo.mutation.SetBreachDate(t)
return huo
}
// SetAddedDate sets the "added_date" field.
func (huo *HIBPUpdateOne) SetAddedDate(t time.Time) *HIBPUpdateOne {
huo.mutation.SetAddedDate(t)
return huo
}
// SetModifiedDate sets the "modified_date" field.
func (huo *HIBPUpdateOne) SetModifiedDate(t time.Time) *HIBPUpdateOne {
huo.mutation.SetModifiedDate(t)
return huo
}
// SetPwnCount sets the "pwn_count" field.
func (huo *HIBPUpdateOne) SetPwnCount(i int) *HIBPUpdateOne {
huo.mutation.ResetPwnCount()
huo.mutation.SetPwnCount(i)
return huo
}
// AddPwnCount adds i to the "pwn_count" field.
func (huo *HIBPUpdateOne) AddPwnCount(i int) *HIBPUpdateOne {
huo.mutation.AddPwnCount(i)
return huo
}
// SetDescription sets the "description" field.
func (huo *HIBPUpdateOne) SetDescription(s string) *HIBPUpdateOne {
huo.mutation.SetDescription(s)
return huo
}
// SetDataclasses sets the "dataclasses" field.
func (huo *HIBPUpdateOne) SetDataclasses(s []string) *HIBPUpdateOne {
huo.mutation.SetDataclasses(s)
return huo
}
// AppendDataclasses appends s to the "dataclasses" field.
func (huo *HIBPUpdateOne) AppendDataclasses(s []string) *HIBPUpdateOne {
huo.mutation.AppendDataclasses(s)
return huo
}
// SetIsVerified sets the "is_verified" field.
func (huo *HIBPUpdateOne) SetIsVerified(b bool) *HIBPUpdateOne {
huo.mutation.SetIsVerified(b)
return huo
}
// SetNillableIsVerified sets the "is_verified" field if the given value is not nil.
func (huo *HIBPUpdateOne) SetNillableIsVerified(b *bool) *HIBPUpdateOne {
if b != nil {
huo.SetIsVerified(*b)
}
return huo
}
// SetIsFabricated sets the "is_fabricated" field.
func (huo *HIBPUpdateOne) SetIsFabricated(b bool) *HIBPUpdateOne {
huo.mutation.SetIsFabricated(b)
return huo
}
// SetNillableIsFabricated sets the "is_fabricated" field if the given value is not nil.
func (huo *HIBPUpdateOne) SetNillableIsFabricated(b *bool) *HIBPUpdateOne {
if b != nil {
huo.SetIsFabricated(*b)
}
return huo
}
// SetIsSensitive sets the "is_sensitive" field.
func (huo *HIBPUpdateOne) SetIsSensitive(b bool) *HIBPUpdateOne {
huo.mutation.SetIsSensitive(b)
return huo
}
// SetNillableIsSensitive sets the "is_sensitive" field if the given value is not nil.
func (huo *HIBPUpdateOne) SetNillableIsSensitive(b *bool) *HIBPUpdateOne {
if b != nil {
huo.SetIsSensitive(*b)
}
return huo
}
// SetIsRetired sets the "is_retired" field.
func (huo *HIBPUpdateOne) SetIsRetired(b bool) *HIBPUpdateOne {
huo.mutation.SetIsRetired(b)
return huo
}
// SetNillableIsRetired sets the "is_retired" field if the given value is not nil.
func (huo *HIBPUpdateOne) SetNillableIsRetired(b *bool) *HIBPUpdateOne {
if b != nil {
huo.SetIsRetired(*b)
}
return huo
}
// SetIsSpamList sets the "is_spamList" field.
func (huo *HIBPUpdateOne) SetIsSpamList(b bool) *HIBPUpdateOne {
huo.mutation.SetIsSpamList(b)
return huo
}
// SetNillableIsSpamList sets the "is_spamList" field if the given value is not nil.
func (huo *HIBPUpdateOne) SetNillableIsSpamList(b *bool) *HIBPUpdateOne {
if b != nil {
huo.SetIsSpamList(*b)
}
return huo
}
// SetIsMalware sets the "is_malware" field.
func (huo *HIBPUpdateOne) SetIsMalware(b bool) *HIBPUpdateOne {
huo.mutation.SetIsMalware(b)
return huo
}
// SetNillableIsMalware sets the "is_malware" field if the given value is not nil.
func (huo *HIBPUpdateOne) SetNillableIsMalware(b *bool) *HIBPUpdateOne {
if b != nil {
huo.SetIsMalware(*b)
}
return huo
}
// SetLogo sets the "logo" field.
func (huo *HIBPUpdateOne) SetLogo(s string) *HIBPUpdateOne {
huo.mutation.SetLogo(s)
return huo
}
// Mutation returns the HIBPMutation object of the builder.
func (huo *HIBPUpdateOne) Mutation() *HIBPMutation {
return huo.mutation
}
// Where appends a list predicates to the HIBPUpdate builder.
func (huo *HIBPUpdateOne) Where(ps ...predicate.HIBP) *HIBPUpdateOne {
huo.mutation.Where(ps...)
return huo
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (huo *HIBPUpdateOne) Select(field string, fields ...string) *HIBPUpdateOne {
huo.fields = append([]string{field}, fields...)
return huo
}
// Save executes the query and returns the updated HIBP entity.
func (huo *HIBPUpdateOne) Save(ctx context.Context) (*HIBP, error) {
return withHooks[*HIBP, HIBPMutation](ctx, huo.sqlSave, huo.mutation, huo.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (huo *HIBPUpdateOne) SaveX(ctx context.Context) *HIBP {
node, err := huo.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (huo *HIBPUpdateOne) Exec(ctx context.Context) error {
_, err := huo.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (huo *HIBPUpdateOne) ExecX(ctx context.Context) {
if err := huo.Exec(ctx); err != nil {
panic(err)
}
}
func (huo *HIBPUpdateOne) sqlSave(ctx context.Context) (_node *HIBP, err error) {
_spec := sqlgraph.NewUpdateSpec(hibp.Table, hibp.Columns, sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID))
id, ok := huo.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "HIBP.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := huo.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, hibp.FieldID)
for _, f := range fields {
if !hibp.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != hibp.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := huo.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := huo.mutation.Name(); ok {
_spec.SetField(hibp.FieldName, field.TypeString, value)
}
if value, ok := huo.mutation.BreachDate(); ok {
_spec.SetField(hibp.FieldBreachDate, field.TypeTime, value)
}
if value, ok := huo.mutation.AddedDate(); ok {
_spec.SetField(hibp.FieldAddedDate, field.TypeTime, value)
}
if value, ok := huo.mutation.ModifiedDate(); ok {
_spec.SetField(hibp.FieldModifiedDate, field.TypeTime, value)
}
if value, ok := huo.mutation.PwnCount(); ok {
_spec.SetField(hibp.FieldPwnCount, field.TypeInt, value)
}
if value, ok := huo.mutation.AddedPwnCount(); ok {
_spec.AddField(hibp.FieldPwnCount, field.TypeInt, value)
}
if value, ok := huo.mutation.Description(); ok {
_spec.SetField(hibp.FieldDescription, field.TypeString, value)
}
if value, ok := huo.mutation.Dataclasses(); ok {
_spec.SetField(hibp.FieldDataclasses, field.TypeJSON, value)
}
if value, ok := huo.mutation.AppendedDataclasses(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, hibp.FieldDataclasses, value)
})
}
if value, ok := huo.mutation.IsVerified(); ok {
_spec.SetField(hibp.FieldIsVerified, field.TypeBool, value)
}
if value, ok := huo.mutation.IsFabricated(); ok {
_spec.SetField(hibp.FieldIsFabricated, field.TypeBool, value)
}
if value, ok := huo.mutation.IsSensitive(); ok {
_spec.SetField(hibp.FieldIsSensitive, field.TypeBool, value)
}
if value, ok := huo.mutation.IsRetired(); ok {
_spec.SetField(hibp.FieldIsRetired, field.TypeBool, value)
}
if value, ok := huo.mutation.IsSpamList(); ok {
_spec.SetField(hibp.FieldIsSpamList, field.TypeBool, value)
}
if value, ok := huo.mutation.IsMalware(); ok {
_spec.SetField(hibp.FieldIsMalware, field.TypeBool, value)
}
if value, ok := huo.mutation.Logo(); ok {
_spec.SetField(hibp.FieldLogo, field.TypeString, value)
}
_node = &HIBP{config: huo.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, huo.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{hibp.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
huo.mutation.done = true
return _node, nil
}

@ -9,6 +9,18 @@ import (
"git.dotya.ml/mirre-mt/pcmt/ent"
)
// The HIBPFunc type is an adapter to allow the use of ordinary
// function as HIBP mutator.
type HIBPFunc func(context.Context, *ent.HIBPMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f HIBPFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.HIBPMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.HIBPMutation", m)
}
// The UserFunc type is an adapter to allow the use of ordinary
// function as User mutator.
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)

@ -8,6 +8,31 @@ import (
)
var (
// HibPsColumns holds the columns for the "hib_ps" table.
HibPsColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID, Unique: true},
{Name: "name", Type: field.TypeString, Unique: true},
{Name: "domain", Type: field.TypeString},
{Name: "breach_date", Type: field.TypeTime},
{Name: "added_date", Type: field.TypeTime},
{Name: "modified_date", Type: field.TypeTime},
{Name: "pwn_count", Type: field.TypeInt},
{Name: "description", Type: field.TypeString},
{Name: "dataclasses", Type: field.TypeJSON},
{Name: "is_verified", Type: field.TypeBool, Default: false},
{Name: "is_fabricated", Type: field.TypeBool, Default: false},
{Name: "is_sensitive", Type: field.TypeBool, Default: false},
{Name: "is_retired", Type: field.TypeBool, Default: false},
{Name: "is_spam_list", Type: field.TypeBool, Default: false},
{Name: "is_malware", Type: field.TypeBool, Default: false},
{Name: "logo", Type: field.TypeString},
}
// HibPsTable holds the schema information for the "hib_ps" table.
HibPsTable = &schema.Table{
Name: "hib_ps",
Columns: HibPsColumns,
PrimaryKey: []*schema.Column{HibPsColumns[0]},
}
// UsersColumns holds the columns for the "users" table.
UsersColumns = []*schema.Column{
{Name: "id", Type: field.TypeUUID, Unique: true},
@ -26,6 +51,7 @@ var (
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
HibPsTable,
UsersTable,
}
)

@ -11,6 +11,7 @@ import (
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
"git.dotya.ml/mirre-mt/pcmt/ent/user"
"github.com/google/uuid"
@ -25,9 +26,1150 @@ const (
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeHIBP = "HIBP"
TypeUser = "User"
)
// HIBPMutation represents an operation that mutates the HIBP nodes in the graph.
type HIBPMutation struct {
config
op Op
typ string
id *uuid.UUID
name *string
domain *string
breach_date *time.Time
added_date *time.Time
modified_date *time.Time
pwn_count *int
addpwn_count *int
description *string
dataclasses *[]string
appenddataclasses []string
is_verified *bool
is_fabricated *bool
is_sensitive *bool
is_retired *bool
is_spamList *bool
is_malware *bool
logo *string
clearedFields map[string]struct{}
done bool
oldValue func(context.Context) (*HIBP, error)
predicates []predicate.HIBP
}
var _ ent.Mutation = (*HIBPMutation)(nil)
// hibpOption allows management of the mutation configuration using functional options.
type hibpOption func(*HIBPMutation)
// newHIBPMutation creates new mutation for the HIBP entity.
func newHIBPMutation(c config, op Op, opts ...hibpOption) *HIBPMutation {
m := &HIBPMutation{
config: c,
op: op,
typ: TypeHIBP,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withHIBPID sets the ID field of the mutation.
func withHIBPID(id uuid.UUID) hibpOption {
return func(m *HIBPMutation) {
var (
err error
once sync.Once
value *HIBP
)
m.oldValue = func(ctx context.Context) (*HIBP, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().HIBP.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withHIBP sets the old HIBP of the mutation.
func withHIBP(node *HIBP) hibpOption {
return func(m *HIBPMutation) {
m.oldValue = func(context.Context) (*HIBP, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m HIBPMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m HIBPMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of HIBP entities.
func (m *HIBPMutation) SetID(id uuid.UUID) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *HIBPMutation) ID() (id uuid.UUID, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *HIBPMutation) IDs(ctx context.Context) ([]uuid.UUID, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []uuid.UUID{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().HIBP.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetName sets the "name" field.
func (m *HIBPMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *HIBPMutation) Name() (r string, exists bool) {
v := m.name
if v == nil {
return
}
return *v, true
}
// OldName returns the old "name" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldName(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldName: %w", err)
}
return oldValue.Name, nil
}
// ResetName resets all changes to the "name" field.
func (m *HIBPMutation) ResetName() {
m.name = nil
}
// SetDomain sets the "domain" field.
func (m *HIBPMutation) SetDomain(s string) {
m.domain = &s
}
// Domain returns the value of the "domain" field in the mutation.
func (m *HIBPMutation) Domain() (r string, exists bool) {
v := m.domain
if v == nil {
return
}
return *v, true
}
// OldDomain returns the old "domain" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldDomain(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDomain is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDomain requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDomain: %w", err)
}
return oldValue.Domain, nil
}
// ResetDomain resets all changes to the "domain" field.
func (m *HIBPMutation) ResetDomain() {
m.domain = nil
}
// SetBreachDate sets the "breach_date" field.
func (m *HIBPMutation) SetBreachDate(t time.Time) {
m.breach_date = &t
}
// BreachDate returns the value of the "breach_date" field in the mutation.
func (m *HIBPMutation) BreachDate() (r time.Time, exists bool) {
v := m.breach_date
if v == nil {
return
}
return *v, true
}
// OldBreachDate returns the old "breach_date" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldBreachDate(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBreachDate is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBreachDate requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBreachDate: %w", err)
}
return oldValue.BreachDate, nil
}
// ResetBreachDate resets all changes to the "breach_date" field.
func (m *HIBPMutation) ResetBreachDate() {
m.breach_date = nil
}
// SetAddedDate sets the "added_date" field.
func (m *HIBPMutation) SetAddedDate(t time.Time) {
m.added_date = &t
}
// AddedDate returns the value of the "added_date" field in the mutation.
func (m *HIBPMutation) AddedDate() (r time.Time, exists bool) {
v := m.added_date
if v == nil {
return
}
return *v, true
}
// OldAddedDate returns the old "added_date" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldAddedDate(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAddedDate is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldAddedDate requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAddedDate: %w", err)
}
return oldValue.AddedDate, nil
}
// ResetAddedDate resets all changes to the "added_date" field.
func (m *HIBPMutation) ResetAddedDate() {
m.added_date = nil
}
// SetModifiedDate sets the "modified_date" field.
func (m *HIBPMutation) SetModifiedDate(t time.Time) {
m.modified_date = &t
}
// ModifiedDate returns the value of the "modified_date" field in the mutation.
func (m *HIBPMutation) ModifiedDate() (r time.Time, exists bool) {
v := m.modified_date
if v == nil {
return
}
return *v, true
}
// OldModifiedDate returns the old "modified_date" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldModifiedDate(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldModifiedDate is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldModifiedDate requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldModifiedDate: %w", err)
}
return oldValue.ModifiedDate, nil
}
// ResetModifiedDate resets all changes to the "modified_date" field.
func (m *HIBPMutation) ResetModifiedDate() {
m.modified_date = nil
}
// SetPwnCount sets the "pwn_count" field.
func (m *HIBPMutation) SetPwnCount(i int) {
m.pwn_count = &i
m.addpwn_count = nil
}
// PwnCount returns the value of the "pwn_count" field in the mutation.
func (m *HIBPMutation) PwnCount() (r int, exists bool) {
v := m.pwn_count
if v == nil {
return
}
return *v, true
}
// OldPwnCount returns the old "pwn_count" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldPwnCount(ctx context.Context) (v int, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPwnCount is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPwnCount requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPwnCount: %w", err)
}
return oldValue.PwnCount, nil
}
// AddPwnCount adds i to the "pwn_count" field.
func (m *HIBPMutation) AddPwnCount(i int) {
if m.addpwn_count != nil {
*m.addpwn_count += i
} else {
m.addpwn_count = &i
}
}
// AddedPwnCount returns the value that was added to the "pwn_count" field in this mutation.
func (m *HIBPMutation) AddedPwnCount() (r int, exists bool) {
v := m.addpwn_count
if v == nil {
return
}
return *v, true
}
// ResetPwnCount resets all changes to the "pwn_count" field.
func (m *HIBPMutation) ResetPwnCount() {
m.pwn_count = nil
m.addpwn_count = nil
}
// SetDescription sets the "description" field.
func (m *HIBPMutation) SetDescription(s string) {
m.description = &s
}
// Description returns the value of the "description" field in the mutation.
func (m *HIBPMutation) Description() (r string, exists bool) {
v := m.description
if v == nil {
return
}
return *v, true
}
// OldDescription returns the old "description" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldDescription(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDescription is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDescription requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDescription: %w", err)
}
return oldValue.Description, nil
}
// ResetDescription resets all changes to the "description" field.
func (m *HIBPMutation) ResetDescription() {
m.description = nil
}
// SetDataclasses sets the "dataclasses" field.
func (m *HIBPMutation) SetDataclasses(s []string) {
m.dataclasses = &s
m.appenddataclasses = nil
}
// Dataclasses returns the value of the "dataclasses" field in the mutation.
func (m *HIBPMutation) Dataclasses() (r []string, exists bool) {
v := m.dataclasses
if v == nil {
return
}
return *v, true
}
// OldDataclasses returns the old "dataclasses" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldDataclasses(ctx context.Context) (v []string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDataclasses is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDataclasses requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDataclasses: %w", err)
}
return oldValue.Dataclasses, nil
}
// AppendDataclasses adds s to the "dataclasses" field.
func (m *HIBPMutation) AppendDataclasses(s []string) {
m.appenddataclasses = append(m.appenddataclasses, s...)
}
// AppendedDataclasses returns the list of values that were appended to the "dataclasses" field in this mutation.
func (m *HIBPMutation) AppendedDataclasses() ([]string, bool) {
if len(m.appenddataclasses) == 0 {
return nil, false
}
return m.appenddataclasses, true
}
// ResetDataclasses resets all changes to the "dataclasses" field.
func (m *HIBPMutation) ResetDataclasses() {
m.dataclasses = nil
m.appenddataclasses = nil
}
// SetIsVerified sets the "is_verified" field.
func (m *HIBPMutation) SetIsVerified(b bool) {
m.is_verified = &b
}
// IsVerified returns the value of the "is_verified" field in the mutation.
func (m *HIBPMutation) IsVerified() (r bool, exists bool) {
v := m.is_verified
if v == nil {
return
}
return *v, true
}
// OldIsVerified returns the old "is_verified" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldIsVerified(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIsVerified is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIsVerified requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIsVerified: %w", err)
}
return oldValue.IsVerified, nil
}
// ResetIsVerified resets all changes to the "is_verified" field.
func (m *HIBPMutation) ResetIsVerified() {
m.is_verified = nil
}
// SetIsFabricated sets the "is_fabricated" field.
func (m *HIBPMutation) SetIsFabricated(b bool) {
m.is_fabricated = &b
}
// IsFabricated returns the value of the "is_fabricated" field in the mutation.
func (m *HIBPMutation) IsFabricated() (r bool, exists bool) {
v := m.is_fabricated
if v == nil {
return
}
return *v, true
}
// OldIsFabricated returns the old "is_fabricated" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldIsFabricated(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIsFabricated is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIsFabricated requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIsFabricated: %w", err)
}
return oldValue.IsFabricated, nil
}
// ResetIsFabricated resets all changes to the "is_fabricated" field.
func (m *HIBPMutation) ResetIsFabricated() {
m.is_fabricated = nil
}
// SetIsSensitive sets the "is_sensitive" field.
func (m *HIBPMutation) SetIsSensitive(b bool) {
m.is_sensitive = &b
}
// IsSensitive returns the value of the "is_sensitive" field in the mutation.
func (m *HIBPMutation) IsSensitive() (r bool, exists bool) {
v := m.is_sensitive
if v == nil {
return
}
return *v, true
}
// OldIsSensitive returns the old "is_sensitive" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldIsSensitive(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIsSensitive is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIsSensitive requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIsSensitive: %w", err)
}
return oldValue.IsSensitive, nil
}
// ResetIsSensitive resets all changes to the "is_sensitive" field.
func (m *HIBPMutation) ResetIsSensitive() {
m.is_sensitive = nil
}
// SetIsRetired sets the "is_retired" field.
func (m *HIBPMutation) SetIsRetired(b bool) {
m.is_retired = &b
}
// IsRetired returns the value of the "is_retired" field in the mutation.
func (m *HIBPMutation) IsRetired() (r bool, exists bool) {
v := m.is_retired
if v == nil {
return
}
return *v, true
}
// OldIsRetired returns the old "is_retired" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldIsRetired(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIsRetired is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIsRetired requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIsRetired: %w", err)
}
return oldValue.IsRetired, nil
}
// ResetIsRetired resets all changes to the "is_retired" field.
func (m *HIBPMutation) ResetIsRetired() {
m.is_retired = nil
}
// SetIsSpamList sets the "is_spamList" field.
func (m *HIBPMutation) SetIsSpamList(b bool) {
m.is_spamList = &b
}
// IsSpamList returns the value of the "is_spamList" field in the mutation.
func (m *HIBPMutation) IsSpamList() (r bool, exists bool) {
v := m.is_spamList
if v == nil {
return
}
return *v, true
}
// OldIsSpamList returns the old "is_spamList" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldIsSpamList(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIsSpamList is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIsSpamList requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIsSpamList: %w", err)
}
return oldValue.IsSpamList, nil
}
// ResetIsSpamList resets all changes to the "is_spamList" field.
func (m *HIBPMutation) ResetIsSpamList() {
m.is_spamList = nil
}
// SetIsMalware sets the "is_malware" field.
func (m *HIBPMutation) SetIsMalware(b bool) {
m.is_malware = &b
}
// IsMalware returns the value of the "is_malware" field in the mutation.
func (m *HIBPMutation) IsMalware() (r bool, exists bool) {
v := m.is_malware
if v == nil {
return
}
return *v, true
}
// OldIsMalware returns the old "is_malware" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldIsMalware(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldIsMalware is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldIsMalware requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldIsMalware: %w", err)
}
return oldValue.IsMalware, nil
}
// ResetIsMalware resets all changes to the "is_malware" field.
func (m *HIBPMutation) ResetIsMalware() {
m.is_malware = nil
}
// SetLogo sets the "logo" field.
func (m *HIBPMutation) SetLogo(s string) {
m.logo = &s
}
// Logo returns the value of the "logo" field in the mutation.
func (m *HIBPMutation) Logo() (r string, exists bool) {
v := m.logo
if v == nil {
return
}
return *v, true
}
// OldLogo returns the old "logo" field's value of the HIBP entity.
// If the HIBP object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *HIBPMutation) OldLogo(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLogo is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldLogo requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLogo: %w", err)
}
return oldValue.Logo, nil
}
// ResetLogo resets all changes to the "logo" field.
func (m *HIBPMutation) ResetLogo() {
m.logo = nil
}
// Where appends a list predicates to the HIBPMutation builder.
func (m *HIBPMutation) Where(ps ...predicate.HIBP) {
m.predicates = append(m.predicates, ps...)
}
// WhereP appends storage-level predicates to the HIBPMutation builder. Using this method,
// users can use type-assertion to append predicates that do not depend on any generated package.
func (m *HIBPMutation) WhereP(ps ...func(*sql.Selector)) {
p := make([]predicate.HIBP, len(ps))
for i := range ps {
p[i] = ps[i]
}
m.Where(p...)
}
// Op returns the operation name.
func (m *HIBPMutation) Op() Op {
return m.op
}
// SetOp allows setting the mutation operation.
func (m *HIBPMutation) SetOp(op Op) {
m.op = op
}
// Type returns the node type of this mutation (HIBP).
func (m *HIBPMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *HIBPMutation) Fields() []string {
fields := make([]string, 0, 15)
if m.name != nil {
fields = append(fields, hibp.FieldName)
}
if m.domain != nil {
fields = append(fields, hibp.FieldDomain)
}
if m.breach_date != nil {
fields = append(fields, hibp.FieldBreachDate)
}
if m.added_date != nil {
fields = append(fields, hibp.FieldAddedDate)
}
if m.modified_date != nil {
fields = append(fields, hibp.FieldModifiedDate)
}
if m.pwn_count != nil {
fields = append(fields, hibp.FieldPwnCount)
}
if m.description != nil {
fields = append(fields, hibp.FieldDescription)
}
if m.dataclasses != nil {
fields = append(fields, hibp.FieldDataclasses)
}
if m.is_verified != nil {
fields = append(fields, hibp.FieldIsVerified)
}
if m.is_fabricated != nil {
fields = append(fields, hibp.FieldIsFabricated)
}
if m.is_sensitive != nil {
fields = append(fields, hibp.FieldIsSensitive)
}
if m.is_retired != nil {
fields = append(fields, hibp.FieldIsRetired)
}
if m.is_spamList != nil {
fields = append(fields, hibp.FieldIsSpamList)
}
if m.is_malware != nil {
fields = append(fields, hibp.FieldIsMalware)
}
if m.logo != nil {
fields = append(fields, hibp.FieldLogo)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *HIBPMutation) Field(name string) (ent.Value, bool) {
switch name {
case hibp.FieldName:
return m.Name()
case hibp.FieldDomain:
return m.Domain()
case hibp.FieldBreachDate:
return m.BreachDate()
case hibp.FieldAddedDate:
return m.AddedDate()
case hibp.FieldModifiedDate:
return m.ModifiedDate()
case hibp.FieldPwnCount:
return m.PwnCount()
case hibp.FieldDescription:
return m.Description()
case hibp.FieldDataclasses:
return m.Dataclasses()
case hibp.FieldIsVerified:
return m.IsVerified()
case hibp.FieldIsFabricated:
return m.IsFabricated()
case hibp.FieldIsSensitive:
return m.IsSensitive()
case hibp.FieldIsRetired:
return m.IsRetired()
case hibp.FieldIsSpamList:
return m.IsSpamList()
case hibp.FieldIsMalware:
return m.IsMalware()
case hibp.FieldLogo:
return m.Logo()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *HIBPMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case hibp.FieldName:
return m.OldName(ctx)
case hibp.FieldDomain:
return m.OldDomain(ctx)
case hibp.FieldBreachDate:
return m.OldBreachDate(ctx)
case hibp.FieldAddedDate:
return m.OldAddedDate(ctx)
case hibp.FieldModifiedDate:
return m.OldModifiedDate(ctx)
case hibp.FieldPwnCount:
return m.OldPwnCount(ctx)
case hibp.FieldDescription:
return m.OldDescription(ctx)
case hibp.FieldDataclasses:
return m.OldDataclasses(ctx)
case hibp.FieldIsVerified:
return m.OldIsVerified(ctx)
case hibp.FieldIsFabricated:
return m.OldIsFabricated(ctx)
case hibp.FieldIsSensitive:
return m.OldIsSensitive(ctx)
case hibp.FieldIsRetired:
return m.OldIsRetired(ctx)
case hibp.FieldIsSpamList:
return m.OldIsSpamList(ctx)
case hibp.FieldIsMalware:
return m.OldIsMalware(ctx)
case hibp.FieldLogo:
return m.OldLogo(ctx)
}
return nil, fmt.Errorf("unknown HIBP field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *HIBPMutation) SetField(name string, value ent.Value) error {
switch name {
case hibp.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case hibp.FieldDomain:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDomain(v)
return nil
case hibp.FieldBreachDate:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBreachDate(v)
return nil
case hibp.FieldAddedDate:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetAddedDate(v)
return nil
case hibp.FieldModifiedDate:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetModifiedDate(v)
return nil
case hibp.FieldPwnCount:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPwnCount(v)
return nil
case hibp.FieldDescription:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDescription(v)
return nil
case hibp.FieldDataclasses:
v, ok := value.([]string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDataclasses(v)
return nil
case hibp.FieldIsVerified:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIsVerified(v)
return nil
case hibp.FieldIsFabricated:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIsFabricated(v)
return nil
case hibp.FieldIsSensitive:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIsSensitive(v)
return nil
case hibp.FieldIsRetired:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIsRetired(v)
return nil
case hibp.FieldIsSpamList:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIsSpamList(v)
return nil
case hibp.FieldIsMalware:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetIsMalware(v)
return nil
case hibp.FieldLogo:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLogo(v)
return nil
}
return fmt.Errorf("unknown HIBP field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *HIBPMutation) AddedFields() []string {
var fields []string
if m.addpwn_count != nil {
fields = append(fields, hibp.FieldPwnCount)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *HIBPMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case hibp.FieldPwnCount:
return m.AddedPwnCount()
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *HIBPMutation) AddField(name string, value ent.Value) error {
switch name {
case hibp.FieldPwnCount:
v, ok := value.(int)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddPwnCount(v)
return nil
}
return fmt.Errorf("unknown HIBP numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *HIBPMutation) ClearedFields() []string {
return nil
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *HIBPMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *HIBPMutation) ClearField(name string) error {
return fmt.Errorf("unknown HIBP nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *HIBPMutation) ResetField(name string) error {
switch name {
case hibp.FieldName:
m.ResetName()
return nil
case hibp.FieldDomain:
m.ResetDomain()
return nil
case hibp.FieldBreachDate:
m.ResetBreachDate()
return nil
case hibp.FieldAddedDate:
m.ResetAddedDate()
return nil
case hibp.FieldModifiedDate:
m.ResetModifiedDate()
return nil
case hibp.FieldPwnCount:
m.ResetPwnCount()
return nil
case hibp.FieldDescription:
m.ResetDescription()
return nil
case hibp.FieldDataclasses:
m.ResetDataclasses()
return nil
case hibp.FieldIsVerified:
m.ResetIsVerified()
return nil
case hibp.FieldIsFabricated:
m.ResetIsFabricated()
return nil
case hibp.FieldIsSensitive:
m.ResetIsSensitive()
return nil
case hibp.FieldIsRetired:
m.ResetIsRetired()
return nil
case hibp.FieldIsSpamList:
m.ResetIsSpamList()
return nil
case hibp.FieldIsMalware:
m.ResetIsMalware()
return nil
case hibp.FieldLogo:
m.ResetLogo()
return nil
}
return fmt.Errorf("unknown HIBP field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *HIBPMutation) AddedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *HIBPMutation) AddedIDs(name string) []ent.Value {
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *HIBPMutation) RemovedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *HIBPMutation) RemovedIDs(name string) []ent.Value {
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *HIBPMutation) ClearedEdges() []string {
edges := make([]string, 0, 0)
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *HIBPMutation) EdgeCleared(name string) bool {
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *HIBPMutation) ClearEdge(name string) error {
return fmt.Errorf("unknown HIBP unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *HIBPMutation) ResetEdge(name string) error {
return fmt.Errorf("unknown HIBP edge %s", name)
}
// UserMutation represents an operation that mutates the User nodes in the graph.
type UserMutation struct {
config

@ -6,5 +6,8 @@ import (
"entgo.io/ent/dialect/sql"
)
// HIBP is the predicate function for hibp builders.
type HIBP func(*sql.Selector)
// User is the predicate function for user builders.
type User func(*sql.Selector)

@ -5,6 +5,7 @@ package ent
import (
"time"
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
"git.dotya.ml/mirre-mt/pcmt/ent/schema"
"git.dotya.ml/mirre-mt/pcmt/ent/user"
"github.com/google/uuid"
@ -14,6 +15,32 @@ import (
// (default values, validators, hooks and policies) and stitches it
// to their package variables.
func init() {
hibpFields := schema.HIBP{}.Fields()
_ = hibpFields
// hibpDescIsVerified is the schema descriptor for is_verified field.
hibpDescIsVerified := hibpFields[9].Descriptor()
// hibp.DefaultIsVerified holds the default value on creation for the is_verified field.
hibp.DefaultIsVerified = hibpDescIsVerified.Default.(bool)
// hibpDescIsFabricated is the schema descriptor for is_fabricated field.
hibpDescIsFabricated := hibpFields[10].Descriptor()
// hibp.DefaultIsFabricated holds the default value on creation for the is_fabricated field.
hibp.DefaultIsFabricated = hibpDescIsFabricated.Default.(bool)
// hibpDescIsSensitive is the schema descriptor for is_sensitive field.
hibpDescIsSensitive := hibpFields[11].Descriptor()
// hibp.DefaultIsSensitive holds the default value on creation for the is_sensitive field.
hibp.DefaultIsSensitive = hibpDescIsSensitive.Default.(bool)
// hibpDescIsRetired is the schema descriptor for is_retired field.
hibpDescIsRetired := hibpFields[12].Descriptor()
// hibp.DefaultIsRetired holds the default value on creation for the is_retired field.
hibp.DefaultIsRetired = hibpDescIsRetired.Default.(bool)
// hibpDescIsSpamList is the schema descriptor for is_spamList field.
hibpDescIsSpamList := hibpFields[13].Descriptor()
// hibp.DefaultIsSpamList holds the default value on creation for the is_spamList field.
hibp.DefaultIsSpamList = hibpDescIsSpamList.Default.(bool)
// hibpDescIsMalware is the schema descriptor for is_malware field.
hibpDescIsMalware := hibpFields[14].Descriptor()
// hibp.DefaultIsMalware holds the default value on creation for the is_malware field.
hibp.DefaultIsMalware = hibpDescIsMalware.Default.(bool)
userFields := schema.User{}.Fields()
_ = userFields
// userDescUsername is the schema descriptor for username field.

54
ent/schema/hibp.go Normal file

@ -0,0 +1,54 @@
package schema
import (
"entgo.io/ent"
"entgo.io/ent/schema/field"
"github.com/google/uuid"
)
// HIBP holds the schema definition for the HIBP entity.
type HIBP struct {
ent.Schema
}
// Fields of the HIBP that model the HIBP API v3, ref:
// https://haveibeenpwned.com/API/v3.
func (HIBP) Fields() []ent.Field {
return []ent.Field{
field.UUID("id", uuid.UUID{}).
Unique().
Immutable(),
// Unique but may change.
field.String("name").
Unique(),
field.String("domain").
Immutable(),
field.Time("breach_date"),
// precision to the minute.
field.Time("added_date"),
field.Time("modified_date"),
field.Int("pwn_count"),
field.String("description").
Comment("May contain HTML markup"),
field.Strings("dataclasses"),
field.Bool("is_verified").
Default(false),
field.Bool("is_fabricated").
Default(false),
field.Bool("is_sensitive").
Default(false),
field.Bool("is_retired").
Default(false),
field.Bool("is_spamList").
Default(false),
field.Bool("is_malware").
Default(false),
field.String("logo").
Comment("Always in PNG format"),
}
}
// Edges of the HIBP.
func (HIBP) Edges() []ent.Edge {
return nil
}

@ -12,6 +12,8 @@ import (
// Tx is a transactional client that is created by calling Client.Tx().
type Tx struct {
config
// HIBP is the client for interacting with the HIBP builders.
HIBP *HIBPClient
// User is the client for interacting with the User builders.
User *UserClient
@ -145,6 +147,7 @@ func (tx *Tx) Client() *Client {
}
func (tx *Tx) init() {
tx.HIBP = NewHIBPClient(tx.config)
tx.User = NewUserClient(tx.config)
}
@ -155,7 +158,7 @@ func (tx *Tx) init() {
// of them in order to commit or rollback the transaction.
//
// If a closed transaction is embedded in one of the generated entities, and the entity
// applies a query, for example: User.QueryXXX(), the query will be executed
// applies a query, for example: HIBP.QueryXXX(), the query will be executed
// through the driver which created this transaction.
//
// Note that txDriver is not goroutine safe.