ent: add/extend entities, tests, validation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5579d77cc3
commit
74546f996b
|
@ -0,0 +1,173 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// AgeKey is the model entity for the AgeKey schema.
|
||||
type AgeKey struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// age ed25519 identity stored encrypted using AES256
|
||||
Key *[]byte `json:"key,omitempty"`
|
||||
// Created holds the value of the "created" field.
|
||||
Created time.Time `json:"created,omitempty"`
|
||||
// Updated holds the value of the "updated" field.
|
||||
Updated time.Time `json:"updated,omitempty"`
|
||||
// id of the key owner
|
||||
Owner uuid.UUID `json:"owner,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the AgeKeyQuery when eager-loading is set.
|
||||
Edges AgeKeyEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// AgeKeyEdges holds the relations/edges for other nodes in the graph.
|
||||
type AgeKeyEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e AgeKeyEdges) UserOrErr() (*User, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.User == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return e.User, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*AgeKey) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case agekey.FieldKey:
|
||||
values[i] = new([]byte)
|
||||
case agekey.FieldCreated, agekey.FieldUpdated:
|
||||
values[i] = new(sql.NullTime)
|
||||
case agekey.FieldID, agekey.FieldOwner:
|
||||
values[i] = new(uuid.UUID)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the AgeKey fields.
|
||||
func (ak *AgeKey) 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 agekey.FieldID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
ak.ID = *value
|
||||
}
|
||||
case agekey.FieldKey:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field key", values[i])
|
||||
} else if value != nil {
|
||||
ak.Key = value
|
||||
}
|
||||
case agekey.FieldCreated:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created", values[i])
|
||||
} else if value.Valid {
|
||||
ak.Created = value.Time
|
||||
}
|
||||
case agekey.FieldUpdated:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field updated", values[i])
|
||||
} else if value.Valid {
|
||||
ak.Updated = value.Time
|
||||
}
|
||||
case agekey.FieldOwner:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field owner", values[i])
|
||||
} else if value != nil {
|
||||
ak.Owner = *value
|
||||
}
|
||||
default:
|
||||
ak.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the AgeKey.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (ak *AgeKey) Value(name string) (ent.Value, error) {
|
||||
return ak.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the AgeKey entity.
|
||||
func (ak *AgeKey) QueryUser() *UserQuery {
|
||||
return NewAgeKeyClient(ak.config).QueryUser(ak)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this AgeKey.
|
||||
// Note that you need to call AgeKey.Unwrap() before calling this method if this AgeKey
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (ak *AgeKey) Update() *AgeKeyUpdateOne {
|
||||
return NewAgeKeyClient(ak.config).UpdateOne(ak)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the AgeKey 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 (ak *AgeKey) Unwrap() *AgeKey {
|
||||
_tx, ok := ak.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: AgeKey is not a transactional entity")
|
||||
}
|
||||
ak.config.driver = _tx.drv
|
||||
return ak
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (ak *AgeKey) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("AgeKey(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", ak.ID))
|
||||
if v := ak.Key; v != nil {
|
||||
builder.WriteString("key=")
|
||||
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created=")
|
||||
builder.WriteString(ak.Created.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("updated=")
|
||||
builder.WriteString(ak.Updated.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("owner=")
|
||||
builder.WriteString(fmt.Sprintf("%v", ak.Owner))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// AgeKeys is a parsable slice of AgeKey.
|
||||
type AgeKeys []*AgeKey
|
|
@ -0,0 +1,104 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package agekey
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the agekey type in the database.
|
||||
Label = "age_key"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldKey holds the string denoting the key field in the database.
|
||||
FieldKey = "key"
|
||||
// FieldCreated holds the string denoting the created field in the database.
|
||||
FieldCreated = "created"
|
||||
// FieldUpdated holds the string denoting the updated field in the database.
|
||||
FieldUpdated = "updated"
|
||||
// FieldOwner holds the string denoting the owner field in the database.
|
||||
FieldOwner = "owner"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// Table holds the table name of the agekey in the database.
|
||||
Table = "age_keys"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "age_keys"
|
||||
// UserInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "owner"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for agekey fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldKey,
|
||||
FieldCreated,
|
||||
FieldUpdated,
|
||||
FieldOwner,
|
||||
}
|
||||
|
||||
// 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 (
|
||||
// KeyValidator is a validator for the "key" field. It is called by the builders before save.
|
||||
KeyValidator func([]byte) error
|
||||
// DefaultCreated holds the default value on creation for the "created" field.
|
||||
DefaultCreated func() time.Time
|
||||
// DefaultUpdated holds the default value on creation for the "updated" field.
|
||||
DefaultUpdated func() time.Time
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the AgeKey queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreated orders the results by the created field.
|
||||
func ByCreated(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreated, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUpdated orders the results by the updated field.
|
||||
func ByUpdated(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUpdated, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOwner orders the results by the owner field.
|
||||
func ByOwner(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOwner, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserField orders the results by user field.
|
||||
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, UserTable, UserColumn),
|
||||
)
|
||||
}
|
|
@ -0,0 +1,272 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package agekey
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"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.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Key applies equality check predicate on the "key" field. It's identical to KeyEQ.
|
||||
func Key(v []byte) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldEQ(FieldKey, v))
|
||||
}
|
||||
|
||||
// Created applies equality check predicate on the "created" field. It's identical to CreatedEQ.
|
||||
func Created(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldEQ(FieldCreated, v))
|
||||
}
|
||||
|
||||
// Updated applies equality check predicate on the "updated" field. It's identical to UpdatedEQ.
|
||||
func Updated(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldEQ(FieldUpdated, v))
|
||||
}
|
||||
|
||||
// Owner applies equality check predicate on the "owner" field. It's identical to OwnerEQ.
|
||||
func Owner(v uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldEQ(FieldOwner, v))
|
||||
}
|
||||
|
||||
// KeyEQ applies the EQ predicate on the "key" field.
|
||||
func KeyEQ(v []byte) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldEQ(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyNEQ applies the NEQ predicate on the "key" field.
|
||||
func KeyNEQ(v []byte) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldNEQ(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyIn applies the In predicate on the "key" field.
|
||||
func KeyIn(vs ...[]byte) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldIn(FieldKey, vs...))
|
||||
}
|
||||
|
||||
// KeyNotIn applies the NotIn predicate on the "key" field.
|
||||
func KeyNotIn(vs ...[]byte) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldNotIn(FieldKey, vs...))
|
||||
}
|
||||
|
||||
// KeyGT applies the GT predicate on the "key" field.
|
||||
func KeyGT(v []byte) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldGT(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyGTE applies the GTE predicate on the "key" field.
|
||||
func KeyGTE(v []byte) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldGTE(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyLT applies the LT predicate on the "key" field.
|
||||
func KeyLT(v []byte) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldLT(FieldKey, v))
|
||||
}
|
||||
|
||||
// KeyLTE applies the LTE predicate on the "key" field.
|
||||
func KeyLTE(v []byte) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldLTE(FieldKey, v))
|
||||
}
|
||||
|
||||
// CreatedEQ applies the EQ predicate on the "created" field.
|
||||
func CreatedEQ(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldEQ(FieldCreated, v))
|
||||
}
|
||||
|
||||
// CreatedNEQ applies the NEQ predicate on the "created" field.
|
||||
func CreatedNEQ(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldNEQ(FieldCreated, v))
|
||||
}
|
||||
|
||||
// CreatedIn applies the In predicate on the "created" field.
|
||||
func CreatedIn(vs ...time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldIn(FieldCreated, vs...))
|
||||
}
|
||||
|
||||
// CreatedNotIn applies the NotIn predicate on the "created" field.
|
||||
func CreatedNotIn(vs ...time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldNotIn(FieldCreated, vs...))
|
||||
}
|
||||
|
||||
// CreatedGT applies the GT predicate on the "created" field.
|
||||
func CreatedGT(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldGT(FieldCreated, v))
|
||||
}
|
||||
|
||||
// CreatedGTE applies the GTE predicate on the "created" field.
|
||||
func CreatedGTE(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldGTE(FieldCreated, v))
|
||||
}
|
||||
|
||||
// CreatedLT applies the LT predicate on the "created" field.
|
||||
func CreatedLT(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldLT(FieldCreated, v))
|
||||
}
|
||||
|
||||
// CreatedLTE applies the LTE predicate on the "created" field.
|
||||
func CreatedLTE(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldLTE(FieldCreated, v))
|
||||
}
|
||||
|
||||
// UpdatedEQ applies the EQ predicate on the "updated" field.
|
||||
func UpdatedEQ(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldEQ(FieldUpdated, v))
|
||||
}
|
||||
|
||||
// UpdatedNEQ applies the NEQ predicate on the "updated" field.
|
||||
func UpdatedNEQ(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldNEQ(FieldUpdated, v))
|
||||
}
|
||||
|
||||
// UpdatedIn applies the In predicate on the "updated" field.
|
||||
func UpdatedIn(vs ...time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldIn(FieldUpdated, vs...))
|
||||
}
|
||||
|
||||
// UpdatedNotIn applies the NotIn predicate on the "updated" field.
|
||||
func UpdatedNotIn(vs ...time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldNotIn(FieldUpdated, vs...))
|
||||
}
|
||||
|
||||
// UpdatedGT applies the GT predicate on the "updated" field.
|
||||
func UpdatedGT(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldGT(FieldUpdated, v))
|
||||
}
|
||||
|
||||
// UpdatedGTE applies the GTE predicate on the "updated" field.
|
||||
func UpdatedGTE(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldGTE(FieldUpdated, v))
|
||||
}
|
||||
|
||||
// UpdatedLT applies the LT predicate on the "updated" field.
|
||||
func UpdatedLT(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldLT(FieldUpdated, v))
|
||||
}
|
||||
|
||||
// UpdatedLTE applies the LTE predicate on the "updated" field.
|
||||
func UpdatedLTE(v time.Time) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldLTE(FieldUpdated, v))
|
||||
}
|
||||
|
||||
// OwnerEQ applies the EQ predicate on the "owner" field.
|
||||
func OwnerEQ(v uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldEQ(FieldOwner, v))
|
||||
}
|
||||
|
||||
// OwnerNEQ applies the NEQ predicate on the "owner" field.
|
||||
func OwnerNEQ(v uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldNEQ(FieldOwner, v))
|
||||
}
|
||||
|
||||
// OwnerIn applies the In predicate on the "owner" field.
|
||||
func OwnerIn(vs ...uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldIn(FieldOwner, vs...))
|
||||
}
|
||||
|
||||
// OwnerNotIn applies the NotIn predicate on the "owner" field.
|
||||
func OwnerNotIn(vs ...uuid.UUID) predicate.AgeKey {
|
||||
return predicate.AgeKey(sql.FieldNotIn(FieldOwner, vs...))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.AgeKey {
|
||||
return predicate.AgeKey(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.User) predicate.AgeKey {
|
||||
return predicate.AgeKey(func(s *sql.Selector) {
|
||||
step := newUserStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.AgeKey) predicate.AgeKey {
|
||||
return predicate.AgeKey(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.AgeKey) predicate.AgeKey {
|
||||
return predicate.AgeKey(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.AgeKey) predicate.AgeKey {
|
||||
return predicate.AgeKey(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
|
@ -0,0 +1,306 @@
|
|||
// 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/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// AgeKeyCreate is the builder for creating a AgeKey entity.
|
||||
type AgeKeyCreate struct {
|
||||
config
|
||||
mutation *AgeKeyMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (akc *AgeKeyCreate) SetKey(b []byte) *AgeKeyCreate {
|
||||
akc.mutation.SetKey(b)
|
||||
return akc
|
||||
}
|
||||
|
||||
// SetCreated sets the "created" field.
|
||||
func (akc *AgeKeyCreate) SetCreated(t time.Time) *AgeKeyCreate {
|
||||
akc.mutation.SetCreated(t)
|
||||
return akc
|
||||
}
|
||||
|
||||
// SetNillableCreated sets the "created" field if the given value is not nil.
|
||||
func (akc *AgeKeyCreate) SetNillableCreated(t *time.Time) *AgeKeyCreate {
|
||||
if t != nil {
|
||||
akc.SetCreated(*t)
|
||||
}
|
||||
return akc
|
||||
}
|
||||
|
||||
// SetUpdated sets the "updated" field.
|
||||
func (akc *AgeKeyCreate) SetUpdated(t time.Time) *AgeKeyCreate {
|
||||
akc.mutation.SetUpdated(t)
|
||||
return akc
|
||||
}
|
||||
|
||||
// SetNillableUpdated sets the "updated" field if the given value is not nil.
|
||||
func (akc *AgeKeyCreate) SetNillableUpdated(t *time.Time) *AgeKeyCreate {
|
||||
if t != nil {
|
||||
akc.SetUpdated(*t)
|
||||
}
|
||||
return akc
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" field.
|
||||
func (akc *AgeKeyCreate) SetOwner(u uuid.UUID) *AgeKeyCreate {
|
||||
akc.mutation.SetOwner(u)
|
||||
return akc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (akc *AgeKeyCreate) SetID(u uuid.UUID) *AgeKeyCreate {
|
||||
akc.mutation.SetID(u)
|
||||
return akc
|
||||
}
|
||||
|
||||
// SetNillableID sets the "id" field if the given value is not nil.
|
||||
func (akc *AgeKeyCreate) SetNillableID(u *uuid.UUID) *AgeKeyCreate {
|
||||
if u != nil {
|
||||
akc.SetID(*u)
|
||||
}
|
||||
return akc
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by ID.
|
||||
func (akc *AgeKeyCreate) SetUserID(id uuid.UUID) *AgeKeyCreate {
|
||||
akc.mutation.SetUserID(id)
|
||||
return akc
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (akc *AgeKeyCreate) SetUser(u *User) *AgeKeyCreate {
|
||||
return akc.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the AgeKeyMutation object of the builder.
|
||||
func (akc *AgeKeyCreate) Mutation() *AgeKeyMutation {
|
||||
return akc.mutation
|
||||
}
|
||||
|
||||
// Save creates the AgeKey in the database.
|
||||
func (akc *AgeKeyCreate) Save(ctx context.Context) (*AgeKey, error) {
|
||||
akc.defaults()
|
||||
return withHooks(ctx, akc.sqlSave, akc.mutation, akc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (akc *AgeKeyCreate) SaveX(ctx context.Context) *AgeKey {
|
||||
v, err := akc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (akc *AgeKeyCreate) Exec(ctx context.Context) error {
|
||||
_, err := akc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (akc *AgeKeyCreate) ExecX(ctx context.Context) {
|
||||
if err := akc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (akc *AgeKeyCreate) defaults() {
|
||||
if _, ok := akc.mutation.Created(); !ok {
|
||||
v := agekey.DefaultCreated()
|
||||
akc.mutation.SetCreated(v)
|
||||
}
|
||||
if _, ok := akc.mutation.Updated(); !ok {
|
||||
v := agekey.DefaultUpdated()
|
||||
akc.mutation.SetUpdated(v)
|
||||
}
|
||||
if _, ok := akc.mutation.ID(); !ok {
|
||||
v := agekey.DefaultID()
|
||||
akc.mutation.SetID(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (akc *AgeKeyCreate) check() error {
|
||||
if _, ok := akc.mutation.Key(); !ok {
|
||||
return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "AgeKey.key"`)}
|
||||
}
|
||||
if v, ok := akc.mutation.Key(); ok {
|
||||
if err := agekey.KeyValidator(v); err != nil {
|
||||
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "AgeKey.key": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := akc.mutation.Created(); !ok {
|
||||
return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "AgeKey.created"`)}
|
||||
}
|
||||
if _, ok := akc.mutation.Updated(); !ok {
|
||||
return &ValidationError{Name: "updated", err: errors.New(`ent: missing required field "AgeKey.updated"`)}
|
||||
}
|
||||
if _, ok := akc.mutation.Owner(); !ok {
|
||||
return &ValidationError{Name: "owner", err: errors.New(`ent: missing required field "AgeKey.owner"`)}
|
||||
}
|
||||
if _, ok := akc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "AgeKey.user"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (akc *AgeKeyCreate) sqlSave(ctx context.Context) (*AgeKey, error) {
|
||||
if err := akc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := akc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, akc.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
|
||||
}
|
||||
}
|
||||
akc.mutation.id = &_node.ID
|
||||
akc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (akc *AgeKeyCreate) createSpec() (*AgeKey, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &AgeKey{config: akc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(agekey.Table, sqlgraph.NewFieldSpec(agekey.FieldID, field.TypeUUID))
|
||||
)
|
||||
if id, ok := akc.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := akc.mutation.Key(); ok {
|
||||
_spec.SetField(agekey.FieldKey, field.TypeBytes, value)
|
||||
_node.Key = &value
|
||||
}
|
||||
if value, ok := akc.mutation.Created(); ok {
|
||||
_spec.SetField(agekey.FieldCreated, field.TypeTime, value)
|
||||
_node.Created = value
|
||||
}
|
||||
if value, ok := akc.mutation.Updated(); ok {
|
||||
_spec.SetField(agekey.FieldUpdated, field.TypeTime, value)
|
||||
_node.Updated = value
|
||||
}
|
||||
if nodes := akc.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: true,
|
||||
Table: agekey.UserTable,
|
||||
Columns: []string{agekey.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.Owner = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// AgeKeyCreateBulk is the builder for creating many AgeKey entities in bulk.
|
||||
type AgeKeyCreateBulk struct {
|
||||
config
|
||||
builders []*AgeKeyCreate
|
||||
}
|
||||
|
||||
// Save creates the AgeKey entities in the database.
|
||||
func (akcb *AgeKeyCreateBulk) Save(ctx context.Context) ([]*AgeKey, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(akcb.builders))
|
||||
nodes := make([]*AgeKey, len(akcb.builders))
|
||||
mutators := make([]Mutator, len(akcb.builders))
|
||||
for i := range akcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := akcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*AgeKeyMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, akcb.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, akcb.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, akcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (akcb *AgeKeyCreateBulk) SaveX(ctx context.Context) []*AgeKey {
|
||||
v, err := akcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (akcb *AgeKeyCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := akcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (akcb *AgeKeyCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := akcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -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/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
)
|
||||
|
||||
// AgeKeyDelete is the builder for deleting a AgeKey entity.
|
||||
type AgeKeyDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *AgeKeyMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the AgeKeyDelete builder.
|
||||
func (akd *AgeKeyDelete) Where(ps ...predicate.AgeKey) *AgeKeyDelete {
|
||||
akd.mutation.Where(ps...)
|
||||
return akd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (akd *AgeKeyDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, akd.sqlExec, akd.mutation, akd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (akd *AgeKeyDelete) ExecX(ctx context.Context) int {
|
||||
n, err := akd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (akd *AgeKeyDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(agekey.Table, sqlgraph.NewFieldSpec(agekey.FieldID, field.TypeUUID))
|
||||
if ps := akd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, akd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
akd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// AgeKeyDeleteOne is the builder for deleting a single AgeKey entity.
|
||||
type AgeKeyDeleteOne struct {
|
||||
akd *AgeKeyDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the AgeKeyDelete builder.
|
||||
func (akdo *AgeKeyDeleteOne) Where(ps ...predicate.AgeKey) *AgeKeyDeleteOne {
|
||||
akdo.akd.mutation.Where(ps...)
|
||||
return akdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (akdo *AgeKeyDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := akdo.akd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{agekey.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (akdo *AgeKeyDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := akdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,606 @@
|
|||
// 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/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// AgeKeyQuery is the builder for querying AgeKey entities.
|
||||
type AgeKeyQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []agekey.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.AgeKey
|
||||
withUser *UserQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the AgeKeyQuery builder.
|
||||
func (akq *AgeKeyQuery) Where(ps ...predicate.AgeKey) *AgeKeyQuery {
|
||||
akq.predicates = append(akq.predicates, ps...)
|
||||
return akq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (akq *AgeKeyQuery) Limit(limit int) *AgeKeyQuery {
|
||||
akq.ctx.Limit = &limit
|
||||
return akq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (akq *AgeKeyQuery) Offset(offset int) *AgeKeyQuery {
|
||||
akq.ctx.Offset = &offset
|
||||
return akq
|
||||
}
|
||||
|
||||
// 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 (akq *AgeKeyQuery) Unique(unique bool) *AgeKeyQuery {
|
||||
akq.ctx.Unique = &unique
|
||||
return akq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (akq *AgeKeyQuery) Order(o ...agekey.OrderOption) *AgeKeyQuery {
|
||||
akq.order = append(akq.order, o...)
|
||||
return akq
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (akq *AgeKeyQuery) QueryUser() *UserQuery {
|
||||
query := (&UserClient{config: akq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := akq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := akq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(agekey.Table, agekey.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, agekey.UserTable, agekey.UserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(akq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first AgeKey entity from the query.
|
||||
// Returns a *NotFoundError when no AgeKey was found.
|
||||
func (akq *AgeKeyQuery) First(ctx context.Context) (*AgeKey, error) {
|
||||
nodes, err := akq.Limit(1).All(setContextOp(ctx, akq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{agekey.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (akq *AgeKeyQuery) FirstX(ctx context.Context) *AgeKey {
|
||||
node, err := akq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first AgeKey ID from the query.
|
||||
// Returns a *NotFoundError when no AgeKey ID was found.
|
||||
func (akq *AgeKeyQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = akq.Limit(1).IDs(setContextOp(ctx, akq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{agekey.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (akq *AgeKeyQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := akq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single AgeKey entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one AgeKey entity is found.
|
||||
// Returns a *NotFoundError when no AgeKey entities are found.
|
||||
func (akq *AgeKeyQuery) Only(ctx context.Context) (*AgeKey, error) {
|
||||
nodes, err := akq.Limit(2).All(setContextOp(ctx, akq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{agekey.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{agekey.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (akq *AgeKeyQuery) OnlyX(ctx context.Context) *AgeKey {
|
||||
node, err := akq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only AgeKey ID in the query.
|
||||
// Returns a *NotSingularError when more than one AgeKey ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (akq *AgeKeyQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = akq.Limit(2).IDs(setContextOp(ctx, akq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{agekey.Label}
|
||||
default:
|
||||
err = &NotSingularError{agekey.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (akq *AgeKeyQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := akq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of AgeKeys.
|
||||
func (akq *AgeKeyQuery) All(ctx context.Context) ([]*AgeKey, error) {
|
||||
ctx = setContextOp(ctx, akq.ctx, "All")
|
||||
if err := akq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*AgeKey, *AgeKeyQuery]()
|
||||
return withInterceptors[[]*AgeKey](ctx, akq, qr, akq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (akq *AgeKeyQuery) AllX(ctx context.Context) []*AgeKey {
|
||||
nodes, err := akq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of AgeKey IDs.
|
||||
func (akq *AgeKeyQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||
if akq.ctx.Unique == nil && akq.path != nil {
|
||||
akq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, akq.ctx, "IDs")
|
||||
if err = akq.Select(agekey.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (akq *AgeKeyQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||
ids, err := akq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (akq *AgeKeyQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, akq.ctx, "Count")
|
||||
if err := akq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, akq, querierCount[*AgeKeyQuery](), akq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (akq *AgeKeyQuery) CountX(ctx context.Context) int {
|
||||
count, err := akq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (akq *AgeKeyQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, akq.ctx, "Exist")
|
||||
switch _, err := akq.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 (akq *AgeKeyQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := akq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the AgeKeyQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (akq *AgeKeyQuery) Clone() *AgeKeyQuery {
|
||||
if akq == nil {
|
||||
return nil
|
||||
}
|
||||
return &AgeKeyQuery{
|
||||
config: akq.config,
|
||||
ctx: akq.ctx.Clone(),
|
||||
order: append([]agekey.OrderOption{}, akq.order...),
|
||||
inters: append([]Interceptor{}, akq.inters...),
|
||||
predicates: append([]predicate.AgeKey{}, akq.predicates...),
|
||||
withUser: akq.withUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: akq.sql.Clone(),
|
||||
path: akq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (akq *AgeKeyQuery) WithUser(opts ...func(*UserQuery)) *AgeKeyQuery {
|
||||
query := (&UserClient{config: akq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
akq.withUser = query
|
||||
return akq
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// Key []byte `json:"key,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.AgeKey.Query().
|
||||
// GroupBy(agekey.FieldKey).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (akq *AgeKeyQuery) GroupBy(field string, fields ...string) *AgeKeyGroupBy {
|
||||
akq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &AgeKeyGroupBy{build: akq}
|
||||
grbuild.flds = &akq.ctx.Fields
|
||||
grbuild.label = agekey.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 {
|
||||
// Key []byte `json:"key,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.AgeKey.Query().
|
||||
// Select(agekey.FieldKey).
|
||||
// Scan(ctx, &v)
|
||||
func (akq *AgeKeyQuery) Select(fields ...string) *AgeKeySelect {
|
||||
akq.ctx.Fields = append(akq.ctx.Fields, fields...)
|
||||
sbuild := &AgeKeySelect{AgeKeyQuery: akq}
|
||||
sbuild.label = agekey.Label
|
||||
sbuild.flds, sbuild.scan = &akq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a AgeKeySelect configured with the given aggregations.
|
||||
func (akq *AgeKeyQuery) Aggregate(fns ...AggregateFunc) *AgeKeySelect {
|
||||
return akq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (akq *AgeKeyQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range akq.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, akq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range akq.ctx.Fields {
|
||||
if !agekey.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if akq.path != nil {
|
||||
prev, err := akq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
akq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (akq *AgeKeyQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AgeKey, error) {
|
||||
var (
|
||||
nodes = []*AgeKey{}
|
||||
_spec = akq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
akq.withUser != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*AgeKey).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &AgeKey{config: akq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, akq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := akq.withUser; query != nil {
|
||||
if err := akq.loadUser(ctx, query, nodes, nil,
|
||||
func(n *AgeKey, e *User) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (akq *AgeKeyQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*AgeKey, init func(*AgeKey), assign func(*AgeKey, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*AgeKey)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].Owner
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "owner" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (akq *AgeKeyQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := akq.querySpec()
|
||||
_spec.Node.Columns = akq.ctx.Fields
|
||||
if len(akq.ctx.Fields) > 0 {
|
||||
_spec.Unique = akq.ctx.Unique != nil && *akq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, akq.driver, _spec)
|
||||
}
|
||||
|
||||
func (akq *AgeKeyQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(agekey.Table, agekey.Columns, sqlgraph.NewFieldSpec(agekey.FieldID, field.TypeUUID))
|
||||
_spec.From = akq.sql
|
||||
if unique := akq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if akq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := akq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, agekey.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != agekey.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if akq.withUser != nil {
|
||||
_spec.Node.AddColumnOnce(agekey.FieldOwner)
|
||||
}
|
||||
}
|
||||
if ps := akq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := akq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := akq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := akq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (akq *AgeKeyQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(akq.driver.Dialect())
|
||||
t1 := builder.Table(agekey.Table)
|
||||
columns := akq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = agekey.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if akq.sql != nil {
|
||||
selector = akq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if akq.ctx.Unique != nil && *akq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range akq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range akq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := akq.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 := akq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// AgeKeyGroupBy is the group-by builder for AgeKey entities.
|
||||
type AgeKeyGroupBy struct {
|
||||
selector
|
||||
build *AgeKeyQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (akgb *AgeKeyGroupBy) Aggregate(fns ...AggregateFunc) *AgeKeyGroupBy {
|
||||
akgb.fns = append(akgb.fns, fns...)
|
||||
return akgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (akgb *AgeKeyGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, akgb.build.ctx, "GroupBy")
|
||||
if err := akgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*AgeKeyQuery, *AgeKeyGroupBy](ctx, akgb.build, akgb, akgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (akgb *AgeKeyGroupBy) sqlScan(ctx context.Context, root *AgeKeyQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(akgb.fns))
|
||||
for _, fn := range akgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*akgb.flds)+len(akgb.fns))
|
||||
for _, f := range *akgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*akgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := akgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// AgeKeySelect is the builder for selecting fields of AgeKey entities.
|
||||
type AgeKeySelect struct {
|
||||
*AgeKeyQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (aks *AgeKeySelect) Aggregate(fns ...AggregateFunc) *AgeKeySelect {
|
||||
aks.fns = append(aks.fns, fns...)
|
||||
return aks
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (aks *AgeKeySelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, aks.ctx, "Select")
|
||||
if err := aks.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*AgeKeyQuery, *AgeKeySelect](ctx, aks.AgeKeyQuery, aks, aks.inters, v)
|
||||
}
|
||||
|
||||
func (aks *AgeKeySelect) sqlScan(ctx context.Context, root *AgeKeyQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(aks.fns))
|
||||
for _, fn := range aks.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*aks.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 := aks.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
|
@ -0,0 +1,260 @@
|
|||
// 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/schema/field"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
)
|
||||
|
||||
// AgeKeyUpdate is the builder for updating AgeKey entities.
|
||||
type AgeKeyUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *AgeKeyMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the AgeKeyUpdate builder.
|
||||
func (aku *AgeKeyUpdate) Where(ps ...predicate.AgeKey) *AgeKeyUpdate {
|
||||
aku.mutation.Where(ps...)
|
||||
return aku
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (aku *AgeKeyUpdate) SetKey(b []byte) *AgeKeyUpdate {
|
||||
aku.mutation.SetKey(b)
|
||||
return aku
|
||||
}
|
||||
|
||||
// SetUpdated sets the "updated" field.
|
||||
func (aku *AgeKeyUpdate) SetUpdated(t time.Time) *AgeKeyUpdate {
|
||||
aku.mutation.SetUpdated(t)
|
||||
return aku
|
||||
}
|
||||
|
||||
// SetNillableUpdated sets the "updated" field if the given value is not nil.
|
||||
func (aku *AgeKeyUpdate) SetNillableUpdated(t *time.Time) *AgeKeyUpdate {
|
||||
if t != nil {
|
||||
aku.SetUpdated(*t)
|
||||
}
|
||||
return aku
|
||||
}
|
||||
|
||||
// Mutation returns the AgeKeyMutation object of the builder.
|
||||
func (aku *AgeKeyUpdate) Mutation() *AgeKeyMutation {
|
||||
return aku.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (aku *AgeKeyUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, aku.sqlSave, aku.mutation, aku.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (aku *AgeKeyUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := aku.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (aku *AgeKeyUpdate) Exec(ctx context.Context) error {
|
||||
_, err := aku.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (aku *AgeKeyUpdate) ExecX(ctx context.Context) {
|
||||
if err := aku.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (aku *AgeKeyUpdate) check() error {
|
||||
if v, ok := aku.mutation.Key(); ok {
|
||||
if err := agekey.KeyValidator(v); err != nil {
|
||||
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "AgeKey.key": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := aku.mutation.UserID(); aku.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "AgeKey.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (aku *AgeKeyUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := aku.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(agekey.Table, agekey.Columns, sqlgraph.NewFieldSpec(agekey.FieldID, field.TypeUUID))
|
||||
if ps := aku.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := aku.mutation.Key(); ok {
|
||||
_spec.SetField(agekey.FieldKey, field.TypeBytes, value)
|
||||
}
|
||||
if value, ok := aku.mutation.Updated(); ok {
|
||||
_spec.SetField(agekey.FieldUpdated, field.TypeTime, value)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, aku.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{agekey.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
aku.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// AgeKeyUpdateOne is the builder for updating a single AgeKey entity.
|
||||
type AgeKeyUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *AgeKeyMutation
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (akuo *AgeKeyUpdateOne) SetKey(b []byte) *AgeKeyUpdateOne {
|
||||
akuo.mutation.SetKey(b)
|
||||
return akuo
|
||||
}
|
||||
|
||||
// SetUpdated sets the "updated" field.
|
||||
func (akuo *AgeKeyUpdateOne) SetUpdated(t time.Time) *AgeKeyUpdateOne {
|
||||
akuo.mutation.SetUpdated(t)
|
||||
return akuo
|
||||
}
|
||||
|
||||
// SetNillableUpdated sets the "updated" field if the given value is not nil.
|
||||
func (akuo *AgeKeyUpdateOne) SetNillableUpdated(t *time.Time) *AgeKeyUpdateOne {
|
||||
if t != nil {
|
||||
akuo.SetUpdated(*t)
|
||||
}
|
||||
return akuo
|
||||
}
|
||||
|
||||
// Mutation returns the AgeKeyMutation object of the builder.
|
||||
func (akuo *AgeKeyUpdateOne) Mutation() *AgeKeyMutation {
|
||||
return akuo.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the AgeKeyUpdate builder.
|
||||
func (akuo *AgeKeyUpdateOne) Where(ps ...predicate.AgeKey) *AgeKeyUpdateOne {
|
||||
akuo.mutation.Where(ps...)
|
||||
return akuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (akuo *AgeKeyUpdateOne) Select(field string, fields ...string) *AgeKeyUpdateOne {
|
||||
akuo.fields = append([]string{field}, fields...)
|
||||
return akuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated AgeKey entity.
|
||||
func (akuo *AgeKeyUpdateOne) Save(ctx context.Context) (*AgeKey, error) {
|
||||
return withHooks(ctx, akuo.sqlSave, akuo.mutation, akuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (akuo *AgeKeyUpdateOne) SaveX(ctx context.Context) *AgeKey {
|
||||
node, err := akuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (akuo *AgeKeyUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := akuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (akuo *AgeKeyUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := akuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (akuo *AgeKeyUpdateOne) check() error {
|
||||
if v, ok := akuo.mutation.Key(); ok {
|
||||
if err := agekey.KeyValidator(v); err != nil {
|
||||
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "AgeKey.key": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := akuo.mutation.UserID(); akuo.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "AgeKey.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (akuo *AgeKeyUpdateOne) sqlSave(ctx context.Context) (_node *AgeKey, err error) {
|
||||
if err := akuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(agekey.Table, agekey.Columns, sqlgraph.NewFieldSpec(agekey.FieldID, field.TypeUUID))
|
||||
id, ok := akuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AgeKey.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := akuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, agekey.FieldID)
|
||||
for _, f := range fields {
|
||||
if !agekey.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != agekey.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := akuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := akuo.mutation.Key(); ok {
|
||||
_spec.SetField(agekey.FieldKey, field.TypeBytes, value)
|
||||
}
|
||||
if value, ok := akuo.mutation.Updated(); ok {
|
||||
_spec.SetField(agekey.FieldUpdated, field.TypeTime, value)
|
||||
}
|
||||
_node = &AgeKey{config: akuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, akuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{agekey.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
akuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
837
ent/client.go
837
ent/client.go
|
@ -14,8 +14,14 @@ import (
|
|||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/settings"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/setup"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
)
|
||||
|
||||
|
@ -24,10 +30,20 @@ type Client struct {
|
|||
config
|
||||
// Schema is the client for creating, migrating and dropping schema.
|
||||
Schema *migrate.Schema
|
||||
// AgeKey is the client for interacting with the AgeKey builders.
|
||||
AgeKey *AgeKeyClient
|
||||
// HIBP is the client for interacting with the HIBP builders.
|
||||
HIBP *HIBPClient
|
||||
// LocalBreach is the client for interacting with the LocalBreach builders.
|
||||
LocalBreach *LocalBreachClient
|
||||
// SearchQuery is the client for interacting with the SearchQuery builders.
|
||||
SearchQuery *SearchQueryClient
|
||||
// Settings is the client for interacting with the Settings builders.
|
||||
Settings *SettingsClient
|
||||
// Setup is the client for interacting with the Setup builders.
|
||||
Setup *SetupClient
|
||||
// TrackedBreaches is the client for interacting with the TrackedBreaches builders.
|
||||
TrackedBreaches *TrackedBreachesClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
}
|
||||
|
@ -43,8 +59,13 @@ func NewClient(opts ...Option) *Client {
|
|||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.AgeKey = NewAgeKeyClient(c.config)
|
||||
c.HIBP = NewHIBPClient(c.config)
|
||||
c.LocalBreach = NewLocalBreachClient(c.config)
|
||||
c.SearchQuery = NewSearchQueryClient(c.config)
|
||||
c.Settings = NewSettingsClient(c.config)
|
||||
c.Setup = NewSetupClient(c.config)
|
||||
c.TrackedBreaches = NewTrackedBreachesClient(c.config)
|
||||
c.User = NewUserClient(c.config)
|
||||
}
|
||||
|
||||
|
@ -126,11 +147,16 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
|||
cfg := c.config
|
||||
cfg.driver = tx
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
HIBP: NewHIBPClient(cfg),
|
||||
Setup: NewSetupClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
AgeKey: NewAgeKeyClient(cfg),
|
||||
HIBP: NewHIBPClient(cfg),
|
||||
LocalBreach: NewLocalBreachClient(cfg),
|
||||
SearchQuery: NewSearchQueryClient(cfg),
|
||||
Settings: NewSettingsClient(cfg),
|
||||
Setup: NewSetupClient(cfg),
|
||||
TrackedBreaches: NewTrackedBreachesClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -148,18 +174,23 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
|||
cfg := c.config
|
||||
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
HIBP: NewHIBPClient(cfg),
|
||||
Setup: NewSetupClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
AgeKey: NewAgeKeyClient(cfg),
|
||||
HIBP: NewHIBPClient(cfg),
|
||||
LocalBreach: NewLocalBreachClient(cfg),
|
||||
SearchQuery: NewSearchQueryClient(cfg),
|
||||
Settings: NewSettingsClient(cfg),
|
||||
Setup: NewSetupClient(cfg),
|
||||
TrackedBreaches: NewTrackedBreachesClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// HIBP.
|
||||
// AgeKey.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
func (c *Client) Debug() *Client {
|
||||
|
@ -181,26 +212,42 @@ 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.Setup.Use(hooks...)
|
||||
c.User.Use(hooks...)
|
||||
for _, n := range []interface{ Use(...Hook) }{
|
||||
c.AgeKey, c.HIBP, c.LocalBreach, c.SearchQuery, c.Settings, c.Setup,
|
||||
c.TrackedBreaches, c.User,
|
||||
} {
|
||||
n.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.Setup.Intercept(interceptors...)
|
||||
c.User.Intercept(interceptors...)
|
||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||
c.AgeKey, c.HIBP, c.LocalBreach, c.SearchQuery, c.Settings, c.Setup,
|
||||
c.TrackedBreaches, c.User,
|
||||
} {
|
||||
n.Intercept(interceptors...)
|
||||
}
|
||||
}
|
||||
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *AgeKeyMutation:
|
||||
return c.AgeKey.mutate(ctx, m)
|
||||
case *HIBPMutation:
|
||||
return c.HIBP.mutate(ctx, m)
|
||||
case *LocalBreachMutation:
|
||||
return c.LocalBreach.mutate(ctx, m)
|
||||
case *SearchQueryMutation:
|
||||
return c.SearchQuery.mutate(ctx, m)
|
||||
case *SettingsMutation:
|
||||
return c.Settings.mutate(ctx, m)
|
||||
case *SetupMutation:
|
||||
return c.Setup.mutate(ctx, m)
|
||||
case *TrackedBreachesMutation:
|
||||
return c.TrackedBreaches.mutate(ctx, m)
|
||||
case *UserMutation:
|
||||
return c.User.mutate(ctx, m)
|
||||
default:
|
||||
|
@ -208,6 +255,140 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
|||
}
|
||||
}
|
||||
|
||||
// AgeKeyClient is a client for the AgeKey schema.
|
||||
type AgeKeyClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewAgeKeyClient returns a client for the AgeKey from the given config.
|
||||
func NewAgeKeyClient(c config) *AgeKeyClient {
|
||||
return &AgeKeyClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `agekey.Hooks(f(g(h())))`.
|
||||
func (c *AgeKeyClient) Use(hooks ...Hook) {
|
||||
c.hooks.AgeKey = append(c.hooks.AgeKey, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `agekey.Intercept(f(g(h())))`.
|
||||
func (c *AgeKeyClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.AgeKey = append(c.inters.AgeKey, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a AgeKey entity.
|
||||
func (c *AgeKeyClient) Create() *AgeKeyCreate {
|
||||
mutation := newAgeKeyMutation(c.config, OpCreate)
|
||||
return &AgeKeyCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of AgeKey entities.
|
||||
func (c *AgeKeyClient) CreateBulk(builders ...*AgeKeyCreate) *AgeKeyCreateBulk {
|
||||
return &AgeKeyCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for AgeKey.
|
||||
func (c *AgeKeyClient) Update() *AgeKeyUpdate {
|
||||
mutation := newAgeKeyMutation(c.config, OpUpdate)
|
||||
return &AgeKeyUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *AgeKeyClient) UpdateOne(ak *AgeKey) *AgeKeyUpdateOne {
|
||||
mutation := newAgeKeyMutation(c.config, OpUpdateOne, withAgeKey(ak))
|
||||
return &AgeKeyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *AgeKeyClient) UpdateOneID(id uuid.UUID) *AgeKeyUpdateOne {
|
||||
mutation := newAgeKeyMutation(c.config, OpUpdateOne, withAgeKeyID(id))
|
||||
return &AgeKeyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for AgeKey.
|
||||
func (c *AgeKeyClient) Delete() *AgeKeyDelete {
|
||||
mutation := newAgeKeyMutation(c.config, OpDelete)
|
||||
return &AgeKeyDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *AgeKeyClient) DeleteOne(ak *AgeKey) *AgeKeyDeleteOne {
|
||||
return c.DeleteOneID(ak.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *AgeKeyClient) DeleteOneID(id uuid.UUID) *AgeKeyDeleteOne {
|
||||
builder := c.Delete().Where(agekey.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &AgeKeyDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for AgeKey.
|
||||
func (c *AgeKeyClient) Query() *AgeKeyQuery {
|
||||
return &AgeKeyQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeAgeKey},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a AgeKey entity by its id.
|
||||
func (c *AgeKeyClient) Get(ctx context.Context, id uuid.UUID) (*AgeKey, error) {
|
||||
return c.Query().Where(agekey.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *AgeKeyClient) GetX(ctx context.Context, id uuid.UUID) *AgeKey {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryUser queries the user edge of a AgeKey.
|
||||
func (c *AgeKeyClient) QueryUser(ak *AgeKey) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := ak.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(agekey.Table, agekey.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, agekey.UserTable, agekey.UserColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(ak.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *AgeKeyClient) Hooks() []Hook {
|
||||
return c.hooks.AgeKey
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *AgeKeyClient) Interceptors() []Interceptor {
|
||||
return c.inters.AgeKey
|
||||
}
|
||||
|
||||
func (c *AgeKeyClient) mutate(ctx context.Context, m *AgeKeyMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&AgeKeyCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&AgeKeyUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&AgeKeyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&AgeKeyDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown AgeKey mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// HIBPClient is a client for the HIBP schema.
|
||||
type HIBPClient struct {
|
||||
config
|
||||
|
@ -301,6 +482,22 @@ func (c *HIBPClient) GetX(ctx context.Context, id uuid.UUID) *HIBP {
|
|||
return obj
|
||||
}
|
||||
|
||||
// QueryTrackedBreaches queries the tracked_breaches edge of a HIBP.
|
||||
func (c *HIBPClient) QueryTrackedBreaches(h *HIBP) *TrackedBreachesQuery {
|
||||
query := (&TrackedBreachesClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := h.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(hibp.Table, hibp.FieldID, id),
|
||||
sqlgraph.To(trackedbreaches.Table, trackedbreaches.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, hibp.TrackedBreachesTable, hibp.TrackedBreachesColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(h.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *HIBPClient) Hooks() []Hook {
|
||||
return c.hooks.HIBP
|
||||
|
@ -326,6 +523,392 @@ func (c *HIBPClient) mutate(ctx context.Context, m *HIBPMutation) (Value, error)
|
|||
}
|
||||
}
|
||||
|
||||
// LocalBreachClient is a client for the LocalBreach schema.
|
||||
type LocalBreachClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewLocalBreachClient returns a client for the LocalBreach from the given config.
|
||||
func NewLocalBreachClient(c config) *LocalBreachClient {
|
||||
return &LocalBreachClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `localbreach.Hooks(f(g(h())))`.
|
||||
func (c *LocalBreachClient) Use(hooks ...Hook) {
|
||||
c.hooks.LocalBreach = append(c.hooks.LocalBreach, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `localbreach.Intercept(f(g(h())))`.
|
||||
func (c *LocalBreachClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.LocalBreach = append(c.inters.LocalBreach, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a LocalBreach entity.
|
||||
func (c *LocalBreachClient) Create() *LocalBreachCreate {
|
||||
mutation := newLocalBreachMutation(c.config, OpCreate)
|
||||
return &LocalBreachCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of LocalBreach entities.
|
||||
func (c *LocalBreachClient) CreateBulk(builders ...*LocalBreachCreate) *LocalBreachCreateBulk {
|
||||
return &LocalBreachCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for LocalBreach.
|
||||
func (c *LocalBreachClient) Update() *LocalBreachUpdate {
|
||||
mutation := newLocalBreachMutation(c.config, OpUpdate)
|
||||
return &LocalBreachUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *LocalBreachClient) UpdateOne(lb *LocalBreach) *LocalBreachUpdateOne {
|
||||
mutation := newLocalBreachMutation(c.config, OpUpdateOne, withLocalBreach(lb))
|
||||
return &LocalBreachUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *LocalBreachClient) UpdateOneID(id uuid.UUID) *LocalBreachUpdateOne {
|
||||
mutation := newLocalBreachMutation(c.config, OpUpdateOne, withLocalBreachID(id))
|
||||
return &LocalBreachUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for LocalBreach.
|
||||
func (c *LocalBreachClient) Delete() *LocalBreachDelete {
|
||||
mutation := newLocalBreachMutation(c.config, OpDelete)
|
||||
return &LocalBreachDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *LocalBreachClient) DeleteOne(lb *LocalBreach) *LocalBreachDeleteOne {
|
||||
return c.DeleteOneID(lb.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *LocalBreachClient) DeleteOneID(id uuid.UUID) *LocalBreachDeleteOne {
|
||||
builder := c.Delete().Where(localbreach.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &LocalBreachDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for LocalBreach.
|
||||
func (c *LocalBreachClient) Query() *LocalBreachQuery {
|
||||
return &LocalBreachQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeLocalBreach},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a LocalBreach entity by its id.
|
||||
func (c *LocalBreachClient) Get(ctx context.Context, id uuid.UUID) (*LocalBreach, error) {
|
||||
return c.Query().Where(localbreach.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *LocalBreachClient) GetX(ctx context.Context, id uuid.UUID) *LocalBreach {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryTrackedBreaches queries the tracked_breaches edge of a LocalBreach.
|
||||
func (c *LocalBreachClient) QueryTrackedBreaches(lb *LocalBreach) *TrackedBreachesQuery {
|
||||
query := (&TrackedBreachesClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := lb.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(localbreach.Table, localbreach.FieldID, id),
|
||||
sqlgraph.To(trackedbreaches.Table, trackedbreaches.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, localbreach.TrackedBreachesTable, localbreach.TrackedBreachesPrimaryKey...),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(lb.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *LocalBreachClient) Hooks() []Hook {
|
||||
return c.hooks.LocalBreach
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *LocalBreachClient) Interceptors() []Interceptor {
|
||||
return c.inters.LocalBreach
|
||||
}
|
||||
|
||||
func (c *LocalBreachClient) mutate(ctx context.Context, m *LocalBreachMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&LocalBreachCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&LocalBreachUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&LocalBreachUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&LocalBreachDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown LocalBreach mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// SearchQueryClient is a client for the SearchQuery schema.
|
||||
type SearchQueryClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSearchQueryClient returns a client for the SearchQuery from the given config.
|
||||
func NewSearchQueryClient(c config) *SearchQueryClient {
|
||||
return &SearchQueryClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `searchquery.Hooks(f(g(h())))`.
|
||||
func (c *SearchQueryClient) Use(hooks ...Hook) {
|
||||
c.hooks.SearchQuery = append(c.hooks.SearchQuery, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `searchquery.Intercept(f(g(h())))`.
|
||||
func (c *SearchQueryClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.SearchQuery = append(c.inters.SearchQuery, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a SearchQuery entity.
|
||||
func (c *SearchQueryClient) Create() *SearchQueryCreate {
|
||||
mutation := newSearchQueryMutation(c.config, OpCreate)
|
||||
return &SearchQueryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of SearchQuery entities.
|
||||
func (c *SearchQueryClient) CreateBulk(builders ...*SearchQueryCreate) *SearchQueryCreateBulk {
|
||||
return &SearchQueryCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for SearchQuery.
|
||||
func (c *SearchQueryClient) Update() *SearchQueryUpdate {
|
||||
mutation := newSearchQueryMutation(c.config, OpUpdate)
|
||||
return &SearchQueryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *SearchQueryClient) UpdateOne(sq *SearchQuery) *SearchQueryUpdateOne {
|
||||
mutation := newSearchQueryMutation(c.config, OpUpdateOne, withSearchQuery(sq))
|
||||
return &SearchQueryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *SearchQueryClient) UpdateOneID(id uuid.UUID) *SearchQueryUpdateOne {
|
||||
mutation := newSearchQueryMutation(c.config, OpUpdateOne, withSearchQueryID(id))
|
||||
return &SearchQueryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for SearchQuery.
|
||||
func (c *SearchQueryClient) Delete() *SearchQueryDelete {
|
||||
mutation := newSearchQueryMutation(c.config, OpDelete)
|
||||
return &SearchQueryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *SearchQueryClient) DeleteOne(sq *SearchQuery) *SearchQueryDeleteOne {
|
||||
return c.DeleteOneID(sq.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *SearchQueryClient) DeleteOneID(id uuid.UUID) *SearchQueryDeleteOne {
|
||||
builder := c.Delete().Where(searchquery.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SearchQueryDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for SearchQuery.
|
||||
func (c *SearchQueryClient) Query() *SearchQueryQuery {
|
||||
return &SearchQueryQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeSearchQuery},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a SearchQuery entity by its id.
|
||||
func (c *SearchQueryClient) Get(ctx context.Context, id uuid.UUID) (*SearchQuery, error) {
|
||||
return c.Query().Where(searchquery.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *SearchQueryClient) GetX(ctx context.Context, id uuid.UUID) *SearchQuery {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryUser queries the user edge of a SearchQuery.
|
||||
func (c *SearchQueryClient) QueryUser(sq *SearchQuery) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := sq.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(searchquery.Table, searchquery.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, searchquery.UserTable, searchquery.UserColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(sq.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SearchQueryClient) Hooks() []Hook {
|
||||
return c.hooks.SearchQuery
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *SearchQueryClient) Interceptors() []Interceptor {
|
||||
return c.inters.SearchQuery
|
||||
}
|
||||
|
||||
func (c *SearchQueryClient) mutate(ctx context.Context, m *SearchQueryMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&SearchQueryCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&SearchQueryUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&SearchQueryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&SearchQueryDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown SearchQuery mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// SettingsClient is a client for the Settings schema.
|
||||
type SettingsClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSettingsClient returns a client for the Settings from the given config.
|
||||
func NewSettingsClient(c config) *SettingsClient {
|
||||
return &SettingsClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `settings.Hooks(f(g(h())))`.
|
||||
func (c *SettingsClient) Use(hooks ...Hook) {
|
||||
c.hooks.Settings = append(c.hooks.Settings, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `settings.Intercept(f(g(h())))`.
|
||||
func (c *SettingsClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Settings = append(c.inters.Settings, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Settings entity.
|
||||
func (c *SettingsClient) Create() *SettingsCreate {
|
||||
mutation := newSettingsMutation(c.config, OpCreate)
|
||||
return &SettingsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Settings entities.
|
||||
func (c *SettingsClient) CreateBulk(builders ...*SettingsCreate) *SettingsCreateBulk {
|
||||
return &SettingsCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Settings.
|
||||
func (c *SettingsClient) Update() *SettingsUpdate {
|
||||
mutation := newSettingsMutation(c.config, OpUpdate)
|
||||
return &SettingsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *SettingsClient) UpdateOne(s *Settings) *SettingsUpdateOne {
|
||||
mutation := newSettingsMutation(c.config, OpUpdateOne, withSettings(s))
|
||||
return &SettingsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *SettingsClient) UpdateOneID(id uuid.UUID) *SettingsUpdateOne {
|
||||
mutation := newSettingsMutation(c.config, OpUpdateOne, withSettingsID(id))
|
||||
return &SettingsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Settings.
|
||||
func (c *SettingsClient) Delete() *SettingsDelete {
|
||||
mutation := newSettingsMutation(c.config, OpDelete)
|
||||
return &SettingsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *SettingsClient) DeleteOne(s *Settings) *SettingsDeleteOne {
|
||||
return c.DeleteOneID(s.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *SettingsClient) DeleteOneID(id uuid.UUID) *SettingsDeleteOne {
|
||||
builder := c.Delete().Where(settings.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SettingsDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Settings.
|
||||
func (c *SettingsClient) Query() *SettingsQuery {
|
||||
return &SettingsQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeSettings},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Settings entity by its id.
|
||||
func (c *SettingsClient) Get(ctx context.Context, id uuid.UUID) (*Settings, error) {
|
||||
return c.Query().Where(settings.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *SettingsClient) GetX(ctx context.Context, id uuid.UUID) *Settings {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SettingsClient) Hooks() []Hook {
|
||||
return c.hooks.Settings
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *SettingsClient) Interceptors() []Interceptor {
|
||||
return c.inters.Settings
|
||||
}
|
||||
|
||||
func (c *SettingsClient) mutate(ctx context.Context, m *SettingsMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&SettingsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&SettingsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&SettingsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&SettingsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Settings mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// SetupClient is a client for the Setup schema.
|
||||
type SetupClient struct {
|
||||
config
|
||||
|
@ -444,6 +1027,172 @@ func (c *SetupClient) mutate(ctx context.Context, m *SetupMutation) (Value, erro
|
|||
}
|
||||
}
|
||||
|
||||
// TrackedBreachesClient is a client for the TrackedBreaches schema.
|
||||
type TrackedBreachesClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewTrackedBreachesClient returns a client for the TrackedBreaches from the given config.
|
||||
func NewTrackedBreachesClient(c config) *TrackedBreachesClient {
|
||||
return &TrackedBreachesClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `trackedbreaches.Hooks(f(g(h())))`.
|
||||
func (c *TrackedBreachesClient) Use(hooks ...Hook) {
|
||||
c.hooks.TrackedBreaches = append(c.hooks.TrackedBreaches, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `trackedbreaches.Intercept(f(g(h())))`.
|
||||
func (c *TrackedBreachesClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.TrackedBreaches = append(c.inters.TrackedBreaches, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a TrackedBreaches entity.
|
||||
func (c *TrackedBreachesClient) Create() *TrackedBreachesCreate {
|
||||
mutation := newTrackedBreachesMutation(c.config, OpCreate)
|
||||
return &TrackedBreachesCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of TrackedBreaches entities.
|
||||
func (c *TrackedBreachesClient) CreateBulk(builders ...*TrackedBreachesCreate) *TrackedBreachesCreateBulk {
|
||||
return &TrackedBreachesCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for TrackedBreaches.
|
||||
func (c *TrackedBreachesClient) Update() *TrackedBreachesUpdate {
|
||||
mutation := newTrackedBreachesMutation(c.config, OpUpdate)
|
||||
return &TrackedBreachesUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *TrackedBreachesClient) UpdateOne(tb *TrackedBreaches) *TrackedBreachesUpdateOne {
|
||||
mutation := newTrackedBreachesMutation(c.config, OpUpdateOne, withTrackedBreaches(tb))
|
||||
return &TrackedBreachesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *TrackedBreachesClient) UpdateOneID(id uuid.UUID) *TrackedBreachesUpdateOne {
|
||||
mutation := newTrackedBreachesMutation(c.config, OpUpdateOne, withTrackedBreachesID(id))
|
||||
return &TrackedBreachesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for TrackedBreaches.
|
||||
func (c *TrackedBreachesClient) Delete() *TrackedBreachesDelete {
|
||||
mutation := newTrackedBreachesMutation(c.config, OpDelete)
|
||||
return &TrackedBreachesDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *TrackedBreachesClient) DeleteOne(tb *TrackedBreaches) *TrackedBreachesDeleteOne {
|
||||
return c.DeleteOneID(tb.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *TrackedBreachesClient) DeleteOneID(id uuid.UUID) *TrackedBreachesDeleteOne {
|
||||
builder := c.Delete().Where(trackedbreaches.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &TrackedBreachesDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for TrackedBreaches.
|
||||
func (c *TrackedBreachesClient) Query() *TrackedBreachesQuery {
|
||||
return &TrackedBreachesQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeTrackedBreaches},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a TrackedBreaches entity by its id.
|
||||
func (c *TrackedBreachesClient) Get(ctx context.Context, id uuid.UUID) (*TrackedBreaches, error) {
|
||||
return c.Query().Where(trackedbreaches.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *TrackedBreachesClient) GetX(ctx context.Context, id uuid.UUID) *TrackedBreaches {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryUser queries the user edge of a TrackedBreaches.
|
||||
func (c *TrackedBreachesClient) QueryUser(tb *TrackedBreaches) *UserQuery {
|
||||
query := (&UserClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := tb.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(trackedbreaches.Table, trackedbreaches.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, trackedbreaches.UserTable, trackedbreaches.UserColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(tb.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryLocalbreach queries the localbreach edge of a TrackedBreaches.
|
||||
func (c *TrackedBreachesClient) QueryLocalbreach(tb *TrackedBreaches) *LocalBreachQuery {
|
||||
query := (&LocalBreachClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := tb.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(trackedbreaches.Table, trackedbreaches.FieldID, id),
|
||||
sqlgraph.To(localbreach.Table, localbreach.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, trackedbreaches.LocalbreachTable, trackedbreaches.LocalbreachPrimaryKey...),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(tb.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryHibp queries the hibp edge of a TrackedBreaches.
|
||||
func (c *TrackedBreachesClient) QueryHibp(tb *TrackedBreaches) *HIBPQuery {
|
||||
query := (&HIBPClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := tb.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(trackedbreaches.Table, trackedbreaches.FieldID, id),
|
||||
sqlgraph.To(hibp.Table, hibp.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, trackedbreaches.HibpTable, trackedbreaches.HibpColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(tb.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *TrackedBreachesClient) Hooks() []Hook {
|
||||
return c.hooks.TrackedBreaches
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *TrackedBreachesClient) Interceptors() []Interceptor {
|
||||
return c.inters.TrackedBreaches
|
||||
}
|
||||
|
||||
func (c *TrackedBreachesClient) mutate(ctx context.Context, m *TrackedBreachesMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&TrackedBreachesCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&TrackedBreachesUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&TrackedBreachesUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&TrackedBreachesDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown TrackedBreaches mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// UserClient is a client for the User schema.
|
||||
type UserClient struct {
|
||||
config
|
||||
|
@ -537,6 +1286,54 @@ func (c *UserClient) GetX(ctx context.Context, id uuid.UUID) *User {
|
|||
return obj
|
||||
}
|
||||
|
||||
// QueryAgekey queries the agekey edge of a User.
|
||||
func (c *UserClient) QueryAgekey(u *User) *AgeKeyQuery {
|
||||
query := (&AgeKeyClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(agekey.Table, agekey.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.AgekeyTable, user.AgekeyColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryTrackedBreaches queries the tracked_breaches edge of a User.
|
||||
func (c *UserClient) QueryTrackedBreaches(u *User) *TrackedBreachesQuery {
|
||||
query := (&TrackedBreachesClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(trackedbreaches.Table, trackedbreaches.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.TrackedBreachesTable, user.TrackedBreachesColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySearchQueries queries the search_queries edge of a User.
|
||||
func (c *UserClient) QuerySearchQueries(u *User) *SearchQueryQuery {
|
||||
query := (&SearchQueryClient{config: c.config}).Query()
|
||||
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
||||
id := u.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, id),
|
||||
sqlgraph.To(searchquery.Table, searchquery.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.SearchQueriesTable, user.SearchQueriesColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *UserClient) Hooks() []Hook {
|
||||
return c.hooks.User
|
||||
|
@ -565,9 +1362,11 @@ func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error)
|
|||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
HIBP, Setup, User []ent.Hook
|
||||
AgeKey, HIBP, LocalBreach, SearchQuery, Settings, Setup, TrackedBreaches,
|
||||
User []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
HIBP, Setup, User []ent.Interceptor
|
||||
AgeKey, HIBP, LocalBreach, SearchQuery, Settings, Setup, TrackedBreaches,
|
||||
User []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
|
16
ent/ent.go
16
ent/ent.go
|
@ -12,8 +12,13 @@ import (
|
|||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/settings"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/setup"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
)
|
||||
|
||||
|
@ -75,9 +80,14 @@ var (
|
|||
func checkColumn(table, column string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
hibp.Table: hibp.ValidColumn,
|
||||
setup.Table: setup.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
agekey.Table: agekey.ValidColumn,
|
||||
hibp.Table: hibp.ValidColumn,
|
||||
localbreach.Table: localbreach.ValidColumn,
|
||||
searchquery.Table: searchquery.ValidColumn,
|
||||
settings.Table: settings.ValidColumn,
|
||||
setup.Table: setup.ValidColumn,
|
||||
trackedbreaches.Table: trackedbreaches.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
})
|
||||
})
|
||||
return columnCheck(table, column)
|
||||
|
|
69
ent/hibp.go
69
ent/hibp.go
|
@ -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/trackedbreaches"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
|
@ -31,8 +32,8 @@ type HIBP struct {
|
|||
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"`
|
||||
// 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.
|
||||
|
@ -47,9 +48,35 @@ type HIBP struct {
|
|||
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"`
|
||||
selectValues sql.SelectValues
|
||||
// Always in PNG format.
|
||||
Logo *string `json:"logo,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the HIBPQuery when eager-loading is set.
|
||||
Edges HIBPEdges `json:"edges"`
|
||||
tracked_breaches_hibp *uuid.UUID
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// HIBPEdges holds the relations/edges for other nodes in the graph.
|
||||
type HIBPEdges struct {
|
||||
// TrackedBreaches holds the value of the tracked_breaches edge.
|
||||
TrackedBreaches *TrackedBreaches `json:"tracked_breaches,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// TrackedBreachesOrErr returns the TrackedBreaches value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e HIBPEdges) TrackedBreachesOrErr() (*TrackedBreaches, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.TrackedBreaches == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: trackedbreaches.Label}
|
||||
}
|
||||
return e.TrackedBreaches, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "tracked_breaches"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
|
@ -69,6 +96,8 @@ func (*HIBP) scanValues(columns []string) ([]any, error) {
|
|||
values[i] = new(sql.NullTime)
|
||||
case hibp.FieldID:
|
||||
values[i] = new(uuid.UUID)
|
||||
case hibp.ForeignKeys[0]: // tracked_breaches_hibp
|
||||
values[i] = &sql.NullScanner{S: new(uuid.UUID)}
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
|
@ -130,7 +159,8 @@ func (h *HIBP) assignValues(columns []string, values []any) error {
|
|||
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
|
||||
h.Description = new(string)
|
||||
*h.Description = value.String
|
||||
}
|
||||
case hibp.FieldDataclasses:
|
||||
if value, ok := values[i].(*[]byte); !ok {
|
||||
|
@ -180,7 +210,15 @@ func (h *HIBP) assignValues(columns []string, values []any) error {
|
|||
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
|
||||
h.Logo = new(string)
|
||||
*h.Logo = value.String
|
||||
}
|
||||
case hibp.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullScanner); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field tracked_breaches_hibp", values[i])
|
||||
} else if value.Valid {
|
||||
h.tracked_breaches_hibp = new(uuid.UUID)
|
||||
*h.tracked_breaches_hibp = *value.S.(*uuid.UUID)
|
||||
}
|
||||
default:
|
||||
h.selectValues.Set(columns[i], values[i])
|
||||
|
@ -195,6 +233,11 @@ func (h *HIBP) Value(name string) (ent.Value, error) {
|
|||
return h.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryTrackedBreaches queries the "tracked_breaches" edge of the HIBP entity.
|
||||
func (h *HIBP) QueryTrackedBreaches() *TrackedBreachesQuery {
|
||||
return NewHIBPClient(h.config).QueryTrackedBreaches(h)
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
@ -236,8 +279,10 @@ func (h *HIBP) String() string {
|
|||
builder.WriteString("pwn_count=")
|
||||
builder.WriteString(fmt.Sprintf("%v", h.PwnCount))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("description=")
|
||||
builder.WriteString(h.Description)
|
||||
if v := h.Description; v != nil {
|
||||
builder.WriteString("description=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("dataclasses=")
|
||||
builder.WriteString(fmt.Sprintf("%v", h.Dataclasses))
|
||||
|
@ -260,8 +305,10 @@ func (h *HIBP) String() string {
|
|||
builder.WriteString("is_malware=")
|
||||
builder.WriteString(fmt.Sprintf("%v", h.IsMalware))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("logo=")
|
||||
builder.WriteString(h.Logo)
|
||||
if v := h.Logo; v != nil {
|
||||
builder.WriteString("logo=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ package hibp
|
|||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -41,8 +42,17 @@ const (
|
|||
FieldIsMalware = "is_malware"
|
||||
// FieldLogo holds the string denoting the logo field in the database.
|
||||
FieldLogo = "logo"
|
||||
// EdgeTrackedBreaches holds the string denoting the tracked_breaches edge name in mutations.
|
||||
EdgeTrackedBreaches = "tracked_breaches"
|
||||
// Table holds the table name of the hibp in the database.
|
||||
Table = "hib_ps"
|
||||
// TrackedBreachesTable is the table that holds the tracked_breaches relation/edge.
|
||||
TrackedBreachesTable = "hib_ps"
|
||||
// TrackedBreachesInverseTable is the table name for the TrackedBreaches entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "trackedbreaches" package.
|
||||
TrackedBreachesInverseTable = "tracked_breaches"
|
||||
// TrackedBreachesColumn is the table column denoting the tracked_breaches relation/edge.
|
||||
TrackedBreachesColumn = "tracked_breaches_hibp"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for hibp fields.
|
||||
|
@ -65,6 +75,12 @@ var Columns = []string{
|
|||
FieldLogo,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "hib_ps"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"tracked_breaches_hibp",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
func ValidColumn(column string) bool {
|
||||
for i := range Columns {
|
||||
|
@ -72,6 +88,11 @@ func ValidColumn(column string) bool {
|
|||
return true
|
||||
}
|
||||
}
|
||||
for i := range ForeignKeys {
|
||||
if column == ForeignKeys[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -167,3 +188,17 @@ func ByIsMalware(opts ...sql.OrderTermOption) OrderOption {
|
|||
func ByLogo(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldLogo, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTrackedBreachesField orders the results by tracked_breaches field.
|
||||
func ByTrackedBreachesField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newTrackedBreachesStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newTrackedBreachesStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(TrackedBreachesInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, TrackedBreachesTable, TrackedBreachesColumn),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -470,6 +471,16 @@ func DescriptionHasSuffix(v string) predicate.HIBP {
|
|||
return predicate.HIBP(sql.FieldHasSuffix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionIsNil applies the IsNil predicate on the "description" field.
|
||||
func DescriptionIsNil() predicate.HIBP {
|
||||
return predicate.HIBP(sql.FieldIsNull(FieldDescription))
|
||||
}
|
||||
|
||||
// DescriptionNotNil applies the NotNil predicate on the "description" field.
|
||||
func DescriptionNotNil() predicate.HIBP {
|
||||
return predicate.HIBP(sql.FieldNotNull(FieldDescription))
|
||||
}
|
||||
|
||||
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||
func DescriptionEqualFold(v string) predicate.HIBP {
|
||||
return predicate.HIBP(sql.FieldEqualFold(FieldDescription, v))
|
||||
|
@ -595,6 +606,16 @@ func LogoHasSuffix(v string) predicate.HIBP {
|
|||
return predicate.HIBP(sql.FieldHasSuffix(FieldLogo, v))
|
||||
}
|
||||
|
||||
// LogoIsNil applies the IsNil predicate on the "logo" field.
|
||||
func LogoIsNil() predicate.HIBP {
|
||||
return predicate.HIBP(sql.FieldIsNull(FieldLogo))
|
||||
}
|
||||
|
||||
// LogoNotNil applies the NotNil predicate on the "logo" field.
|
||||
func LogoNotNil() predicate.HIBP {
|
||||
return predicate.HIBP(sql.FieldNotNull(FieldLogo))
|
||||
}
|
||||
|
||||
// LogoEqualFold applies the EqualFold predicate on the "logo" field.
|
||||
func LogoEqualFold(v string) predicate.HIBP {
|
||||
return predicate.HIBP(sql.FieldEqualFold(FieldLogo, v))
|
||||
|
@ -605,6 +626,29 @@ func LogoContainsFold(v string) predicate.HIBP {
|
|||
return predicate.HIBP(sql.FieldContainsFold(FieldLogo, v))
|
||||
}
|
||||
|
||||
// HasTrackedBreaches applies the HasEdge predicate on the "tracked_breaches" edge.
|
||||
func HasTrackedBreaches() predicate.HIBP {
|
||||
return predicate.HIBP(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, TrackedBreachesTable, TrackedBreachesColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasTrackedBreachesWith applies the HasEdge predicate on the "tracked_breaches" edge with a given conditions (other predicates).
|
||||
func HasTrackedBreachesWith(preds ...predicate.TrackedBreaches) predicate.HIBP {
|
||||
return predicate.HIBP(func(s *sql.Selector) {
|
||||
step := newTrackedBreachesStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.HIBP) predicate.HIBP {
|
||||
return predicate.HIBP(func(s *sql.Selector) {
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"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/trackedbreaches"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
|
@ -63,6 +64,14 @@ func (hc *HIBPCreate) SetDescription(s string) *HIBPCreate {
|
|||
return hc
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (hc *HIBPCreate) SetNillableDescription(s *string) *HIBPCreate {
|
||||
if s != nil {
|
||||
hc.SetDescription(*s)
|
||||
}
|
||||
return hc
|
||||
}
|
||||
|
||||
// SetDataclasses sets the "dataclasses" field.
|
||||
func (hc *HIBPCreate) SetDataclasses(s []string) *HIBPCreate {
|
||||
hc.mutation.SetDataclasses(s)
|
||||
|
@ -159,12 +168,39 @@ func (hc *HIBPCreate) SetLogo(s string) *HIBPCreate {
|
|||
return hc
|
||||
}
|
||||
|
||||
// SetNillableLogo sets the "logo" field if the given value is not nil.
|
||||
func (hc *HIBPCreate) SetNillableLogo(s *string) *HIBPCreate {
|
||||
if s != nil {
|
||||
hc.SetLogo(*s)
|
||||
}
|
||||
return hc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (hc *HIBPCreate) SetID(u uuid.UUID) *HIBPCreate {
|
||||
hc.mutation.SetID(u)
|
||||
return hc
|
||||
}
|
||||
|
||||
// SetTrackedBreachesID sets the "tracked_breaches" edge to the TrackedBreaches entity by ID.
|
||||
func (hc *HIBPCreate) SetTrackedBreachesID(id uuid.UUID) *HIBPCreate {
|
||||
hc.mutation.SetTrackedBreachesID(id)
|
||||
return hc
|
||||
}
|
||||
|
||||
// SetNillableTrackedBreachesID sets the "tracked_breaches" edge to the TrackedBreaches entity by ID if the given value is not nil.
|
||||
func (hc *HIBPCreate) SetNillableTrackedBreachesID(id *uuid.UUID) *HIBPCreate {
|
||||
if id != nil {
|
||||
hc = hc.SetTrackedBreachesID(*id)
|
||||
}
|
||||
return hc
|
||||
}
|
||||
|
||||
// SetTrackedBreaches sets the "tracked_breaches" edge to the TrackedBreaches entity.
|
||||
func (hc *HIBPCreate) SetTrackedBreaches(t *TrackedBreaches) *HIBPCreate {
|
||||
return hc.SetTrackedBreachesID(t.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the HIBPMutation object of the builder.
|
||||
func (hc *HIBPCreate) Mutation() *HIBPMutation {
|
||||
return hc.mutation
|
||||
|
@ -246,9 +282,6 @@ func (hc *HIBPCreate) check() error {
|
|||
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"`)}
|
||||
}
|
||||
|
@ -270,9 +303,6 @@ func (hc *HIBPCreate) check() error {
|
|||
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
|
||||
}
|
||||
|
||||
|
@ -334,7 +364,7 @@ func (hc *HIBPCreate) createSpec() (*HIBP, *sqlgraph.CreateSpec) {
|
|||
}
|
||||
if value, ok := hc.mutation.Description(); ok {
|
||||
_spec.SetField(hibp.FieldDescription, field.TypeString, value)
|
||||
_node.Description = value
|
||||
_node.Description = &value
|
||||
}
|
||||
if value, ok := hc.mutation.Dataclasses(); ok {
|
||||
_spec.SetField(hibp.FieldDataclasses, field.TypeJSON, value)
|
||||
|
@ -366,7 +396,24 @@ func (hc *HIBPCreate) createSpec() (*HIBP, *sqlgraph.CreateSpec) {
|
|||
}
|
||||
if value, ok := hc.mutation.Logo(); ok {
|
||||
_spec.SetField(hibp.FieldLogo, field.TypeString, value)
|
||||
_node.Logo = value
|
||||
_node.Logo = &value
|
||||
}
|
||||
if nodes := hc.mutation.TrackedBreachesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: hibp.TrackedBreachesTable,
|
||||
Columns: []string{hibp.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.tracked_breaches_hibp = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
|
|
@ -12,16 +12,19 @@ import (
|
|||
"entgo.io/ent/schema/field"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// HIBPQuery is the builder for querying HIBP entities.
|
||||
type HIBPQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []hibp.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.HIBP
|
||||
ctx *QueryContext
|
||||
order []hibp.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.HIBP
|
||||
withTrackedBreaches *TrackedBreachesQuery
|
||||
withFKs bool
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
@ -58,6 +61,28 @@ func (hq *HIBPQuery) Order(o ...hibp.OrderOption) *HIBPQuery {
|
|||
return hq
|
||||
}
|
||||
|
||||
// QueryTrackedBreaches chains the current query on the "tracked_breaches" edge.
|
||||
func (hq *HIBPQuery) QueryTrackedBreaches() *TrackedBreachesQuery {
|
||||
query := (&TrackedBreachesClient{config: hq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := hq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := hq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(hibp.Table, hibp.FieldID, selector),
|
||||
sqlgraph.To(trackedbreaches.Table, trackedbreaches.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, hibp.TrackedBreachesTable, hibp.TrackedBreachesColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(hq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
@ -245,17 +270,29 @@ func (hq *HIBPQuery) Clone() *HIBPQuery {
|
|||
return nil
|
||||
}
|
||||
return &HIBPQuery{
|
||||
config: hq.config,
|
||||
ctx: hq.ctx.Clone(),
|
||||
order: append([]hibp.OrderOption{}, hq.order...),
|
||||
inters: append([]Interceptor{}, hq.inters...),
|
||||
predicates: append([]predicate.HIBP{}, hq.predicates...),
|
||||
config: hq.config,
|
||||
ctx: hq.ctx.Clone(),
|
||||
order: append([]hibp.OrderOption{}, hq.order...),
|
||||
inters: append([]Interceptor{}, hq.inters...),
|
||||
predicates: append([]predicate.HIBP{}, hq.predicates...),
|
||||
withTrackedBreaches: hq.withTrackedBreaches.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: hq.sql.Clone(),
|
||||
path: hq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithTrackedBreaches tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "tracked_breaches" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (hq *HIBPQuery) WithTrackedBreaches(opts ...func(*TrackedBreachesQuery)) *HIBPQuery {
|
||||
query := (&TrackedBreachesClient{config: hq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
hq.withTrackedBreaches = query
|
||||
return hq
|
||||
}
|
||||
|
||||
// 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.
|
||||
//
|
||||
|
@ -332,15 +369,26 @@ func (hq *HIBPQuery) prepareQuery(ctx context.Context) error {
|
|||
|
||||
func (hq *HIBPQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*HIBP, error) {
|
||||
var (
|
||||
nodes = []*HIBP{}
|
||||
_spec = hq.querySpec()
|
||||
nodes = []*HIBP{}
|
||||
withFKs = hq.withFKs
|
||||
_spec = hq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
hq.withTrackedBreaches != nil,
|
||||
}
|
||||
)
|
||||
if hq.withTrackedBreaches != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, hibp.ForeignKeys...)
|
||||
}
|
||||
_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)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
|
@ -352,9 +400,48 @@ func (hq *HIBPQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*HIBP, e
|
|||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := hq.withTrackedBreaches; query != nil {
|
||||
if err := hq.loadTrackedBreaches(ctx, query, nodes, nil,
|
||||
func(n *HIBP, e *TrackedBreaches) { n.Edges.TrackedBreaches = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (hq *HIBPQuery) loadTrackedBreaches(ctx context.Context, query *TrackedBreachesQuery, nodes []*HIBP, init func(*HIBP), assign func(*HIBP, *TrackedBreaches)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*HIBP)
|
||||
for i := range nodes {
|
||||
if nodes[i].tracked_breaches_hibp == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].tracked_breaches_hibp
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(trackedbreaches.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "tracked_breaches_hibp" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (hq *HIBPQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := hq.querySpec()
|
||||
_spec.Node.Columns = hq.ctx.Fields
|
||||
|
|
|
@ -14,6 +14,8 @@ import (
|
|||
"entgo.io/ent/schema/field"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// HIBPUpdate is the builder for updating HIBP entities.
|
||||
|
@ -72,6 +74,20 @@ func (hu *HIBPUpdate) SetDescription(s string) *HIBPUpdate {
|
|||
return hu
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (hu *HIBPUpdate) SetNillableDescription(s *string) *HIBPUpdate {
|
||||
if s != nil {
|
||||
hu.SetDescription(*s)
|
||||
}
|
||||
return hu
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (hu *HIBPUpdate) ClearDescription() *HIBPUpdate {
|
||||
hu.mutation.ClearDescription()
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetDataclasses sets the "dataclasses" field.
|
||||
func (hu *HIBPUpdate) SetDataclasses(s []string) *HIBPUpdate {
|
||||
hu.mutation.SetDataclasses(s)
|
||||
|
@ -174,11 +190,50 @@ func (hu *HIBPUpdate) SetLogo(s string) *HIBPUpdate {
|
|||
return hu
|
||||
}
|
||||
|
||||
// SetNillableLogo sets the "logo" field if the given value is not nil.
|
||||
func (hu *HIBPUpdate) SetNillableLogo(s *string) *HIBPUpdate {
|
||||
if s != nil {
|
||||
hu.SetLogo(*s)
|
||||
}
|
||||
return hu
|
||||
}
|
||||
|
||||
// ClearLogo clears the value of the "logo" field.
|
||||
func (hu *HIBPUpdate) ClearLogo() *HIBPUpdate {
|
||||
hu.mutation.ClearLogo()
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetTrackedBreachesID sets the "tracked_breaches" edge to the TrackedBreaches entity by ID.
|
||||
func (hu *HIBPUpdate) SetTrackedBreachesID(id uuid.UUID) *HIBPUpdate {
|
||||
hu.mutation.SetTrackedBreachesID(id)
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetNillableTrackedBreachesID sets the "tracked_breaches" edge to the TrackedBreaches entity by ID if the given value is not nil.
|
||||
func (hu *HIBPUpdate) SetNillableTrackedBreachesID(id *uuid.UUID) *HIBPUpdate {
|
||||
if id != nil {
|
||||
hu = hu.SetTrackedBreachesID(*id)
|
||||
}
|
||||
return hu
|
||||
}
|
||||
|
||||
// SetTrackedBreaches sets the "tracked_breaches" edge to the TrackedBreaches entity.
|
||||
func (hu *HIBPUpdate) SetTrackedBreaches(t *TrackedBreaches) *HIBPUpdate {
|
||||
return hu.SetTrackedBreachesID(t.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the HIBPMutation object of the builder.
|
||||
func (hu *HIBPUpdate) Mutation() *HIBPMutation {
|
||||
return hu.mutation
|
||||
}
|
||||
|
||||
// ClearTrackedBreaches clears the "tracked_breaches" edge to the TrackedBreaches entity.
|
||||
func (hu *HIBPUpdate) ClearTrackedBreaches() *HIBPUpdate {
|
||||
hu.mutation.ClearTrackedBreaches()
|
||||
return hu
|
||||
}
|
||||
|
||||
// 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(ctx, hu.sqlSave, hu.mutation, hu.hooks)
|
||||
|
@ -236,6 +291,9 @@ func (hu *HIBPUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
if value, ok := hu.mutation.Description(); ok {
|
||||
_spec.SetField(hibp.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if hu.mutation.DescriptionCleared() {
|
||||
_spec.ClearField(hibp.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := hu.mutation.Dataclasses(); ok {
|
||||
_spec.SetField(hibp.FieldDataclasses, field.TypeJSON, value)
|
||||
}
|
||||
|
@ -265,6 +323,38 @@ func (hu *HIBPUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
if value, ok := hu.mutation.Logo(); ok {
|
||||
_spec.SetField(hibp.FieldLogo, field.TypeString, value)
|
||||
}
|
||||
if hu.mutation.LogoCleared() {
|
||||
_spec.ClearField(hibp.FieldLogo, field.TypeString)
|
||||
}
|
||||
if hu.mutation.TrackedBreachesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: hibp.TrackedBreachesTable,
|
||||
Columns: []string{hibp.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := hu.mutation.TrackedBreachesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: hibp.TrackedBreachesTable,
|
||||
Columns: []string{hibp.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, hu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{hibp.Label}
|
||||
|
@ -328,6 +418,20 @@ func (huo *HIBPUpdateOne) SetDescription(s string) *HIBPUpdateOne {
|
|||
return huo
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (huo *HIBPUpdateOne) SetNillableDescription(s *string) *HIBPUpdateOne {
|
||||
if s != nil {
|
||||
huo.SetDescription(*s)
|
||||
}
|
||||
return huo
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (huo *HIBPUpdateOne) ClearDescription() *HIBPUpdateOne {
|
||||
huo.mutation.ClearDescription()
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetDataclasses sets the "dataclasses" field.
|
||||
func (huo *HIBPUpdateOne) SetDataclasses(s []string) *HIBPUpdateOne {
|
||||
huo.mutation.SetDataclasses(s)
|
||||
|
@ -430,11 +534,50 @@ func (huo *HIBPUpdateOne) SetLogo(s string) *HIBPUpdateOne {
|
|||
return huo
|
||||
}
|
||||
|
||||
// SetNillableLogo sets the "logo" field if the given value is not nil.
|
||||
func (huo *HIBPUpdateOne) SetNillableLogo(s *string) *HIBPUpdateOne {
|
||||
if s != nil {
|
||||
huo.SetLogo(*s)
|
||||
}
|
||||
return huo
|
||||
}
|
||||
|
||||
// ClearLogo clears the value of the "logo" field.
|
||||
func (huo *HIBPUpdateOne) ClearLogo() *HIBPUpdateOne {
|
||||
huo.mutation.ClearLogo()
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetTrackedBreachesID sets the "tracked_breaches" edge to the TrackedBreaches entity by ID.
|
||||
func (huo *HIBPUpdateOne) SetTrackedBreachesID(id uuid.UUID) *HIBPUpdateOne {
|
||||
huo.mutation.SetTrackedBreachesID(id)
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetNillableTrackedBreachesID sets the "tracked_breaches" edge to the TrackedBreaches entity by ID if the given value is not nil.
|
||||
func (huo *HIBPUpdateOne) SetNillableTrackedBreachesID(id *uuid.UUID) *HIBPUpdateOne {
|
||||
if id != nil {
|
||||
huo = huo.SetTrackedBreachesID(*id)
|
||||
}
|
||||
return huo
|
||||
}
|
||||
|
||||
// SetTrackedBreaches sets the "tracked_breaches" edge to the TrackedBreaches entity.
|
||||
func (huo *HIBPUpdateOne) SetTrackedBreaches(t *TrackedBreaches) *HIBPUpdateOne {
|
||||
return huo.SetTrackedBreachesID(t.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the HIBPMutation object of the builder.
|
||||
func (huo *HIBPUpdateOne) Mutation() *HIBPMutation {
|
||||
return huo.mutation
|
||||
}
|
||||
|
||||
// ClearTrackedBreaches clears the "tracked_breaches" edge to the TrackedBreaches entity.
|
||||
func (huo *HIBPUpdateOne) ClearTrackedBreaches() *HIBPUpdateOne {
|
||||
huo.mutation.ClearTrackedBreaches()
|
||||
return huo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the HIBPUpdate builder.
|
||||
func (huo *HIBPUpdateOne) Where(ps ...predicate.HIBP) *HIBPUpdateOne {
|
||||
huo.mutation.Where(ps...)
|
||||
|
@ -522,6 +665,9 @@ func (huo *HIBPUpdateOne) sqlSave(ctx context.Context) (_node *HIBP, err error)
|
|||
if value, ok := huo.mutation.Description(); ok {
|
||||
_spec.SetField(hibp.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if huo.mutation.DescriptionCleared() {
|
||||
_spec.ClearField(hibp.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := huo.mutation.Dataclasses(); ok {
|
||||
_spec.SetField(hibp.FieldDataclasses, field.TypeJSON, value)
|
||||
}
|
||||
|
@ -551,6 +697,38 @@ func (huo *HIBPUpdateOne) sqlSave(ctx context.Context) (_node *HIBP, err error)
|
|||
if value, ok := huo.mutation.Logo(); ok {
|
||||
_spec.SetField(hibp.FieldLogo, field.TypeString, value)
|
||||
}
|
||||
if huo.mutation.LogoCleared() {
|
||||
_spec.ClearField(hibp.FieldLogo, field.TypeString)
|
||||
}
|
||||
if huo.mutation.TrackedBreachesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: hibp.TrackedBreachesTable,
|
||||
Columns: []string{hibp.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := huo.mutation.TrackedBreachesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: hibp.TrackedBreachesTable,
|
||||
Columns: []string{hibp.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &HIBP{config: huo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
|
|
@ -9,6 +9,18 @@ import (
|
|||
"git.dotya.ml/mirre-mt/pcmt/ent"
|
||||
)
|
||||
|
||||
// The AgeKeyFunc type is an adapter to allow the use of ordinary
|
||||
// function as AgeKey mutator.
|
||||
type AgeKeyFunc func(context.Context, *ent.AgeKeyMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f AgeKeyFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.AgeKeyMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AgeKeyMutation", m)
|
||||
}
|
||||
|
||||
// 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)
|
||||
|
@ -21,6 +33,42 @@ func (f HIBPFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error)
|
|||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.HIBPMutation", m)
|
||||
}
|
||||
|
||||
// The LocalBreachFunc type is an adapter to allow the use of ordinary
|
||||
// function as LocalBreach mutator.
|
||||
type LocalBreachFunc func(context.Context, *ent.LocalBreachMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f LocalBreachFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.LocalBreachMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LocalBreachMutation", m)
|
||||
}
|
||||
|
||||
// The SearchQueryFunc type is an adapter to allow the use of ordinary
|
||||
// function as SearchQuery mutator.
|
||||
type SearchQueryFunc func(context.Context, *ent.SearchQueryMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f SearchQueryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.SearchQueryMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SearchQueryMutation", m)
|
||||
}
|
||||
|
||||
// The SettingsFunc type is an adapter to allow the use of ordinary
|
||||
// function as Settings mutator.
|
||||
type SettingsFunc func(context.Context, *ent.SettingsMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f SettingsFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.SettingsMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SettingsMutation", m)
|
||||
}
|
||||
|
||||
// The SetupFunc type is an adapter to allow the use of ordinary
|
||||
// function as Setup mutator.
|
||||
type SetupFunc func(context.Context, *ent.SetupMutation) (ent.Value, error)
|
||||
|
@ -33,6 +81,18 @@ func (f SetupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error
|
|||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SetupMutation", m)
|
||||
}
|
||||
|
||||
// The TrackedBreachesFunc type is an adapter to allow the use of ordinary
|
||||
// function as TrackedBreaches mutator.
|
||||
type TrackedBreachesFunc func(context.Context, *ent.TrackedBreachesMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f TrackedBreachesFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.TrackedBreachesMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TrackedBreachesMutation", 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)
|
||||
|
|
|
@ -0,0 +1,271 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/localbreach"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// LocalBreach is the model entity for the LocalBreach schema.
|
||||
type LocalBreach 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"`
|
||||
// Date holds the value of the "date" field.
|
||||
Date time.Time `json:"date,omitempty"`
|
||||
// Description holds the value of the "description" field.
|
||||
Description *string `json:"description,omitempty"`
|
||||
// IsVerified holds the value of the "is_verified" field.
|
||||
IsVerified bool `json:"is_verified,omitempty"`
|
||||
// ContainsPasswds holds the value of the "contains_passwds" field.
|
||||
ContainsPasswds bool `json:"contains_passwds,omitempty"`
|
||||
// ContainsHashes holds the value of the "contains_hashes" field.
|
||||
ContainsHashes bool `json:"contains_hashes,omitempty"`
|
||||
// ContainsEmails holds the value of the "contains_emails" field.
|
||||
ContainsEmails bool `json:"contains_emails,omitempty"`
|
||||
// MD5, SHA1, Argon2id...
|
||||
HashType *string `json:"hash_type,omitempty"`
|
||||
// HashSalted holds the value of the "hash_salted" field.
|
||||
HashSalted *bool `json:"hash_salted,omitempty"`
|
||||
// HashPeppered holds the value of the "hash_peppered" field.
|
||||
HashPeppered *bool `json:"hash_peppered,omitempty"`
|
||||
// Data holds the value of the "data" field.
|
||||
Data *string `json:"data,omitempty"`
|
||||
// CreatedAt holds the value of the "created_at" field.
|
||||
CreatedAt time.Time `json:"created_at,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the LocalBreachQuery when eager-loading is set.
|
||||
Edges LocalBreachEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// LocalBreachEdges holds the relations/edges for other nodes in the graph.
|
||||
type LocalBreachEdges struct {
|
||||
// TrackedBreaches holds the value of the tracked_breaches edge.
|
||||
TrackedBreaches []*TrackedBreaches `json:"tracked_breaches,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// TrackedBreachesOrErr returns the TrackedBreaches value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e LocalBreachEdges) TrackedBreachesOrErr() ([]*TrackedBreaches, error) {
|
||||
if e.loadedTypes[0] {
|
||||
return e.TrackedBreaches, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "tracked_breaches"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*LocalBreach) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case localbreach.FieldIsVerified, localbreach.FieldContainsPasswds, localbreach.FieldContainsHashes, localbreach.FieldContainsEmails, localbreach.FieldHashSalted, localbreach.FieldHashPeppered:
|
||||
values[i] = new(sql.NullBool)
|
||||
case localbreach.FieldName, localbreach.FieldDescription, localbreach.FieldHashType, localbreach.FieldData:
|
||||
values[i] = new(sql.NullString)
|
||||
case localbreach.FieldDate, localbreach.FieldCreatedAt:
|
||||
values[i] = new(sql.NullTime)
|
||||
case localbreach.FieldID:
|
||||
values[i] = new(uuid.UUID)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the LocalBreach fields.
|
||||
func (lb *LocalBreach) 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 localbreach.FieldID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
lb.ID = *value
|
||||
}
|
||||
case localbreach.FieldName:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||
} else if value.Valid {
|
||||
lb.Name = value.String
|
||||
}
|
||||
case localbreach.FieldDate:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field date", values[i])
|
||||
} else if value.Valid {
|
||||
lb.Date = value.Time
|
||||
}
|
||||
case localbreach.FieldDescription:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||
} else if value.Valid {
|
||||
lb.Description = new(string)
|
||||
*lb.Description = value.String
|
||||
}
|
||||
case localbreach.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 {
|
||||
lb.IsVerified = value.Bool
|
||||
}
|
||||
case localbreach.FieldContainsPasswds:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field contains_passwds", values[i])
|
||||
} else if value.Valid {
|
||||
lb.ContainsPasswds = value.Bool
|
||||
}
|
||||
case localbreach.FieldContainsHashes:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field contains_hashes", values[i])
|
||||
} else if value.Valid {
|
||||
lb.ContainsHashes = value.Bool
|
||||
}
|
||||
case localbreach.FieldContainsEmails:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field contains_emails", values[i])
|
||||
} else if value.Valid {
|
||||
lb.ContainsEmails = value.Bool
|
||||
}
|
||||
case localbreach.FieldHashType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field hash_type", values[i])
|
||||
} else if value.Valid {
|
||||
lb.HashType = new(string)
|
||||
*lb.HashType = value.String
|
||||
}
|
||||
case localbreach.FieldHashSalted:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field hash_salted", values[i])
|
||||
} else if value.Valid {
|
||||
lb.HashSalted = new(bool)
|
||||
*lb.HashSalted = value.Bool
|
||||
}
|
||||
case localbreach.FieldHashPeppered:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field hash_peppered", values[i])
|
||||
} else if value.Valid {
|
||||
lb.HashPeppered = new(bool)
|
||||
*lb.HashPeppered = value.Bool
|
||||
}
|
||||
case localbreach.FieldData:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field data", values[i])
|
||||
} else if value.Valid {
|
||||
lb.Data = new(string)
|
||||
*lb.Data = value.String
|
||||
}
|
||||
case localbreach.FieldCreatedAt:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created_at", values[i])
|
||||
} else if value.Valid {
|
||||
lb.CreatedAt = value.Time
|
||||
}
|
||||
default:
|
||||
lb.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the LocalBreach.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (lb *LocalBreach) Value(name string) (ent.Value, error) {
|
||||
return lb.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryTrackedBreaches queries the "tracked_breaches" edge of the LocalBreach entity.
|
||||
func (lb *LocalBreach) QueryTrackedBreaches() *TrackedBreachesQuery {
|
||||
return NewLocalBreachClient(lb.config).QueryTrackedBreaches(lb)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this LocalBreach.
|
||||
// Note that you need to call LocalBreach.Unwrap() before calling this method if this LocalBreach
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (lb *LocalBreach) Update() *LocalBreachUpdateOne {
|
||||
return NewLocalBreachClient(lb.config).UpdateOne(lb)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the LocalBreach 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 (lb *LocalBreach) Unwrap() *LocalBreach {
|
||||
_tx, ok := lb.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: LocalBreach is not a transactional entity")
|
||||
}
|
||||
lb.config.driver = _tx.drv
|
||||
return lb
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (lb *LocalBreach) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("LocalBreach(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", lb.ID))
|
||||
builder.WriteString("name=")
|
||||
builder.WriteString(lb.Name)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("date=")
|
||||
builder.WriteString(lb.Date.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
if v := lb.Description; v != nil {
|
||||
builder.WriteString("description=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("is_verified=")
|
||||
builder.WriteString(fmt.Sprintf("%v", lb.IsVerified))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("contains_passwds=")
|
||||
builder.WriteString(fmt.Sprintf("%v", lb.ContainsPasswds))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("contains_hashes=")
|
||||
builder.WriteString(fmt.Sprintf("%v", lb.ContainsHashes))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("contains_emails=")
|
||||
builder.WriteString(fmt.Sprintf("%v", lb.ContainsEmails))
|
||||
builder.WriteString(", ")
|
||||
if v := lb.HashType; v != nil {
|
||||
builder.WriteString("hash_type=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := lb.HashSalted; v != nil {
|
||||
builder.WriteString("hash_salted=")
|
||||
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := lb.HashPeppered; v != nil {
|
||||
builder.WriteString("hash_peppered=")
|
||||
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
if v := lb.Data; v != nil {
|
||||
builder.WriteString("data=")
|
||||
builder.WriteString(*v)
|
||||
}
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created_at=")
|
||||
builder.WriteString(lb.CreatedAt.Format(time.ANSIC))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// LocalBreaches is a parsable slice of LocalBreach.
|
||||
type LocalBreaches []*LocalBreach
|
|
@ -0,0 +1,184 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package localbreach
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the localbreach type in the database.
|
||||
Label = "local_breach"
|
||||
// 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"
|
||||
// FieldDate holds the string denoting the date field in the database.
|
||||
FieldDate = "date"
|
||||
// FieldDescription holds the string denoting the description field in the database.
|
||||
FieldDescription = "description"
|
||||
// FieldIsVerified holds the string denoting the is_verified field in the database.
|
||||
FieldIsVerified = "is_verified"
|
||||
// FieldContainsPasswds holds the string denoting the contains_passwds field in the database.
|
||||
FieldContainsPasswds = "contains_passwds"
|
||||
// FieldContainsHashes holds the string denoting the contains_hashes field in the database.
|
||||
FieldContainsHashes = "contains_hashes"
|
||||
// FieldContainsEmails holds the string denoting the contains_emails field in the database.
|
||||
FieldContainsEmails = "contains_emails"
|
||||
// FieldHashType holds the string denoting the hash_type field in the database.
|
||||
FieldHashType = "hash_type"
|
||||
// FieldHashSalted holds the string denoting the hash_salted field in the database.
|
||||
FieldHashSalted = "hash_salted"
|
||||
// FieldHashPeppered holds the string denoting the hash_peppered field in the database.
|
||||
FieldHashPeppered = "hash_peppered"
|
||||
// FieldData holds the string denoting the data field in the database.
|
||||
FieldData = "data"
|
||||
// FieldCreatedAt holds the string denoting the created_at field in the database.
|
||||
FieldCreatedAt = "created_at"
|
||||
// EdgeTrackedBreaches holds the string denoting the tracked_breaches edge name in mutations.
|
||||
EdgeTrackedBreaches = "tracked_breaches"
|
||||
// Table holds the table name of the localbreach in the database.
|
||||
Table = "local_breaches"
|
||||
// TrackedBreachesTable is the table that holds the tracked_breaches relation/edge. The primary key declared below.
|
||||
TrackedBreachesTable = "tracked_breaches_localbreach"
|
||||
// TrackedBreachesInverseTable is the table name for the TrackedBreaches entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "trackedbreaches" package.
|
||||
TrackedBreachesInverseTable = "tracked_breaches"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for localbreach fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldName,
|
||||
FieldDate,
|
||||
FieldDescription,
|
||||
FieldIsVerified,
|
||||
FieldContainsPasswds,
|
||||
FieldContainsHashes,
|
||||
FieldContainsEmails,
|
||||
FieldHashType,
|
||||
FieldHashSalted,
|
||||
FieldHashPeppered,
|
||||
FieldData,
|
||||
FieldCreatedAt,
|
||||
}
|
||||
|
||||
var (
|
||||
// TrackedBreachesPrimaryKey and TrackedBreachesColumn2 are the table columns denoting the
|
||||
// primary key for the tracked_breaches relation (M2M).
|
||||
TrackedBreachesPrimaryKey = []string{"tracked_breaches_id", "local_breach_id"}
|
||||
)
|
||||
|
||||
// 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 (
|
||||
// NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
NameValidator func(string) error
|
||||
// DefaultDate holds the default value on creation for the "date" field.
|
||||
DefaultDate time.Time
|
||||
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
|
||||
DefaultCreatedAt time.Time
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the LocalBreach queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByName orders the results by the name field.
|
||||
func ByName(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldName, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDate orders the results by the date field.
|
||||
func ByDate(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDate, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDescription orders the results by the description field.
|
||||
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDescription, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByIsVerified orders the results by the is_verified field.
|
||||
func ByIsVerified(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldIsVerified, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByContainsPasswds orders the results by the contains_passwds field.
|
||||
func ByContainsPasswds(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldContainsPasswds, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByContainsHashes orders the results by the contains_hashes field.
|
||||
func ByContainsHashes(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldContainsHashes, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByContainsEmails orders the results by the contains_emails field.
|
||||
func ByContainsEmails(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldContainsEmails, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByHashType orders the results by the hash_type field.
|
||||
func ByHashType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldHashType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByHashSalted orders the results by the hash_salted field.
|
||||
func ByHashSalted(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldHashSalted, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByHashPeppered orders the results by the hash_peppered field.
|
||||
func ByHashPeppered(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldHashPeppered, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByData orders the results by the data field.
|
||||
func ByData(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldData, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedAt orders the results by the created_at field.
|
||||
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByTrackedBreachesCount orders the results by tracked_breaches count.
|
||||
func ByTrackedBreachesCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newTrackedBreachesStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByTrackedBreaches orders the results by tracked_breaches terms.
|
||||
func ByTrackedBreaches(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newTrackedBreachesStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newTrackedBreachesStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(TrackedBreachesInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, TrackedBreachesTable, TrackedBreachesPrimaryKey...),
|
||||
)
|
||||
}
|
|
@ -0,0 +1,622 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package localbreach
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"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.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id uuid.UUID) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id uuid.UUID) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...uuid.UUID) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...uuid.UUID) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id uuid.UUID) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id uuid.UUID) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id uuid.UUID) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id uuid.UUID) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
|
||||
func Name(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// Date applies equality check predicate on the "date" field. It's identical to DateEQ.
|
||||
func Date(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldDate, v))
|
||||
}
|
||||
|
||||
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
|
||||
func Description(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// IsVerified applies equality check predicate on the "is_verified" field. It's identical to IsVerifiedEQ.
|
||||
func IsVerified(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldIsVerified, v))
|
||||
}
|
||||
|
||||
// ContainsPasswds applies equality check predicate on the "contains_passwds" field. It's identical to ContainsPasswdsEQ.
|
||||
func ContainsPasswds(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldContainsPasswds, v))
|
||||
}
|
||||
|
||||
// ContainsHashes applies equality check predicate on the "contains_hashes" field. It's identical to ContainsHashesEQ.
|
||||
func ContainsHashes(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldContainsHashes, v))
|
||||
}
|
||||
|
||||
// ContainsEmails applies equality check predicate on the "contains_emails" field. It's identical to ContainsEmailsEQ.
|
||||
func ContainsEmails(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldContainsEmails, v))
|
||||
}
|
||||
|
||||
// HashType applies equality check predicate on the "hash_type" field. It's identical to HashTypeEQ.
|
||||
func HashType(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashSalted applies equality check predicate on the "hash_salted" field. It's identical to HashSaltedEQ.
|
||||
func HashSalted(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldHashSalted, v))
|
||||
}
|
||||
|
||||
// HashPeppered applies equality check predicate on the "hash_peppered" field. It's identical to HashPepperedEQ.
|
||||
func HashPeppered(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldHashPeppered, v))
|
||||
}
|
||||
|
||||
// Data applies equality check predicate on the "data" field. It's identical to DataEQ.
|
||||
func Data(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldData, v))
|
||||
}
|
||||
|
||||
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
|
||||
func CreatedAt(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// NameEQ applies the EQ predicate on the "name" field.
|
||||
func NameEQ(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameNEQ applies the NEQ predicate on the "name" field.
|
||||
func NameNEQ(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldName, v))
|
||||
}
|
||||
|
||||
// NameIn applies the In predicate on the "name" field.
|
||||
func NameIn(vs ...string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameNotIn applies the NotIn predicate on the "name" field.
|
||||
func NameNotIn(vs ...string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotIn(FieldName, vs...))
|
||||
}
|
||||
|
||||
// NameGT applies the GT predicate on the "name" field.
|
||||
func NameGT(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameGTE applies the GTE predicate on the "name" field.
|
||||
func NameGTE(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLT applies the LT predicate on the "name" field.
|
||||
func NameLT(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLT(FieldName, v))
|
||||
}
|
||||
|
||||
// NameLTE applies the LTE predicate on the "name" field.
|
||||
func NameLTE(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLTE(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContains applies the Contains predicate on the "name" field.
|
||||
func NameContains(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldContains(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
|
||||
func NameHasPrefix(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldHasPrefix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
|
||||
func NameHasSuffix(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldHasSuffix(FieldName, v))
|
||||
}
|
||||
|
||||
// NameEqualFold applies the EqualFold predicate on the "name" field.
|
||||
func NameEqualFold(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEqualFold(FieldName, v))
|
||||
}
|
||||
|
||||
// NameContainsFold applies the ContainsFold predicate on the "name" field.
|
||||
func NameContainsFold(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldContainsFold(FieldName, v))
|
||||
}
|
||||
|
||||
// DateEQ applies the EQ predicate on the "date" field.
|
||||
func DateEQ(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldDate, v))
|
||||
}
|
||||
|
||||
// DateNEQ applies the NEQ predicate on the "date" field.
|
||||
func DateNEQ(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldDate, v))
|
||||
}
|
||||
|
||||
// DateIn applies the In predicate on the "date" field.
|
||||
func DateIn(vs ...time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIn(FieldDate, vs...))
|
||||
}
|
||||
|
||||
// DateNotIn applies the NotIn predicate on the "date" field.
|
||||
func DateNotIn(vs ...time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotIn(FieldDate, vs...))
|
||||
}
|
||||
|
||||
// DateGT applies the GT predicate on the "date" field.
|
||||
func DateGT(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGT(FieldDate, v))
|
||||
}
|
||||
|
||||
// DateGTE applies the GTE predicate on the "date" field.
|
||||
func DateGTE(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGTE(FieldDate, v))
|
||||
}
|
||||
|
||||
// DateLT applies the LT predicate on the "date" field.
|
||||
func DateLT(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLT(FieldDate, v))
|
||||
}
|
||||
|
||||
// DateLTE applies the LTE predicate on the "date" field.
|
||||
func DateLTE(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLTE(FieldDate, v))
|
||||
}
|
||||
|
||||
// DescriptionEQ applies the EQ predicate on the "description" field.
|
||||
func DescriptionEQ(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionNEQ applies the NEQ predicate on the "description" field.
|
||||
func DescriptionNEQ(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionIn applies the In predicate on the "description" field.
|
||||
func DescriptionIn(vs ...string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIn(FieldDescription, vs...))
|
||||
}
|
||||
|
||||
// DescriptionNotIn applies the NotIn predicate on the "description" field.
|
||||
func DescriptionNotIn(vs ...string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotIn(FieldDescription, vs...))
|
||||
}
|
||||
|
||||
// DescriptionGT applies the GT predicate on the "description" field.
|
||||
func DescriptionGT(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGT(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionGTE applies the GTE predicate on the "description" field.
|
||||
func DescriptionGTE(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGTE(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionLT applies the LT predicate on the "description" field.
|
||||
func DescriptionLT(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLT(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionLTE applies the LTE predicate on the "description" field.
|
||||
func DescriptionLTE(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLTE(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionContains applies the Contains predicate on the "description" field.
|
||||
func DescriptionContains(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldContains(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
|
||||
func DescriptionHasPrefix(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldHasPrefix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
|
||||
func DescriptionHasSuffix(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldHasSuffix(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionIsNil applies the IsNil predicate on the "description" field.
|
||||
func DescriptionIsNil() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIsNull(FieldDescription))
|
||||
}
|
||||
|
||||
// DescriptionNotNil applies the NotNil predicate on the "description" field.
|
||||
func DescriptionNotNil() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotNull(FieldDescription))
|
||||
}
|
||||
|
||||
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
|
||||
func DescriptionEqualFold(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEqualFold(FieldDescription, v))
|
||||
}
|
||||
|
||||
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
|
||||
func DescriptionContainsFold(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldContainsFold(FieldDescription, v))
|
||||
}
|
||||
|
||||
// IsVerifiedEQ applies the EQ predicate on the "is_verified" field.
|
||||
func IsVerifiedEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldIsVerified, v))
|
||||
}
|
||||
|
||||
// IsVerifiedNEQ applies the NEQ predicate on the "is_verified" field.
|
||||
func IsVerifiedNEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldIsVerified, v))
|
||||
}
|
||||
|
||||
// ContainsPasswdsEQ applies the EQ predicate on the "contains_passwds" field.
|
||||
func ContainsPasswdsEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldContainsPasswds, v))
|
||||
}
|
||||
|
||||
// ContainsPasswdsNEQ applies the NEQ predicate on the "contains_passwds" field.
|
||||
func ContainsPasswdsNEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldContainsPasswds, v))
|
||||
}
|
||||
|
||||
// ContainsHashesEQ applies the EQ predicate on the "contains_hashes" field.
|
||||
func ContainsHashesEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldContainsHashes, v))
|
||||
}
|
||||
|
||||
// ContainsHashesNEQ applies the NEQ predicate on the "contains_hashes" field.
|
||||
func ContainsHashesNEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldContainsHashes, v))
|
||||
}
|
||||
|
||||
// ContainsEmailsEQ applies the EQ predicate on the "contains_emails" field.
|
||||
func ContainsEmailsEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldContainsEmails, v))
|
||||
}
|
||||
|
||||
// ContainsEmailsNEQ applies the NEQ predicate on the "contains_emails" field.
|
||||
func ContainsEmailsNEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldContainsEmails, v))
|
||||
}
|
||||
|
||||
// HashTypeEQ applies the EQ predicate on the "hash_type" field.
|
||||
func HashTypeEQ(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashTypeNEQ applies the NEQ predicate on the "hash_type" field.
|
||||
func HashTypeNEQ(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashTypeIn applies the In predicate on the "hash_type" field.
|
||||
func HashTypeIn(vs ...string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIn(FieldHashType, vs...))
|
||||
}
|
||||
|
||||
// HashTypeNotIn applies the NotIn predicate on the "hash_type" field.
|
||||
func HashTypeNotIn(vs ...string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotIn(FieldHashType, vs...))
|
||||
}
|
||||
|
||||
// HashTypeGT applies the GT predicate on the "hash_type" field.
|
||||
func HashTypeGT(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGT(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashTypeGTE applies the GTE predicate on the "hash_type" field.
|
||||
func HashTypeGTE(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGTE(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashTypeLT applies the LT predicate on the "hash_type" field.
|
||||
func HashTypeLT(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLT(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashTypeLTE applies the LTE predicate on the "hash_type" field.
|
||||
func HashTypeLTE(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLTE(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashTypeContains applies the Contains predicate on the "hash_type" field.
|
||||
func HashTypeContains(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldContains(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashTypeHasPrefix applies the HasPrefix predicate on the "hash_type" field.
|
||||
func HashTypeHasPrefix(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldHasPrefix(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashTypeHasSuffix applies the HasSuffix predicate on the "hash_type" field.
|
||||
func HashTypeHasSuffix(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldHasSuffix(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashTypeIsNil applies the IsNil predicate on the "hash_type" field.
|
||||
func HashTypeIsNil() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIsNull(FieldHashType))
|
||||
}
|
||||
|
||||
// HashTypeNotNil applies the NotNil predicate on the "hash_type" field.
|
||||
func HashTypeNotNil() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotNull(FieldHashType))
|
||||
}
|
||||
|
||||
// HashTypeEqualFold applies the EqualFold predicate on the "hash_type" field.
|
||||
func HashTypeEqualFold(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEqualFold(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashTypeContainsFold applies the ContainsFold predicate on the "hash_type" field.
|
||||
func HashTypeContainsFold(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldContainsFold(FieldHashType, v))
|
||||
}
|
||||
|
||||
// HashSaltedEQ applies the EQ predicate on the "hash_salted" field.
|
||||
func HashSaltedEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldHashSalted, v))
|
||||
}
|
||||
|
||||
// HashSaltedNEQ applies the NEQ predicate on the "hash_salted" field.
|
||||
func HashSaltedNEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldHashSalted, v))
|
||||
}
|
||||
|
||||
// HashSaltedIsNil applies the IsNil predicate on the "hash_salted" field.
|
||||
func HashSaltedIsNil() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIsNull(FieldHashSalted))
|
||||
}
|
||||
|
||||
// HashSaltedNotNil applies the NotNil predicate on the "hash_salted" field.
|
||||
func HashSaltedNotNil() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotNull(FieldHashSalted))
|
||||
}
|
||||
|
||||
// HashPepperedEQ applies the EQ predicate on the "hash_peppered" field.
|
||||
func HashPepperedEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldHashPeppered, v))
|
||||
}
|
||||
|
||||
// HashPepperedNEQ applies the NEQ predicate on the "hash_peppered" field.
|
||||
func HashPepperedNEQ(v bool) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldHashPeppered, v))
|
||||
}
|
||||
|
||||
// HashPepperedIsNil applies the IsNil predicate on the "hash_peppered" field.
|
||||
func HashPepperedIsNil() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIsNull(FieldHashPeppered))
|
||||
}
|
||||
|
||||
// HashPepperedNotNil applies the NotNil predicate on the "hash_peppered" field.
|
||||
func HashPepperedNotNil() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotNull(FieldHashPeppered))
|
||||
}
|
||||
|
||||
// DataEQ applies the EQ predicate on the "data" field.
|
||||
func DataEQ(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldData, v))
|
||||
}
|
||||
|
||||
// DataNEQ applies the NEQ predicate on the "data" field.
|
||||
func DataNEQ(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldData, v))
|
||||
}
|
||||
|
||||
// DataIn applies the In predicate on the "data" field.
|
||||
func DataIn(vs ...string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIn(FieldData, vs...))
|
||||
}
|
||||
|
||||
// DataNotIn applies the NotIn predicate on the "data" field.
|
||||
func DataNotIn(vs ...string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotIn(FieldData, vs...))
|
||||
}
|
||||
|
||||
// DataGT applies the GT predicate on the "data" field.
|
||||
func DataGT(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGT(FieldData, v))
|
||||
}
|
||||
|
||||
// DataGTE applies the GTE predicate on the "data" field.
|
||||
func DataGTE(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGTE(FieldData, v))
|
||||
}
|
||||
|
||||
// DataLT applies the LT predicate on the "data" field.
|
||||
func DataLT(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLT(FieldData, v))
|
||||
}
|
||||
|
||||
// DataLTE applies the LTE predicate on the "data" field.
|
||||
func DataLTE(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLTE(FieldData, v))
|
||||
}
|
||||
|
||||
// DataContains applies the Contains predicate on the "data" field.
|
||||
func DataContains(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldContains(FieldData, v))
|
||||
}
|
||||
|
||||
// DataHasPrefix applies the HasPrefix predicate on the "data" field.
|
||||
func DataHasPrefix(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldHasPrefix(FieldData, v))
|
||||
}
|
||||
|
||||
// DataHasSuffix applies the HasSuffix predicate on the "data" field.
|
||||
func DataHasSuffix(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldHasSuffix(FieldData, v))
|
||||
}
|
||||
|
||||
// DataIsNil applies the IsNil predicate on the "data" field.
|
||||
func DataIsNil() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIsNull(FieldData))
|
||||
}
|
||||
|
||||
// DataNotNil applies the NotNil predicate on the "data" field.
|
||||
func DataNotNil() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotNull(FieldData))
|
||||
}
|
||||
|
||||
// DataEqualFold applies the EqualFold predicate on the "data" field.
|
||||
func DataEqualFold(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEqualFold(FieldData, v))
|
||||
}
|
||||
|
||||
// DataContainsFold applies the ContainsFold predicate on the "data" field.
|
||||
func DataContainsFold(v string) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldContainsFold(FieldData, v))
|
||||
}
|
||||
|
||||
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
|
||||
func CreatedAtEQ(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
|
||||
func CreatedAtNEQ(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNEQ(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtIn applies the In predicate on the "created_at" field.
|
||||
func CreatedAtIn(vs ...time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
|
||||
func CreatedAtNotIn(vs ...time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldNotIn(FieldCreatedAt, vs...))
|
||||
}
|
||||
|
||||
// CreatedAtGT applies the GT predicate on the "created_at" field.
|
||||
func CreatedAtGT(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
|
||||
func CreatedAtGTE(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldGTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLT applies the LT predicate on the "created_at" field.
|
||||
func CreatedAtLT(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLT(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
|
||||
func CreatedAtLTE(v time.Time) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(sql.FieldLTE(FieldCreatedAt, v))
|
||||
}
|
||||
|
||||
// HasTrackedBreaches applies the HasEdge predicate on the "tracked_breaches" edge.
|
||||
func HasTrackedBreaches() predicate.LocalBreach {
|
||||
return predicate.LocalBreach(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, TrackedBreachesTable, TrackedBreachesPrimaryKey...),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasTrackedBreachesWith applies the HasEdge predicate on the "tracked_breaches" edge with a given conditions (other predicates).
|
||||
func HasTrackedBreachesWith(preds ...predicate.TrackedBreaches) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(func(s *sql.Selector) {
|
||||
step := newTrackedBreachesStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.LocalBreach) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(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.LocalBreach) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(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.LocalBreach) predicate.LocalBreach {
|
||||
return predicate.LocalBreach(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
|
@ -0,0 +1,439 @@
|
|||
// 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/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// LocalBreachCreate is the builder for creating a LocalBreach entity.
|
||||
type LocalBreachCreate struct {
|
||||
config
|
||||
mutation *LocalBreachMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (lbc *LocalBreachCreate) SetName(s string) *LocalBreachCreate {
|
||||
lbc.mutation.SetName(s)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetDate sets the "date" field.
|
||||
func (lbc *LocalBreachCreate) SetDate(t time.Time) *LocalBreachCreate {
|
||||
lbc.mutation.SetDate(t)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||
func (lbc *LocalBreachCreate) SetNillableDate(t *time.Time) *LocalBreachCreate {
|
||||
if t != nil {
|
||||
lbc.SetDate(*t)
|
||||
}
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (lbc *LocalBreachCreate) SetDescription(s string) *LocalBreachCreate {
|
||||
lbc.mutation.SetDescription(s)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (lbc *LocalBreachCreate) SetNillableDescription(s *string) *LocalBreachCreate {
|
||||
if s != nil {
|
||||
lbc.SetDescription(*s)
|
||||
}
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetIsVerified sets the "is_verified" field.
|
||||
func (lbc *LocalBreachCreate) SetIsVerified(b bool) *LocalBreachCreate {
|
||||
lbc.mutation.SetIsVerified(b)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetContainsPasswds sets the "contains_passwds" field.
|
||||
func (lbc *LocalBreachCreate) SetContainsPasswds(b bool) *LocalBreachCreate {
|
||||
lbc.mutation.SetContainsPasswds(b)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetContainsHashes sets the "contains_hashes" field.
|
||||
func (lbc *LocalBreachCreate) SetContainsHashes(b bool) *LocalBreachCreate {
|
||||
lbc.mutation.SetContainsHashes(b)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetContainsEmails sets the "contains_emails" field.
|
||||
func (lbc *LocalBreachCreate) SetContainsEmails(b bool) *LocalBreachCreate {
|
||||
lbc.mutation.SetContainsEmails(b)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetHashType sets the "hash_type" field.
|
||||
func (lbc *LocalBreachCreate) SetHashType(s string) *LocalBreachCreate {
|
||||
lbc.mutation.SetHashType(s)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetNillableHashType sets the "hash_type" field if the given value is not nil.
|
||||
func (lbc *LocalBreachCreate) SetNillableHashType(s *string) *LocalBreachCreate {
|
||||
if s != nil {
|
||||
lbc.SetHashType(*s)
|
||||
}
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetHashSalted sets the "hash_salted" field.
|
||||
func (lbc *LocalBreachCreate) SetHashSalted(b bool) *LocalBreachCreate {
|
||||
lbc.mutation.SetHashSalted(b)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetNillableHashSalted sets the "hash_salted" field if the given value is not nil.
|
||||
func (lbc *LocalBreachCreate) SetNillableHashSalted(b *bool) *LocalBreachCreate {
|
||||
if b != nil {
|
||||
lbc.SetHashSalted(*b)
|
||||
}
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetHashPeppered sets the "hash_peppered" field.
|
||||
func (lbc *LocalBreachCreate) SetHashPeppered(b bool) *LocalBreachCreate {
|
||||
lbc.mutation.SetHashPeppered(b)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetNillableHashPeppered sets the "hash_peppered" field if the given value is not nil.
|
||||
func (lbc *LocalBreachCreate) SetNillableHashPeppered(b *bool) *LocalBreachCreate {
|
||||
if b != nil {
|
||||
lbc.SetHashPeppered(*b)
|
||||
}
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetData sets the "data" field.
|
||||
func (lbc *LocalBreachCreate) SetData(s string) *LocalBreachCreate {
|
||||
lbc.mutation.SetData(s)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetNillableData sets the "data" field if the given value is not nil.
|
||||
func (lbc *LocalBreachCreate) SetNillableData(s *string) *LocalBreachCreate {
|
||||
if s != nil {
|
||||
lbc.SetData(*s)
|
||||
}
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (lbc *LocalBreachCreate) SetCreatedAt(t time.Time) *LocalBreachCreate {
|
||||
lbc.mutation.SetCreatedAt(t)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (lbc *LocalBreachCreate) SetNillableCreatedAt(t *time.Time) *LocalBreachCreate {
|
||||
if t != nil {
|
||||
lbc.SetCreatedAt(*t)
|
||||
}
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (lbc *LocalBreachCreate) SetID(u uuid.UUID) *LocalBreachCreate {
|
||||
lbc.mutation.SetID(u)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// SetNillableID sets the "id" field if the given value is not nil.
|
||||
func (lbc *LocalBreachCreate) SetNillableID(u *uuid.UUID) *LocalBreachCreate {
|
||||
if u != nil {
|
||||
lbc.SetID(*u)
|
||||
}
|
||||
return lbc
|
||||
}
|
||||
|
||||
// AddTrackedBreachIDs adds the "tracked_breaches" edge to the TrackedBreaches entity by IDs.
|
||||
func (lbc *LocalBreachCreate) AddTrackedBreachIDs(ids ...uuid.UUID) *LocalBreachCreate {
|
||||
lbc.mutation.AddTrackedBreachIDs(ids...)
|
||||
return lbc
|
||||
}
|
||||
|
||||
// AddTrackedBreaches adds the "tracked_breaches" edges to the TrackedBreaches entity.
|
||||
func (lbc *LocalBreachCreate) AddTrackedBreaches(t ...*TrackedBreaches) *LocalBreachCreate {
|
||||
ids := make([]uuid.UUID, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return lbc.AddTrackedBreachIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the LocalBreachMutation object of the builder.
|
||||
func (lbc *LocalBreachCreate) Mutation() *LocalBreachMutation {
|
||||
return lbc.mutation
|
||||
}
|
||||
|
||||
// Save creates the LocalBreach in the database.
|
||||
func (lbc *LocalBreachCreate) Save(ctx context.Context) (*LocalBreach, error) {
|
||||
lbc.defaults()
|
||||
return withHooks(ctx, lbc.sqlSave, lbc.mutation, lbc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (lbc *LocalBreachCreate) SaveX(ctx context.Context) *LocalBreach {
|
||||
v, err := lbc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (lbc *LocalBreachCreate) Exec(ctx context.Context) error {
|
||||
_, err := lbc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (lbc *LocalBreachCreate) ExecX(ctx context.Context) {
|
||||
if err := lbc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (lbc *LocalBreachCreate) defaults() {
|
||||
if _, ok := lbc.mutation.Date(); !ok {
|
||||
v := localbreach.DefaultDate
|
||||
lbc.mutation.SetDate(v)
|
||||
}
|
||||
if _, ok := lbc.mutation.CreatedAt(); !ok {
|
||||
v := localbreach.DefaultCreatedAt
|
||||
lbc.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := lbc.mutation.ID(); !ok {
|
||||
v := localbreach.DefaultID()
|
||||
lbc.mutation.SetID(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (lbc *LocalBreachCreate) check() error {
|
||||
if _, ok := lbc.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "LocalBreach.name"`)}
|
||||
}
|
||||
if v, ok := lbc.mutation.Name(); ok {
|
||||
if err := localbreach.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "LocalBreach.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := lbc.mutation.Date(); !ok {
|
||||
return &ValidationError{Name: "date", err: errors.New(`ent: missing required field "LocalBreach.date"`)}
|
||||
}
|
||||
if _, ok := lbc.mutation.IsVerified(); !ok {
|
||||
return &ValidationError{Name: "is_verified", err: errors.New(`ent: missing required field "LocalBreach.is_verified"`)}
|
||||
}
|
||||
if _, ok := lbc.mutation.ContainsPasswds(); !ok {
|
||||
return &ValidationError{Name: "contains_passwds", err: errors.New(`ent: missing required field "LocalBreach.contains_passwds"`)}
|
||||
}
|
||||
if _, ok := lbc.mutation.ContainsHashes(); !ok {
|
||||
return &ValidationError{Name: "contains_hashes", err: errors.New(`ent: missing required field "LocalBreach.contains_hashes"`)}
|
||||
}
|
||||
if _, ok := lbc.mutation.ContainsEmails(); !ok {
|
||||
return &ValidationError{Name: "contains_emails", err: errors.New(`ent: missing required field "LocalBreach.contains_emails"`)}
|
||||
}
|
||||
if _, ok := lbc.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "LocalBreach.created_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbc *LocalBreachCreate) sqlSave(ctx context.Context) (*LocalBreach, error) {
|
||||
if err := lbc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := lbc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, lbc.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
|
||||
}
|
||||
}
|
||||
lbc.mutation.id = &_node.ID
|
||||
lbc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (lbc *LocalBreachCreate) createSpec() (*LocalBreach, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &LocalBreach{config: lbc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(localbreach.Table, sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID))
|
||||
)
|
||||
if id, ok := lbc.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := lbc.mutation.Name(); ok {
|
||||
_spec.SetField(localbreach.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := lbc.mutation.Date(); ok {
|
||||
_spec.SetField(localbreach.FieldDate, field.TypeTime, value)
|
||||
_node.Date = value
|
||||
}
|
||||
if value, ok := lbc.mutation.Description(); ok {
|
||||
_spec.SetField(localbreach.FieldDescription, field.TypeString, value)
|
||||
_node.Description = &value
|
||||
}
|
||||
if value, ok := lbc.mutation.IsVerified(); ok {
|
||||
_spec.SetField(localbreach.FieldIsVerified, field.TypeBool, value)
|
||||
_node.IsVerified = value
|
||||
}
|
||||
if value, ok := lbc.mutation.ContainsPasswds(); ok {
|
||||
_spec.SetField(localbreach.FieldContainsPasswds, field.TypeBool, value)
|
||||
_node.ContainsPasswds = value
|
||||
}
|
||||
if value, ok := lbc.mutation.ContainsHashes(); ok {
|
||||
_spec.SetField(localbreach.FieldContainsHashes, field.TypeBool, value)
|
||||
_node.ContainsHashes = value
|
||||
}
|
||||
if value, ok := lbc.mutation.ContainsEmails(); ok {
|
||||
_spec.SetField(localbreach.FieldContainsEmails, field.TypeBool, value)
|
||||
_node.ContainsEmails = value
|
||||
}
|
||||
if value, ok := lbc.mutation.HashType(); ok {
|
||||
_spec.SetField(localbreach.FieldHashType, field.TypeString, value)
|
||||
_node.HashType = &value
|
||||
}
|
||||
if value, ok := lbc.mutation.HashSalted(); ok {
|
||||
_spec.SetField(localbreach.FieldHashSalted, field.TypeBool, value)
|
||||
_node.HashSalted = &value
|
||||
}
|
||||
if value, ok := lbc.mutation.HashPeppered(); ok {
|
||||
_spec.SetField(localbreach.FieldHashPeppered, field.TypeBool, value)
|
||||
_node.HashPeppered = &value
|
||||
}
|
||||
if value, ok := lbc.mutation.Data(); ok {
|
||||
_spec.SetField(localbreach.FieldData, field.TypeString, value)
|
||||
_node.Data = &value
|
||||
}
|
||||
if value, ok := lbc.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(localbreach.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if nodes := lbc.mutation.TrackedBreachesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: localbreach.TrackedBreachesTable,
|
||||
Columns: localbreach.TrackedBreachesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// LocalBreachCreateBulk is the builder for creating many LocalBreach entities in bulk.
|
||||
type LocalBreachCreateBulk struct {
|
||||
config
|
||||
builders []*LocalBreachCreate
|
||||
}
|
||||
|
||||
// Save creates the LocalBreach entities in the database.
|
||||
func (lbcb *LocalBreachCreateBulk) Save(ctx context.Context) ([]*LocalBreach, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(lbcb.builders))
|
||||
nodes := make([]*LocalBreach, len(lbcb.builders))
|
||||
mutators := make([]Mutator, len(lbcb.builders))
|
||||
for i := range lbcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := lbcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*LocalBreachMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, lbcb.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, lbcb.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, lbcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (lbcb *LocalBreachCreateBulk) SaveX(ctx context.Context) []*LocalBreach {
|
||||
v, err := lbcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (lbcb *LocalBreachCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := lbcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (lbcb *LocalBreachCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := lbcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -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/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
)
|
||||
|
||||
// LocalBreachDelete is the builder for deleting a LocalBreach entity.
|
||||
type LocalBreachDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *LocalBreachMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the LocalBreachDelete builder.
|
||||
func (lbd *LocalBreachDelete) Where(ps ...predicate.LocalBreach) *LocalBreachDelete {
|
||||
lbd.mutation.Where(ps...)
|
||||
return lbd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (lbd *LocalBreachDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, lbd.sqlExec, lbd.mutation, lbd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (lbd *LocalBreachDelete) ExecX(ctx context.Context) int {
|
||||
n, err := lbd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (lbd *LocalBreachDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(localbreach.Table, sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID))
|
||||
if ps := lbd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, lbd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
lbd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// LocalBreachDeleteOne is the builder for deleting a single LocalBreach entity.
|
||||
type LocalBreachDeleteOne struct {
|
||||
lbd *LocalBreachDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the LocalBreachDelete builder.
|
||||
func (lbdo *LocalBreachDeleteOne) Where(ps ...predicate.LocalBreach) *LocalBreachDeleteOne {
|
||||
lbdo.lbd.mutation.Where(ps...)
|
||||
return lbdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (lbdo *LocalBreachDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := lbdo.lbd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{localbreach.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (lbdo *LocalBreachDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := lbdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,637 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"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/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// LocalBreachQuery is the builder for querying LocalBreach entities.
|
||||
type LocalBreachQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []localbreach.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.LocalBreach
|
||||
withTrackedBreaches *TrackedBreachesQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the LocalBreachQuery builder.
|
||||
func (lbq *LocalBreachQuery) Where(ps ...predicate.LocalBreach) *LocalBreachQuery {
|
||||
lbq.predicates = append(lbq.predicates, ps...)
|
||||
return lbq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (lbq *LocalBreachQuery) Limit(limit int) *LocalBreachQuery {
|
||||
lbq.ctx.Limit = &limit
|
||||
return lbq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (lbq *LocalBreachQuery) Offset(offset int) *LocalBreachQuery {
|
||||
lbq.ctx.Offset = &offset
|
||||
return lbq
|
||||
}
|
||||
|
||||
// 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 (lbq *LocalBreachQuery) Unique(unique bool) *LocalBreachQuery {
|
||||
lbq.ctx.Unique = &unique
|
||||
return lbq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (lbq *LocalBreachQuery) Order(o ...localbreach.OrderOption) *LocalBreachQuery {
|
||||
lbq.order = append(lbq.order, o...)
|
||||
return lbq
|
||||
}
|
||||
|
||||
// QueryTrackedBreaches chains the current query on the "tracked_breaches" edge.
|
||||
func (lbq *LocalBreachQuery) QueryTrackedBreaches() *TrackedBreachesQuery {
|
||||
query := (&TrackedBreachesClient{config: lbq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := lbq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := lbq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(localbreach.Table, localbreach.FieldID, selector),
|
||||
sqlgraph.To(trackedbreaches.Table, trackedbreaches.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, true, localbreach.TrackedBreachesTable, localbreach.TrackedBreachesPrimaryKey...),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(lbq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first LocalBreach entity from the query.
|
||||
// Returns a *NotFoundError when no LocalBreach was found.
|
||||
func (lbq *LocalBreachQuery) First(ctx context.Context) (*LocalBreach, error) {
|
||||
nodes, err := lbq.Limit(1).All(setContextOp(ctx, lbq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{localbreach.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (lbq *LocalBreachQuery) FirstX(ctx context.Context) *LocalBreach {
|
||||
node, err := lbq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first LocalBreach ID from the query.
|
||||
// Returns a *NotFoundError when no LocalBreach ID was found.
|
||||
func (lbq *LocalBreachQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = lbq.Limit(1).IDs(setContextOp(ctx, lbq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{localbreach.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (lbq *LocalBreachQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := lbq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single LocalBreach entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one LocalBreach entity is found.
|
||||
// Returns a *NotFoundError when no LocalBreach entities are found.
|
||||
func (lbq *LocalBreachQuery) Only(ctx context.Context) (*LocalBreach, error) {
|
||||
nodes, err := lbq.Limit(2).All(setContextOp(ctx, lbq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{localbreach.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{localbreach.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (lbq *LocalBreachQuery) OnlyX(ctx context.Context) *LocalBreach {
|
||||
node, err := lbq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only LocalBreach ID in the query.
|
||||
// Returns a *NotSingularError when more than one LocalBreach ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (lbq *LocalBreachQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = lbq.Limit(2).IDs(setContextOp(ctx, lbq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{localbreach.Label}
|
||||
default:
|
||||
err = &NotSingularError{localbreach.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (lbq *LocalBreachQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := lbq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of LocalBreaches.
|
||||
func (lbq *LocalBreachQuery) All(ctx context.Context) ([]*LocalBreach, error) {
|
||||
ctx = setContextOp(ctx, lbq.ctx, "All")
|
||||
if err := lbq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*LocalBreach, *LocalBreachQuery]()
|
||||
return withInterceptors[[]*LocalBreach](ctx, lbq, qr, lbq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (lbq *LocalBreachQuery) AllX(ctx context.Context) []*LocalBreach {
|
||||
nodes, err := lbq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of LocalBreach IDs.
|
||||
func (lbq *LocalBreachQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||
if lbq.ctx.Unique == nil && lbq.path != nil {
|
||||
lbq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, lbq.ctx, "IDs")
|
||||
if err = lbq.Select(localbreach.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (lbq *LocalBreachQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||
ids, err := lbq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (lbq *LocalBreachQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, lbq.ctx, "Count")
|
||||
if err := lbq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, lbq, querierCount[*LocalBreachQuery](), lbq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (lbq *LocalBreachQuery) CountX(ctx context.Context) int {
|
||||
count, err := lbq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (lbq *LocalBreachQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, lbq.ctx, "Exist")
|
||||
switch _, err := lbq.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 (lbq *LocalBreachQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := lbq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the LocalBreachQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (lbq *LocalBreachQuery) Clone() *LocalBreachQuery {
|
||||
if lbq == nil {
|
||||
return nil
|
||||
}
|
||||
return &LocalBreachQuery{
|
||||
config: lbq.config,
|
||||
ctx: lbq.ctx.Clone(),
|
||||
order: append([]localbreach.OrderOption{}, lbq.order...),
|
||||
inters: append([]Interceptor{}, lbq.inters...),
|
||||
predicates: append([]predicate.LocalBreach{}, lbq.predicates...),
|
||||
withTrackedBreaches: lbq.withTrackedBreaches.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: lbq.sql.Clone(),
|
||||
path: lbq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithTrackedBreaches tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "tracked_breaches" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (lbq *LocalBreachQuery) WithTrackedBreaches(opts ...func(*TrackedBreachesQuery)) *LocalBreachQuery {
|
||||
query := (&TrackedBreachesClient{config: lbq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
lbq.withTrackedBreaches = query
|
||||
return lbq
|
||||
}
|
||||
|
||||
// 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.LocalBreach.Query().
|
||||
// GroupBy(localbreach.FieldName).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (lbq *LocalBreachQuery) GroupBy(field string, fields ...string) *LocalBreachGroupBy {
|
||||
lbq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &LocalBreachGroupBy{build: lbq}
|
||||
grbuild.flds = &lbq.ctx.Fields
|
||||
grbuild.label = localbreach.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.LocalBreach.Query().
|
||||
// Select(localbreach.FieldName).
|
||||
// Scan(ctx, &v)
|
||||
func (lbq *LocalBreachQuery) Select(fields ...string) *LocalBreachSelect {
|
||||
lbq.ctx.Fields = append(lbq.ctx.Fields, fields...)
|
||||
sbuild := &LocalBreachSelect{LocalBreachQuery: lbq}
|
||||
sbuild.label = localbreach.Label
|
||||
sbuild.flds, sbuild.scan = &lbq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a LocalBreachSelect configured with the given aggregations.
|
||||
func (lbq *LocalBreachQuery) Aggregate(fns ...AggregateFunc) *LocalBreachSelect {
|
||||
return lbq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (lbq *LocalBreachQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range lbq.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, lbq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range lbq.ctx.Fields {
|
||||
if !localbreach.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if lbq.path != nil {
|
||||
prev, err := lbq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
lbq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbq *LocalBreachQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*LocalBreach, error) {
|
||||
var (
|
||||
nodes = []*LocalBreach{}
|
||||
_spec = lbq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
lbq.withTrackedBreaches != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*LocalBreach).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &LocalBreach{config: lbq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, lbq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := lbq.withTrackedBreaches; query != nil {
|
||||
if err := lbq.loadTrackedBreaches(ctx, query, nodes,
|
||||
func(n *LocalBreach) { n.Edges.TrackedBreaches = []*TrackedBreaches{} },
|
||||
func(n *LocalBreach, e *TrackedBreaches) { n.Edges.TrackedBreaches = append(n.Edges.TrackedBreaches, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (lbq *LocalBreachQuery) loadTrackedBreaches(ctx context.Context, query *TrackedBreachesQuery, nodes []*LocalBreach, init func(*LocalBreach), assign func(*LocalBreach, *TrackedBreaches)) error {
|
||||
edgeIDs := make([]driver.Value, len(nodes))
|
||||
byID := make(map[uuid.UUID]*LocalBreach)
|
||||
nids := make(map[uuid.UUID]map[*LocalBreach]struct{})
|
||||
for i, node := range nodes {
|
||||
edgeIDs[i] = node.ID
|
||||
byID[node.ID] = node
|
||||
if init != nil {
|
||||
init(node)
|
||||
}
|
||||
}
|
||||
query.Where(func(s *sql.Selector) {
|
||||
joinT := sql.Table(localbreach.TrackedBreachesTable)
|
||||
s.Join(joinT).On(s.C(trackedbreaches.FieldID), joinT.C(localbreach.TrackedBreachesPrimaryKey[0]))
|
||||
s.Where(sql.InValues(joinT.C(localbreach.TrackedBreachesPrimaryKey[1]), edgeIDs...))
|
||||
columns := s.SelectedColumns()
|
||||
s.Select(joinT.C(localbreach.TrackedBreachesPrimaryKey[1]))
|
||||
s.AppendSelect(columns...)
|
||||
s.SetDistinct(false)
|
||||
})
|
||||
if err := query.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||
assign := spec.Assign
|
||||
values := spec.ScanValues
|
||||
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
values, err := values(columns[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append([]any{new(uuid.UUID)}, values...), nil
|
||||
}
|
||||
spec.Assign = func(columns []string, values []any) error {
|
||||
outValue := *values[0].(*uuid.UUID)
|
||||
inValue := *values[1].(*uuid.UUID)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*LocalBreach]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
})
|
||||
})
|
||||
neighbors, err := withInterceptors[[]*TrackedBreaches](ctx, query, qr, query.inters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected "tracked_breaches" node returned %v`, n.ID)
|
||||
}
|
||||
for kn := range nodes {
|
||||
assign(kn, n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbq *LocalBreachQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := lbq.querySpec()
|
||||
_spec.Node.Columns = lbq.ctx.Fields
|
||||
if len(lbq.ctx.Fields) > 0 {
|
||||
_spec.Unique = lbq.ctx.Unique != nil && *lbq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, lbq.driver, _spec)
|
||||
}
|
||||
|
||||
func (lbq *LocalBreachQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(localbreach.Table, localbreach.Columns, sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID))
|
||||
_spec.From = lbq.sql
|
||||
if unique := lbq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if lbq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := lbq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, localbreach.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != localbreach.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := lbq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := lbq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := lbq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := lbq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (lbq *LocalBreachQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(lbq.driver.Dialect())
|
||||
t1 := builder.Table(localbreach.Table)
|
||||
columns := lbq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = localbreach.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if lbq.sql != nil {
|
||||
selector = lbq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if lbq.ctx.Unique != nil && *lbq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range lbq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range lbq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := lbq.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 := lbq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// LocalBreachGroupBy is the group-by builder for LocalBreach entities.
|
||||
type LocalBreachGroupBy struct {
|
||||
selector
|
||||
build *LocalBreachQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (lbgb *LocalBreachGroupBy) Aggregate(fns ...AggregateFunc) *LocalBreachGroupBy {
|
||||
lbgb.fns = append(lbgb.fns, fns...)
|
||||
return lbgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (lbgb *LocalBreachGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, lbgb.build.ctx, "GroupBy")
|
||||
if err := lbgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*LocalBreachQuery, *LocalBreachGroupBy](ctx, lbgb.build, lbgb, lbgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (lbgb *LocalBreachGroupBy) sqlScan(ctx context.Context, root *LocalBreachQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(lbgb.fns))
|
||||
for _, fn := range lbgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*lbgb.flds)+len(lbgb.fns))
|
||||
for _, f := range *lbgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*lbgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := lbgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// LocalBreachSelect is the builder for selecting fields of LocalBreach entities.
|
||||
type LocalBreachSelect struct {
|
||||
*LocalBreachQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (lbs *LocalBreachSelect) Aggregate(fns ...AggregateFunc) *LocalBreachSelect {
|
||||
lbs.fns = append(lbs.fns, fns...)
|
||||
return lbs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (lbs *LocalBreachSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, lbs.ctx, "Select")
|
||||
if err := lbs.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*LocalBreachQuery, *LocalBreachSelect](ctx, lbs.LocalBreachQuery, lbs, lbs.inters, v)
|
||||
}
|
||||
|
||||
func (lbs *LocalBreachSelect) sqlScan(ctx context.Context, root *LocalBreachQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(lbs.fns))
|
||||
for _, fn := range lbs.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*lbs.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 := lbs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
|
@ -0,0 +1,750 @@
|
|||
// 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/schema/field"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// LocalBreachUpdate is the builder for updating LocalBreach entities.
|
||||
type LocalBreachUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *LocalBreachMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the LocalBreachUpdate builder.
|
||||
func (lbu *LocalBreachUpdate) Where(ps ...predicate.LocalBreach) *LocalBreachUpdate {
|
||||
lbu.mutation.Where(ps...)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (lbu *LocalBreachUpdate) SetName(s string) *LocalBreachUpdate {
|
||||
lbu.mutation.SetName(s)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetDate sets the "date" field.
|
||||
func (lbu *LocalBreachUpdate) SetDate(t time.Time) *LocalBreachUpdate {
|
||||
lbu.mutation.SetDate(t)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||
func (lbu *LocalBreachUpdate) SetNillableDate(t *time.Time) *LocalBreachUpdate {
|
||||
if t != nil {
|
||||
lbu.SetDate(*t)
|
||||
}
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (lbu *LocalBreachUpdate) SetDescription(s string) *LocalBreachUpdate {
|
||||
lbu.mutation.SetDescription(s)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (lbu *LocalBreachUpdate) SetNillableDescription(s *string) *LocalBreachUpdate {
|
||||
if s != nil {
|
||||
lbu.SetDescription(*s)
|
||||
}
|
||||
return lbu
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (lbu *LocalBreachUpdate) ClearDescription() *LocalBreachUpdate {
|
||||
lbu.mutation.ClearDescription()
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetIsVerified sets the "is_verified" field.
|
||||
func (lbu *LocalBreachUpdate) SetIsVerified(b bool) *LocalBreachUpdate {
|
||||
lbu.mutation.SetIsVerified(b)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetContainsPasswds sets the "contains_passwds" field.
|
||||
func (lbu *LocalBreachUpdate) SetContainsPasswds(b bool) *LocalBreachUpdate {
|
||||
lbu.mutation.SetContainsPasswds(b)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetContainsHashes sets the "contains_hashes" field.
|
||||
func (lbu *LocalBreachUpdate) SetContainsHashes(b bool) *LocalBreachUpdate {
|
||||
lbu.mutation.SetContainsHashes(b)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetContainsEmails sets the "contains_emails" field.
|
||||
func (lbu *LocalBreachUpdate) SetContainsEmails(b bool) *LocalBreachUpdate {
|
||||
lbu.mutation.SetContainsEmails(b)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetHashType sets the "hash_type" field.
|
||||
func (lbu *LocalBreachUpdate) SetHashType(s string) *LocalBreachUpdate {
|
||||
lbu.mutation.SetHashType(s)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetNillableHashType sets the "hash_type" field if the given value is not nil.
|
||||
func (lbu *LocalBreachUpdate) SetNillableHashType(s *string) *LocalBreachUpdate {
|
||||
if s != nil {
|
||||
lbu.SetHashType(*s)
|
||||
}
|
||||
return lbu
|
||||
}
|
||||
|
||||
// ClearHashType clears the value of the "hash_type" field.
|
||||
func (lbu *LocalBreachUpdate) ClearHashType() *LocalBreachUpdate {
|
||||
lbu.mutation.ClearHashType()
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetHashSalted sets the "hash_salted" field.
|
||||
func (lbu *LocalBreachUpdate) SetHashSalted(b bool) *LocalBreachUpdate {
|
||||
lbu.mutation.SetHashSalted(b)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetNillableHashSalted sets the "hash_salted" field if the given value is not nil.
|
||||
func (lbu *LocalBreachUpdate) SetNillableHashSalted(b *bool) *LocalBreachUpdate {
|
||||
if b != nil {
|
||||
lbu.SetHashSalted(*b)
|
||||
}
|
||||
return lbu
|
||||
}
|
||||
|
||||
// ClearHashSalted clears the value of the "hash_salted" field.
|
||||
func (lbu *LocalBreachUpdate) ClearHashSalted() *LocalBreachUpdate {
|
||||
lbu.mutation.ClearHashSalted()
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetHashPeppered sets the "hash_peppered" field.
|
||||
func (lbu *LocalBreachUpdate) SetHashPeppered(b bool) *LocalBreachUpdate {
|
||||
lbu.mutation.SetHashPeppered(b)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetNillableHashPeppered sets the "hash_peppered" field if the given value is not nil.
|
||||
func (lbu *LocalBreachUpdate) SetNillableHashPeppered(b *bool) *LocalBreachUpdate {
|
||||
if b != nil {
|
||||
lbu.SetHashPeppered(*b)
|
||||
}
|
||||
return lbu
|
||||
}
|
||||
|
||||
// ClearHashPeppered clears the value of the "hash_peppered" field.
|
||||
func (lbu *LocalBreachUpdate) ClearHashPeppered() *LocalBreachUpdate {
|
||||
lbu.mutation.ClearHashPeppered()
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetData sets the "data" field.
|
||||
func (lbu *LocalBreachUpdate) SetData(s string) *LocalBreachUpdate {
|
||||
lbu.mutation.SetData(s)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// SetNillableData sets the "data" field if the given value is not nil.
|
||||
func (lbu *LocalBreachUpdate) SetNillableData(s *string) *LocalBreachUpdate {
|
||||
if s != nil {
|
||||
lbu.SetData(*s)
|
||||
}
|
||||
return lbu
|
||||
}
|
||||
|
||||
// ClearData clears the value of the "data" field.
|
||||
func (lbu *LocalBreachUpdate) ClearData() *LocalBreachUpdate {
|
||||
lbu.mutation.ClearData()
|
||||
return lbu
|
||||
}
|
||||
|
||||
// AddTrackedBreachIDs adds the "tracked_breaches" edge to the TrackedBreaches entity by IDs.
|
||||
func (lbu *LocalBreachUpdate) AddTrackedBreachIDs(ids ...uuid.UUID) *LocalBreachUpdate {
|
||||
lbu.mutation.AddTrackedBreachIDs(ids...)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// AddTrackedBreaches adds the "tracked_breaches" edges to the TrackedBreaches entity.
|
||||
func (lbu *LocalBreachUpdate) AddTrackedBreaches(t ...*TrackedBreaches) *LocalBreachUpdate {
|
||||
ids := make([]uuid.UUID, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return lbu.AddTrackedBreachIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the LocalBreachMutation object of the builder.
|
||||
func (lbu *LocalBreachUpdate) Mutation() *LocalBreachMutation {
|
||||
return lbu.mutation
|
||||
}
|
||||
|
||||
// ClearTrackedBreaches clears all "tracked_breaches" edges to the TrackedBreaches entity.
|
||||
func (lbu *LocalBreachUpdate) ClearTrackedBreaches() *LocalBreachUpdate {
|
||||
lbu.mutation.ClearTrackedBreaches()
|
||||
return lbu
|
||||
}
|
||||
|
||||
// RemoveTrackedBreachIDs removes the "tracked_breaches" edge to TrackedBreaches entities by IDs.
|
||||
func (lbu *LocalBreachUpdate) RemoveTrackedBreachIDs(ids ...uuid.UUID) *LocalBreachUpdate {
|
||||
lbu.mutation.RemoveTrackedBreachIDs(ids...)
|
||||
return lbu
|
||||
}
|
||||
|
||||
// RemoveTrackedBreaches removes "tracked_breaches" edges to TrackedBreaches entities.
|
||||
func (lbu *LocalBreachUpdate) RemoveTrackedBreaches(t ...*TrackedBreaches) *LocalBreachUpdate {
|
||||
ids := make([]uuid.UUID, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return lbu.RemoveTrackedBreachIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (lbu *LocalBreachUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, lbu.sqlSave, lbu.mutation, lbu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (lbu *LocalBreachUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := lbu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (lbu *LocalBreachUpdate) Exec(ctx context.Context) error {
|
||||
_, err := lbu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (lbu *LocalBreachUpdate) ExecX(ctx context.Context) {
|
||||
if err := lbu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (lbu *LocalBreachUpdate) check() error {
|
||||
if v, ok := lbu.mutation.Name(); ok {
|
||||
if err := localbreach.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "LocalBreach.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbu *LocalBreachUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := lbu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(localbreach.Table, localbreach.Columns, sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID))
|
||||
if ps := lbu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := lbu.mutation.Name(); ok {
|
||||
_spec.SetField(localbreach.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := lbu.mutation.Date(); ok {
|
||||
_spec.SetField(localbreach.FieldDate, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := lbu.mutation.Description(); ok {
|
||||
_spec.SetField(localbreach.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if lbu.mutation.DescriptionCleared() {
|
||||
_spec.ClearField(localbreach.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := lbu.mutation.IsVerified(); ok {
|
||||
_spec.SetField(localbreach.FieldIsVerified, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := lbu.mutation.ContainsPasswds(); ok {
|
||||
_spec.SetField(localbreach.FieldContainsPasswds, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := lbu.mutation.ContainsHashes(); ok {
|
||||
_spec.SetField(localbreach.FieldContainsHashes, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := lbu.mutation.ContainsEmails(); ok {
|
||||
_spec.SetField(localbreach.FieldContainsEmails, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := lbu.mutation.HashType(); ok {
|
||||
_spec.SetField(localbreach.FieldHashType, field.TypeString, value)
|
||||
}
|
||||
if lbu.mutation.HashTypeCleared() {
|
||||
_spec.ClearField(localbreach.FieldHashType, field.TypeString)
|
||||
}
|
||||
if value, ok := lbu.mutation.HashSalted(); ok {
|
||||
_spec.SetField(localbreach.FieldHashSalted, field.TypeBool, value)
|
||||
}
|
||||
if lbu.mutation.HashSaltedCleared() {
|
||||
_spec.ClearField(localbreach.FieldHashSalted, field.TypeBool)
|
||||
}
|
||||
if value, ok := lbu.mutation.HashPeppered(); ok {
|
||||
_spec.SetField(localbreach.FieldHashPeppered, field.TypeBool, value)
|
||||
}
|
||||
if lbu.mutation.HashPepperedCleared() {
|
||||
_spec.ClearField(localbreach.FieldHashPeppered, field.TypeBool)
|
||||
}
|
||||
if value, ok := lbu.mutation.Data(); ok {
|
||||
_spec.SetField(localbreach.FieldData, field.TypeString, value)
|
||||
}
|
||||
if lbu.mutation.DataCleared() {
|
||||
_spec.ClearField(localbreach.FieldData, field.TypeString)
|
||||
}
|
||||
if lbu.mutation.TrackedBreachesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: localbreach.TrackedBreachesTable,
|
||||
Columns: localbreach.TrackedBreachesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := lbu.mutation.RemovedTrackedBreachesIDs(); len(nodes) > 0 && !lbu.mutation.TrackedBreachesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: localbreach.TrackedBreachesTable,
|
||||
Columns: localbreach.TrackedBreachesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := lbu.mutation.TrackedBreachesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: localbreach.TrackedBreachesTable,
|
||||
Columns: localbreach.TrackedBreachesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, lbu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{localbreach.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
lbu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// LocalBreachUpdateOne is the builder for updating a single LocalBreach entity.
|
||||
type LocalBreachUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *LocalBreachMutation
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetName(s string) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetName(s)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetDate sets the "date" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetDate(t time.Time) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetDate(t)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetNillableDate sets the "date" field if the given value is not nil.
|
||||
func (lbuo *LocalBreachUpdateOne) SetNillableDate(t *time.Time) *LocalBreachUpdateOne {
|
||||
if t != nil {
|
||||
lbuo.SetDate(*t)
|
||||
}
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetDescription sets the "description" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetDescription(s string) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetDescription(s)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||
func (lbuo *LocalBreachUpdateOne) SetNillableDescription(s *string) *LocalBreachUpdateOne {
|
||||
if s != nil {
|
||||
lbuo.SetDescription(*s)
|
||||
}
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// ClearDescription clears the value of the "description" field.
|
||||
func (lbuo *LocalBreachUpdateOne) ClearDescription() *LocalBreachUpdateOne {
|
||||
lbuo.mutation.ClearDescription()
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetIsVerified sets the "is_verified" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetIsVerified(b bool) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetIsVerified(b)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetContainsPasswds sets the "contains_passwds" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetContainsPasswds(b bool) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetContainsPasswds(b)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetContainsHashes sets the "contains_hashes" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetContainsHashes(b bool) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetContainsHashes(b)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetContainsEmails sets the "contains_emails" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetContainsEmails(b bool) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetContainsEmails(b)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetHashType sets the "hash_type" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetHashType(s string) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetHashType(s)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetNillableHashType sets the "hash_type" field if the given value is not nil.
|
||||
func (lbuo *LocalBreachUpdateOne) SetNillableHashType(s *string) *LocalBreachUpdateOne {
|
||||
if s != nil {
|
||||
lbuo.SetHashType(*s)
|
||||
}
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// ClearHashType clears the value of the "hash_type" field.
|
||||
func (lbuo *LocalBreachUpdateOne) ClearHashType() *LocalBreachUpdateOne {
|
||||
lbuo.mutation.ClearHashType()
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetHashSalted sets the "hash_salted" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetHashSalted(b bool) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetHashSalted(b)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetNillableHashSalted sets the "hash_salted" field if the given value is not nil.
|
||||
func (lbuo *LocalBreachUpdateOne) SetNillableHashSalted(b *bool) *LocalBreachUpdateOne {
|
||||
if b != nil {
|
||||
lbuo.SetHashSalted(*b)
|
||||
}
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// ClearHashSalted clears the value of the "hash_salted" field.
|
||||
func (lbuo *LocalBreachUpdateOne) ClearHashSalted() *LocalBreachUpdateOne {
|
||||
lbuo.mutation.ClearHashSalted()
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetHashPeppered sets the "hash_peppered" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetHashPeppered(b bool) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetHashPeppered(b)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetNillableHashPeppered sets the "hash_peppered" field if the given value is not nil.
|
||||
func (lbuo *LocalBreachUpdateOne) SetNillableHashPeppered(b *bool) *LocalBreachUpdateOne {
|
||||
if b != nil {
|
||||
lbuo.SetHashPeppered(*b)
|
||||
}
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// ClearHashPeppered clears the value of the "hash_peppered" field.
|
||||
func (lbuo *LocalBreachUpdateOne) ClearHashPeppered() *LocalBreachUpdateOne {
|
||||
lbuo.mutation.ClearHashPeppered()
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetData sets the "data" field.
|
||||
func (lbuo *LocalBreachUpdateOne) SetData(s string) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.SetData(s)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// SetNillableData sets the "data" field if the given value is not nil.
|
||||
func (lbuo *LocalBreachUpdateOne) SetNillableData(s *string) *LocalBreachUpdateOne {
|
||||
if s != nil {
|
||||
lbuo.SetData(*s)
|
||||
}
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// ClearData clears the value of the "data" field.
|
||||
func (lbuo *LocalBreachUpdateOne) ClearData() *LocalBreachUpdateOne {
|
||||
lbuo.mutation.ClearData()
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// AddTrackedBreachIDs adds the "tracked_breaches" edge to the TrackedBreaches entity by IDs.
|
||||
func (lbuo *LocalBreachUpdateOne) AddTrackedBreachIDs(ids ...uuid.UUID) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.AddTrackedBreachIDs(ids...)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// AddTrackedBreaches adds the "tracked_breaches" edges to the TrackedBreaches entity.
|
||||
func (lbuo *LocalBreachUpdateOne) AddTrackedBreaches(t ...*TrackedBreaches) *LocalBreachUpdateOne {
|
||||
ids := make([]uuid.UUID, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return lbuo.AddTrackedBreachIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the LocalBreachMutation object of the builder.
|
||||
func (lbuo *LocalBreachUpdateOne) Mutation() *LocalBreachMutation {
|
||||
return lbuo.mutation
|
||||
}
|
||||
|
||||
// ClearTrackedBreaches clears all "tracked_breaches" edges to the TrackedBreaches entity.
|
||||
func (lbuo *LocalBreachUpdateOne) ClearTrackedBreaches() *LocalBreachUpdateOne {
|
||||
lbuo.mutation.ClearTrackedBreaches()
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// RemoveTrackedBreachIDs removes the "tracked_breaches" edge to TrackedBreaches entities by IDs.
|
||||
func (lbuo *LocalBreachUpdateOne) RemoveTrackedBreachIDs(ids ...uuid.UUID) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.RemoveTrackedBreachIDs(ids...)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// RemoveTrackedBreaches removes "tracked_breaches" edges to TrackedBreaches entities.
|
||||
func (lbuo *LocalBreachUpdateOne) RemoveTrackedBreaches(t ...*TrackedBreaches) *LocalBreachUpdateOne {
|
||||
ids := make([]uuid.UUID, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return lbuo.RemoveTrackedBreachIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the LocalBreachUpdate builder.
|
||||
func (lbuo *LocalBreachUpdateOne) Where(ps ...predicate.LocalBreach) *LocalBreachUpdateOne {
|
||||
lbuo.mutation.Where(ps...)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (lbuo *LocalBreachUpdateOne) Select(field string, fields ...string) *LocalBreachUpdateOne {
|
||||
lbuo.fields = append([]string{field}, fields...)
|
||||
return lbuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated LocalBreach entity.
|
||||
func (lbuo *LocalBreachUpdateOne) Save(ctx context.Context) (*LocalBreach, error) {
|
||||
return withHooks(ctx, lbuo.sqlSave, lbuo.mutation, lbuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (lbuo *LocalBreachUpdateOne) SaveX(ctx context.Context) *LocalBreach {
|
||||
node, err := lbuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (lbuo *LocalBreachUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := lbuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (lbuo *LocalBreachUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := lbuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (lbuo *LocalBreachUpdateOne) check() error {
|
||||
if v, ok := lbuo.mutation.Name(); ok {
|
||||
if err := localbreach.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "LocalBreach.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lbuo *LocalBreachUpdateOne) sqlSave(ctx context.Context) (_node *LocalBreach, err error) {
|
||||
if err := lbuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(localbreach.Table, localbreach.Columns, sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID))
|
||||
id, ok := lbuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "LocalBreach.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := lbuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, localbreach.FieldID)
|
||||
for _, f := range fields {
|
||||
if !localbreach.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != localbreach.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := lbuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := lbuo.mutation.Name(); ok {
|
||||
_spec.SetField(localbreach.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := lbuo.mutation.Date(); ok {
|
||||
_spec.SetField(localbreach.FieldDate, field.TypeTime, value)
|
||||
}
|
||||
if value, ok := lbuo.mutation.Description(); ok {
|
||||
_spec.SetField(localbreach.FieldDescription, field.TypeString, value)
|
||||
}
|
||||
if lbuo.mutation.DescriptionCleared() {
|
||||
_spec.ClearField(localbreach.FieldDescription, field.TypeString)
|
||||
}
|
||||
if value, ok := lbuo.mutation.IsVerified(); ok {
|
||||
_spec.SetField(localbreach.FieldIsVerified, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := lbuo.mutation.ContainsPasswds(); ok {
|
||||
_spec.SetField(localbreach.FieldContainsPasswds, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := lbuo.mutation.ContainsHashes(); ok {
|
||||
_spec.SetField(localbreach.FieldContainsHashes, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := lbuo.mutation.ContainsEmails(); ok {
|
||||
_spec.SetField(localbreach.FieldContainsEmails, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := lbuo.mutation.HashType(); ok {
|
||||
_spec.SetField(localbreach.FieldHashType, field.TypeString, value)
|
||||
}
|
||||
if lbuo.mutation.HashTypeCleared() {
|
||||
_spec.ClearField(localbreach.FieldHashType, field.TypeString)
|
||||
}
|
||||
if value, ok := lbuo.mutation.HashSalted(); ok {
|
||||
_spec.SetField(localbreach.FieldHashSalted, field.TypeBool, value)
|
||||
}
|
||||
if lbuo.mutation.HashSaltedCleared() {
|
||||
_spec.ClearField(localbreach.FieldHashSalted, field.TypeBool)
|
||||
}
|
||||
if value, ok := lbuo.mutation.HashPeppered(); ok {
|
||||
_spec.SetField(localbreach.FieldHashPeppered, field.TypeBool, value)
|
||||
}
|
||||
if lbuo.mutation.HashPepperedCleared() {
|
||||
_spec.ClearField(localbreach.FieldHashPeppered, field.TypeBool)
|
||||
}
|
||||
if value, ok := lbuo.mutation.Data(); ok {
|
||||
_spec.SetField(localbreach.FieldData, field.TypeString, value)
|
||||
}
|
||||
if lbuo.mutation.DataCleared() {
|
||||
_spec.ClearField(localbreach.FieldData, field.TypeString)
|
||||
}
|
||||
if lbuo.mutation.TrackedBreachesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: localbreach.TrackedBreachesTable,
|
||||
Columns: localbreach.TrackedBreachesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := lbuo.mutation.RemovedTrackedBreachesIDs(); len(nodes) > 0 && !lbuo.mutation.TrackedBreachesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: localbreach.TrackedBreachesTable,
|
||||
Columns: localbreach.TrackedBreachesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := lbuo.mutation.TrackedBreachesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: true,
|
||||
Table: localbreach.TrackedBreachesTable,
|
||||
Columns: localbreach.TrackedBreachesPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &LocalBreach{config: lbuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, lbuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{localbreach.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
lbuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
|
@ -8,6 +8,28 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
// AgeKeysColumns holds the columns for the "age_keys" table.
|
||||
AgeKeysColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID, Unique: true},
|
||||
{Name: "key", Type: field.TypeBytes},
|
||||
{Name: "created", Type: field.TypeTime},
|
||||
{Name: "updated", Type: field.TypeTime},
|
||||
{Name: "owner", Type: field.TypeUUID, Unique: true},
|
||||
}
|
||||
// AgeKeysTable holds the schema information for the "age_keys" table.
|
||||
AgeKeysTable = &schema.Table{
|
||||
Name: "age_keys",
|
||||
Columns: AgeKeysColumns,
|
||||
PrimaryKey: []*schema.Column{AgeKeysColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "age_keys_users_agekey",
|
||||
Columns: []*schema.Column{AgeKeysColumns[4]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
}
|
||||
// HibPsColumns holds the columns for the "hib_ps" table.
|
||||
HibPsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID, Unique: true},
|
||||
|
@ -17,7 +39,7 @@ var (
|
|||
{Name: "added_date", Type: field.TypeTime},
|
||||
{Name: "modified_date", Type: field.TypeTime},
|
||||
{Name: "pwn_count", Type: field.TypeInt},
|
||||
{Name: "description", Type: field.TypeString},
|
||||
{Name: "description", Type: field.TypeString, Nullable: true},
|
||||
{Name: "dataclasses", Type: field.TypeJSON},
|
||||
{Name: "is_verified", Type: field.TypeBool, Default: false},
|
||||
{Name: "is_fabricated", Type: field.TypeBool, Default: false},
|
||||
|
@ -25,13 +47,78 @@ var (
|
|||
{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},
|
||||
{Name: "logo", Type: field.TypeString, Nullable: true},
|
||||
{Name: "tracked_breaches_hibp", Type: field.TypeUUID, Nullable: true},
|
||||
}
|
||||
// HibPsTable holds the schema information for the "hib_ps" table.
|
||||
HibPsTable = &schema.Table{
|
||||
Name: "hib_ps",
|
||||
Columns: HibPsColumns,
|
||||
PrimaryKey: []*schema.Column{HibPsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "hib_ps_tracked_breaches_hibp",
|
||||
Columns: []*schema.Column{HibPsColumns[16]},
|
||||
RefColumns: []*schema.Column{TrackedBreachesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
}
|
||||
// LocalBreachesColumns holds the columns for the "local_breaches" table.
|
||||
LocalBreachesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID, Unique: true},
|
||||
{Name: "name", Type: field.TypeString, Unique: true},
|
||||
{Name: "date", Type: field.TypeTime},
|
||||
{Name: "description", Type: field.TypeString, Nullable: true},
|
||||
{Name: "is_verified", Type: field.TypeBool},
|
||||
{Name: "contains_passwds", Type: field.TypeBool},
|
||||
{Name: "contains_hashes", Type: field.TypeBool},
|
||||
{Name: "contains_emails", Type: field.TypeBool},
|
||||
{Name: "hash_type", Type: field.TypeString, Nullable: true},
|
||||
{Name: "hash_salted", Type: field.TypeBool, Nullable: true},
|
||||
{Name: "hash_peppered", Type: field.TypeBool, Nullable: true},
|
||||
{Name: "data", Type: field.TypeString, Nullable: true},
|
||||
{Name: "created_at", Type: field.TypeTime},
|
||||
}
|
||||
// LocalBreachesTable holds the schema information for the "local_breaches" table.
|
||||
LocalBreachesTable = &schema.Table{
|
||||
Name: "local_breaches",
|
||||
Columns: LocalBreachesColumns,
|
||||
PrimaryKey: []*schema.Column{LocalBreachesColumns[0]},
|
||||
}
|
||||
// SearchQueriesColumns holds the columns for the "search_queries" table.
|
||||
SearchQueriesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID, Unique: true},
|
||||
{Name: "query", Type: field.TypeString},
|
||||
{Name: "created", Type: field.TypeTime},
|
||||
{Name: "owner", Type: field.TypeUUID},
|
||||
}
|
||||
// SearchQueriesTable holds the schema information for the "search_queries" table.
|
||||
SearchQueriesTable = &schema.Table{
|
||||
Name: "search_queries",
|
||||
Columns: SearchQueriesColumns,
|
||||
PrimaryKey: []*schema.Column{SearchQueriesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "search_queries_users_search_queries",
|
||||
Columns: []*schema.Column{SearchQueriesColumns[3]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
}
|
||||
// SettingsColumns holds the columns for the "settings" table.
|
||||
SettingsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID, Unique: true},
|
||||
{Name: "hibp_api_key", Type: field.TypeString, Unique: true, Nullable: true},
|
||||
{Name: "dehashed_api_key", Type: field.TypeString, Unique: true, Nullable: true},
|
||||
{Name: "searches", Type: field.TypeUint64, Default: 0},
|
||||
}
|
||||
// SettingsTable holds the schema information for the "settings" table.
|
||||
SettingsTable = &schema.Table{
|
||||
Name: "settings",
|
||||
Columns: SettingsColumns,
|
||||
PrimaryKey: []*schema.Column{SettingsColumns[0]},
|
||||
}
|
||||
// SetupsColumns holds the columns for the "setups" table.
|
||||
SetupsColumns = []*schema.Column{
|
||||
|
@ -44,6 +131,27 @@ var (
|
|||
Columns: SetupsColumns,
|
||||
PrimaryKey: []*schema.Column{SetupsColumns[0]},
|
||||
}
|
||||
// TrackedBreachesColumns holds the columns for the "tracked_breaches" table.
|
||||
TrackedBreachesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID, Unique: true},
|
||||
{Name: "breach", Type: field.TypeUUID},
|
||||
{Name: "online", Type: field.TypeBool, Default: true},
|
||||
{Name: "owner", Type: field.TypeUUID},
|
||||
}
|
||||
// TrackedBreachesTable holds the schema information for the "tracked_breaches" table.
|
||||
TrackedBreachesTable = &schema.Table{
|
||||
Name: "tracked_breaches",
|
||||
Columns: TrackedBreachesColumns,
|
||||
PrimaryKey: []*schema.Column{TrackedBreachesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "tracked_breaches_users_tracked_breaches",
|
||||
Columns: []*schema.Column{TrackedBreachesColumns[3]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
},
|
||||
}
|
||||
// UsersColumns holds the columns for the "users" table.
|
||||
UsersColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeUUID, Unique: true},
|
||||
|
@ -62,13 +170,50 @@ var (
|
|||
Columns: UsersColumns,
|
||||
PrimaryKey: []*schema.Column{UsersColumns[0]},
|
||||
}
|
||||
// TrackedBreachesLocalbreachColumns holds the columns for the "tracked_breaches_localbreach" table.
|
||||
TrackedBreachesLocalbreachColumns = []*schema.Column{
|
||||
{Name: "tracked_breaches_id", Type: field.TypeUUID},
|
||||
{Name: "local_breach_id", Type: field.TypeUUID},
|
||||
}
|
||||
// TrackedBreachesLocalbreachTable holds the schema information for the "tracked_breaches_localbreach" table.
|
||||
TrackedBreachesLocalbreachTable = &schema.Table{
|
||||
Name: "tracked_breaches_localbreach",
|
||||
Columns: TrackedBreachesLocalbreachColumns,
|
||||
PrimaryKey: []*schema.Column{TrackedBreachesLocalbreachColumns[0], TrackedBreachesLocalbreachColumns[1]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "tracked_breaches_localbreach_tracked_breaches_id",
|
||||
Columns: []*schema.Column{TrackedBreachesLocalbreachColumns[0]},
|
||||
RefColumns: []*schema.Column{TrackedBreachesColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "tracked_breaches_localbreach_local_breach_id",
|
||||
Columns: []*schema.Column{TrackedBreachesLocalbreachColumns[1]},
|
||||
RefColumns: []*schema.Column{LocalBreachesColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
},
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
AgeKeysTable,
|
||||
HibPsTable,
|
||||
LocalBreachesTable,
|
||||
SearchQueriesTable,
|
||||
SettingsTable,
|
||||
SetupsTable,
|
||||
TrackedBreachesTable,
|
||||
UsersTable,
|
||||
TrackedBreachesLocalbreachTable,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
AgeKeysTable.ForeignKeys[0].RefTable = UsersTable
|
||||
HibPsTable.ForeignKeys[0].RefTable = TrackedBreachesTable
|
||||
SearchQueriesTable.ForeignKeys[0].RefTable = UsersTable
|
||||
TrackedBreachesTable.ForeignKeys[0].RefTable = UsersTable
|
||||
TrackedBreachesLocalbreachTable.ForeignKeys[0].RefTable = TrackedBreachesTable
|
||||
TrackedBreachesLocalbreachTable.ForeignKeys[1].RefTable = LocalBreachesTable
|
||||
}
|
||||
|
|
3829
ent/mutation.go
3829
ent/mutation.go
File diff suppressed because it is too large
Load Diff
|
@ -6,11 +6,26 @@ import (
|
|||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// AgeKey is the predicate function for agekey builders.
|
||||
type AgeKey func(*sql.Selector)
|
||||
|
||||
// HIBP is the predicate function for hibp builders.
|
||||
type HIBP func(*sql.Selector)
|
||||
|
||||
// LocalBreach is the predicate function for localbreach builders.
|
||||
type LocalBreach func(*sql.Selector)
|
||||
|
||||
// SearchQuery is the predicate function for searchquery builders.
|
||||
type SearchQuery func(*sql.Selector)
|
||||
|
||||
// Settings is the predicate function for settings builders.
|
||||
type Settings func(*sql.Selector)
|
||||
|
||||
// Setup is the predicate function for setup builders.
|
||||
type Setup func(*sql.Selector)
|
||||
|
||||
// TrackedBreaches is the predicate function for trackedbreaches builders.
|
||||
type TrackedBreaches func(*sql.Selector)
|
||||
|
||||
// User is the predicate function for user builders.
|
||||
type User func(*sql.Selector)
|
||||
|
|
108
ent/runtime.go
108
ent/runtime.go
|
@ -5,9 +5,14 @@ package ent
|
|||
import (
|
||||
"time"
|
||||
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/hibp"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/schema"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/settings"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/setup"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -16,6 +21,24 @@ import (
|
|||
// (default values, validators, hooks and policies) and stitches it
|
||||
// to their package variables.
|
||||
func init() {
|
||||
agekeyFields := schema.AgeKey{}.Fields()
|
||||
_ = agekeyFields
|
||||
// agekeyDescKey is the schema descriptor for key field.
|
||||
agekeyDescKey := agekeyFields[1].Descriptor()
|
||||
// agekey.KeyValidator is a validator for the "key" field. It is called by the builders before save.
|
||||
agekey.KeyValidator = agekeyDescKey.Validators[0].(func([]byte) error)
|
||||
// agekeyDescCreated is the schema descriptor for created field.
|
||||
agekeyDescCreated := agekeyFields[2].Descriptor()
|
||||
// agekey.DefaultCreated holds the default value on creation for the created field.
|
||||
agekey.DefaultCreated = agekeyDescCreated.Default.(func() time.Time)
|
||||
// agekeyDescUpdated is the schema descriptor for updated field.
|
||||
agekeyDescUpdated := agekeyFields[3].Descriptor()
|
||||
// agekey.DefaultUpdated holds the default value on creation for the updated field.
|
||||
agekey.DefaultUpdated = agekeyDescUpdated.Default.(func() time.Time)
|
||||
// agekeyDescID is the schema descriptor for id field.
|
||||
agekeyDescID := agekeyFields[0].Descriptor()
|
||||
// agekey.DefaultID holds the default value on creation for the id field.
|
||||
agekey.DefaultID = agekeyDescID.Default.(func() uuid.UUID)
|
||||
hibpFields := schema.HIBP{}.Fields()
|
||||
_ = hibpFields
|
||||
// hibpDescIsVerified is the schema descriptor for is_verified field.
|
||||
|
@ -42,6 +65,48 @@ func init() {
|
|||
hibpDescIsMalware := hibpFields[14].Descriptor()
|
||||
// hibp.DefaultIsMalware holds the default value on creation for the is_malware field.
|
||||
hibp.DefaultIsMalware = hibpDescIsMalware.Default.(bool)
|
||||
localbreachFields := schema.LocalBreach{}.Fields()
|
||||
_ = localbreachFields
|
||||
// localbreachDescName is the schema descriptor for name field.
|
||||
localbreachDescName := localbreachFields[1].Descriptor()
|
||||
// localbreach.NameValidator is a validator for the "name" field. It is called by the builders before save.
|
||||
localbreach.NameValidator = localbreachDescName.Validators[0].(func(string) error)
|
||||
// localbreachDescDate is the schema descriptor for date field.
|
||||
localbreachDescDate := localbreachFields[2].Descriptor()
|
||||
// localbreach.DefaultDate holds the default value on creation for the date field.
|
||||
localbreach.DefaultDate = localbreachDescDate.Default.(time.Time)
|
||||
// localbreachDescCreatedAt is the schema descriptor for created_at field.
|
||||
localbreachDescCreatedAt := localbreachFields[12].Descriptor()
|
||||
// localbreach.DefaultCreatedAt holds the default value on creation for the created_at field.
|
||||
localbreach.DefaultCreatedAt = localbreachDescCreatedAt.Default.(time.Time)
|
||||
// localbreachDescID is the schema descriptor for id field.
|
||||
localbreachDescID := localbreachFields[0].Descriptor()
|
||||
// localbreach.DefaultID holds the default value on creation for the id field.
|
||||
localbreach.DefaultID = localbreachDescID.Default.(func() uuid.UUID)
|
||||
searchqueryFields := schema.SearchQuery{}.Fields()
|
||||
_ = searchqueryFields
|
||||
// searchqueryDescQuery is the schema descriptor for query field.
|
||||
searchqueryDescQuery := searchqueryFields[1].Descriptor()
|
||||
// searchquery.QueryValidator is a validator for the "query" field. It is called by the builders before save.
|
||||
searchquery.QueryValidator = searchqueryDescQuery.Validators[0].(func(string) error)
|
||||
// searchqueryDescCreated is the schema descriptor for created field.
|
||||
searchqueryDescCreated := searchqueryFields[2].Descriptor()
|
||||
// searchquery.DefaultCreated holds the default value on creation for the created field.
|
||||
searchquery.DefaultCreated = searchqueryDescCreated.Default.(func() time.Time)
|
||||
// searchqueryDescID is the schema descriptor for id field.
|
||||
searchqueryDescID := searchqueryFields[0].Descriptor()
|
||||
// searchquery.DefaultID holds the default value on creation for the id field.
|
||||
searchquery.DefaultID = searchqueryDescID.Default.(func() uuid.UUID)
|
||||
settingsFields := schema.Settings{}.Fields()
|
||||
_ = settingsFields
|
||||
// settingsDescSearches is the schema descriptor for searches field.
|
||||
settingsDescSearches := settingsFields[3].Descriptor()
|
||||
// settings.DefaultSearches holds the default value on creation for the searches field.
|
||||
settings.DefaultSearches = settingsDescSearches.Default.(uint64)
|
||||
// settingsDescID is the schema descriptor for id field.
|
||||
settingsDescID := settingsFields[0].Descriptor()
|
||||
// settings.DefaultID holds the default value on creation for the id field.
|
||||
settings.DefaultID = settingsDescID.Default.(func() uuid.UUID)
|
||||
setupFields := schema.Setup{}.Fields()
|
||||
_ = setupFields
|
||||
// setupDescSetUpAt is the schema descriptor for set_up_at field.
|
||||
|
@ -52,16 +117,55 @@ func init() {
|
|||
setupDescID := setupFields[0].Descriptor()
|
||||
// setup.DefaultID holds the default value on creation for the id field.
|
||||
setup.DefaultID = setupDescID.Default.(func() uuid.UUID)
|
||||
trackedbreachesFields := schema.TrackedBreaches{}.Fields()
|
||||
_ = trackedbreachesFields
|
||||
// trackedbreachesDescOnline is the schema descriptor for online field.
|
||||
trackedbreachesDescOnline := trackedbreachesFields[2].Descriptor()
|
||||
// trackedbreaches.DefaultOnline holds the default value on creation for the online field.
|
||||
trackedbreaches.DefaultOnline = trackedbreachesDescOnline.Default.(bool)
|
||||
// trackedbreachesDescID is the schema descriptor for id field.
|
||||
trackedbreachesDescID := trackedbreachesFields[0].Descriptor()
|
||||
// trackedbreaches.DefaultID holds the default value on creation for the id field.
|
||||
trackedbreaches.DefaultID = trackedbreachesDescID.Default.(func() uuid.UUID)
|
||||
userFields := schema.User{}.Fields()
|
||||
_ = userFields
|
||||
// userDescUsername is the schema descriptor for username field.
|
||||
userDescUsername := userFields[1].Descriptor()
|
||||
// user.UsernameValidator is a validator for the "username" field. It is called by the builders before save.
|
||||
user.UsernameValidator = userDescUsername.Validators[0].(func(string) error)
|
||||
user.UsernameValidator = func() func(string) error {
|
||||
validators := userDescUsername.Validators
|
||||
fns := [...]func(string) error{
|
||||
validators[0].(func(string) error),
|
||||
validators[1].(func(string) error),
|
||||
validators[2].(func(string) error),
|
||||
}
|
||||
return func(username string) error {
|
||||
for _, fn := range fns {
|
||||
if err := fn(username); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}()
|
||||
// userDescEmail is the schema descriptor for email field.
|
||||
userDescEmail := userFields[2].Descriptor()
|
||||
// user.EmailValidator is a validator for the "email" field. It is called by the builders before save.
|
||||
user.EmailValidator = userDescEmail.Validators[0].(func(string) error)
|
||||
user.EmailValidator = func() func(string) error {
|
||||
validators := userDescEmail.Validators
|
||||
fns := [...]func(string) error{
|
||||
validators[0].(func(string) error),
|
||||
validators[1].(func(string) error),
|
||||
}
|
||||
return func(email string) error {
|
||||
for _, fn := range fns {
|
||||
if err := fn(email); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}()
|
||||
// userDescPassword is the schema descriptor for password field.
|
||||
userDescPassword := userFields[3].Descriptor()
|
||||
// user.PasswordValidator is a validator for the "password" field. It is called by the builders before save.
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// AgeKey holds the schema definition for the AgeKey entity.
|
||||
type AgeKey struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the AgeKey.
|
||||
func (AgeKey) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New).
|
||||
Unique().
|
||||
Immutable(),
|
||||
field.Bytes("key").
|
||||
Nillable().
|
||||
NotEmpty().
|
||||
Comment("age ed25519 identity stored encrypted using AES256"),
|
||||
field.Time("created").
|
||||
Default(time.Now).
|
||||
Immutable(),
|
||||
field.Time("updated").
|
||||
Default(time.Now),
|
||||
field.UUID("owner", uuid.UUID{}).
|
||||
Comment("id of the key owner").
|
||||
// every user should only ever have one key, so no id should ever
|
||||
// be used twice in this column.
|
||||
Unique().
|
||||
// the owner of the key never changes.
|
||||
Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the AgeKey.
|
||||
func (AgeKey) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).
|
||||
Ref("agekey").
|
||||
Field("owner").
|
||||
Unique().
|
||||
Immutable().
|
||||
Required(),
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ package schema
|
|||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -32,7 +33,9 @@ func (HIBP) Fields() []ent.Field {
|
|||
field.Time("modified_date"),
|
||||
field.Int("pwn_count"),
|
||||
field.String("description").
|
||||
Comment("May contain HTML markup"),
|
||||
Comment("May contain HTML markup.").
|
||||
Optional().
|
||||
Nillable(),
|
||||
field.Strings("dataclasses"),
|
||||
field.Bool("is_verified").
|
||||
Default(false),
|
||||
|
@ -47,11 +50,17 @@ func (HIBP) Fields() []ent.Field {
|
|||
field.Bool("is_malware").
|
||||
Default(false),
|
||||
field.String("logo").
|
||||
Comment("Always in PNG format"),
|
||||
Comment("Always in PNG format.").
|
||||
Optional().
|
||||
Nillable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the HIBP.
|
||||
func (HIBP) Edges() []ent.Edge {
|
||||
return nil
|
||||
return []ent.Edge{
|
||||
edge.From("tracked_breaches", TrackedBreaches.Type).
|
||||
Ref("hibp").
|
||||
Unique(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// LocalBreach holds the schema definition for the LocalBreach entity.
|
||||
type LocalBreach struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the LocalBreach.
|
||||
func (LocalBreach) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New).
|
||||
Unique().
|
||||
Immutable(),
|
||||
// Unique but may change.
|
||||
field.String("name").
|
||||
Unique().
|
||||
NotEmpty(),
|
||||
field.Time("date").
|
||||
Default(time.Now()),
|
||||
field.String("description").
|
||||
Optional().
|
||||
Nillable(),
|
||||
field.Bool("is_verified"),
|
||||
field.Bool("contains_passwds"),
|
||||
field.Bool("contains_hashes"),
|
||||
field.Bool("contains_emails"),
|
||||
field.String("hash_type").
|
||||
Comment("MD5, SHA1, Argon2id...").
|
||||
Optional().
|
||||
Nillable(),
|
||||
field.Bool("hash_salted").
|
||||
Optional().
|
||||
Nillable(),
|
||||
field.Bool("hash_peppered").
|
||||
Optional().
|
||||
Nillable(),
|
||||
field.String("data").
|
||||
Optional().
|
||||
Nillable(),
|
||||
field.Time("created_at").
|
||||
Default(time.Now()).
|
||||
Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the LocalBreach.
|
||||
func (LocalBreach) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("tracked_breaches", TrackedBreaches.Type).
|
||||
Ref("localbreach"),
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// SearchQuery holds the schema definition for the SearchQuery entity.
|
||||
type SearchQuery struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the SearchQuery.
|
||||
func (SearchQuery) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New).
|
||||
Unique().
|
||||
Immutable(),
|
||||
field.String("query").
|
||||
NotEmpty().
|
||||
Immutable(),
|
||||
field.Time("created").
|
||||
Default(time.Now).
|
||||
Immutable(),
|
||||
field.UUID("owner", uuid.UUID{}).
|
||||
Comment("id of the user that's done the search query").
|
||||
Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the SearchQuery.
|
||||
func (SearchQuery) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).
|
||||
Ref("search_queries").
|
||||
Field("owner").
|
||||
Unique().
|
||||
Immutable().
|
||||
Required(),
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Settings holds the schema definition for the Settings entity.
|
||||
type Settings struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Settings.
|
||||
func (Settings) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New).
|
||||
Unique().
|
||||
Immutable(),
|
||||
field.String("hibp_api_key").
|
||||
Comment("api key for the hibp service").
|
||||
Sensitive().
|
||||
Optional().
|
||||
Unique(),
|
||||
field.String("dehashed_api_key").
|
||||
Comment("api key for the dehashed.com service").
|
||||
Sensitive().
|
||||
Optional().
|
||||
Unique(),
|
||||
field.Uint64("searches").
|
||||
Comment("the number of searches performed").
|
||||
Default(0),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Settings.
|
||||
func (Settings) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// TrackedBreaches holds the schema definition for the TrackedBreaches entity.
|
||||
type TrackedBreaches struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the TrackedBreaches.
|
||||
func (TrackedBreaches) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.UUID("id", uuid.UUID{}).
|
||||
Default(uuid.New).
|
||||
Unique().
|
||||
Immutable(),
|
||||
field.UUID("breach", uuid.UUID{}),
|
||||
field.Bool("online").
|
||||
Default(true).
|
||||
Immutable().
|
||||
Comment("Whether the breach is a locally added one or obtained from an online service"),
|
||||
field.UUID("owner", uuid.UUID{}).
|
||||
Comment("id of the user tracking the breach").
|
||||
Immutable(),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the TrackedBreaches.
|
||||
func (TrackedBreaches) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).
|
||||
Ref("tracked_breaches").
|
||||
Field("owner").
|
||||
Unique().
|
||||
Immutable().
|
||||
Required(),
|
||||
edge.To("localbreach", LocalBreach.Type),
|
||||
edge.To("hibp", HIBP.Type),
|
||||
}
|
||||
}
|
|
@ -4,9 +4,12 @@
|
|||
package schema
|
||||
|
||||
import (
|
||||
"net/mail"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -16,6 +19,8 @@ type User struct {
|
|||
ent.Schema
|
||||
}
|
||||
|
||||
const usernameRegex = `(^[\S]+)([A-Za-z1-9<>~+_-])$`
|
||||
|
||||
// Fields of the User.
|
||||
func (User) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
|
@ -25,10 +30,17 @@ func (User) Fields() []ent.Field {
|
|||
Immutable(),
|
||||
field.String("username").
|
||||
NotEmpty().
|
||||
Unique(),
|
||||
Unique().
|
||||
MinLen(2).
|
||||
Match(regexp.MustCompile(usernameRegex)).
|
||||
Comment("user's handle, allowed `<>~+-_` symbols and alphanumeric ASCII characters, including capital letters"),
|
||||
field.String("email").
|
||||
NotEmpty().
|
||||
Unique(),
|
||||
Unique().
|
||||
Validate(func(email string) error {
|
||||
_, err := mail.ParseAddress(email)
|
||||
return err
|
||||
}),
|
||||
field.Bytes("password").
|
||||
Sensitive().
|
||||
NotEmpty(),
|
||||
|
@ -45,10 +57,18 @@ func (User) Fields() []ent.Field {
|
|||
field.Time("last_login").
|
||||
Default(time.Unix(0, 0)).
|
||||
UpdateDefault(time.Now),
|
||||
// field.Bool("save_search_queries").
|
||||
// Default(true),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return nil
|
||||
return []ent.Edge{
|
||||
edge.To("agekey", AgeKey.Type).
|
||||
Unique().
|
||||
Immutable(),
|
||||
edge.To("tracked_breaches", TrackedBreaches.Type),
|
||||
edge.To("search_queries", SearchQuery.Type),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,121 @@
|
|||
// Copyright 2023 wanderer <a_mirre at utb dot cz>
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package schema
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUsernameRegex(t *testing.T) {
|
||||
testCases := []struct {
|
||||
Username string
|
||||
Match bool
|
||||
}{
|
||||
{
|
||||
Username: "", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "a", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "aa", Match: true,
|
||||
},
|
||||
{
|
||||
Username: "admin", Match: true,
|
||||
},
|
||||
{
|
||||
Username: "+asd+", Match: true,
|
||||
},
|
||||
{
|
||||
Username: "a~", Match: true,
|
||||
},
|
||||
{
|
||||
Username: "a~a", Match: true,
|
||||
},
|
||||
{
|
||||
Username: ".", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "...", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "_____~", Match: true,
|
||||
},
|
||||
{
|
||||
Username: "a_____", Match: true,
|
||||
},
|
||||
{
|
||||
Username: "+_+", Match: true,
|
||||
},
|
||||
{
|
||||
Username: "+ _+", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "+_+ ", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "+_ +", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "dsa dfsa", Match: false,
|
||||
},
|
||||
{
|
||||
Username: " ", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "\t ", Match: false,
|
||||
},
|
||||
{
|
||||
Username: " <M dsa>", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "<Mdsa>", Match: true,
|
||||
},
|
||||
{
|
||||
Username: "[]", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "[a]", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "a]", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "]", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "[a]]", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "[[a]", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "{}", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "{a}", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "()", Match: false,
|
||||
},
|
||||
{
|
||||
Username: "(a)", Match: false,
|
||||
},
|
||||
}
|
||||
|
||||
r := regexp.MustCompile(usernameRegex)
|
||||
|
||||
for _, tc := range testCases {
|
||||
want := tc.Match
|
||||
got := r.MatchString(tc.Username)
|
||||
|
||||
if got != want {
|
||||
t.Errorf("mismatch for username %q: want: %t, got: %t", tc.Username, want, got)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,160 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// SearchQuery is the model entity for the SearchQuery schema.
|
||||
type SearchQuery struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// Query holds the value of the "query" field.
|
||||
Query string `json:"query,omitempty"`
|
||||
// Created holds the value of the "created" field.
|
||||
Created time.Time `json:"created,omitempty"`
|
||||
// id of the user that's done the search query
|
||||
Owner uuid.UUID `json:"owner,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the SearchQueryQuery when eager-loading is set.
|
||||
Edges SearchQueryEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// SearchQueryEdges holds the relations/edges for other nodes in the graph.
|
||||
type SearchQueryEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e SearchQueryEdges) UserOrErr() (*User, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.User == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return e.User, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*SearchQuery) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case searchquery.FieldQuery:
|
||||
values[i] = new(sql.NullString)
|
||||
case searchquery.FieldCreated:
|
||||
values[i] = new(sql.NullTime)
|
||||
case searchquery.FieldID, searchquery.FieldOwner:
|
||||
values[i] = new(uuid.UUID)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the SearchQuery fields.
|
||||
func (sq *SearchQuery) 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 searchquery.FieldID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
sq.ID = *value
|
||||
}
|
||||
case searchquery.FieldQuery:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field query", values[i])
|
||||
} else if value.Valid {
|
||||
sq.Query = value.String
|
||||
}
|
||||
case searchquery.FieldCreated:
|
||||
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field created", values[i])
|
||||
} else if value.Valid {
|
||||
sq.Created = value.Time
|
||||
}
|
||||
case searchquery.FieldOwner:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field owner", values[i])
|
||||
} else if value != nil {
|
||||
sq.Owner = *value
|
||||
}
|
||||
default:
|
||||
sq.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the SearchQuery.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (sq *SearchQuery) Value(name string) (ent.Value, error) {
|
||||
return sq.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the SearchQuery entity.
|
||||
func (sq *SearchQuery) QueryUser() *UserQuery {
|
||||
return NewSearchQueryClient(sq.config).QueryUser(sq)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this SearchQuery.
|
||||
// Note that you need to call SearchQuery.Unwrap() before calling this method if this SearchQuery
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (sq *SearchQuery) Update() *SearchQueryUpdateOne {
|
||||
return NewSearchQueryClient(sq.config).UpdateOne(sq)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the SearchQuery 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 (sq *SearchQuery) Unwrap() *SearchQuery {
|
||||
_tx, ok := sq.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: SearchQuery is not a transactional entity")
|
||||
}
|
||||
sq.config.driver = _tx.drv
|
||||
return sq
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (sq *SearchQuery) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("SearchQuery(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", sq.ID))
|
||||
builder.WriteString("query=")
|
||||
builder.WriteString(sq.Query)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("created=")
|
||||
builder.WriteString(sq.Created.Format(time.ANSIC))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("owner=")
|
||||
builder.WriteString(fmt.Sprintf("%v", sq.Owner))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// SearchQueries is a parsable slice of SearchQuery.
|
||||
type SearchQueries []*SearchQuery
|
|
@ -0,0 +1,99 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package searchquery
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the searchquery type in the database.
|
||||
Label = "search_query"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldQuery holds the string denoting the query field in the database.
|
||||
FieldQuery = "query"
|
||||
// FieldCreated holds the string denoting the created field in the database.
|
||||
FieldCreated = "created"
|
||||
// FieldOwner holds the string denoting the owner field in the database.
|
||||
FieldOwner = "owner"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// Table holds the table name of the searchquery in the database.
|
||||
Table = "search_queries"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "search_queries"
|
||||
// UserInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "owner"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for searchquery fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldQuery,
|
||||
FieldCreated,
|
||||
FieldOwner,
|
||||
}
|
||||
|
||||
// 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 (
|
||||
// QueryValidator is a validator for the "query" field. It is called by the builders before save.
|
||||
QueryValidator func(string) error
|
||||
// DefaultCreated holds the default value on creation for the "created" field.
|
||||
DefaultCreated func() time.Time
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the SearchQuery queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByQuery orders the results by the query field.
|
||||
func ByQuery(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldQuery, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreated orders the results by the created field.
|
||||
func ByCreated(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldCreated, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOwner orders the results by the owner field.
|
||||
func ByOwner(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOwner, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserField orders the results by user field.
|
||||
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
}
|
|
@ -0,0 +1,252 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package searchquery
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"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.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Query applies equality check predicate on the "query" field. It's identical to QueryEQ.
|
||||
func Query(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldEQ(FieldQuery, v))
|
||||
}
|
||||
|
||||
// Created applies equality check predicate on the "created" field. It's identical to CreatedEQ.
|
||||
func Created(v time.Time) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldEQ(FieldCreated, v))
|
||||
}
|
||||
|
||||
// Owner applies equality check predicate on the "owner" field. It's identical to OwnerEQ.
|
||||
func Owner(v uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldEQ(FieldOwner, v))
|
||||
}
|
||||
|
||||
// QueryEQ applies the EQ predicate on the "query" field.
|
||||
func QueryEQ(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldEQ(FieldQuery, v))
|
||||
}
|
||||
|
||||
// QueryNEQ applies the NEQ predicate on the "query" field.
|
||||
func QueryNEQ(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldNEQ(FieldQuery, v))
|
||||
}
|
||||
|
||||
// QueryIn applies the In predicate on the "query" field.
|
||||
func QueryIn(vs ...string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldIn(FieldQuery, vs...))
|
||||
}
|
||||
|
||||
// QueryNotIn applies the NotIn predicate on the "query" field.
|
||||
func QueryNotIn(vs ...string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldNotIn(FieldQuery, vs...))
|
||||
}
|
||||
|
||||
// QueryGT applies the GT predicate on the "query" field.
|
||||
func QueryGT(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldGT(FieldQuery, v))
|
||||
}
|
||||
|
||||
// QueryGTE applies the GTE predicate on the "query" field.
|
||||
func QueryGTE(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldGTE(FieldQuery, v))
|
||||
}
|
||||
|
||||
// QueryLT applies the LT predicate on the "query" field.
|
||||
func QueryLT(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldLT(FieldQuery, v))
|
||||
}
|
||||
|
||||
// QueryLTE applies the LTE predicate on the "query" field.
|
||||
func QueryLTE(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldLTE(FieldQuery, v))
|
||||
}
|
||||
|
||||
// QueryContains applies the Contains predicate on the "query" field.
|
||||
func QueryContains(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldContains(FieldQuery, v))
|
||||
}
|
||||
|
||||
// QueryHasPrefix applies the HasPrefix predicate on the "query" field.
|
||||
func QueryHasPrefix(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldHasPrefix(FieldQuery, v))
|
||||
}
|
||||
|
||||
// QueryHasSuffix applies the HasSuffix predicate on the "query" field.
|
||||
func QueryHasSuffix(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldHasSuffix(FieldQuery, v))
|
||||
}
|
||||
|
||||
// QueryEqualFold applies the EqualFold predicate on the "query" field.
|
||||
func QueryEqualFold(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldEqualFold(FieldQuery, v))
|
||||
}
|
||||
|
||||
// QueryContainsFold applies the ContainsFold predicate on the "query" field.
|
||||
func QueryContainsFold(v string) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldContainsFold(FieldQuery, v))
|
||||
}
|
||||
|
||||
// CreatedEQ applies the EQ predicate on the "created" field.
|
||||
func CreatedEQ(v time.Time) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldEQ(FieldCreated, v))
|
||||
}
|
||||
|
||||
// CreatedNEQ applies the NEQ predicate on the "created" field.
|
||||
func CreatedNEQ(v time.Time) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldNEQ(FieldCreated, v))
|
||||
}
|
||||
|
||||
// CreatedIn applies the In predicate on the "created" field.
|
||||
func CreatedIn(vs ...time.Time) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldIn(FieldCreated, vs...))
|
||||
}
|
||||
|
||||
// CreatedNotIn applies the NotIn predicate on the "created" field.
|
||||
func CreatedNotIn(vs ...time.Time) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldNotIn(FieldCreated, vs...))
|
||||
}
|
||||
|
||||
// CreatedGT applies the GT predicate on the "created" field.
|
||||
func CreatedGT(v time.Time) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldGT(FieldCreated, v))
|
||||
}
|
||||
|
||||
// CreatedGTE applies the GTE predicate on the "created" field.
|
||||
func CreatedGTE(v time.Time) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldGTE(FieldCreated, v))
|
||||
}
|
||||
|
||||
// CreatedLT applies the LT predicate on the "created" field.
|
||||
func CreatedLT(v time.Time) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldLT(FieldCreated, v))
|
||||
}
|
||||
|
||||
// CreatedLTE applies the LTE predicate on the "created" field.
|
||||
func CreatedLTE(v time.Time) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldLTE(FieldCreated, v))
|
||||
}
|
||||
|
||||
// OwnerEQ applies the EQ predicate on the "owner" field.
|
||||
func OwnerEQ(v uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldEQ(FieldOwner, v))
|
||||
}
|
||||
|
||||
// OwnerNEQ applies the NEQ predicate on the "owner" field.
|
||||
func OwnerNEQ(v uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldNEQ(FieldOwner, v))
|
||||
}
|
||||
|
||||
// OwnerIn applies the In predicate on the "owner" field.
|
||||
func OwnerIn(vs ...uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldIn(FieldOwner, vs...))
|
||||
}
|
||||
|
||||
// OwnerNotIn applies the NotIn predicate on the "owner" field.
|
||||
func OwnerNotIn(vs ...uuid.UUID) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(sql.FieldNotIn(FieldOwner, vs...))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.SearchQuery {
|
||||
return predicate.SearchQuery(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.User) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(func(s *sql.Selector) {
|
||||
step := newUserStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.SearchQuery) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(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.SearchQuery) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(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.SearchQuery) predicate.SearchQuery {
|
||||
return predicate.SearchQuery(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
|
@ -0,0 +1,281 @@
|
|||
// 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/searchquery"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// SearchQueryCreate is the builder for creating a SearchQuery entity.
|
||||
type SearchQueryCreate struct {
|
||||
config
|
||||
mutation *SearchQueryMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetQuery sets the "query" field.
|
||||
func (sqc *SearchQueryCreate) SetQuery(s string) *SearchQueryCreate {
|
||||
sqc.mutation.SetQuery(s)
|
||||
return sqc
|
||||
}
|
||||
|
||||
// SetCreated sets the "created" field.
|
||||
func (sqc *SearchQueryCreate) SetCreated(t time.Time) *SearchQueryCreate {
|
||||
sqc.mutation.SetCreated(t)
|
||||
return sqc
|
||||
}
|
||||
|
||||
// SetNillableCreated sets the "created" field if the given value is not nil.
|
||||
func (sqc *SearchQueryCreate) SetNillableCreated(t *time.Time) *SearchQueryCreate {
|
||||
if t != nil {
|
||||
sqc.SetCreated(*t)
|
||||
}
|
||||
return sqc
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" field.
|
||||
func (sqc *SearchQueryCreate) SetOwner(u uuid.UUID) *SearchQueryCreate {
|
||||
sqc.mutation.SetOwner(u)
|
||||
return sqc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (sqc *SearchQueryCreate) SetID(u uuid.UUID) *SearchQueryCreate {
|
||||
sqc.mutation.SetID(u)
|
||||
return sqc
|
||||
}
|
||||
|
||||
// SetNillableID sets the "id" field if the given value is not nil.
|
||||
func (sqc *SearchQueryCreate) SetNillableID(u *uuid.UUID) *SearchQueryCreate {
|
||||
if u != nil {
|
||||
sqc.SetID(*u)
|
||||
}
|
||||
return sqc
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by ID.
|
||||
func (sqc *SearchQueryCreate) SetUserID(id uuid.UUID) *SearchQueryCreate {
|
||||
sqc.mutation.SetUserID(id)
|
||||
return sqc
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (sqc *SearchQueryCreate) SetUser(u *User) *SearchQueryCreate {
|
||||
return sqc.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SearchQueryMutation object of the builder.
|
||||
func (sqc *SearchQueryCreate) Mutation() *SearchQueryMutation {
|
||||
return sqc.mutation
|
||||
}
|
||||
|
||||
// Save creates the SearchQuery in the database.
|
||||
func (sqc *SearchQueryCreate) Save(ctx context.Context) (*SearchQuery, error) {
|
||||
sqc.defaults()
|
||||
return withHooks(ctx, sqc.sqlSave, sqc.mutation, sqc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (sqc *SearchQueryCreate) SaveX(ctx context.Context) *SearchQuery {
|
||||
v, err := sqc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (sqc *SearchQueryCreate) Exec(ctx context.Context) error {
|
||||
_, err := sqc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sqc *SearchQueryCreate) ExecX(ctx context.Context) {
|
||||
if err := sqc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (sqc *SearchQueryCreate) defaults() {
|
||||
if _, ok := sqc.mutation.Created(); !ok {
|
||||
v := searchquery.DefaultCreated()
|
||||
sqc.mutation.SetCreated(v)
|
||||
}
|
||||
if _, ok := sqc.mutation.ID(); !ok {
|
||||
v := searchquery.DefaultID()
|
||||
sqc.mutation.SetID(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (sqc *SearchQueryCreate) check() error {
|
||||
if _, ok := sqc.mutation.Query(); !ok {
|
||||
return &ValidationError{Name: "query", err: errors.New(`ent: missing required field "SearchQuery.query"`)}
|
||||
}
|
||||
if v, ok := sqc.mutation.Query(); ok {
|
||||
if err := searchquery.QueryValidator(v); err != nil {
|
||||
return &ValidationError{Name: "query", err: fmt.Errorf(`ent: validator failed for field "SearchQuery.query": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := sqc.mutation.Created(); !ok {
|
||||
return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "SearchQuery.created"`)}
|
||||
}
|
||||
if _, ok := sqc.mutation.Owner(); !ok {
|
||||
return &ValidationError{Name: "owner", err: errors.New(`ent: missing required field "SearchQuery.owner"`)}
|
||||
}
|
||||
if _, ok := sqc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "SearchQuery.user"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sqc *SearchQueryCreate) sqlSave(ctx context.Context) (*SearchQuery, error) {
|
||||
if err := sqc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := sqc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, sqc.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
|
||||
}
|
||||
}
|
||||
sqc.mutation.id = &_node.ID
|
||||
sqc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (sqc *SearchQueryCreate) createSpec() (*SearchQuery, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &SearchQuery{config: sqc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(searchquery.Table, sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID))
|
||||
)
|
||||
if id, ok := sqc.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := sqc.mutation.Query(); ok {
|
||||
_spec.SetField(searchquery.FieldQuery, field.TypeString, value)
|
||||
_node.Query = value
|
||||
}
|
||||
if value, ok := sqc.mutation.Created(); ok {
|
||||
_spec.SetField(searchquery.FieldCreated, field.TypeTime, value)
|
||||
_node.Created = value
|
||||
}
|
||||
if nodes := sqc.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: searchquery.UserTable,
|
||||
Columns: []string{searchquery.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.Owner = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// SearchQueryCreateBulk is the builder for creating many SearchQuery entities in bulk.
|
||||
type SearchQueryCreateBulk struct {
|
||||
config
|
||||
builders []*SearchQueryCreate
|
||||
}
|
||||
|
||||
// Save creates the SearchQuery entities in the database.
|
||||
func (sqcb *SearchQueryCreateBulk) Save(ctx context.Context) ([]*SearchQuery, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(sqcb.builders))
|
||||
nodes := make([]*SearchQuery, len(sqcb.builders))
|
||||
mutators := make([]Mutator, len(sqcb.builders))
|
||||
for i := range sqcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := sqcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SearchQueryMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, sqcb.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, sqcb.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, sqcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (sqcb *SearchQueryCreateBulk) SaveX(ctx context.Context) []*SearchQuery {
|
||||
v, err := sqcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (sqcb *SearchQueryCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := sqcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sqcb *SearchQueryCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := sqcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -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/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
|
||||
)
|
||||
|
||||
// SearchQueryDelete is the builder for deleting a SearchQuery entity.
|
||||
type SearchQueryDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SearchQueryMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SearchQueryDelete builder.
|
||||
func (sqd *SearchQueryDelete) Where(ps ...predicate.SearchQuery) *SearchQueryDelete {
|
||||
sqd.mutation.Where(ps...)
|
||||
return sqd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (sqd *SearchQueryDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, sqd.sqlExec, sqd.mutation, sqd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sqd *SearchQueryDelete) ExecX(ctx context.Context) int {
|
||||
n, err := sqd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (sqd *SearchQueryDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(searchquery.Table, sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID))
|
||||
if ps := sqd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, sqd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
sqd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SearchQueryDeleteOne is the builder for deleting a single SearchQuery entity.
|
||||
type SearchQueryDeleteOne struct {
|
||||
sqd *SearchQueryDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SearchQueryDelete builder.
|
||||
func (sqdo *SearchQueryDeleteOne) Where(ps ...predicate.SearchQuery) *SearchQueryDeleteOne {
|
||||
sqdo.sqd.mutation.Where(ps...)
|
||||
return sqdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (sqdo *SearchQueryDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := sqdo.sqd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{searchquery.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sqdo *SearchQueryDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := sqdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,606 @@
|
|||
// 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/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// SearchQueryQuery is the builder for querying SearchQuery entities.
|
||||
type SearchQueryQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []searchquery.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.SearchQuery
|
||||
withUser *UserQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the SearchQueryQuery builder.
|
||||
func (sqq *SearchQueryQuery) Where(ps ...predicate.SearchQuery) *SearchQueryQuery {
|
||||
sqq.predicates = append(sqq.predicates, ps...)
|
||||
return sqq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (sqq *SearchQueryQuery) Limit(limit int) *SearchQueryQuery {
|
||||
sqq.ctx.Limit = &limit
|
||||
return sqq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (sqq *SearchQueryQuery) Offset(offset int) *SearchQueryQuery {
|
||||
sqq.ctx.Offset = &offset
|
||||
return sqq
|
||||
}
|
||||
|
||||
// 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 (sqq *SearchQueryQuery) Unique(unique bool) *SearchQueryQuery {
|
||||
sqq.ctx.Unique = &unique
|
||||
return sqq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (sqq *SearchQueryQuery) Order(o ...searchquery.OrderOption) *SearchQueryQuery {
|
||||
sqq.order = append(sqq.order, o...)
|
||||
return sqq
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (sqq *SearchQueryQuery) QueryUser() *UserQuery {
|
||||
query := (&UserClient{config: sqq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := sqq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := sqq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(searchquery.Table, searchquery.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, searchquery.UserTable, searchquery.UserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(sqq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first SearchQuery entity from the query.
|
||||
// Returns a *NotFoundError when no SearchQuery was found.
|
||||
func (sqq *SearchQueryQuery) First(ctx context.Context) (*SearchQuery, error) {
|
||||
nodes, err := sqq.Limit(1).All(setContextOp(ctx, sqq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{searchquery.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (sqq *SearchQueryQuery) FirstX(ctx context.Context) *SearchQuery {
|
||||
node, err := sqq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first SearchQuery ID from the query.
|
||||
// Returns a *NotFoundError when no SearchQuery ID was found.
|
||||
func (sqq *SearchQueryQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = sqq.Limit(1).IDs(setContextOp(ctx, sqq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{searchquery.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (sqq *SearchQueryQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := sqq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single SearchQuery entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one SearchQuery entity is found.
|
||||
// Returns a *NotFoundError when no SearchQuery entities are found.
|
||||
func (sqq *SearchQueryQuery) Only(ctx context.Context) (*SearchQuery, error) {
|
||||
nodes, err := sqq.Limit(2).All(setContextOp(ctx, sqq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{searchquery.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{searchquery.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (sqq *SearchQueryQuery) OnlyX(ctx context.Context) *SearchQuery {
|
||||
node, err := sqq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only SearchQuery ID in the query.
|
||||
// Returns a *NotSingularError when more than one SearchQuery ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (sqq *SearchQueryQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = sqq.Limit(2).IDs(setContextOp(ctx, sqq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{searchquery.Label}
|
||||
default:
|
||||
err = &NotSingularError{searchquery.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (sqq *SearchQueryQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := sqq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of SearchQueries.
|
||||
func (sqq *SearchQueryQuery) All(ctx context.Context) ([]*SearchQuery, error) {
|
||||
ctx = setContextOp(ctx, sqq.ctx, "All")
|
||||
if err := sqq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*SearchQuery, *SearchQueryQuery]()
|
||||
return withInterceptors[[]*SearchQuery](ctx, sqq, qr, sqq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (sqq *SearchQueryQuery) AllX(ctx context.Context) []*SearchQuery {
|
||||
nodes, err := sqq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of SearchQuery IDs.
|
||||
func (sqq *SearchQueryQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||
if sqq.ctx.Unique == nil && sqq.path != nil {
|
||||
sqq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, sqq.ctx, "IDs")
|
||||
if err = sqq.Select(searchquery.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (sqq *SearchQueryQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||
ids, err := sqq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (sqq *SearchQueryQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, sqq.ctx, "Count")
|
||||
if err := sqq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, sqq, querierCount[*SearchQueryQuery](), sqq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (sqq *SearchQueryQuery) CountX(ctx context.Context) int {
|
||||
count, err := sqq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (sqq *SearchQueryQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, sqq.ctx, "Exist")
|
||||
switch _, err := sqq.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 (sqq *SearchQueryQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := sqq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the SearchQueryQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (sqq *SearchQueryQuery) Clone() *SearchQueryQuery {
|
||||
if sqq == nil {
|
||||
return nil
|
||||
}
|
||||
return &SearchQueryQuery{
|
||||
config: sqq.config,
|
||||
ctx: sqq.ctx.Clone(),
|
||||
order: append([]searchquery.OrderOption{}, sqq.order...),
|
||||
inters: append([]Interceptor{}, sqq.inters...),
|
||||
predicates: append([]predicate.SearchQuery{}, sqq.predicates...),
|
||||
withUser: sqq.withUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: sqq.sql.Clone(),
|
||||
path: sqq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (sqq *SearchQueryQuery) WithUser(opts ...func(*UserQuery)) *SearchQueryQuery {
|
||||
query := (&UserClient{config: sqq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
sqq.withUser = query
|
||||
return sqq
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// Query string `json:"query,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.SearchQuery.Query().
|
||||
// GroupBy(searchquery.FieldQuery).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (sqq *SearchQueryQuery) GroupBy(field string, fields ...string) *SearchQueryGroupBy {
|
||||
sqq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &SearchQueryGroupBy{build: sqq}
|
||||
grbuild.flds = &sqq.ctx.Fields
|
||||
grbuild.label = searchquery.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 {
|
||||
// Query string `json:"query,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.SearchQuery.Query().
|
||||
// Select(searchquery.FieldQuery).
|
||||
// Scan(ctx, &v)
|
||||
func (sqq *SearchQueryQuery) Select(fields ...string) *SearchQuerySelect {
|
||||
sqq.ctx.Fields = append(sqq.ctx.Fields, fields...)
|
||||
sbuild := &SearchQuerySelect{SearchQueryQuery: sqq}
|
||||
sbuild.label = searchquery.Label
|
||||
sbuild.flds, sbuild.scan = &sqq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a SearchQuerySelect configured with the given aggregations.
|
||||
func (sqq *SearchQueryQuery) Aggregate(fns ...AggregateFunc) *SearchQuerySelect {
|
||||
return sqq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (sqq *SearchQueryQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range sqq.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, sqq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range sqq.ctx.Fields {
|
||||
if !searchquery.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if sqq.path != nil {
|
||||
prev, err := sqq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sqq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sqq *SearchQueryQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*SearchQuery, error) {
|
||||
var (
|
||||
nodes = []*SearchQuery{}
|
||||
_spec = sqq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
sqq.withUser != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*SearchQuery).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &SearchQuery{config: sqq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, sqq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := sqq.withUser; query != nil {
|
||||
if err := sqq.loadUser(ctx, query, nodes, nil,
|
||||
func(n *SearchQuery, e *User) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (sqq *SearchQueryQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*SearchQuery, init func(*SearchQuery), assign func(*SearchQuery, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*SearchQuery)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].Owner
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "owner" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sqq *SearchQueryQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := sqq.querySpec()
|
||||
_spec.Node.Columns = sqq.ctx.Fields
|
||||
if len(sqq.ctx.Fields) > 0 {
|
||||
_spec.Unique = sqq.ctx.Unique != nil && *sqq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, sqq.driver, _spec)
|
||||
}
|
||||
|
||||
func (sqq *SearchQueryQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(searchquery.Table, searchquery.Columns, sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID))
|
||||
_spec.From = sqq.sql
|
||||
if unique := sqq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if sqq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := sqq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, searchquery.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != searchquery.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if sqq.withUser != nil {
|
||||
_spec.Node.AddColumnOnce(searchquery.FieldOwner)
|
||||
}
|
||||
}
|
||||
if ps := sqq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := sqq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := sqq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := sqq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (sqq *SearchQueryQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(sqq.driver.Dialect())
|
||||
t1 := builder.Table(searchquery.Table)
|
||||
columns := sqq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = searchquery.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if sqq.sql != nil {
|
||||
selector = sqq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if sqq.ctx.Unique != nil && *sqq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range sqq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range sqq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := sqq.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 := sqq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// SearchQueryGroupBy is the group-by builder for SearchQuery entities.
|
||||
type SearchQueryGroupBy struct {
|
||||
selector
|
||||
build *SearchQueryQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (sqgb *SearchQueryGroupBy) Aggregate(fns ...AggregateFunc) *SearchQueryGroupBy {
|
||||
sqgb.fns = append(sqgb.fns, fns...)
|
||||
return sqgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (sqgb *SearchQueryGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, sqgb.build.ctx, "GroupBy")
|
||||
if err := sqgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*SearchQueryQuery, *SearchQueryGroupBy](ctx, sqgb.build, sqgb, sqgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (sqgb *SearchQueryGroupBy) sqlScan(ctx context.Context, root *SearchQueryQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(sqgb.fns))
|
||||
for _, fn := range sqgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*sqgb.flds)+len(sqgb.fns))
|
||||
for _, f := range *sqgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*sqgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := sqgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// SearchQuerySelect is the builder for selecting fields of SearchQuery entities.
|
||||
type SearchQuerySelect struct {
|
||||
*SearchQueryQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (sqs *SearchQuerySelect) Aggregate(fns ...AggregateFunc) *SearchQuerySelect {
|
||||
sqs.fns = append(sqs.fns, fns...)
|
||||
return sqs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (sqs *SearchQuerySelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, sqs.ctx, "Select")
|
||||
if err := sqs.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*SearchQueryQuery, *SearchQuerySelect](ctx, sqs.SearchQueryQuery, sqs, sqs.inters, v)
|
||||
}
|
||||
|
||||
func (sqs *SearchQuerySelect) sqlScan(ctx context.Context, root *SearchQueryQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(sqs.fns))
|
||||
for _, fn := range sqs.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*sqs.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 := sqs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
|
@ -0,0 +1,197 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
|
||||
)
|
||||
|
||||
// SearchQueryUpdate is the builder for updating SearchQuery entities.
|
||||
type SearchQueryUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SearchQueryMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SearchQueryUpdate builder.
|
||||
func (squ *SearchQueryUpdate) Where(ps ...predicate.SearchQuery) *SearchQueryUpdate {
|
||||
squ.mutation.Where(ps...)
|
||||
return squ
|
||||
}
|
||||
|
||||
// Mutation returns the SearchQueryMutation object of the builder.
|
||||
func (squ *SearchQueryUpdate) Mutation() *SearchQueryMutation {
|
||||
return squ.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (squ *SearchQueryUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, squ.sqlSave, squ.mutation, squ.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (squ *SearchQueryUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := squ.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (squ *SearchQueryUpdate) Exec(ctx context.Context) error {
|
||||
_, err := squ.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (squ *SearchQueryUpdate) ExecX(ctx context.Context) {
|
||||
if err := squ.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (squ *SearchQueryUpdate) check() error {
|
||||
if _, ok := squ.mutation.UserID(); squ.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "SearchQuery.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (squ *SearchQueryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := squ.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(searchquery.Table, searchquery.Columns, sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID))
|
||||
if ps := squ.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, squ.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{searchquery.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
squ.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// SearchQueryUpdateOne is the builder for updating a single SearchQuery entity.
|
||||
type SearchQueryUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *SearchQueryMutation
|
||||
}
|
||||
|
||||
// Mutation returns the SearchQueryMutation object of the builder.
|
||||
func (squo *SearchQueryUpdateOne) Mutation() *SearchQueryMutation {
|
||||
return squo.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SearchQueryUpdate builder.
|
||||
func (squo *SearchQueryUpdateOne) Where(ps ...predicate.SearchQuery) *SearchQueryUpdateOne {
|
||||
squo.mutation.Where(ps...)
|
||||
return squo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (squo *SearchQueryUpdateOne) Select(field string, fields ...string) *SearchQueryUpdateOne {
|
||||
squo.fields = append([]string{field}, fields...)
|
||||
return squo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated SearchQuery entity.
|
||||
func (squo *SearchQueryUpdateOne) Save(ctx context.Context) (*SearchQuery, error) {
|
||||
return withHooks(ctx, squo.sqlSave, squo.mutation, squo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (squo *SearchQueryUpdateOne) SaveX(ctx context.Context) *SearchQuery {
|
||||
node, err := squo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (squo *SearchQueryUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := squo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (squo *SearchQueryUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := squo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (squo *SearchQueryUpdateOne) check() error {
|
||||
if _, ok := squo.mutation.UserID(); squo.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "SearchQuery.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (squo *SearchQueryUpdateOne) sqlSave(ctx context.Context) (_node *SearchQuery, err error) {
|
||||
if err := squo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(searchquery.Table, searchquery.Columns, sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID))
|
||||
id, ok := squo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "SearchQuery.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := squo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, searchquery.FieldID)
|
||||
for _, f := range fields {
|
||||
if !searchquery.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != searchquery.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := squo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
_node = &SearchQuery{config: squo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, squo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{searchquery.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
squo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/settings"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// Settings is the model entity for the Settings schema.
|
||||
type Settings struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// api key for the hibp service
|
||||
HibpAPIKey string `json:"-"`
|
||||
// api key for the dehashed.com service
|
||||
DehashedAPIKey string `json:"-"`
|
||||
// the number of searches performed
|
||||
Searches uint64 `json:"searches,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Settings) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case settings.FieldSearches:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case settings.FieldHibpAPIKey, settings.FieldDehashedAPIKey:
|
||||
values[i] = new(sql.NullString)
|
||||
case settings.FieldID:
|
||||
values[i] = new(uuid.UUID)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Settings fields.
|
||||
func (s *Settings) 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 settings.FieldID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
s.ID = *value
|
||||
}
|
||||
case settings.FieldHibpAPIKey:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field hibp_api_key", values[i])
|
||||
} else if value.Valid {
|
||||
s.HibpAPIKey = value.String
|
||||
}
|
||||
case settings.FieldDehashedAPIKey:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field dehashed_api_key", values[i])
|
||||
} else if value.Valid {
|
||||
s.DehashedAPIKey = value.String
|
||||
}
|
||||
case settings.FieldSearches:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field searches", values[i])
|
||||
} else if value.Valid {
|
||||
s.Searches = uint64(value.Int64)
|
||||
}
|
||||
default:
|
||||
s.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Settings.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (s *Settings) Value(name string) (ent.Value, error) {
|
||||
return s.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Settings.
|
||||
// Note that you need to call Settings.Unwrap() before calling this method if this Settings
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (s *Settings) Update() *SettingsUpdateOne {
|
||||
return NewSettingsClient(s.config).UpdateOne(s)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Settings 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 (s *Settings) Unwrap() *Settings {
|
||||
_tx, ok := s.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Settings is not a transactional entity")
|
||||
}
|
||||
s.config.driver = _tx.drv
|
||||
return s
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (s *Settings) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Settings(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", s.ID))
|
||||
builder.WriteString("hibp_api_key=<sensitive>")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("dehashed_api_key=<sensitive>")
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("searches=")
|
||||
builder.WriteString(fmt.Sprintf("%v", s.Searches))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// SettingsSlice is a parsable slice of Settings.
|
||||
type SettingsSlice []*Settings
|
|
@ -0,0 +1,71 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the settings type in the database.
|
||||
Label = "settings"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldHibpAPIKey holds the string denoting the hibp_api_key field in the database.
|
||||
FieldHibpAPIKey = "hibp_api_key"
|
||||
// FieldDehashedAPIKey holds the string denoting the dehashed_api_key field in the database.
|
||||
FieldDehashedAPIKey = "dehashed_api_key"
|
||||
// FieldSearches holds the string denoting the searches field in the database.
|
||||
FieldSearches = "searches"
|
||||
// Table holds the table name of the settings in the database.
|
||||
Table = "settings"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for settings fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldHibpAPIKey,
|
||||
FieldDehashedAPIKey,
|
||||
FieldSearches,
|
||||
}
|
||||
|
||||
// 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 (
|
||||
// DefaultSearches holds the default value on creation for the "searches" field.
|
||||
DefaultSearches uint64
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the Settings queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByHibpAPIKey orders the results by the hibp_api_key field.
|
||||
func ByHibpAPIKey(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldHibpAPIKey, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByDehashedAPIKey orders the results by the dehashed_api_key field.
|
||||
func ByDehashedAPIKey(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldDehashedAPIKey, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySearches orders the results by the searches field.
|
||||
func BySearches(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSearches, opts...).ToFunc()
|
||||
}
|
|
@ -0,0 +1,291 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package settings
|
||||
|
||||
import (
|
||||
"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.Settings {
|
||||
return predicate.Settings(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id uuid.UUID) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id uuid.UUID) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...uuid.UUID) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...uuid.UUID) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id uuid.UUID) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id uuid.UUID) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id uuid.UUID) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id uuid.UUID) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// HibpAPIKey applies equality check predicate on the "hibp_api_key" field. It's identical to HibpAPIKeyEQ.
|
||||
func HibpAPIKey(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldEQ(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKey applies equality check predicate on the "dehashed_api_key" field. It's identical to DehashedAPIKeyEQ.
|
||||
func DehashedAPIKey(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldEQ(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// Searches applies equality check predicate on the "searches" field. It's identical to SearchesEQ.
|
||||
func Searches(v uint64) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldEQ(FieldSearches, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyEQ applies the EQ predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyEQ(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldEQ(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyNEQ applies the NEQ predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyNEQ(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldNEQ(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyIn applies the In predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyIn(vs ...string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldIn(FieldHibpAPIKey, vs...))
|
||||
}
|
||||
|
||||
// HibpAPIKeyNotIn applies the NotIn predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyNotIn(vs ...string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldNotIn(FieldHibpAPIKey, vs...))
|
||||
}
|
||||
|
||||
// HibpAPIKeyGT applies the GT predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyGT(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldGT(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyGTE applies the GTE predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyGTE(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldGTE(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyLT applies the LT predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyLT(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldLT(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyLTE applies the LTE predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyLTE(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldLTE(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyContains applies the Contains predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyContains(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldContains(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyHasPrefix applies the HasPrefix predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyHasPrefix(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldHasPrefix(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyHasSuffix applies the HasSuffix predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyHasSuffix(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldHasSuffix(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyIsNil applies the IsNil predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyIsNil() predicate.Settings {
|
||||
return predicate.Settings(sql.FieldIsNull(FieldHibpAPIKey))
|
||||
}
|
||||
|
||||
// HibpAPIKeyNotNil applies the NotNil predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyNotNil() predicate.Settings {
|
||||
return predicate.Settings(sql.FieldNotNull(FieldHibpAPIKey))
|
||||
}
|
||||
|
||||
// HibpAPIKeyEqualFold applies the EqualFold predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyEqualFold(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldEqualFold(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// HibpAPIKeyContainsFold applies the ContainsFold predicate on the "hibp_api_key" field.
|
||||
func HibpAPIKeyContainsFold(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldContainsFold(FieldHibpAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyEQ applies the EQ predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyEQ(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldEQ(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyNEQ applies the NEQ predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyNEQ(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldNEQ(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyIn applies the In predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyIn(vs ...string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldIn(FieldDehashedAPIKey, vs...))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyNotIn applies the NotIn predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyNotIn(vs ...string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldNotIn(FieldDehashedAPIKey, vs...))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyGT applies the GT predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyGT(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldGT(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyGTE applies the GTE predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyGTE(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldGTE(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyLT applies the LT predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyLT(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldLT(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyLTE applies the LTE predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyLTE(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldLTE(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyContains applies the Contains predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyContains(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldContains(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyHasPrefix applies the HasPrefix predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyHasPrefix(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldHasPrefix(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyHasSuffix applies the HasSuffix predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyHasSuffix(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldHasSuffix(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyIsNil applies the IsNil predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyIsNil() predicate.Settings {
|
||||
return predicate.Settings(sql.FieldIsNull(FieldDehashedAPIKey))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyNotNil applies the NotNil predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyNotNil() predicate.Settings {
|
||||
return predicate.Settings(sql.FieldNotNull(FieldDehashedAPIKey))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyEqualFold applies the EqualFold predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyEqualFold(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldEqualFold(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// DehashedAPIKeyContainsFold applies the ContainsFold predicate on the "dehashed_api_key" field.
|
||||
func DehashedAPIKeyContainsFold(v string) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldContainsFold(FieldDehashedAPIKey, v))
|
||||
}
|
||||
|
||||
// SearchesEQ applies the EQ predicate on the "searches" field.
|
||||
func SearchesEQ(v uint64) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldEQ(FieldSearches, v))
|
||||
}
|
||||
|
||||
// SearchesNEQ applies the NEQ predicate on the "searches" field.
|
||||
func SearchesNEQ(v uint64) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldNEQ(FieldSearches, v))
|
||||
}
|
||||
|
||||
// SearchesIn applies the In predicate on the "searches" field.
|
||||
func SearchesIn(vs ...uint64) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldIn(FieldSearches, vs...))
|
||||
}
|
||||
|
||||
// SearchesNotIn applies the NotIn predicate on the "searches" field.
|
||||
func SearchesNotIn(vs ...uint64) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldNotIn(FieldSearches, vs...))
|
||||
}
|
||||
|
||||
// SearchesGT applies the GT predicate on the "searches" field.
|
||||
func SearchesGT(v uint64) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldGT(FieldSearches, v))
|
||||
}
|
||||
|
||||
// SearchesGTE applies the GTE predicate on the "searches" field.
|
||||
func SearchesGTE(v uint64) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldGTE(FieldSearches, v))
|
||||
}
|
||||
|
||||
// SearchesLT applies the LT predicate on the "searches" field.
|
||||
func SearchesLT(v uint64) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldLT(FieldSearches, v))
|
||||
}
|
||||
|
||||
// SearchesLTE applies the LTE predicate on the "searches" field.
|
||||
func SearchesLTE(v uint64) predicate.Settings {
|
||||
return predicate.Settings(sql.FieldLTE(FieldSearches, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Settings) predicate.Settings {
|
||||
return predicate.Settings(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.Settings) predicate.Settings {
|
||||
return predicate.Settings(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.Settings) predicate.Settings {
|
||||
return predicate.Settings(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
|
@ -0,0 +1,257 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/settings"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// SettingsCreate is the builder for creating a Settings entity.
|
||||
type SettingsCreate struct {
|
||||
config
|
||||
mutation *SettingsMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetHibpAPIKey sets the "hibp_api_key" field.
|
||||
func (sc *SettingsCreate) SetHibpAPIKey(s string) *SettingsCreate {
|
||||
sc.mutation.SetHibpAPIKey(s)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableHibpAPIKey sets the "hibp_api_key" field if the given value is not nil.
|
||||
func (sc *SettingsCreate) SetNillableHibpAPIKey(s *string) *SettingsCreate {
|
||||
if s != nil {
|
||||
sc.SetHibpAPIKey(*s)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetDehashedAPIKey sets the "dehashed_api_key" field.
|
||||
func (sc *SettingsCreate) SetDehashedAPIKey(s string) *SettingsCreate {
|
||||
sc.mutation.SetDehashedAPIKey(s)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableDehashedAPIKey sets the "dehashed_api_key" field if the given value is not nil.
|
||||
func (sc *SettingsCreate) SetNillableDehashedAPIKey(s *string) *SettingsCreate {
|
||||
if s != nil {
|
||||
sc.SetDehashedAPIKey(*s)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetSearches sets the "searches" field.
|
||||
func (sc *SettingsCreate) SetSearches(u uint64) *SettingsCreate {
|
||||
sc.mutation.SetSearches(u)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableSearches sets the "searches" field if the given value is not nil.
|
||||
func (sc *SettingsCreate) SetNillableSearches(u *uint64) *SettingsCreate {
|
||||
if u != nil {
|
||||
sc.SetSearches(*u)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (sc *SettingsCreate) SetID(u uuid.UUID) *SettingsCreate {
|
||||
sc.mutation.SetID(u)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetNillableID sets the "id" field if the given value is not nil.
|
||||
func (sc *SettingsCreate) SetNillableID(u *uuid.UUID) *SettingsCreate {
|
||||
if u != nil {
|
||||
sc.SetID(*u)
|
||||
}
|
||||
return sc
|
||||
}
|
||||
|
||||
// Mutation returns the SettingsMutation object of the builder.
|
||||
func (sc *SettingsCreate) Mutation() *SettingsMutation {
|
||||
return sc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Settings in the database.
|
||||
func (sc *SettingsCreate) Save(ctx context.Context) (*Settings, error) {
|
||||
sc.defaults()
|
||||
return withHooks(ctx, sc.sqlSave, sc.mutation, sc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (sc *SettingsCreate) SaveX(ctx context.Context) *Settings {
|
||||
v, err := sc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (sc *SettingsCreate) Exec(ctx context.Context) error {
|
||||
_, err := sc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sc *SettingsCreate) ExecX(ctx context.Context) {
|
||||
if err := sc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (sc *SettingsCreate) defaults() {
|
||||
if _, ok := sc.mutation.Searches(); !ok {
|
||||
v := settings.DefaultSearches
|
||||
sc.mutation.SetSearches(v)
|
||||
}
|
||||
if _, ok := sc.mutation.ID(); !ok {
|
||||
v := settings.DefaultID()
|
||||
sc.mutation.SetID(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (sc *SettingsCreate) check() error {
|
||||
if _, ok := sc.mutation.Searches(); !ok {
|
||||
return &ValidationError{Name: "searches", err: errors.New(`ent: missing required field "Settings.searches"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sc *SettingsCreate) sqlSave(ctx context.Context) (*Settings, error) {
|
||||
if err := sc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := sc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, sc.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
|
||||
}
|
||||
}
|
||||
sc.mutation.id = &_node.ID
|
||||
sc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (sc *SettingsCreate) createSpec() (*Settings, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Settings{config: sc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(settings.Table, sqlgraph.NewFieldSpec(settings.FieldID, field.TypeUUID))
|
||||
)
|
||||
if id, ok := sc.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := sc.mutation.HibpAPIKey(); ok {
|
||||
_spec.SetField(settings.FieldHibpAPIKey, field.TypeString, value)
|
||||
_node.HibpAPIKey = value
|
||||
}
|
||||
if value, ok := sc.mutation.DehashedAPIKey(); ok {
|
||||
_spec.SetField(settings.FieldDehashedAPIKey, field.TypeString, value)
|
||||
_node.DehashedAPIKey = value
|
||||
}
|
||||
if value, ok := sc.mutation.Searches(); ok {
|
||||
_spec.SetField(settings.FieldSearches, field.TypeUint64, value)
|
||||
_node.Searches = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// SettingsCreateBulk is the builder for creating many Settings entities in bulk.
|
||||
type SettingsCreateBulk struct {
|
||||
config
|
||||
builders []*SettingsCreate
|
||||
}
|
||||
|
||||
// Save creates the Settings entities in the database.
|
||||
func (scb *SettingsCreateBulk) Save(ctx context.Context) ([]*Settings, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
|
||||
nodes := make([]*Settings, len(scb.builders))
|
||||
mutators := make([]Mutator, len(scb.builders))
|
||||
for i := range scb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := scb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SettingsMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, scb.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, scb.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, scb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (scb *SettingsCreateBulk) SaveX(ctx context.Context) []*Settings {
|
||||
v, err := scb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (scb *SettingsCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := scb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (scb *SettingsCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := scb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -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/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/settings"
|
||||
)
|
||||
|
||||
// SettingsDelete is the builder for deleting a Settings entity.
|
||||
type SettingsDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SettingsMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SettingsDelete builder.
|
||||
func (sd *SettingsDelete) Where(ps ...predicate.Settings) *SettingsDelete {
|
||||
sd.mutation.Where(ps...)
|
||||
return sd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (sd *SettingsDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, sd.sqlExec, sd.mutation, sd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sd *SettingsDelete) ExecX(ctx context.Context) int {
|
||||
n, err := sd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (sd *SettingsDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(settings.Table, sqlgraph.NewFieldSpec(settings.FieldID, field.TypeUUID))
|
||||
if ps := sd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, sd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
sd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SettingsDeleteOne is the builder for deleting a single Settings entity.
|
||||
type SettingsDeleteOne struct {
|
||||
sd *SettingsDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SettingsDelete builder.
|
||||
func (sdo *SettingsDeleteOne) Where(ps ...predicate.Settings) *SettingsDeleteOne {
|
||||
sdo.sd.mutation.Where(ps...)
|
||||
return sdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (sdo *SettingsDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := sdo.sd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{settings.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sdo *SettingsDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := sdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -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/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/settings"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// SettingsQuery is the builder for querying Settings entities.
|
||||
type SettingsQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []settings.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Settings
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the SettingsQuery builder.
|
||||
func (sq *SettingsQuery) Where(ps ...predicate.Settings) *SettingsQuery {
|
||||
sq.predicates = append(sq.predicates, ps...)
|
||||
return sq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (sq *SettingsQuery) Limit(limit int) *SettingsQuery {
|
||||
sq.ctx.Limit = &limit
|
||||
return sq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (sq *SettingsQuery) Offset(offset int) *SettingsQuery {
|
||||
sq.ctx.Offset = &offset
|
||||
return sq
|
||||
}
|
||||
|
||||
// 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 (sq *SettingsQuery) Unique(unique bool) *SettingsQuery {
|
||||
sq.ctx.Unique = &unique
|
||||
return sq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (sq *SettingsQuery) Order(o ...settings.OrderOption) *SettingsQuery {
|
||||
sq.order = append(sq.order, o...)
|
||||
return sq
|
||||
}
|
||||
|
||||
// First returns the first Settings entity from the query.
|
||||
// Returns a *NotFoundError when no Settings was found.
|
||||
func (sq *SettingsQuery) First(ctx context.Context) (*Settings, error) {
|
||||
nodes, err := sq.Limit(1).All(setContextOp(ctx, sq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{settings.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (sq *SettingsQuery) FirstX(ctx context.Context) *Settings {
|
||||
node, err := sq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Settings ID from the query.
|
||||
// Returns a *NotFoundError when no Settings ID was found.
|
||||
func (sq *SettingsQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = sq.Limit(1).IDs(setContextOp(ctx, sq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{settings.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (sq *SettingsQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := sq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Settings entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Settings entity is found.
|
||||
// Returns a *NotFoundError when no Settings entities are found.
|
||||
func (sq *SettingsQuery) Only(ctx context.Context) (*Settings, error) {
|
||||
nodes, err := sq.Limit(2).All(setContextOp(ctx, sq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{settings.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{settings.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (sq *SettingsQuery) OnlyX(ctx context.Context) *Settings {
|
||||
node, err := sq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Settings ID in the query.
|
||||
// Returns a *NotSingularError when more than one Settings ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (sq *SettingsQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{settings.Label}
|
||||
default:
|
||||
err = &NotSingularError{settings.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (sq *SettingsQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := sq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of SettingsSlice.
|
||||
func (sq *SettingsQuery) All(ctx context.Context) ([]*Settings, error) {
|
||||
ctx = setContextOp(ctx, sq.ctx, "All")
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Settings, *SettingsQuery]()
|
||||
return withInterceptors[[]*Settings](ctx, sq, qr, sq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (sq *SettingsQuery) AllX(ctx context.Context) []*Settings {
|
||||
nodes, err := sq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Settings IDs.
|
||||
func (sq *SettingsQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||
if sq.ctx.Unique == nil && sq.path != nil {
|
||||
sq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, sq.ctx, "IDs")
|
||||
if err = sq.Select(settings.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (sq *SettingsQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||
ids, err := sq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (sq *SettingsQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, sq.ctx, "Count")
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, sq, querierCount[*SettingsQuery](), sq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (sq *SettingsQuery) CountX(ctx context.Context) int {
|
||||
count, err := sq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (sq *SettingsQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, sq.ctx, "Exist")
|
||||
switch _, err := sq.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 (sq *SettingsQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := sq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the SettingsQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (sq *SettingsQuery) Clone() *SettingsQuery {
|
||||
if sq == nil {
|
||||
return nil
|
||||
}
|
||||
return &SettingsQuery{
|
||||
config: sq.config,
|
||||
ctx: sq.ctx.Clone(),
|
||||
order: append([]settings.OrderOption{}, sq.order...),
|
||||
inters: append([]Interceptor{}, sq.inters...),
|
||||
predicates: append([]predicate.Settings{}, sq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: sq.sql.Clone(),
|
||||
path: sq.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 {
|
||||
// HibpAPIKey string `json:"hibp_api_key,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Settings.Query().
|
||||
// GroupBy(settings.FieldHibpAPIKey).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (sq *SettingsQuery) GroupBy(field string, fields ...string) *SettingsGroupBy {
|
||||
sq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &SettingsGroupBy{build: sq}
|
||||
grbuild.flds = &sq.ctx.Fields
|
||||
grbuild.label = settings.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 {
|
||||
// HibpAPIKey string `json:"hibp_api_key,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Settings.Query().
|
||||
// Select(settings.FieldHibpAPIKey).
|
||||
// Scan(ctx, &v)
|
||||
func (sq *SettingsQuery) Select(fields ...string) *SettingsSelect {
|
||||
sq.ctx.Fields = append(sq.ctx.Fields, fields...)
|
||||
sbuild := &SettingsSelect{SettingsQuery: sq}
|
||||
sbuild.label = settings.Label
|
||||
sbuild.flds, sbuild.scan = &sq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a SettingsSelect configured with the given aggregations.
|
||||
func (sq *SettingsQuery) Aggregate(fns ...AggregateFunc) *SettingsSelect {
|
||||
return sq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (sq *SettingsQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range sq.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, sq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range sq.ctx.Fields {
|
||||
if !settings.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if sq.path != nil {
|
||||
prev, err := sq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sq *SettingsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Settings, error) {
|
||||
var (
|
||||
nodes = []*Settings{}
|
||||
_spec = sq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Settings).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Settings{config: sq.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, sq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (sq *SettingsQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := sq.querySpec()
|
||||
_spec.Node.Columns = sq.ctx.Fields
|
||||
if len(sq.ctx.Fields) > 0 {
|
||||
_spec.Unique = sq.ctx.Unique != nil && *sq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, sq.driver, _spec)
|
||||
}
|
||||
|
||||
func (sq *SettingsQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(settings.Table, settings.Columns, sqlgraph.NewFieldSpec(settings.FieldID, field.TypeUUID))
|
||||
_spec.From = sq.sql
|
||||
if unique := sq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if sq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := sq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, settings.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != settings.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := sq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := sq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := sq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := sq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (sq *SettingsQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(sq.driver.Dialect())
|
||||
t1 := builder.Table(settings.Table)
|
||||
columns := sq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = settings.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if sq.sql != nil {
|
||||
selector = sq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if sq.ctx.Unique != nil && *sq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range sq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range sq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := sq.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 := sq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// SettingsGroupBy is the group-by builder for Settings entities.
|
||||
type SettingsGroupBy struct {
|
||||
selector
|
||||
build *SettingsQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (sgb *SettingsGroupBy) Aggregate(fns ...AggregateFunc) *SettingsGroupBy {
|
||||
sgb.fns = append(sgb.fns, fns...)
|
||||
return sgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (sgb *SettingsGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, sgb.build.ctx, "GroupBy")
|
||||
if err := sgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*SettingsQuery, *SettingsGroupBy](ctx, sgb.build, sgb, sgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (sgb *SettingsGroupBy) sqlScan(ctx context.Context, root *SettingsQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(sgb.fns))
|
||||
for _, fn := range sgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*sgb.flds)+len(sgb.fns))
|
||||
for _, f := range *sgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*sgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := sgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// SettingsSelect is the builder for selecting fields of Settings entities.
|
||||
type SettingsSelect struct {
|
||||
*SettingsQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ss *SettingsSelect) Aggregate(fns ...AggregateFunc) *SettingsSelect {
|
||||
ss.fns = append(ss.fns, fns...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ss *SettingsSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ss.ctx, "Select")
|
||||
if err := ss.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*SettingsQuery, *SettingsSelect](ctx, ss.SettingsQuery, ss, ss.inters, v)
|
||||
}
|
||||
|
||||
func (ss *SettingsSelect) sqlScan(ctx context.Context, root *SettingsQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ss.fns))
|
||||
for _, fn := range ss.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ss.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 := ss.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
|
@ -0,0 +1,333 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/settings"
|
||||
)
|
||||
|
||||
// SettingsUpdate is the builder for updating Settings entities.
|
||||
type SettingsUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SettingsMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SettingsUpdate builder.
|
||||
func (su *SettingsUpdate) Where(ps ...predicate.Settings) *SettingsUpdate {
|
||||
su.mutation.Where(ps...)
|
||||
return su
|
||||
}
|
||||
|
||||
// SetHibpAPIKey sets the "hibp_api_key" field.
|
||||
func (su *SettingsUpdate) SetHibpAPIKey(s string) *SettingsUpdate {
|
||||
su.mutation.SetHibpAPIKey(s)
|
||||
return su
|
||||
}
|
||||
|
||||
// SetNillableHibpAPIKey sets the "hibp_api_key" field if the given value is not nil.
|
||||
func (su *SettingsUpdate) SetNillableHibpAPIKey(s *string) *SettingsUpdate {
|
||||
if s != nil {
|
||||
su.SetHibpAPIKey(*s)
|
||||
}
|
||||
return su
|
||||
}
|
||||
|
||||
// ClearHibpAPIKey clears the value of the "hibp_api_key" field.
|
||||
func (su *SettingsUpdate) ClearHibpAPIKey() *SettingsUpdate {
|
||||
su.mutation.ClearHibpAPIKey()
|
||||
return su
|
||||
}
|
||||
|
||||
// SetDehashedAPIKey sets the "dehashed_api_key" field.
|
||||
func (su *SettingsUpdate) SetDehashedAPIKey(s string) *SettingsUpdate {
|
||||
su.mutation.SetDehashedAPIKey(s)
|
||||
return su
|
||||
}
|
||||
|
||||
// SetNillableDehashedAPIKey sets the "dehashed_api_key" field if the given value is not nil.
|
||||
func (su *SettingsUpdate) SetNillableDehashedAPIKey(s *string) *SettingsUpdate {
|
||||
if s != nil {
|
||||
su.SetDehashedAPIKey(*s)
|
||||
}
|
||||
return su
|
||||
}
|
||||
|
||||
// ClearDehashedAPIKey clears the value of the "dehashed_api_key" field.
|
||||
func (su *SettingsUpdate) ClearDehashedAPIKey() *SettingsUpdate {
|
||||
su.mutation.ClearDehashedAPIKey()
|
||||
return su
|
||||
}
|
||||
|
||||
// SetSearches sets the "searches" field.
|
||||
func (su *SettingsUpdate) SetSearches(u uint64) *SettingsUpdate {
|
||||
su.mutation.ResetSearches()
|
||||
su.mutation.SetSearches(u)
|
||||
return su
|
||||
}
|
||||
|
||||
// SetNillableSearches sets the "searches" field if the given value is not nil.
|
||||
func (su *SettingsUpdate) SetNillableSearches(u *uint64) *SettingsUpdate {
|
||||
if u != nil {
|
||||
su.SetSearches(*u)
|
||||
}
|
||||
return su
|
||||
}
|
||||
|
||||
// AddSearches adds u to the "searches" field.
|
||||
func (su *SettingsUpdate) AddSearches(u int64) *SettingsUpdate {
|
||||
su.mutation.AddSearches(u)
|
||||
return su
|
||||
}
|
||||
|
||||
// Mutation returns the SettingsMutation object of the builder.
|
||||
func (su *SettingsUpdate) Mutation() *SettingsMutation {
|
||||
return su.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (su *SettingsUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, su.sqlSave, su.mutation, su.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (su *SettingsUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := su.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (su *SettingsUpdate) Exec(ctx context.Context) error {
|
||||
_, err := su.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (su *SettingsUpdate) ExecX(ctx context.Context) {
|
||||
if err := su.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (su *SettingsUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(settings.Table, settings.Columns, sqlgraph.NewFieldSpec(settings.FieldID, field.TypeUUID))
|
||||
if ps := su.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := su.mutation.HibpAPIKey(); ok {
|
||||
_spec.SetField(settings.FieldHibpAPIKey, field.TypeString, value)
|
||||
}
|
||||
if su.mutation.HibpAPIKeyCleared() {
|
||||
_spec.ClearField(settings.FieldHibpAPIKey, field.TypeString)
|
||||
}
|
||||
if value, ok := su.mutation.DehashedAPIKey(); ok {
|
||||
_spec.SetField(settings.FieldDehashedAPIKey, field.TypeString, value)
|
||||
}
|
||||
if su.mutation.DehashedAPIKeyCleared() {
|
||||
_spec.ClearField(settings.FieldDehashedAPIKey, field.TypeString)
|
||||
}
|
||||
if value, ok := su.mutation.Searches(); ok {
|
||||
_spec.SetField(settings.FieldSearches, field.TypeUint64, value)
|
||||
}
|
||||
if value, ok := su.mutation.AddedSearches(); ok {
|
||||
_spec.AddField(settings.FieldSearches, field.TypeUint64, value)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{settings.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
su.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// SettingsUpdateOne is the builder for updating a single Settings entity.
|
||||
type SettingsUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *SettingsMutation
|
||||
}
|
||||
|
||||
// SetHibpAPIKey sets the "hibp_api_key" field.
|
||||
func (suo *SettingsUpdateOne) SetHibpAPIKey(s string) *SettingsUpdateOne {
|
||||
suo.mutation.SetHibpAPIKey(s)
|
||||
return suo
|
||||
}
|
||||
|
||||
// SetNillableHibpAPIKey sets the "hibp_api_key" field if the given value is not nil.
|
||||
func (suo *SettingsUpdateOne) SetNillableHibpAPIKey(s *string) *SettingsUpdateOne {
|
||||
if s != nil {
|
||||
suo.SetHibpAPIKey(*s)
|
||||
}
|
||||
return suo
|
||||
}
|
||||
|
||||
// ClearHibpAPIKey clears the value of the "hibp_api_key" field.
|
||||
func (suo *SettingsUpdateOne) ClearHibpAPIKey() *SettingsUpdateOne {
|
||||
suo.mutation.ClearHibpAPIKey()
|
||||
return suo
|
||||
}
|
||||
|
||||
// SetDehashedAPIKey sets the "dehashed_api_key" field.
|
||||
func (suo *SettingsUpdateOne) SetDehashedAPIKey(s string) *SettingsUpdateOne {
|
||||
suo.mutation.SetDehashedAPIKey(s)
|
||||
return suo
|
||||
}
|
||||
|
||||
// SetNillableDehashedAPIKey sets the "dehashed_api_key" field if the given value is not nil.
|
||||
func (suo *SettingsUpdateOne) SetNillableDehashedAPIKey(s *string) *SettingsUpdateOne {
|
||||
if s != nil {
|
||||
suo.SetDehashedAPIKey(*s)
|
||||
}
|
||||
return suo
|
||||
}
|
||||
|
||||
// ClearDehashedAPIKey clears the value of the "dehashed_api_key" field.
|
||||
func (suo *SettingsUpdateOne) ClearDehashedAPIKey() *SettingsUpdateOne {
|
||||
suo.mutation.ClearDehashedAPIKey()
|
||||
return suo
|
||||
}
|
||||
|
||||
// SetSearches sets the "searches" field.
|
||||
func (suo *SettingsUpdateOne) SetSearches(u uint64) *SettingsUpdateOne {
|
||||
suo.mutation.ResetSearches()
|
||||
suo.mutation.SetSearches(u)
|
||||
return suo
|
||||
}
|
||||
|
||||
// SetNillableSearches sets the "searches" field if the given value is not nil.
|
||||
func (suo *SettingsUpdateOne) SetNillableSearches(u *uint64) *SettingsUpdateOne {
|
||||
if u != nil {
|
||||
suo.SetSearches(*u)
|
||||
}
|
||||
return suo
|
||||
}
|
||||
|
||||
// AddSearches adds u to the "searches" field.
|
||||
func (suo *SettingsUpdateOne) AddSearches(u int64) *SettingsUpdateOne {
|
||||
suo.mutation.AddSearches(u)
|
||||
return suo
|
||||
}
|
||||
|
||||
// Mutation returns the SettingsMutation object of the builder.
|
||||
func (suo *SettingsUpdateOne) Mutation() *SettingsMutation {
|
||||
return suo.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SettingsUpdate builder.
|
||||
func (suo *SettingsUpdateOne) Where(ps ...predicate.Settings) *SettingsUpdateOne {
|
||||
suo.mutation.Where(ps...)
|
||||
return suo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (suo *SettingsUpdateOne) Select(field string, fields ...string) *SettingsUpdateOne {
|
||||
suo.fields = append([]string{field}, fields...)
|
||||
return suo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Settings entity.
|
||||
func (suo *SettingsUpdateOne) Save(ctx context.Context) (*Settings, error) {
|
||||
return withHooks(ctx, suo.sqlSave, suo.mutation, suo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (suo *SettingsUpdateOne) SaveX(ctx context.Context) *Settings {
|
||||
node, err := suo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (suo *SettingsUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := suo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (suo *SettingsUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := suo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (suo *SettingsUpdateOne) sqlSave(ctx context.Context) (_node *Settings, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(settings.Table, settings.Columns, sqlgraph.NewFieldSpec(settings.FieldID, field.TypeUUID))
|
||||
id, ok := suo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Settings.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := suo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, settings.FieldID)
|
||||
for _, f := range fields {
|
||||
if !settings.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != settings.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := suo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := suo.mutation.HibpAPIKey(); ok {
|
||||
_spec.SetField(settings.FieldHibpAPIKey, field.TypeString, value)
|
||||
}
|
||||
if suo.mutation.HibpAPIKeyCleared() {
|
||||
_spec.ClearField(settings.FieldHibpAPIKey, field.TypeString)
|
||||
}
|
||||
if value, ok := suo.mutation.DehashedAPIKey(); ok {
|
||||
_spec.SetField(settings.FieldDehashedAPIKey, field.TypeString, value)
|
||||
}
|
||||
if suo.mutation.DehashedAPIKeyCleared() {
|
||||
_spec.ClearField(settings.FieldDehashedAPIKey, field.TypeString)
|
||||
}
|
||||
if value, ok := suo.mutation.Searches(); ok {
|
||||
_spec.SetField(settings.FieldSearches, field.TypeUint64, value)
|
||||
}
|
||||
if value, ok := suo.mutation.AddedSearches(); ok {
|
||||
_spec.AddField(settings.FieldSearches, field.TypeUint64, value)
|
||||
}
|
||||
_node = &Settings{config: suo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{settings.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
suo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// TrackedBreaches is the model entity for the TrackedBreaches schema.
|
||||
type TrackedBreaches struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// Breach holds the value of the "breach" field.
|
||||
Breach uuid.UUID `json:"breach,omitempty"`
|
||||
// Whether the breach is a locally added one or obtained from an online service
|
||||
Online bool `json:"online,omitempty"`
|
||||
// id of the user tracking the breach
|
||||
Owner uuid.UUID `json:"owner,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the TrackedBreachesQuery when eager-loading is set.
|
||||
Edges TrackedBreachesEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// TrackedBreachesEdges holds the relations/edges for other nodes in the graph.
|
||||
type TrackedBreachesEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// Localbreach holds the value of the localbreach edge.
|
||||
Localbreach []*LocalBreach `json:"localbreach,omitempty"`
|
||||
// Hibp holds the value of the hibp edge.
|
||||
Hibp []*HIBP `json:"hibp,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [3]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e TrackedBreachesEdges) UserOrErr() (*User, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.User == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return e.User, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// LocalbreachOrErr returns the Localbreach value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e TrackedBreachesEdges) LocalbreachOrErr() ([]*LocalBreach, error) {
|
||||
if e.loadedTypes[1] {
|
||||
return e.Localbreach, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "localbreach"}
|
||||
}
|
||||
|
||||
// HibpOrErr returns the Hibp value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e TrackedBreachesEdges) HibpOrErr() ([]*HIBP, error) {
|
||||
if e.loadedTypes[2] {
|
||||
return e.Hibp, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "hibp"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*TrackedBreaches) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case trackedbreaches.FieldOnline:
|
||||
values[i] = new(sql.NullBool)
|
||||
case trackedbreaches.FieldID, trackedbreaches.FieldBreach, trackedbreaches.FieldOwner:
|
||||
values[i] = new(uuid.UUID)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the TrackedBreaches fields.
|
||||
func (tb *TrackedBreaches) 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 trackedbreaches.FieldID:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", values[i])
|
||||
} else if value != nil {
|
||||
tb.ID = *value
|
||||
}
|
||||
case trackedbreaches.FieldBreach:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field breach", values[i])
|
||||
} else if value != nil {
|
||||
tb.Breach = *value
|
||||
}
|
||||
case trackedbreaches.FieldOnline:
|
||||
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field online", values[i])
|
||||
} else if value.Valid {
|
||||
tb.Online = value.Bool
|
||||
}
|
||||
case trackedbreaches.FieldOwner:
|
||||
if value, ok := values[i].(*uuid.UUID); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field owner", values[i])
|
||||
} else if value != nil {
|
||||
tb.Owner = *value
|
||||
}
|
||||
default:
|
||||
tb.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the TrackedBreaches.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (tb *TrackedBreaches) Value(name string) (ent.Value, error) {
|
||||
return tb.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryUser queries the "user" edge of the TrackedBreaches entity.
|
||||
func (tb *TrackedBreaches) QueryUser() *UserQuery {
|
||||
return NewTrackedBreachesClient(tb.config).QueryUser(tb)
|
||||
}
|
||||
|
||||
// QueryLocalbreach queries the "localbreach" edge of the TrackedBreaches entity.
|
||||
func (tb *TrackedBreaches) QueryLocalbreach() *LocalBreachQuery {
|
||||
return NewTrackedBreachesClient(tb.config).QueryLocalbreach(tb)
|
||||
}
|
||||
|
||||
// QueryHibp queries the "hibp" edge of the TrackedBreaches entity.
|
||||
func (tb *TrackedBreaches) QueryHibp() *HIBPQuery {
|
||||
return NewTrackedBreachesClient(tb.config).QueryHibp(tb)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this TrackedBreaches.
|
||||
// Note that you need to call TrackedBreaches.Unwrap() before calling this method if this TrackedBreaches
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (tb *TrackedBreaches) Update() *TrackedBreachesUpdateOne {
|
||||
return NewTrackedBreachesClient(tb.config).UpdateOne(tb)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the TrackedBreaches 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 (tb *TrackedBreaches) Unwrap() *TrackedBreaches {
|
||||
_tx, ok := tb.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: TrackedBreaches is not a transactional entity")
|
||||
}
|
||||
tb.config.driver = _tx.drv
|
||||
return tb
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (tb *TrackedBreaches) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("TrackedBreaches(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", tb.ID))
|
||||
builder.WriteString("breach=")
|
||||
builder.WriteString(fmt.Sprintf("%v", tb.Breach))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("online=")
|
||||
builder.WriteString(fmt.Sprintf("%v", tb.Online))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("owner=")
|
||||
builder.WriteString(fmt.Sprintf("%v", tb.Owner))
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// TrackedBreachesSlice is a parsable slice of TrackedBreaches.
|
||||
type TrackedBreachesSlice []*TrackedBreaches
|
|
@ -0,0 +1,159 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package trackedbreaches
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the trackedbreaches type in the database.
|
||||
Label = "tracked_breaches"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldBreach holds the string denoting the breach field in the database.
|
||||
FieldBreach = "breach"
|
||||
// FieldOnline holds the string denoting the online field in the database.
|
||||
FieldOnline = "online"
|
||||
// FieldOwner holds the string denoting the owner field in the database.
|
||||
FieldOwner = "owner"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// EdgeLocalbreach holds the string denoting the localbreach edge name in mutations.
|
||||
EdgeLocalbreach = "localbreach"
|
||||
// EdgeHibp holds the string denoting the hibp edge name in mutations.
|
||||
EdgeHibp = "hibp"
|
||||
// Table holds the table name of the trackedbreaches in the database.
|
||||
Table = "tracked_breaches"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
UserTable = "tracked_breaches"
|
||||
// UserInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "owner"
|
||||
// LocalbreachTable is the table that holds the localbreach relation/edge. The primary key declared below.
|
||||
LocalbreachTable = "tracked_breaches_localbreach"
|
||||
// LocalbreachInverseTable is the table name for the LocalBreach entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "localbreach" package.
|
||||
LocalbreachInverseTable = "local_breaches"
|
||||
// HibpTable is the table that holds the hibp relation/edge.
|
||||
HibpTable = "hib_ps"
|
||||
// HibpInverseTable is the table name for the HIBP entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "hibp" package.
|
||||
HibpInverseTable = "hib_ps"
|
||||
// HibpColumn is the table column denoting the hibp relation/edge.
|
||||
HibpColumn = "tracked_breaches_hibp"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for trackedbreaches fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldBreach,
|
||||
FieldOnline,
|
||||
FieldOwner,
|
||||
}
|
||||
|
||||
var (
|
||||
// LocalbreachPrimaryKey and LocalbreachColumn2 are the table columns denoting the
|
||||
// primary key for the localbreach relation (M2M).
|
||||
LocalbreachPrimaryKey = []string{"tracked_breaches_id", "local_breach_id"}
|
||||
)
|
||||
|
||||
// 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 (
|
||||
// DefaultOnline holds the default value on creation for the "online" field.
|
||||
DefaultOnline bool
|
||||
// DefaultID holds the default value on creation for the "id" field.
|
||||
DefaultID func() uuid.UUID
|
||||
)
|
||||
|
||||
// OrderOption defines the ordering options for the TrackedBreaches queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByBreach orders the results by the breach field.
|
||||
func ByBreach(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldBreach, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOnline orders the results by the online field.
|
||||
func ByOnline(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOnline, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByOwner orders the results by the owner field.
|
||||
func ByOwner(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldOwner, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUserField orders the results by user field.
|
||||
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByLocalbreachCount orders the results by localbreach count.
|
||||
func ByLocalbreachCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newLocalbreachStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByLocalbreach orders the results by localbreach terms.
|
||||
func ByLocalbreach(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newLocalbreachStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByHibpCount orders the results by hibp count.
|
||||
func ByHibpCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newHibpStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByHibp orders the results by hibp terms.
|
||||
func ByHibp(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newHibpStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(UserInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
}
|
||||
func newLocalbreachStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(LocalbreachInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, LocalbreachTable, LocalbreachPrimaryKey...),
|
||||
)
|
||||
}
|
||||
func newHibpStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(HibpInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, HibpTable, HibpColumn),
|
||||
)
|
||||
}
|
|
@ -0,0 +1,241 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package trackedbreaches
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"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.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Breach applies equality check predicate on the "breach" field. It's identical to BreachEQ.
|
||||
func Breach(v uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldEQ(FieldBreach, v))
|
||||
}
|
||||
|
||||
// Online applies equality check predicate on the "online" field. It's identical to OnlineEQ.
|
||||
func Online(v bool) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldEQ(FieldOnline, v))
|
||||
}
|
||||
|
||||
// Owner applies equality check predicate on the "owner" field. It's identical to OwnerEQ.
|
||||
func Owner(v uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldEQ(FieldOwner, v))
|
||||
}
|
||||
|
||||
// BreachEQ applies the EQ predicate on the "breach" field.
|
||||
func BreachEQ(v uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldEQ(FieldBreach, v))
|
||||
}
|
||||
|
||||
// BreachNEQ applies the NEQ predicate on the "breach" field.
|
||||
func BreachNEQ(v uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldNEQ(FieldBreach, v))
|
||||
}
|
||||
|
||||
// BreachIn applies the In predicate on the "breach" field.
|
||||
func BreachIn(vs ...uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldIn(FieldBreach, vs...))
|
||||
}
|
||||
|
||||
// BreachNotIn applies the NotIn predicate on the "breach" field.
|
||||
func BreachNotIn(vs ...uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldNotIn(FieldBreach, vs...))
|
||||
}
|
||||
|
||||
// BreachGT applies the GT predicate on the "breach" field.
|
||||
func BreachGT(v uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldGT(FieldBreach, v))
|
||||
}
|
||||
|
||||
// BreachGTE applies the GTE predicate on the "breach" field.
|
||||
func BreachGTE(v uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldGTE(FieldBreach, v))
|
||||
}
|
||||
|
||||
// BreachLT applies the LT predicate on the "breach" field.
|
||||
func BreachLT(v uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldLT(FieldBreach, v))
|
||||
}
|
||||
|
||||
// BreachLTE applies the LTE predicate on the "breach" field.
|
||||
func BreachLTE(v uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldLTE(FieldBreach, v))
|
||||
}
|
||||
|
||||
// OnlineEQ applies the EQ predicate on the "online" field.
|
||||
func OnlineEQ(v bool) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldEQ(FieldOnline, v))
|
||||
}
|
||||
|
||||
// OnlineNEQ applies the NEQ predicate on the "online" field.
|
||||
func OnlineNEQ(v bool) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldNEQ(FieldOnline, v))
|
||||
}
|
||||
|
||||
// OwnerEQ applies the EQ predicate on the "owner" field.
|
||||
func OwnerEQ(v uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldEQ(FieldOwner, v))
|
||||
}
|
||||
|
||||
// OwnerNEQ applies the NEQ predicate on the "owner" field.
|
||||
func OwnerNEQ(v uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldNEQ(FieldOwner, v))
|
||||
}
|
||||
|
||||
// OwnerIn applies the In predicate on the "owner" field.
|
||||
func OwnerIn(vs ...uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldIn(FieldOwner, vs...))
|
||||
}
|
||||
|
||||
// OwnerNotIn applies the NotIn predicate on the "owner" field.
|
||||
func OwnerNotIn(vs ...uuid.UUID) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(sql.FieldNotIn(FieldOwner, vs...))
|
||||
}
|
||||
|
||||
// HasUser applies the HasEdge predicate on the "user" edge.
|
||||
func HasUser() predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasUserWith applies the HasEdge predicate on the "user" edge with a given conditions (other predicates).
|
||||
func HasUserWith(preds ...predicate.User) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(func(s *sql.Selector) {
|
||||
step := newUserStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasLocalbreach applies the HasEdge predicate on the "localbreach" edge.
|
||||
func HasLocalbreach() predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, LocalbreachTable, LocalbreachPrimaryKey...),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasLocalbreachWith applies the HasEdge predicate on the "localbreach" edge with a given conditions (other predicates).
|
||||
func HasLocalbreachWith(preds ...predicate.LocalBreach) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(func(s *sql.Selector) {
|
||||
step := newLocalbreachStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasHibp applies the HasEdge predicate on the "hibp" edge.
|
||||
func HasHibp() predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, HibpTable, HibpColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasHibpWith applies the HasEdge predicate on the "hibp" edge with a given conditions (other predicates).
|
||||
func HasHibpWith(preds ...predicate.HIBP) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(func(s *sql.Selector) {
|
||||
step := newHibpStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.TrackedBreaches) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(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.TrackedBreaches) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(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.TrackedBreaches) predicate.TrackedBreaches {
|
||||
return predicate.TrackedBreaches(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
|
@ -0,0 +1,339 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"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/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// TrackedBreachesCreate is the builder for creating a TrackedBreaches entity.
|
||||
type TrackedBreachesCreate struct {
|
||||
config
|
||||
mutation *TrackedBreachesMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetBreach sets the "breach" field.
|
||||
func (tbc *TrackedBreachesCreate) SetBreach(u uuid.UUID) *TrackedBreachesCreate {
|
||||
tbc.mutation.SetBreach(u)
|
||||
return tbc
|
||||
}
|
||||
|
||||
// SetOnline sets the "online" field.
|
||||
func (tbc *TrackedBreachesCreate) SetOnline(b bool) *TrackedBreachesCreate {
|
||||
tbc.mutation.SetOnline(b)
|
||||
return tbc
|
||||
}
|
||||
|
||||
// SetNillableOnline sets the "online" field if the given value is not nil.
|
||||
func (tbc *TrackedBreachesCreate) SetNillableOnline(b *bool) *TrackedBreachesCreate {
|
||||
if b != nil {
|
||||
tbc.SetOnline(*b)
|
||||
}
|
||||
return tbc
|
||||
}
|
||||
|
||||
// SetOwner sets the "owner" field.
|
||||
func (tbc *TrackedBreachesCreate) SetOwner(u uuid.UUID) *TrackedBreachesCreate {
|
||||
tbc.mutation.SetOwner(u)
|
||||
return tbc
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (tbc *TrackedBreachesCreate) SetID(u uuid.UUID) *TrackedBreachesCreate {
|
||||
tbc.mutation.SetID(u)
|
||||
return tbc
|
||||
}
|
||||
|
||||
// SetNillableID sets the "id" field if the given value is not nil.
|
||||
func (tbc *TrackedBreachesCreate) SetNillableID(u *uuid.UUID) *TrackedBreachesCreate {
|
||||
if u != nil {
|
||||
tbc.SetID(*u)
|
||||
}
|
||||
return tbc
|
||||
}
|
||||
|
||||
// SetUserID sets the "user" edge to the User entity by ID.
|
||||
func (tbc *TrackedBreachesCreate) SetUserID(id uuid.UUID) *TrackedBreachesCreate {
|
||||
tbc.mutation.SetUserID(id)
|
||||
return tbc
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (tbc *TrackedBreachesCreate) SetUser(u *User) *TrackedBreachesCreate {
|
||||
return tbc.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// AddLocalbreachIDs adds the "localbreach" edge to the LocalBreach entity by IDs.
|
||||
func (tbc *TrackedBreachesCreate) AddLocalbreachIDs(ids ...uuid.UUID) *TrackedBreachesCreate {
|
||||
tbc.mutation.AddLocalbreachIDs(ids...)
|
||||
return tbc
|
||||
}
|
||||
|
||||
// AddLocalbreach adds the "localbreach" edges to the LocalBreach entity.
|
||||
func (tbc *TrackedBreachesCreate) AddLocalbreach(l ...*LocalBreach) *TrackedBreachesCreate {
|
||||
ids := make([]uuid.UUID, len(l))
|
||||
for i := range l {
|
||||
ids[i] = l[i].ID
|
||||
}
|
||||
return tbc.AddLocalbreachIDs(ids...)
|
||||
}
|
||||
|
||||
// AddHibpIDs adds the "hibp" edge to the HIBP entity by IDs.
|
||||
func (tbc *TrackedBreachesCreate) AddHibpIDs(ids ...uuid.UUID) *TrackedBreachesCreate {
|
||||
tbc.mutation.AddHibpIDs(ids...)
|
||||
return tbc
|
||||
}
|
||||
|
||||
// AddHibp adds the "hibp" edges to the HIBP entity.
|
||||
func (tbc *TrackedBreachesCreate) AddHibp(h ...*HIBP) *TrackedBreachesCreate {
|
||||
ids := make([]uuid.UUID, len(h))
|
||||
for i := range h {
|
||||
ids[i] = h[i].ID
|
||||
}
|
||||
return tbc.AddHibpIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the TrackedBreachesMutation object of the builder.
|
||||
func (tbc *TrackedBreachesCreate) Mutation() *TrackedBreachesMutation {
|
||||
return tbc.mutation
|
||||
}
|
||||
|
||||
// Save creates the TrackedBreaches in the database.
|
||||
func (tbc *TrackedBreachesCreate) Save(ctx context.Context) (*TrackedBreaches, error) {
|
||||
tbc.defaults()
|
||||
return withHooks(ctx, tbc.sqlSave, tbc.mutation, tbc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (tbc *TrackedBreachesCreate) SaveX(ctx context.Context) *TrackedBreaches {
|
||||
v, err := tbc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (tbc *TrackedBreachesCreate) Exec(ctx context.Context) error {
|
||||
_, err := tbc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tbc *TrackedBreachesCreate) ExecX(ctx context.Context) {
|
||||
if err := tbc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (tbc *TrackedBreachesCreate) defaults() {
|
||||
if _, ok := tbc.mutation.Online(); !ok {
|
||||
v := trackedbreaches.DefaultOnline
|
||||
tbc.mutation.SetOnline(v)
|
||||
}
|
||||
if _, ok := tbc.mutation.ID(); !ok {
|
||||
v := trackedbreaches.DefaultID()
|
||||
tbc.mutation.SetID(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (tbc *TrackedBreachesCreate) check() error {
|
||||
if _, ok := tbc.mutation.Breach(); !ok {
|
||||
return &ValidationError{Name: "breach", err: errors.New(`ent: missing required field "TrackedBreaches.breach"`)}
|
||||
}
|
||||
if _, ok := tbc.mutation.Online(); !ok {
|
||||
return &ValidationError{Name: "online", err: errors.New(`ent: missing required field "TrackedBreaches.online"`)}
|
||||
}
|
||||
if _, ok := tbc.mutation.Owner(); !ok {
|
||||
return &ValidationError{Name: "owner", err: errors.New(`ent: missing required field "TrackedBreaches.owner"`)}
|
||||
}
|
||||
if _, ok := tbc.mutation.UserID(); !ok {
|
||||
return &ValidationError{Name: "user", err: errors.New(`ent: missing required edge "TrackedBreaches.user"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tbc *TrackedBreachesCreate) sqlSave(ctx context.Context) (*TrackedBreaches, error) {
|
||||
if err := tbc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := tbc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, tbc.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
|
||||
}
|
||||
}
|
||||
tbc.mutation.id = &_node.ID
|
||||
tbc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (tbc *TrackedBreachesCreate) createSpec() (*TrackedBreaches, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &TrackedBreaches{config: tbc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(trackedbreaches.Table, sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID))
|
||||
)
|
||||
if id, ok := tbc.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = &id
|
||||
}
|
||||
if value, ok := tbc.mutation.Breach(); ok {
|
||||
_spec.SetField(trackedbreaches.FieldBreach, field.TypeUUID, value)
|
||||
_node.Breach = value
|
||||
}
|
||||
if value, ok := tbc.mutation.Online(); ok {
|
||||
_spec.SetField(trackedbreaches.FieldOnline, field.TypeBool, value)
|
||||
_node.Online = value
|
||||
}
|
||||
if nodes := tbc.mutation.UserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: true,
|
||||
Table: trackedbreaches.UserTable,
|
||||
Columns: []string{trackedbreaches.UserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.Owner = nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := tbc.mutation.LocalbreachIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.LocalbreachTable,
|
||||
Columns: trackedbreaches.LocalbreachPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := tbc.mutation.HibpIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.HibpTable,
|
||||
Columns: []string{trackedbreaches.HibpColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// TrackedBreachesCreateBulk is the builder for creating many TrackedBreaches entities in bulk.
|
||||
type TrackedBreachesCreateBulk struct {
|
||||
config
|
||||
builders []*TrackedBreachesCreate
|
||||
}
|
||||
|
||||
// Save creates the TrackedBreaches entities in the database.
|
||||
func (tbcb *TrackedBreachesCreateBulk) Save(ctx context.Context) ([]*TrackedBreaches, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(tbcb.builders))
|
||||
nodes := make([]*TrackedBreaches, len(tbcb.builders))
|
||||
mutators := make([]Mutator, len(tbcb.builders))
|
||||
for i := range tbcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := tbcb.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*TrackedBreachesMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, tbcb.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, tbcb.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, tbcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tbcb *TrackedBreachesCreateBulk) SaveX(ctx context.Context) []*TrackedBreaches {
|
||||
v, err := tbcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (tbcb *TrackedBreachesCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := tbcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tbcb *TrackedBreachesCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := tbcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -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/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
)
|
||||
|
||||
// TrackedBreachesDelete is the builder for deleting a TrackedBreaches entity.
|
||||
type TrackedBreachesDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *TrackedBreachesMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TrackedBreachesDelete builder.
|
||||
func (tbd *TrackedBreachesDelete) Where(ps ...predicate.TrackedBreaches) *TrackedBreachesDelete {
|
||||
tbd.mutation.Where(ps...)
|
||||
return tbd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (tbd *TrackedBreachesDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, tbd.sqlExec, tbd.mutation, tbd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tbd *TrackedBreachesDelete) ExecX(ctx context.Context) int {
|
||||
n, err := tbd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (tbd *TrackedBreachesDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(trackedbreaches.Table, sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID))
|
||||
if ps := tbd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, tbd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
tbd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// TrackedBreachesDeleteOne is the builder for deleting a single TrackedBreaches entity.
|
||||
type TrackedBreachesDeleteOne struct {
|
||||
tbd *TrackedBreachesDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TrackedBreachesDelete builder.
|
||||
func (tbdo *TrackedBreachesDeleteOne) Where(ps ...predicate.TrackedBreaches) *TrackedBreachesDeleteOne {
|
||||
tbdo.tbd.mutation.Where(ps...)
|
||||
return tbdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (tbdo *TrackedBreachesDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := tbdo.tbd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{trackedbreaches.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tbdo *TrackedBreachesDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := tbdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,787 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"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/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// TrackedBreachesQuery is the builder for querying TrackedBreaches entities.
|
||||
type TrackedBreachesQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []trackedbreaches.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.TrackedBreaches
|
||||
withUser *UserQuery
|
||||
withLocalbreach *LocalBreachQuery
|
||||
withHibp *HIBPQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the TrackedBreachesQuery builder.
|
||||
func (tbq *TrackedBreachesQuery) Where(ps ...predicate.TrackedBreaches) *TrackedBreachesQuery {
|
||||
tbq.predicates = append(tbq.predicates, ps...)
|
||||
return tbq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (tbq *TrackedBreachesQuery) Limit(limit int) *TrackedBreachesQuery {
|
||||
tbq.ctx.Limit = &limit
|
||||
return tbq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (tbq *TrackedBreachesQuery) Offset(offset int) *TrackedBreachesQuery {
|
||||
tbq.ctx.Offset = &offset
|
||||
return tbq
|
||||
}
|
||||
|
||||
// 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 (tbq *TrackedBreachesQuery) Unique(unique bool) *TrackedBreachesQuery {
|
||||
tbq.ctx.Unique = &unique
|
||||
return tbq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (tbq *TrackedBreachesQuery) Order(o ...trackedbreaches.OrderOption) *TrackedBreachesQuery {
|
||||
tbq.order = append(tbq.order, o...)
|
||||
return tbq
|
||||
}
|
||||
|
||||
// QueryUser chains the current query on the "user" edge.
|
||||
func (tbq *TrackedBreachesQuery) QueryUser() *UserQuery {
|
||||
query := (&UserClient{config: tbq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := tbq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := tbq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(trackedbreaches.Table, trackedbreaches.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, true, trackedbreaches.UserTable, trackedbreaches.UserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(tbq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryLocalbreach chains the current query on the "localbreach" edge.
|
||||
func (tbq *TrackedBreachesQuery) QueryLocalbreach() *LocalBreachQuery {
|
||||
query := (&LocalBreachClient{config: tbq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := tbq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := tbq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(trackedbreaches.Table, trackedbreaches.FieldID, selector),
|
||||
sqlgraph.To(localbreach.Table, localbreach.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2M, false, trackedbreaches.LocalbreachTable, trackedbreaches.LocalbreachPrimaryKey...),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(tbq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryHibp chains the current query on the "hibp" edge.
|
||||
func (tbq *TrackedBreachesQuery) QueryHibp() *HIBPQuery {
|
||||
query := (&HIBPClient{config: tbq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := tbq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := tbq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(trackedbreaches.Table, trackedbreaches.FieldID, selector),
|
||||
sqlgraph.To(hibp.Table, hibp.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, trackedbreaches.HibpTable, trackedbreaches.HibpColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(tbq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first TrackedBreaches entity from the query.
|
||||
// Returns a *NotFoundError when no TrackedBreaches was found.
|
||||
func (tbq *TrackedBreachesQuery) First(ctx context.Context) (*TrackedBreaches, error) {
|
||||
nodes, err := tbq.Limit(1).All(setContextOp(ctx, tbq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{trackedbreaches.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (tbq *TrackedBreachesQuery) FirstX(ctx context.Context) *TrackedBreaches {
|
||||
node, err := tbq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first TrackedBreaches ID from the query.
|
||||
// Returns a *NotFoundError when no TrackedBreaches ID was found.
|
||||
func (tbq *TrackedBreachesQuery) FirstID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = tbq.Limit(1).IDs(setContextOp(ctx, tbq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{trackedbreaches.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (tbq *TrackedBreachesQuery) FirstIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := tbq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single TrackedBreaches entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one TrackedBreaches entity is found.
|
||||
// Returns a *NotFoundError when no TrackedBreaches entities are found.
|
||||
func (tbq *TrackedBreachesQuery) Only(ctx context.Context) (*TrackedBreaches, error) {
|
||||
nodes, err := tbq.Limit(2).All(setContextOp(ctx, tbq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{trackedbreaches.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{trackedbreaches.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (tbq *TrackedBreachesQuery) OnlyX(ctx context.Context) *TrackedBreaches {
|
||||
node, err := tbq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only TrackedBreaches ID in the query.
|
||||
// Returns a *NotSingularError when more than one TrackedBreaches ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (tbq *TrackedBreachesQuery) OnlyID(ctx context.Context) (id uuid.UUID, err error) {
|
||||
var ids []uuid.UUID
|
||||
if ids, err = tbq.Limit(2).IDs(setContextOp(ctx, tbq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{trackedbreaches.Label}
|
||||
default:
|
||||
err = &NotSingularError{trackedbreaches.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (tbq *TrackedBreachesQuery) OnlyIDX(ctx context.Context) uuid.UUID {
|
||||
id, err := tbq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of TrackedBreachesSlice.
|
||||
func (tbq *TrackedBreachesQuery) All(ctx context.Context) ([]*TrackedBreaches, error) {
|
||||
ctx = setContextOp(ctx, tbq.ctx, "All")
|
||||
if err := tbq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*TrackedBreaches, *TrackedBreachesQuery]()
|
||||
return withInterceptors[[]*TrackedBreaches](ctx, tbq, qr, tbq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (tbq *TrackedBreachesQuery) AllX(ctx context.Context) []*TrackedBreaches {
|
||||
nodes, err := tbq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of TrackedBreaches IDs.
|
||||
func (tbq *TrackedBreachesQuery) IDs(ctx context.Context) (ids []uuid.UUID, err error) {
|
||||
if tbq.ctx.Unique == nil && tbq.path != nil {
|
||||
tbq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, tbq.ctx, "IDs")
|
||||
if err = tbq.Select(trackedbreaches.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (tbq *TrackedBreachesQuery) IDsX(ctx context.Context) []uuid.UUID {
|
||||
ids, err := tbq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (tbq *TrackedBreachesQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, tbq.ctx, "Count")
|
||||
if err := tbq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, tbq, querierCount[*TrackedBreachesQuery](), tbq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (tbq *TrackedBreachesQuery) CountX(ctx context.Context) int {
|
||||
count, err := tbq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (tbq *TrackedBreachesQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, tbq.ctx, "Exist")
|
||||
switch _, err := tbq.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 (tbq *TrackedBreachesQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := tbq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the TrackedBreachesQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (tbq *TrackedBreachesQuery) Clone() *TrackedBreachesQuery {
|
||||
if tbq == nil {
|
||||
return nil
|
||||
}
|
||||
return &TrackedBreachesQuery{
|
||||
config: tbq.config,
|
||||
ctx: tbq.ctx.Clone(),
|
||||
order: append([]trackedbreaches.OrderOption{}, tbq.order...),
|
||||
inters: append([]Interceptor{}, tbq.inters...),
|
||||
predicates: append([]predicate.TrackedBreaches{}, tbq.predicates...),
|
||||
withUser: tbq.withUser.Clone(),
|
||||
withLocalbreach: tbq.withLocalbreach.Clone(),
|
||||
withHibp: tbq.withHibp.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: tbq.sql.Clone(),
|
||||
path: tbq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (tbq *TrackedBreachesQuery) WithUser(opts ...func(*UserQuery)) *TrackedBreachesQuery {
|
||||
query := (&UserClient{config: tbq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
tbq.withUser = query
|
||||
return tbq
|
||||
}
|
||||
|
||||
// WithLocalbreach tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "localbreach" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (tbq *TrackedBreachesQuery) WithLocalbreach(opts ...func(*LocalBreachQuery)) *TrackedBreachesQuery {
|
||||
query := (&LocalBreachClient{config: tbq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
tbq.withLocalbreach = query
|
||||
return tbq
|
||||
}
|
||||
|
||||
// WithHibp tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "hibp" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (tbq *TrackedBreachesQuery) WithHibp(opts ...func(*HIBPQuery)) *TrackedBreachesQuery {
|
||||
query := (&HIBPClient{config: tbq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
tbq.withHibp = query
|
||||
return tbq
|
||||
}
|
||||
|
||||
// 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 {
|
||||
// Breach uuid.UUID `json:"breach,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.TrackedBreaches.Query().
|
||||
// GroupBy(trackedbreaches.FieldBreach).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (tbq *TrackedBreachesQuery) GroupBy(field string, fields ...string) *TrackedBreachesGroupBy {
|
||||
tbq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &TrackedBreachesGroupBy{build: tbq}
|
||||
grbuild.flds = &tbq.ctx.Fields
|
||||
grbuild.label = trackedbreaches.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 {
|
||||
// Breach uuid.UUID `json:"breach,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.TrackedBreaches.Query().
|
||||
// Select(trackedbreaches.FieldBreach).
|
||||
// Scan(ctx, &v)
|
||||
func (tbq *TrackedBreachesQuery) Select(fields ...string) *TrackedBreachesSelect {
|
||||
tbq.ctx.Fields = append(tbq.ctx.Fields, fields...)
|
||||
sbuild := &TrackedBreachesSelect{TrackedBreachesQuery: tbq}
|
||||
sbuild.label = trackedbreaches.Label
|
||||
sbuild.flds, sbuild.scan = &tbq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a TrackedBreachesSelect configured with the given aggregations.
|
||||
func (tbq *TrackedBreachesQuery) Aggregate(fns ...AggregateFunc) *TrackedBreachesSelect {
|
||||
return tbq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (tbq *TrackedBreachesQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range tbq.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, tbq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range tbq.ctx.Fields {
|
||||
if !trackedbreaches.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if tbq.path != nil {
|
||||
prev, err := tbq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tbq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tbq *TrackedBreachesQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*TrackedBreaches, error) {
|
||||
var (
|
||||
nodes = []*TrackedBreaches{}
|
||||
_spec = tbq.querySpec()
|
||||
loadedTypes = [3]bool{
|
||||
tbq.withUser != nil,
|
||||
tbq.withLocalbreach != nil,
|
||||
tbq.withHibp != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*TrackedBreaches).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &TrackedBreaches{config: tbq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, tbq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := tbq.withUser; query != nil {
|
||||
if err := tbq.loadUser(ctx, query, nodes, nil,
|
||||
func(n *TrackedBreaches, e *User) { n.Edges.User = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := tbq.withLocalbreach; query != nil {
|
||||
if err := tbq.loadLocalbreach(ctx, query, nodes,
|
||||
func(n *TrackedBreaches) { n.Edges.Localbreach = []*LocalBreach{} },
|
||||
func(n *TrackedBreaches, e *LocalBreach) { n.Edges.Localbreach = append(n.Edges.Localbreach, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := tbq.withHibp; query != nil {
|
||||
if err := tbq.loadHibp(ctx, query, nodes,
|
||||
func(n *TrackedBreaches) { n.Edges.Hibp = []*HIBP{} },
|
||||
func(n *TrackedBreaches, e *HIBP) { n.Edges.Hibp = append(n.Edges.Hibp, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (tbq *TrackedBreachesQuery) loadUser(ctx context.Context, query *UserQuery, nodes []*TrackedBreaches, init func(*TrackedBreaches), assign func(*TrackedBreaches, *User)) error {
|
||||
ids := make([]uuid.UUID, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID][]*TrackedBreaches)
|
||||
for i := range nodes {
|
||||
fk := nodes[i].Owner
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "owner" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (tbq *TrackedBreachesQuery) loadLocalbreach(ctx context.Context, query *LocalBreachQuery, nodes []*TrackedBreaches, init func(*TrackedBreaches), assign func(*TrackedBreaches, *LocalBreach)) error {
|
||||
edgeIDs := make([]driver.Value, len(nodes))
|
||||
byID := make(map[uuid.UUID]*TrackedBreaches)
|
||||
nids := make(map[uuid.UUID]map[*TrackedBreaches]struct{})
|
||||
for i, node := range nodes {
|
||||
edgeIDs[i] = node.ID
|
||||
byID[node.ID] = node
|
||||
if init != nil {
|
||||
init(node)
|
||||
}
|
||||
}
|
||||
query.Where(func(s *sql.Selector) {
|
||||
joinT := sql.Table(trackedbreaches.LocalbreachTable)
|
||||
s.Join(joinT).On(s.C(localbreach.FieldID), joinT.C(trackedbreaches.LocalbreachPrimaryKey[1]))
|
||||
s.Where(sql.InValues(joinT.C(trackedbreaches.LocalbreachPrimaryKey[0]), edgeIDs...))
|
||||
columns := s.SelectedColumns()
|
||||
s.Select(joinT.C(trackedbreaches.LocalbreachPrimaryKey[0]))
|
||||
s.AppendSelect(columns...)
|
||||
s.SetDistinct(false)
|
||||
})
|
||||
if err := query.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
qr := QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
|
||||
return query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||
assign := spec.Assign
|
||||
values := spec.ScanValues
|
||||
spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
values, err := values(columns[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append([]any{new(uuid.UUID)}, values...), nil
|
||||
}
|
||||
spec.Assign = func(columns []string, values []any) error {
|
||||
outValue := *values[0].(*uuid.UUID)
|
||||
inValue := *values[1].(*uuid.UUID)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*TrackedBreaches]struct{}{byID[outValue]: {}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
})
|
||||
})
|
||||
neighbors, err := withInterceptors[[]*LocalBreach](ctx, query, qr, query.inters)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected "localbreach" node returned %v`, n.ID)
|
||||
}
|
||||
for kn := range nodes {
|
||||
assign(kn, n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (tbq *TrackedBreachesQuery) loadHibp(ctx context.Context, query *HIBPQuery, nodes []*TrackedBreaches, init func(*TrackedBreaches), assign func(*TrackedBreaches, *HIBP)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*TrackedBreaches)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.HIBP(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(trackedbreaches.HibpColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.tracked_breaches_hibp
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "tracked_breaches_hibp" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "tracked_breaches_hibp" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tbq *TrackedBreachesQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := tbq.querySpec()
|
||||
_spec.Node.Columns = tbq.ctx.Fields
|
||||
if len(tbq.ctx.Fields) > 0 {
|
||||
_spec.Unique = tbq.ctx.Unique != nil && *tbq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, tbq.driver, _spec)
|
||||
}
|
||||
|
||||
func (tbq *TrackedBreachesQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(trackedbreaches.Table, trackedbreaches.Columns, sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID))
|
||||
_spec.From = tbq.sql
|
||||
if unique := tbq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if tbq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := tbq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, trackedbreaches.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != trackedbreaches.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
if tbq.withUser != nil {
|
||||
_spec.Node.AddColumnOnce(trackedbreaches.FieldOwner)
|
||||
}
|
||||
}
|
||||
if ps := tbq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := tbq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := tbq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := tbq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (tbq *TrackedBreachesQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(tbq.driver.Dialect())
|
||||
t1 := builder.Table(trackedbreaches.Table)
|
||||
columns := tbq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = trackedbreaches.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if tbq.sql != nil {
|
||||
selector = tbq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if tbq.ctx.Unique != nil && *tbq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range tbq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range tbq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := tbq.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 := tbq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// TrackedBreachesGroupBy is the group-by builder for TrackedBreaches entities.
|
||||
type TrackedBreachesGroupBy struct {
|
||||
selector
|
||||
build *TrackedBreachesQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (tbgb *TrackedBreachesGroupBy) Aggregate(fns ...AggregateFunc) *TrackedBreachesGroupBy {
|
||||
tbgb.fns = append(tbgb.fns, fns...)
|
||||
return tbgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (tbgb *TrackedBreachesGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, tbgb.build.ctx, "GroupBy")
|
||||
if err := tbgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*TrackedBreachesQuery, *TrackedBreachesGroupBy](ctx, tbgb.build, tbgb, tbgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (tbgb *TrackedBreachesGroupBy) sqlScan(ctx context.Context, root *TrackedBreachesQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(tbgb.fns))
|
||||
for _, fn := range tbgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*tbgb.flds)+len(tbgb.fns))
|
||||
for _, f := range *tbgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*tbgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := tbgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// TrackedBreachesSelect is the builder for selecting fields of TrackedBreaches entities.
|
||||
type TrackedBreachesSelect struct {
|
||||
*TrackedBreachesQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (tbs *TrackedBreachesSelect) Aggregate(fns ...AggregateFunc) *TrackedBreachesSelect {
|
||||
tbs.fns = append(tbs.fns, fns...)
|
||||
return tbs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (tbs *TrackedBreachesSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, tbs.ctx, "Select")
|
||||
if err := tbs.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*TrackedBreachesQuery, *TrackedBreachesSelect](ctx, tbs.TrackedBreachesQuery, tbs, tbs.inters, v)
|
||||
}
|
||||
|
||||
func (tbs *TrackedBreachesSelect) sqlScan(ctx context.Context, root *TrackedBreachesQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(tbs.fns))
|
||||
for _, fn := range tbs.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*tbs.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 := tbs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
|
@ -0,0 +1,542 @@
|
|||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"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/localbreach"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// TrackedBreachesUpdate is the builder for updating TrackedBreaches entities.
|
||||
type TrackedBreachesUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *TrackedBreachesMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TrackedBreachesUpdate builder.
|
||||
func (tbu *TrackedBreachesUpdate) Where(ps ...predicate.TrackedBreaches) *TrackedBreachesUpdate {
|
||||
tbu.mutation.Where(ps...)
|
||||
return tbu
|
||||
}
|
||||
|
||||
// SetBreach sets the "breach" field.
|
||||
func (tbu *TrackedBreachesUpdate) SetBreach(u uuid.UUID) *TrackedBreachesUpdate {
|
||||
tbu.mutation.SetBreach(u)
|
||||
return tbu
|
||||
}
|
||||
|
||||
// AddLocalbreachIDs adds the "localbreach" edge to the LocalBreach entity by IDs.
|
||||
func (tbu *TrackedBreachesUpdate) AddLocalbreachIDs(ids ...uuid.UUID) *TrackedBreachesUpdate {
|
||||
tbu.mutation.AddLocalbreachIDs(ids...)
|
||||
return tbu
|
||||
}
|
||||
|
||||
// AddLocalbreach adds the "localbreach" edges to the LocalBreach entity.
|
||||
func (tbu *TrackedBreachesUpdate) AddLocalbreach(l ...*LocalBreach) *TrackedBreachesUpdate {
|
||||
ids := make([]uuid.UUID, len(l))
|
||||
for i := range l {
|
||||
ids[i] = l[i].ID
|
||||
}
|
||||
return tbu.AddLocalbreachIDs(ids...)
|
||||
}
|
||||
|
||||
// AddHibpIDs adds the "hibp" edge to the HIBP entity by IDs.
|
||||
func (tbu *TrackedBreachesUpdate) AddHibpIDs(ids ...uuid.UUID) *TrackedBreachesUpdate {
|
||||
tbu.mutation.AddHibpIDs(ids...)
|
||||
return tbu
|
||||
}
|
||||
|
||||
// AddHibp adds the "hibp" edges to the HIBP entity.
|
||||
func (tbu *TrackedBreachesUpdate) AddHibp(h ...*HIBP) *TrackedBreachesUpdate {
|
||||
ids := make([]uuid.UUID, len(h))
|
||||
for i := range h {
|
||||
ids[i] = h[i].ID
|
||||
}
|
||||
return tbu.AddHibpIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the TrackedBreachesMutation object of the builder.
|
||||
func (tbu *TrackedBreachesUpdate) Mutation() *TrackedBreachesMutation {
|
||||
return tbu.mutation
|
||||
}
|
||||
|
||||
// ClearLocalbreach clears all "localbreach" edges to the LocalBreach entity.
|
||||
func (tbu *TrackedBreachesUpdate) ClearLocalbreach() *TrackedBreachesUpdate {
|
||||
tbu.mutation.ClearLocalbreach()
|
||||
return tbu
|
||||
}
|
||||
|
||||
// RemoveLocalbreachIDs removes the "localbreach" edge to LocalBreach entities by IDs.
|
||||
func (tbu *TrackedBreachesUpdate) RemoveLocalbreachIDs(ids ...uuid.UUID) *TrackedBreachesUpdate {
|
||||
tbu.mutation.RemoveLocalbreachIDs(ids...)
|
||||
return tbu
|
||||
}
|
||||
|
||||
// RemoveLocalbreach removes "localbreach" edges to LocalBreach entities.
|
||||
func (tbu *TrackedBreachesUpdate) RemoveLocalbreach(l ...*LocalBreach) *TrackedBreachesUpdate {
|
||||
ids := make([]uuid.UUID, len(l))
|
||||
for i := range l {
|
||||
ids[i] = l[i].ID
|
||||
}
|
||||
return tbu.RemoveLocalbreachIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearHibp clears all "hibp" edges to the HIBP entity.
|
||||
func (tbu *TrackedBreachesUpdate) ClearHibp() *TrackedBreachesUpdate {
|
||||
tbu.mutation.ClearHibp()
|
||||
return tbu
|
||||
}
|
||||
|
||||
// RemoveHibpIDs removes the "hibp" edge to HIBP entities by IDs.
|
||||
func (tbu *TrackedBreachesUpdate) RemoveHibpIDs(ids ...uuid.UUID) *TrackedBreachesUpdate {
|
||||
tbu.mutation.RemoveHibpIDs(ids...)
|
||||
return tbu
|
||||
}
|
||||
|
||||
// RemoveHibp removes "hibp" edges to HIBP entities.
|
||||
func (tbu *TrackedBreachesUpdate) RemoveHibp(h ...*HIBP) *TrackedBreachesUpdate {
|
||||
ids := make([]uuid.UUID, len(h))
|
||||
for i := range h {
|
||||
ids[i] = h[i].ID
|
||||
}
|
||||
return tbu.RemoveHibpIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (tbu *TrackedBreachesUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, tbu.sqlSave, tbu.mutation, tbu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tbu *TrackedBreachesUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := tbu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (tbu *TrackedBreachesUpdate) Exec(ctx context.Context) error {
|
||||
_, err := tbu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tbu *TrackedBreachesUpdate) ExecX(ctx context.Context) {
|
||||
if err := tbu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (tbu *TrackedBreachesUpdate) check() error {
|
||||
if _, ok := tbu.mutation.UserID(); tbu.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "TrackedBreaches.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tbu *TrackedBreachesUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := tbu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(trackedbreaches.Table, trackedbreaches.Columns, sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID))
|
||||
if ps := tbu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := tbu.mutation.Breach(); ok {
|
||||
_spec.SetField(trackedbreaches.FieldBreach, field.TypeUUID, value)
|
||||
}
|
||||
if tbu.mutation.LocalbreachCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.LocalbreachTable,
|
||||
Columns: trackedbreaches.LocalbreachPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tbu.mutation.RemovedLocalbreachIDs(); len(nodes) > 0 && !tbu.mutation.LocalbreachCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.LocalbreachTable,
|
||||
Columns: trackedbreaches.LocalbreachPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tbu.mutation.LocalbreachIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.LocalbreachTable,
|
||||
Columns: trackedbreaches.LocalbreachPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if tbu.mutation.HibpCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.HibpTable,
|
||||
Columns: []string{trackedbreaches.HibpColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tbu.mutation.RemovedHibpIDs(); len(nodes) > 0 && !tbu.mutation.HibpCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.HibpTable,
|
||||
Columns: []string{trackedbreaches.HibpColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tbu.mutation.HibpIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.HibpTable,
|
||||
Columns: []string{trackedbreaches.HibpColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, tbu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{trackedbreaches.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
tbu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// TrackedBreachesUpdateOne is the builder for updating a single TrackedBreaches entity.
|
||||
type TrackedBreachesUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *TrackedBreachesMutation
|
||||
}
|
||||
|
||||
// SetBreach sets the "breach" field.
|
||||
func (tbuo *TrackedBreachesUpdateOne) SetBreach(u uuid.UUID) *TrackedBreachesUpdateOne {
|
||||
tbuo.mutation.SetBreach(u)
|
||||
return tbuo
|
||||
}
|
||||
|
||||
// AddLocalbreachIDs adds the "localbreach" edge to the LocalBreach entity by IDs.
|
||||
func (tbuo *TrackedBreachesUpdateOne) AddLocalbreachIDs(ids ...uuid.UUID) *TrackedBreachesUpdateOne {
|
||||
tbuo.mutation.AddLocalbreachIDs(ids...)
|
||||
return tbuo
|
||||
}
|
||||
|
||||
// AddLocalbreach adds the "localbreach" edges to the LocalBreach entity.
|
||||
func (tbuo *TrackedBreachesUpdateOne) AddLocalbreach(l ...*LocalBreach) *TrackedBreachesUpdateOne {
|
||||
ids := make([]uuid.UUID, len(l))
|
||||
for i := range l {
|
||||
ids[i] = l[i].ID
|
||||
}
|
||||
return tbuo.AddLocalbreachIDs(ids...)
|
||||
}
|
||||
|
||||
// AddHibpIDs adds the "hibp" edge to the HIBP entity by IDs.
|
||||
func (tbuo *TrackedBreachesUpdateOne) AddHibpIDs(ids ...uuid.UUID) *TrackedBreachesUpdateOne {
|
||||
tbuo.mutation.AddHibpIDs(ids...)
|
||||
return tbuo
|
||||
}
|
||||
|
||||
// AddHibp adds the "hibp" edges to the HIBP entity.
|
||||
func (tbuo *TrackedBreachesUpdateOne) AddHibp(h ...*HIBP) *TrackedBreachesUpdateOne {
|
||||
ids := make([]uuid.UUID, len(h))
|
||||
for i := range h {
|
||||
ids[i] = h[i].ID
|
||||
}
|
||||
return tbuo.AddHibpIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the TrackedBreachesMutation object of the builder.
|
||||
func (tbuo *TrackedBreachesUpdateOne) Mutation() *TrackedBreachesMutation {
|
||||
return tbuo.mutation
|
||||
}
|
||||
|
||||
// ClearLocalbreach clears all "localbreach" edges to the LocalBreach entity.
|
||||
func (tbuo *TrackedBreachesUpdateOne) ClearLocalbreach() *TrackedBreachesUpdateOne {
|
||||
tbuo.mutation.ClearLocalbreach()
|
||||
return tbuo
|
||||
}
|
||||
|
||||
// RemoveLocalbreachIDs removes the "localbreach" edge to LocalBreach entities by IDs.
|
||||
func (tbuo *TrackedBreachesUpdateOne) RemoveLocalbreachIDs(ids ...uuid.UUID) *TrackedBreachesUpdateOne {
|
||||
tbuo.mutation.RemoveLocalbreachIDs(ids...)
|
||||
return tbuo
|
||||
}
|
||||
|
||||
// RemoveLocalbreach removes "localbreach" edges to LocalBreach entities.
|
||||
func (tbuo *TrackedBreachesUpdateOne) RemoveLocalbreach(l ...*LocalBreach) *TrackedBreachesUpdateOne {
|
||||
ids := make([]uuid.UUID, len(l))
|
||||
for i := range l {
|
||||
ids[i] = l[i].ID
|
||||
}
|
||||
return tbuo.RemoveLocalbreachIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearHibp clears all "hibp" edges to the HIBP entity.
|
||||
func (tbuo *TrackedBreachesUpdateOne) ClearHibp() *TrackedBreachesUpdateOne {
|
||||
tbuo.mutation.ClearHibp()
|
||||
return tbuo
|
||||
}
|
||||
|
||||
// RemoveHibpIDs removes the "hibp" edge to HIBP entities by IDs.
|
||||
func (tbuo *TrackedBreachesUpdateOne) RemoveHibpIDs(ids ...uuid.UUID) *TrackedBreachesUpdateOne {
|
||||
tbuo.mutation.RemoveHibpIDs(ids...)
|
||||
return tbuo
|
||||
}
|
||||
|
||||
// RemoveHibp removes "hibp" edges to HIBP entities.
|
||||
func (tbuo *TrackedBreachesUpdateOne) RemoveHibp(h ...*HIBP) *TrackedBreachesUpdateOne {
|
||||
ids := make([]uuid.UUID, len(h))
|
||||
for i := range h {
|
||||
ids[i] = h[i].ID
|
||||
}
|
||||
return tbuo.RemoveHibpIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TrackedBreachesUpdate builder.
|
||||
func (tbuo *TrackedBreachesUpdateOne) Where(ps ...predicate.TrackedBreaches) *TrackedBreachesUpdateOne {
|
||||
tbuo.mutation.Where(ps...)
|
||||
return tbuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (tbuo *TrackedBreachesUpdateOne) Select(field string, fields ...string) *TrackedBreachesUpdateOne {
|
||||
tbuo.fields = append([]string{field}, fields...)
|
||||
return tbuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated TrackedBreaches entity.
|
||||
func (tbuo *TrackedBreachesUpdateOne) Save(ctx context.Context) (*TrackedBreaches, error) {
|
||||
return withHooks(ctx, tbuo.sqlSave, tbuo.mutation, tbuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tbuo *TrackedBreachesUpdateOne) SaveX(ctx context.Context) *TrackedBreaches {
|
||||
node, err := tbuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (tbuo *TrackedBreachesUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := tbuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tbuo *TrackedBreachesUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := tbuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (tbuo *TrackedBreachesUpdateOne) check() error {
|
||||
if _, ok := tbuo.mutation.UserID(); tbuo.mutation.UserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "TrackedBreaches.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tbuo *TrackedBreachesUpdateOne) sqlSave(ctx context.Context) (_node *TrackedBreaches, err error) {
|
||||
if err := tbuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(trackedbreaches.Table, trackedbreaches.Columns, sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID))
|
||||
id, ok := tbuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "TrackedBreaches.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := tbuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, trackedbreaches.FieldID)
|
||||
for _, f := range fields {
|
||||
if !trackedbreaches.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != trackedbreaches.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := tbuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := tbuo.mutation.Breach(); ok {
|
||||
_spec.SetField(trackedbreaches.FieldBreach, field.TypeUUID, value)
|
||||
}
|
||||
if tbuo.mutation.LocalbreachCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.LocalbreachTable,
|
||||
Columns: trackedbreaches.LocalbreachPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tbuo.mutation.RemovedLocalbreachIDs(); len(nodes) > 0 && !tbuo.mutation.LocalbreachCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.LocalbreachTable,
|
||||
Columns: trackedbreaches.LocalbreachPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tbuo.mutation.LocalbreachIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.LocalbreachTable,
|
||||
Columns: trackedbreaches.LocalbreachPrimaryKey,
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(localbreach.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if tbuo.mutation.HibpCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.HibpTable,
|
||||
Columns: []string{trackedbreaches.HibpColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tbuo.mutation.RemovedHibpIDs(); len(nodes) > 0 && !tbuo.mutation.HibpCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.HibpTable,
|
||||
Columns: []string{trackedbreaches.HibpColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tbuo.mutation.HibpIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: trackedbreaches.HibpTable,
|
||||
Columns: []string{trackedbreaches.HibpColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(hibp.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &TrackedBreaches{config: tbuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, tbuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{trackedbreaches.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
tbuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
17
ent/tx.go
17
ent/tx.go
|
@ -12,10 +12,20 @@ import (
|
|||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// AgeKey is the client for interacting with the AgeKey builders.
|
||||
AgeKey *AgeKeyClient
|
||||
// HIBP is the client for interacting with the HIBP builders.
|
||||
HIBP *HIBPClient
|
||||
// LocalBreach is the client for interacting with the LocalBreach builders.
|
||||
LocalBreach *LocalBreachClient
|
||||
// SearchQuery is the client for interacting with the SearchQuery builders.
|
||||
SearchQuery *SearchQueryClient
|
||||
// Settings is the client for interacting with the Settings builders.
|
||||
Settings *SettingsClient
|
||||
// Setup is the client for interacting with the Setup builders.
|
||||
Setup *SetupClient
|
||||
// TrackedBreaches is the client for interacting with the TrackedBreaches builders.
|
||||
TrackedBreaches *TrackedBreachesClient
|
||||
// User is the client for interacting with the User builders.
|
||||
User *UserClient
|
||||
|
||||
|
@ -149,8 +159,13 @@ func (tx *Tx) Client() *Client {
|
|||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.AgeKey = NewAgeKeyClient(tx.config)
|
||||
tx.HIBP = NewHIBPClient(tx.config)
|
||||
tx.LocalBreach = NewLocalBreachClient(tx.config)
|
||||
tx.SearchQuery = NewSearchQueryClient(tx.config)
|
||||
tx.Settings = NewSettingsClient(tx.config)
|
||||
tx.Setup = NewSetupClient(tx.config)
|
||||
tx.TrackedBreaches = NewTrackedBreachesClient(tx.config)
|
||||
tx.User = NewUserClient(tx.config)
|
||||
}
|
||||
|
||||
|
@ -161,7 +176,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: HIBP.QueryXXX(), the query will be executed
|
||||
// applies a query, for example: AgeKey.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
|
|
67
ent/user.go
67
ent/user.go
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -18,7 +19,7 @@ type User struct {
|
|||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID uuid.UUID `json:"id,omitempty"`
|
||||
// Username holds the value of the "username" field.
|
||||
// user's handle, allowed `<>~+-_` symbols and alphanumeric ASCII characters, including capital letters
|
||||
Username string `json:"username,omitempty"`
|
||||
// Email holds the value of the "email" field.
|
||||
Email string `json:"email,omitempty"`
|
||||
|
@ -33,10 +34,57 @@ type User struct {
|
|||
// UpdatedAt holds the value of the "updated_at" field.
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
// LastLogin holds the value of the "last_login" field.
|
||||
LastLogin time.Time `json:"last_login,omitempty"`
|
||||
LastLogin time.Time `json:"last_login,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the UserQuery when eager-loading is set.
|
||||
Edges UserEdges `json:"edges"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// UserEdges holds the relations/edges for other nodes in the graph.
|
||||
type UserEdges struct {
|
||||
// Agekey holds the value of the agekey edge.
|
||||
Agekey *AgeKey `json:"agekey,omitempty"`
|
||||
// TrackedBreaches holds the value of the tracked_breaches edge.
|
||||
TrackedBreaches []*TrackedBreaches `json:"tracked_breaches,omitempty"`
|
||||
// SearchQueries holds the value of the search_queries edge.
|
||||
SearchQueries []*SearchQuery `json:"search_queries,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [3]bool
|
||||
}
|
||||
|
||||
// AgekeyOrErr returns the Agekey value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e UserEdges) AgekeyOrErr() (*AgeKey, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.Agekey == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: agekey.Label}
|
||||
}
|
||||
return e.Agekey, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "agekey"}
|
||||
}
|
||||
|
||||
// TrackedBreachesOrErr returns the TrackedBreaches value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) TrackedBreachesOrErr() ([]*TrackedBreaches, error) {
|
||||
if e.loadedTypes[1] {
|
||||
return e.TrackedBreaches, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "tracked_breaches"}
|
||||
}
|
||||
|
||||
// SearchQueriesOrErr returns the SearchQueries value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) SearchQueriesOrErr() ([]*SearchQuery, error) {
|
||||
if e.loadedTypes[2] {
|
||||
return e.SearchQueries, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "search_queries"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*User) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
|
@ -134,6 +182,21 @@ func (u *User) Value(name string) (ent.Value, error) {
|
|||
return u.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryAgekey queries the "agekey" edge of the User entity.
|
||||
func (u *User) QueryAgekey() *AgeKeyQuery {
|
||||
return NewUserClient(u.config).QueryAgekey(u)
|
||||
}
|
||||
|
||||
// QueryTrackedBreaches queries the "tracked_breaches" edge of the User entity.
|
||||
func (u *User) QueryTrackedBreaches() *TrackedBreachesQuery {
|
||||
return NewUserClient(u.config).QueryTrackedBreaches(u)
|
||||
}
|
||||
|
||||
// QuerySearchQueries queries the "search_queries" edge of the User entity.
|
||||
func (u *User) QuerySearchQueries() *SearchQueryQuery {
|
||||
return NewUserClient(u.config).QuerySearchQueries(u)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this User.
|
||||
// Note that you need to call User.Unwrap() before calling this method if this User
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
|
@ -30,8 +31,35 @@ const (
|
|||
FieldUpdatedAt = "updated_at"
|
||||
// FieldLastLogin holds the string denoting the last_login field in the database.
|
||||
FieldLastLogin = "last_login"
|
||||
// EdgeAgekey holds the string denoting the agekey edge name in mutations.
|
||||
EdgeAgekey = "agekey"
|
||||
// EdgeTrackedBreaches holds the string denoting the tracked_breaches edge name in mutations.
|
||||
EdgeTrackedBreaches = "tracked_breaches"
|
||||
// EdgeSearchQueries holds the string denoting the search_queries edge name in mutations.
|
||||
EdgeSearchQueries = "search_queries"
|
||||
// Table holds the table name of the user in the database.
|
||||
Table = "users"
|
||||
// AgekeyTable is the table that holds the agekey relation/edge.
|
||||
AgekeyTable = "age_keys"
|
||||
// AgekeyInverseTable is the table name for the AgeKey entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "agekey" package.
|
||||
AgekeyInverseTable = "age_keys"
|
||||
// AgekeyColumn is the table column denoting the agekey relation/edge.
|
||||
AgekeyColumn = "owner"
|
||||
// TrackedBreachesTable is the table that holds the tracked_breaches relation/edge.
|
||||
TrackedBreachesTable = "tracked_breaches"
|
||||
// TrackedBreachesInverseTable is the table name for the TrackedBreaches entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "trackedbreaches" package.
|
||||
TrackedBreachesInverseTable = "tracked_breaches"
|
||||
// TrackedBreachesColumn is the table column denoting the tracked_breaches relation/edge.
|
||||
TrackedBreachesColumn = "owner"
|
||||
// SearchQueriesTable is the table that holds the search_queries relation/edge.
|
||||
SearchQueriesTable = "search_queries"
|
||||
// SearchQueriesInverseTable is the table name for the SearchQuery entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "searchquery" package.
|
||||
SearchQueriesInverseTable = "search_queries"
|
||||
// SearchQueriesColumn is the table column denoting the search_queries relation/edge.
|
||||
SearchQueriesColumn = "owner"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for user fields.
|
||||
|
@ -124,3 +152,59 @@ func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
|
|||
func ByLastLogin(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldLastLogin, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByAgekeyField orders the results by agekey field.
|
||||
func ByAgekeyField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newAgekeyStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByTrackedBreachesCount orders the results by tracked_breaches count.
|
||||
func ByTrackedBreachesCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newTrackedBreachesStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByTrackedBreaches orders the results by tracked_breaches terms.
|
||||
func ByTrackedBreaches(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newTrackedBreachesStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
// BySearchQueriesCount orders the results by search_queries count.
|
||||
func BySearchQueriesCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newSearchQueriesStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// BySearchQueries orders the results by search_queries terms.
|
||||
func BySearchQueries(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newSearchQueriesStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newAgekeyStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(AgekeyInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, AgekeyTable, AgekeyColumn),
|
||||
)
|
||||
}
|
||||
func newTrackedBreachesStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(TrackedBreachesInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, TrackedBreachesTable, TrackedBreachesColumn),
|
||||
)
|
||||
}
|
||||
func newSearchQueriesStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(SearchQueriesInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, SearchQueriesTable, SearchQueriesColumn),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -405,6 +406,75 @@ func LastLoginLTE(v time.Time) predicate.User {
|
|||
return predicate.User(sql.FieldLTE(FieldLastLogin, v))
|
||||
}
|
||||
|
||||
// HasAgekey applies the HasEdge predicate on the "agekey" edge.
|
||||
func HasAgekey() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, AgekeyTable, AgekeyColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasAgekeyWith applies the HasEdge predicate on the "agekey" edge with a given conditions (other predicates).
|
||||
func HasAgekeyWith(preds ...predicate.AgeKey) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newAgekeyStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasTrackedBreaches applies the HasEdge predicate on the "tracked_breaches" edge.
|
||||
func HasTrackedBreaches() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, TrackedBreachesTable, TrackedBreachesColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasTrackedBreachesWith applies the HasEdge predicate on the "tracked_breaches" edge with a given conditions (other predicates).
|
||||
func HasTrackedBreachesWith(preds ...predicate.TrackedBreaches) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newTrackedBreachesStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// HasSearchQueries applies the HasEdge predicate on the "search_queries" edge.
|
||||
func HasSearchQueries() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, SearchQueriesTable, SearchQueriesColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasSearchQueriesWith applies the HasEdge predicate on the "search_queries" edge with a given conditions (other predicates).
|
||||
func HasSearchQueriesWith(preds ...predicate.SearchQuery) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newSearchQueriesStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
|
|
|
@ -10,6 +10,9 @@ import (
|
|||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -123,6 +126,55 @@ func (uc *UserCreate) SetNillableID(u *uuid.UUID) *UserCreate {
|
|||
return uc
|
||||
}
|
||||
|
||||
// SetAgekeyID sets the "agekey" edge to the AgeKey entity by ID.
|
||||
func (uc *UserCreate) SetAgekeyID(id uuid.UUID) *UserCreate {
|
||||
uc.mutation.SetAgekeyID(id)
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetNillableAgekeyID sets the "agekey" edge to the AgeKey entity by ID if the given value is not nil.
|
||||
func (uc *UserCreate) SetNillableAgekeyID(id *uuid.UUID) *UserCreate {
|
||||
if id != nil {
|
||||
uc = uc.SetAgekeyID(*id)
|
||||
}
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetAgekey sets the "agekey" edge to the AgeKey entity.
|
||||
func (uc *UserCreate) SetAgekey(a *AgeKey) *UserCreate {
|
||||
return uc.SetAgekeyID(a.ID)
|
||||
}
|
||||
|
||||
// AddTrackedBreachIDs adds the "tracked_breaches" edge to the TrackedBreaches entity by IDs.
|
||||
func (uc *UserCreate) AddTrackedBreachIDs(ids ...uuid.UUID) *UserCreate {
|
||||
uc.mutation.AddTrackedBreachIDs(ids...)
|
||||
return uc
|
||||
}
|
||||
|
||||
// AddTrackedBreaches adds the "tracked_breaches" edges to the TrackedBreaches entity.
|
||||
func (uc *UserCreate) AddTrackedBreaches(t ...*TrackedBreaches) *UserCreate {
|
||||
ids := make([]uuid.UUID, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return uc.AddTrackedBreachIDs(ids...)
|
||||
}
|
||||
|
||||
// AddSearchQueryIDs adds the "search_queries" edge to the SearchQuery entity by IDs.
|
||||
func (uc *UserCreate) AddSearchQueryIDs(ids ...uuid.UUID) *UserCreate {
|
||||
uc.mutation.AddSearchQueryIDs(ids...)
|
||||
return uc
|
||||
}
|
||||
|
||||
// AddSearchQueries adds the "search_queries" edges to the SearchQuery entity.
|
||||
func (uc *UserCreate) AddSearchQueries(s ...*SearchQuery) *UserCreate {
|
||||
ids := make([]uuid.UUID, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return uc.AddSearchQueryIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uc *UserCreate) Mutation() *UserMutation {
|
||||
return uc.mutation
|
||||
|
@ -292,6 +344,54 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
|||
_spec.SetField(user.FieldLastLogin, field.TypeTime, value)
|
||||
_node.LastLogin = value
|
||||
}
|
||||
if nodes := uc.mutation.AgekeyIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2O,
|
||||
Inverse: false,
|
||||
Table: user.AgekeyTable,
|
||||
Columns: []string{user.AgekeyColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(agekey.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := uc.mutation.TrackedBreachesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.TrackedBreachesTable,
|
||||
Columns: []string{user.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := uc.mutation.SearchQueriesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.SearchQueriesTable,
|
||||
Columns: []string{user.SearchQueriesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
|
|
@ -4,13 +4,17 @@ package ent
|
|||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"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/agekey"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -18,10 +22,13 @@ import (
|
|||
// UserQuery is the builder for querying User entities.
|
||||
type UserQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []user.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.User
|
||||
ctx *QueryContext
|
||||
order []user.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.User
|
||||
withAgekey *AgeKeyQuery
|
||||
withTrackedBreaches *TrackedBreachesQuery
|
||||
withSearchQueries *SearchQueryQuery
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
|
@ -58,6 +65,72 @@ func (uq *UserQuery) Order(o ...user.OrderOption) *UserQuery {
|
|||
return uq
|
||||
}
|
||||
|
||||
// QueryAgekey chains the current query on the "agekey" edge.
|
||||
func (uq *UserQuery) QueryAgekey() *AgeKeyQuery {
|
||||
query := (&AgeKeyClient{config: uq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := uq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(agekey.Table, agekey.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2O, false, user.AgekeyTable, user.AgekeyColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryTrackedBreaches chains the current query on the "tracked_breaches" edge.
|
||||
func (uq *UserQuery) QueryTrackedBreaches() *TrackedBreachesQuery {
|
||||
query := (&TrackedBreachesClient{config: uq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := uq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(trackedbreaches.Table, trackedbreaches.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.TrackedBreachesTable, user.TrackedBreachesColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySearchQueries chains the current query on the "search_queries" edge.
|
||||
func (uq *UserQuery) QuerySearchQueries() *SearchQueryQuery {
|
||||
query := (&SearchQueryClient{config: uq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := uq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(searchquery.Table, searchquery.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, user.SearchQueriesTable, user.SearchQueriesColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first User entity from the query.
|
||||
// Returns a *NotFoundError when no User was found.
|
||||
func (uq *UserQuery) First(ctx context.Context) (*User, error) {
|
||||
|
@ -245,17 +318,53 @@ func (uq *UserQuery) Clone() *UserQuery {
|
|||
return nil
|
||||
}
|
||||
return &UserQuery{
|
||||
config: uq.config,
|
||||
ctx: uq.ctx.Clone(),
|
||||
order: append([]user.OrderOption{}, uq.order...),
|
||||
inters: append([]Interceptor{}, uq.inters...),
|
||||
predicates: append([]predicate.User{}, uq.predicates...),
|
||||
config: uq.config,
|
||||
ctx: uq.ctx.Clone(),
|
||||
order: append([]user.OrderOption{}, uq.order...),
|
||||
inters: append([]Interceptor{}, uq.inters...),
|
||||
predicates: append([]predicate.User{}, uq.predicates...),
|
||||
withAgekey: uq.withAgekey.Clone(),
|
||||
withTrackedBreaches: uq.withTrackedBreaches.Clone(),
|
||||
withSearchQueries: uq.withSearchQueries.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: uq.sql.Clone(),
|
||||
path: uq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithAgekey tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "agekey" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithAgekey(opts ...func(*AgeKeyQuery)) *UserQuery {
|
||||
query := (&AgeKeyClient{config: uq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
uq.withAgekey = query
|
||||
return uq
|
||||
}
|
||||
|
||||
// WithTrackedBreaches tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "tracked_breaches" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithTrackedBreaches(opts ...func(*TrackedBreachesQuery)) *UserQuery {
|
||||
query := (&TrackedBreachesClient{config: uq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
uq.withTrackedBreaches = query
|
||||
return uq
|
||||
}
|
||||
|
||||
// WithSearchQueries tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "search_queries" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithSearchQueries(opts ...func(*SearchQueryQuery)) *UserQuery {
|
||||
query := (&SearchQueryClient{config: uq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
uq.withSearchQueries = query
|
||||
return uq
|
||||
}
|
||||
|
||||
// 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.
|
||||
//
|
||||
|
@ -332,8 +441,13 @@ func (uq *UserQuery) prepareQuery(ctx context.Context) error {
|
|||
|
||||
func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, error) {
|
||||
var (
|
||||
nodes = []*User{}
|
||||
_spec = uq.querySpec()
|
||||
nodes = []*User{}
|
||||
_spec = uq.querySpec()
|
||||
loadedTypes = [3]bool{
|
||||
uq.withAgekey != nil,
|
||||
uq.withTrackedBreaches != nil,
|
||||
uq.withSearchQueries != nil,
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*User).scanValues(nil, columns)
|
||||
|
@ -341,6 +455,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
|
|||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &User{config: uq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
|
@ -352,9 +467,117 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
|
|||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := uq.withAgekey; query != nil {
|
||||
if err := uq.loadAgekey(ctx, query, nodes, nil,
|
||||
func(n *User, e *AgeKey) { n.Edges.Agekey = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := uq.withTrackedBreaches; query != nil {
|
||||
if err := uq.loadTrackedBreaches(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.TrackedBreaches = []*TrackedBreaches{} },
|
||||
func(n *User, e *TrackedBreaches) { n.Edges.TrackedBreaches = append(n.Edges.TrackedBreaches, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := uq.withSearchQueries; query != nil {
|
||||
if err := uq.loadSearchQueries(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.SearchQueries = []*SearchQuery{} },
|
||||
func(n *User, e *SearchQuery) { n.Edges.SearchQueries = append(n.Edges.SearchQueries, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) loadAgekey(ctx context.Context, query *AgeKeyQuery, nodes []*User, init func(*User), assign func(*User, *AgeKey)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(agekey.FieldOwner)
|
||||
}
|
||||
query.Where(predicate.AgeKey(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.AgekeyColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.Owner
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "owner" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (uq *UserQuery) loadTrackedBreaches(ctx context.Context, query *TrackedBreachesQuery, nodes []*User, init func(*User), assign func(*User, *TrackedBreaches)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(trackedbreaches.FieldOwner)
|
||||
}
|
||||
query.Where(predicate.TrackedBreaches(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.TrackedBreachesColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.Owner
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "owner" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (uq *UserQuery) loadSearchQueries(ctx context.Context, query *SearchQueryQuery, nodes []*User, init func(*User), assign func(*User, *SearchQuery)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uuid.UUID]*User)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
if len(query.ctx.Fields) > 0 {
|
||||
query.ctx.AppendFieldOnce(searchquery.FieldOwner)
|
||||
}
|
||||
query.Where(predicate.SearchQuery(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.SearchQueriesColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.Owner
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "owner" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := uq.querySpec()
|
||||
_spec.Node.Columns = uq.ctx.Fields
|
||||
|
|
|
@ -12,7 +12,10 @@ import (
|
|||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/predicate"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/searchquery"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/trackedbreaches"
|
||||
"git.dotya.ml/mirre-mt/pcmt/ent/user"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// UserUpdate is the builder for updating User entities.
|
||||
|
@ -86,11 +89,83 @@ func (uu *UserUpdate) SetLastLogin(t time.Time) *UserUpdate {
|
|||
return uu
|
||||
}
|
||||
|
||||
// AddTrackedBreachIDs adds the "tracked_breaches" edge to the TrackedBreaches entity by IDs.
|
||||
func (uu *UserUpdate) AddTrackedBreachIDs(ids ...uuid.UUID) *UserUpdate {
|
||||
uu.mutation.AddTrackedBreachIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// AddTrackedBreaches adds the "tracked_breaches" edges to the TrackedBreaches entity.
|
||||
func (uu *UserUpdate) AddTrackedBreaches(t ...*TrackedBreaches) *UserUpdate {
|
||||
ids := make([]uuid.UUID, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return uu.AddTrackedBreachIDs(ids...)
|
||||
}
|
||||
|
||||
// AddSearchQueryIDs adds the "search_queries" edge to the SearchQuery entity by IDs.
|
||||
func (uu *UserUpdate) AddSearchQueryIDs(ids ...uuid.UUID) *UserUpdate {
|
||||
uu.mutation.AddSearchQueryIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// AddSearchQueries adds the "search_queries" edges to the SearchQuery entity.
|
||||
func (uu *UserUpdate) AddSearchQueries(s ...*SearchQuery) *UserUpdate {
|
||||
ids := make([]uuid.UUID, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return uu.AddSearchQueryIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uu *UserUpdate) Mutation() *UserMutation {
|
||||
return uu.mutation
|
||||
}
|
||||
|
||||
// ClearTrackedBreaches clears all "tracked_breaches" edges to the TrackedBreaches entity.
|
||||
func (uu *UserUpdate) ClearTrackedBreaches() *UserUpdate {
|
||||
uu.mutation.ClearTrackedBreaches()
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveTrackedBreachIDs removes the "tracked_breaches" edge to TrackedBreaches entities by IDs.
|
||||
func (uu *UserUpdate) RemoveTrackedBreachIDs(ids ...uuid.UUID) *UserUpdate {
|
||||
uu.mutation.RemoveTrackedBreachIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveTrackedBreaches removes "tracked_breaches" edges to TrackedBreaches entities.
|
||||
func (uu *UserUpdate) RemoveTrackedBreaches(t ...*TrackedBreaches) *UserUpdate {
|
||||
ids := make([]uuid.UUID, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return uu.RemoveTrackedBreachIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearSearchQueries clears all "search_queries" edges to the SearchQuery entity.
|
||||
func (uu *UserUpdate) ClearSearchQueries() *UserUpdate {
|
||||
uu.mutation.ClearSearchQueries()
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveSearchQueryIDs removes the "search_queries" edge to SearchQuery entities by IDs.
|
||||
func (uu *UserUpdate) RemoveSearchQueryIDs(ids ...uuid.UUID) *UserUpdate {
|
||||
uu.mutation.RemoveSearchQueryIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveSearchQueries removes "search_queries" edges to SearchQuery entities.
|
||||
func (uu *UserUpdate) RemoveSearchQueries(s ...*SearchQuery) *UserUpdate {
|
||||
ids := make([]uuid.UUID, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return uu.RemoveSearchQueryIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
|
||||
uu.defaults()
|
||||
|
@ -184,6 +259,96 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||
if value, ok := uu.mutation.LastLogin(); ok {
|
||||
_spec.SetField(user.FieldLastLogin, field.TypeTime, value)
|
||||
}
|
||||
if uu.mutation.TrackedBreachesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.TrackedBreachesTable,
|
||||
Columns: []string{user.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.RemovedTrackedBreachesIDs(); len(nodes) > 0 && !uu.mutation.TrackedBreachesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.TrackedBreachesTable,
|
||||
Columns: []string{user.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.TrackedBreachesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.TrackedBreachesTable,
|
||||
Columns: []string{user.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if uu.mutation.SearchQueriesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.SearchQueriesTable,
|
||||
Columns: []string{user.SearchQueriesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.RemovedSearchQueriesIDs(); len(nodes) > 0 && !uu.mutation.SearchQueriesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.SearchQueriesTable,
|
||||
Columns: []string{user.SearchQueriesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.SearchQueriesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.SearchQueriesTable,
|
||||
Columns: []string{user.SearchQueriesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{user.Label}
|
||||
|
@ -262,11 +427,83 @@ func (uuo *UserUpdateOne) SetLastLogin(t time.Time) *UserUpdateOne {
|
|||
return uuo
|
||||
}
|
||||
|
||||
// AddTrackedBreachIDs adds the "tracked_breaches" edge to the TrackedBreaches entity by IDs.
|
||||
func (uuo *UserUpdateOne) AddTrackedBreachIDs(ids ...uuid.UUID) *UserUpdateOne {
|
||||
uuo.mutation.AddTrackedBreachIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// AddTrackedBreaches adds the "tracked_breaches" edges to the TrackedBreaches entity.
|
||||
func (uuo *UserUpdateOne) AddTrackedBreaches(t ...*TrackedBreaches) *UserUpdateOne {
|
||||
ids := make([]uuid.UUID, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return uuo.AddTrackedBreachIDs(ids...)
|
||||
}
|
||||
|
||||
// AddSearchQueryIDs adds the "search_queries" edge to the SearchQuery entity by IDs.
|
||||
func (uuo *UserUpdateOne) AddSearchQueryIDs(ids ...uuid.UUID) *UserUpdateOne {
|
||||
uuo.mutation.AddSearchQueryIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// AddSearchQueries adds the "search_queries" edges to the SearchQuery entity.
|
||||
func (uuo *UserUpdateOne) AddSearchQueries(s ...*SearchQuery) *UserUpdateOne {
|
||||
ids := make([]uuid.UUID, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return uuo.AddSearchQueryIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uuo *UserUpdateOne) Mutation() *UserMutation {
|
||||
return uuo.mutation
|
||||
}
|
||||
|
||||
// ClearTrackedBreaches clears all "tracked_breaches" edges to the TrackedBreaches entity.
|
||||
func (uuo *UserUpdateOne) ClearTrackedBreaches() *UserUpdateOne {
|
||||
uuo.mutation.ClearTrackedBreaches()
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveTrackedBreachIDs removes the "tracked_breaches" edge to TrackedBreaches entities by IDs.
|
||||
func (uuo *UserUpdateOne) RemoveTrackedBreachIDs(ids ...uuid.UUID) *UserUpdateOne {
|
||||
uuo.mutation.RemoveTrackedBreachIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveTrackedBreaches removes "tracked_breaches" edges to TrackedBreaches entities.
|
||||
func (uuo *UserUpdateOne) RemoveTrackedBreaches(t ...*TrackedBreaches) *UserUpdateOne {
|
||||
ids := make([]uuid.UUID, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return uuo.RemoveTrackedBreachIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearSearchQueries clears all "search_queries" edges to the SearchQuery entity.
|
||||
func (uuo *UserUpdateOne) ClearSearchQueries() *UserUpdateOne {
|
||||
uuo.mutation.ClearSearchQueries()
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveSearchQueryIDs removes the "search_queries" edge to SearchQuery entities by IDs.
|
||||
func (uuo *UserUpdateOne) RemoveSearchQueryIDs(ids ...uuid.UUID) *UserUpdateOne {
|
||||
uuo.mutation.RemoveSearchQueryIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveSearchQueries removes "search_queries" edges to SearchQuery entities.
|
||||
func (uuo *UserUpdateOne) RemoveSearchQueries(s ...*SearchQuery) *UserUpdateOne {
|
||||
ids := make([]uuid.UUID, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
}
|
||||
return uuo.RemoveSearchQueryIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserUpdate builder.
|
||||
func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
|
||||
uuo.mutation.Where(ps...)
|
||||
|
@ -390,6 +627,96 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
|
|||
if value, ok := uuo.mutation.LastLogin(); ok {
|
||||
_spec.SetField(user.FieldLastLogin, field.TypeTime, value)
|
||||
}
|
||||
if uuo.mutation.TrackedBreachesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.TrackedBreachesTable,
|
||||
Columns: []string{user.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.RemovedTrackedBreachesIDs(); len(nodes) > 0 && !uuo.mutation.TrackedBreachesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.TrackedBreachesTable,
|
||||
Columns: []string{user.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.TrackedBreachesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.TrackedBreachesTable,
|
||||
Columns: []string{user.TrackedBreachesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(trackedbreaches.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if uuo.mutation.SearchQueriesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.SearchQueriesTable,
|
||||
Columns: []string{user.SearchQueriesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.RemovedSearchQueriesIDs(); len(nodes) > 0 && !uuo.mutation.SearchQueriesCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.SearchQueriesTable,
|
||||
Columns: []string{user.SearchQueriesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.SearchQueriesIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: user.SearchQueriesTable,
|
||||
Columns: []string{user.SearchQueriesColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(searchquery.FieldID, field.TypeUUID),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &User{config: uuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
|
Loading…
Reference in New Issue