ent schema post generation
This commit is contained in:
parent
6a3b64ed28
commit
e9955b3a28
198
ent/account.go
Normal file
198
ent/account.go
Normal file
@ -0,0 +1,198 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Account is the model entity for the Account schema.
|
||||||
|
type Account struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// Created holds the value of the "created" field.
|
||||||
|
Created time.Time `json:"created,omitempty"`
|
||||||
|
// Modified holds the value of the "modified" field.
|
||||||
|
Modified time.Time `json:"modified,omitempty"`
|
||||||
|
// Username holds the value of the "username" field.
|
||||||
|
Username string `json:"username,omitempty"`
|
||||||
|
// Password holds the value of the "password" field.
|
||||||
|
Password []byte `json:"password,omitempty"`
|
||||||
|
// Super holds the value of the "super" field.
|
||||||
|
Super bool `json:"super,omitempty"`
|
||||||
|
// Active holds the value of the "active" field.
|
||||||
|
Active bool `json:"active,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the AccountQuery when eager-loading is set.
|
||||||
|
Edges AccountEdges `json:"edges"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type AccountEdges struct {
|
||||||
|
// Domains holds the value of the domains edge.
|
||||||
|
Domains []*Domain `json:"domains,omitempty"`
|
||||||
|
// Logs holds the value of the logs edge.
|
||||||
|
Logs []*Logentry `json:"logs,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [2]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainsOrErr returns the Domains value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e AccountEdges) DomainsOrErr() ([]*Domain, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
return e.Domains, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "domains"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogsOrErr returns the Logs value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e AccountEdges) LogsOrErr() ([]*Logentry, error) {
|
||||||
|
if e.loadedTypes[1] {
|
||||||
|
return e.Logs, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "logs"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Account) scanValues(columns []string) ([]interface{}, error) {
|
||||||
|
values := make([]interface{}, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case account.FieldPassword:
|
||||||
|
values[i] = new([]byte)
|
||||||
|
case account.FieldSuper, account.FieldActive:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case account.FieldID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case account.FieldUsername:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case account.FieldCreated, account.FieldModified:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unexpected column %q for type Account", columns[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Account fields.
|
||||||
|
func (a *Account) assignValues(columns []string, values []interface{}) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case account.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
a.ID = int64(value.Int64)
|
||||||
|
case account.FieldCreated:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
a.Created = value.Time
|
||||||
|
}
|
||||||
|
case account.FieldModified:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field modified", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
a.Modified = value.Time
|
||||||
|
}
|
||||||
|
case account.FieldUsername:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field username", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
a.Username = value.String
|
||||||
|
}
|
||||||
|
case account.FieldPassword:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field password", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
a.Password = *value
|
||||||
|
}
|
||||||
|
case account.FieldSuper:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field super", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
a.Super = value.Bool
|
||||||
|
}
|
||||||
|
case account.FieldActive:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field active", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
a.Active = value.Bool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryDomains queries the "domains" edge of the Account entity.
|
||||||
|
func (a *Account) QueryDomains() *DomainQuery {
|
||||||
|
return (&AccountClient{config: a.config}).QueryDomains(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryLogs queries the "logs" edge of the Account entity.
|
||||||
|
func (a *Account) QueryLogs() *LogentryQuery {
|
||||||
|
return (&AccountClient{config: a.config}).QueryLogs(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Account.
|
||||||
|
// Note that you need to call Account.Unwrap() before calling this method if this Account
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (a *Account) Update() *AccountUpdateOne {
|
||||||
|
return (&AccountClient{config: a.config}).UpdateOne(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Account entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (a *Account) Unwrap() *Account {
|
||||||
|
tx, ok := a.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: Account is not a transactional entity")
|
||||||
|
}
|
||||||
|
a.config.driver = tx.drv
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (a *Account) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Account(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v", a.ID))
|
||||||
|
builder.WriteString(", created=")
|
||||||
|
builder.WriteString(a.Created.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", modified=")
|
||||||
|
builder.WriteString(a.Modified.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", username=")
|
||||||
|
builder.WriteString(a.Username)
|
||||||
|
builder.WriteString(", password=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", a.Password))
|
||||||
|
builder.WriteString(", super=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", a.Super))
|
||||||
|
builder.WriteString(", active=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", a.Active))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Accounts is a parsable slice of Account.
|
||||||
|
type Accounts []*Account
|
||||||
|
|
||||||
|
func (a Accounts) config(cfg config) {
|
||||||
|
for _i := range a {
|
||||||
|
a[_i].config = cfg
|
||||||
|
}
|
||||||
|
}
|
80
ent/account/account.go
Normal file
80
ent/account/account.go
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the account type in the database.
|
||||||
|
Label = "account"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreated holds the string denoting the created field in the database.
|
||||||
|
FieldCreated = "created"
|
||||||
|
// FieldModified holds the string denoting the modified field in the database.
|
||||||
|
FieldModified = "modified"
|
||||||
|
// FieldUsername holds the string denoting the username field in the database.
|
||||||
|
FieldUsername = "username"
|
||||||
|
// FieldPassword holds the string denoting the password field in the database.
|
||||||
|
FieldPassword = "password"
|
||||||
|
// FieldSuper holds the string denoting the super field in the database.
|
||||||
|
FieldSuper = "super"
|
||||||
|
// FieldActive holds the string denoting the active field in the database.
|
||||||
|
FieldActive = "active"
|
||||||
|
// EdgeDomains holds the string denoting the domains edge name in mutations.
|
||||||
|
EdgeDomains = "domains"
|
||||||
|
// EdgeLogs holds the string denoting the logs edge name in mutations.
|
||||||
|
EdgeLogs = "logs"
|
||||||
|
// Table holds the table name of the account in the database.
|
||||||
|
Table = "accounts"
|
||||||
|
// DomainsTable is the table that holds the domains relation/edge. The primary key declared below.
|
||||||
|
DomainsTable = "account_domains"
|
||||||
|
// DomainsInverseTable is the table name for the Domain entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "domain" package.
|
||||||
|
DomainsInverseTable = "domains"
|
||||||
|
// LogsTable is the table that holds the logs relation/edge.
|
||||||
|
LogsTable = "logentries"
|
||||||
|
// LogsInverseTable is the table name for the Logentry entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "logentry" package.
|
||||||
|
LogsInverseTable = "logentries"
|
||||||
|
// LogsColumn is the table column denoting the logs relation/edge.
|
||||||
|
LogsColumn = "account_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for account fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreated,
|
||||||
|
FieldModified,
|
||||||
|
FieldUsername,
|
||||||
|
FieldPassword,
|
||||||
|
FieldSuper,
|
||||||
|
FieldActive,
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// DomainsPrimaryKey and DomainsColumn2 are the table columns denoting the
|
||||||
|
// primary key for the domains relation (M2M).
|
||||||
|
DomainsPrimaryKey = []string{"account_id", "domain_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 (
|
||||||
|
// DefaultCreated holds the default value on creation for the "created" field.
|
||||||
|
DefaultCreated func() time.Time
|
||||||
|
// DefaultModified holds the default value on creation for the "modified" field.
|
||||||
|
DefaultModified func() time.Time
|
||||||
|
// UpdateDefaultModified holds the default value on update for the "modified" field.
|
||||||
|
UpdateDefaultModified func() time.Time
|
||||||
|
)
|
605
ent/account/where.go
Normal file
605
ent/account/where.go
Normal file
@ -0,0 +1,605 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package account
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(ids) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v := make([]interface{}, len(ids))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = ids[i]
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(ids) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v := make([]interface{}, len(ids))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = ids[i]
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Created applies equality check predicate on the "created" field. It's identical to CreatedEQ.
|
||||||
|
func Created(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modified applies equality check predicate on the "modified" field. It's identical to ModifiedEQ.
|
||||||
|
func Modified(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Username applies equality check predicate on the "username" field. It's identical to UsernameEQ.
|
||||||
|
func Username(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ.
|
||||||
|
func Password(v []byte) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldPassword), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Super applies equality check predicate on the "super" field. It's identical to SuperEQ.
|
||||||
|
func Super(v bool) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldSuper), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Active applies equality check predicate on the "active" field. It's identical to ActiveEQ.
|
||||||
|
func Active(v bool) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldActive), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedEQ applies the EQ predicate on the "created" field.
|
||||||
|
func CreatedEQ(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedNEQ applies the NEQ predicate on the "created" field.
|
||||||
|
func CreatedNEQ(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedIn applies the In predicate on the "created" field.
|
||||||
|
func CreatedIn(vs ...time.Time) predicate.Account {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldCreated), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedNotIn applies the NotIn predicate on the "created" field.
|
||||||
|
func CreatedNotIn(vs ...time.Time) predicate.Account {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldCreated), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedGT applies the GT predicate on the "created" field.
|
||||||
|
func CreatedGT(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedGTE applies the GTE predicate on the "created" field.
|
||||||
|
func CreatedGTE(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedLT applies the LT predicate on the "created" field.
|
||||||
|
func CreatedLT(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedLTE applies the LTE predicate on the "created" field.
|
||||||
|
func CreatedLTE(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedEQ applies the EQ predicate on the "modified" field.
|
||||||
|
func ModifiedEQ(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedNEQ applies the NEQ predicate on the "modified" field.
|
||||||
|
func ModifiedNEQ(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedIn applies the In predicate on the "modified" field.
|
||||||
|
func ModifiedIn(vs ...time.Time) predicate.Account {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldModified), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedNotIn applies the NotIn predicate on the "modified" field.
|
||||||
|
func ModifiedNotIn(vs ...time.Time) predicate.Account {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldModified), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedGT applies the GT predicate on the "modified" field.
|
||||||
|
func ModifiedGT(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedGTE applies the GTE predicate on the "modified" field.
|
||||||
|
func ModifiedGTE(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedLT applies the LT predicate on the "modified" field.
|
||||||
|
func ModifiedLT(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedLTE applies the LTE predicate on the "modified" field.
|
||||||
|
func ModifiedLTE(v time.Time) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedIsNil applies the IsNil predicate on the "modified" field.
|
||||||
|
func ModifiedIsNil() predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.IsNull(s.C(FieldModified)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedNotNil applies the NotNil predicate on the "modified" field.
|
||||||
|
func ModifiedNotNil() predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotNull(s.C(FieldModified)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameEQ applies the EQ predicate on the "username" field.
|
||||||
|
func UsernameEQ(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameNEQ applies the NEQ predicate on the "username" field.
|
||||||
|
func UsernameNEQ(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameIn applies the In predicate on the "username" field.
|
||||||
|
func UsernameIn(vs ...string) predicate.Account {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldUsername), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameNotIn applies the NotIn predicate on the "username" field.
|
||||||
|
func UsernameNotIn(vs ...string) predicate.Account {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldUsername), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameGT applies the GT predicate on the "username" field.
|
||||||
|
func UsernameGT(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameGTE applies the GTE predicate on the "username" field.
|
||||||
|
func UsernameGTE(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameLT applies the LT predicate on the "username" field.
|
||||||
|
func UsernameLT(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameLTE applies the LTE predicate on the "username" field.
|
||||||
|
func UsernameLTE(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameContains applies the Contains predicate on the "username" field.
|
||||||
|
func UsernameContains(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.Contains(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameHasPrefix applies the HasPrefix predicate on the "username" field.
|
||||||
|
func UsernameHasPrefix(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasPrefix(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameHasSuffix applies the HasSuffix predicate on the "username" field.
|
||||||
|
func UsernameHasSuffix(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasSuffix(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameEqualFold applies the EqualFold predicate on the "username" field.
|
||||||
|
func UsernameEqualFold(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EqualFold(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// UsernameContainsFold applies the ContainsFold predicate on the "username" field.
|
||||||
|
func UsernameContainsFold(v string) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.ContainsFold(s.C(FieldUsername), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// PasswordEQ applies the EQ predicate on the "password" field.
|
||||||
|
func PasswordEQ(v []byte) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldPassword), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// PasswordNEQ applies the NEQ predicate on the "password" field.
|
||||||
|
func PasswordNEQ(v []byte) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldPassword), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// PasswordIn applies the In predicate on the "password" field.
|
||||||
|
func PasswordIn(vs ...[]byte) predicate.Account {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldPassword), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// PasswordNotIn applies the NotIn predicate on the "password" field.
|
||||||
|
func PasswordNotIn(vs ...[]byte) predicate.Account {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldPassword), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// PasswordGT applies the GT predicate on the "password" field.
|
||||||
|
func PasswordGT(v []byte) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldPassword), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// PasswordGTE applies the GTE predicate on the "password" field.
|
||||||
|
func PasswordGTE(v []byte) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldPassword), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// PasswordLT applies the LT predicate on the "password" field.
|
||||||
|
func PasswordLT(v []byte) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldPassword), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// PasswordLTE applies the LTE predicate on the "password" field.
|
||||||
|
func PasswordLTE(v []byte) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldPassword), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SuperEQ applies the EQ predicate on the "super" field.
|
||||||
|
func SuperEQ(v bool) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldSuper), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// SuperNEQ applies the NEQ predicate on the "super" field.
|
||||||
|
func SuperNEQ(v bool) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldSuper), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActiveEQ applies the EQ predicate on the "active" field.
|
||||||
|
func ActiveEQ(v bool) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldActive), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActiveNEQ applies the NEQ predicate on the "active" field.
|
||||||
|
func ActiveNEQ(v bool) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldActive), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasDomains applies the HasEdge predicate on the "domains" edge.
|
||||||
|
func HasDomains() predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(DomainsTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, DomainsTable, DomainsPrimaryKey...),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasDomainsWith applies the HasEdge predicate on the "domains" edge with a given conditions (other predicates).
|
||||||
|
func HasDomainsWith(preds ...predicate.Domain) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(DomainsInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, DomainsTable, DomainsPrimaryKey...),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasLogs applies the HasEdge predicate on the "logs" edge.
|
||||||
|
func HasLogs() predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(LogsTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, LogsTable, LogsColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasLogsWith applies the HasEdge predicate on the "logs" edge with a given conditions (other predicates).
|
||||||
|
func HasLogsWith(preds ...predicate.Logentry) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(LogsInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, LogsTable, LogsColumn),
|
||||||
|
)
|
||||||
|
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.Account) predicate.Account {
|
||||||
|
return predicate.Account(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.Account) predicate.Account {
|
||||||
|
return predicate.Account(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.Account) predicate.Account {
|
||||||
|
return predicate.Account(func(s *sql.Selector) {
|
||||||
|
p(s.Not())
|
||||||
|
})
|
||||||
|
}
|
415
ent/account_create.go
Normal file
415
ent/account_create.go
Normal file
@ -0,0 +1,415 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/logentry"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AccountCreate is the builder for creating a Account entity.
|
||||||
|
type AccountCreate struct {
|
||||||
|
config
|
||||||
|
mutation *AccountMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreated sets the "created" field.
|
||||||
|
func (ac *AccountCreate) SetCreated(t time.Time) *AccountCreate {
|
||||||
|
ac.mutation.SetCreated(t)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreated sets the "created" field if the given value is not nil.
|
||||||
|
func (ac *AccountCreate) SetNillableCreated(t *time.Time) *AccountCreate {
|
||||||
|
if t != nil {
|
||||||
|
ac.SetCreated(*t)
|
||||||
|
}
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModified sets the "modified" field.
|
||||||
|
func (ac *AccountCreate) SetModified(t time.Time) *AccountCreate {
|
||||||
|
ac.mutation.SetModified(t)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableModified sets the "modified" field if the given value is not nil.
|
||||||
|
func (ac *AccountCreate) SetNillableModified(t *time.Time) *AccountCreate {
|
||||||
|
if t != nil {
|
||||||
|
ac.SetModified(*t)
|
||||||
|
}
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUsername sets the "username" field.
|
||||||
|
func (ac *AccountCreate) SetUsername(s string) *AccountCreate {
|
||||||
|
ac.mutation.SetUsername(s)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPassword sets the "password" field.
|
||||||
|
func (ac *AccountCreate) SetPassword(b []byte) *AccountCreate {
|
||||||
|
ac.mutation.SetPassword(b)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSuper sets the "super" field.
|
||||||
|
func (ac *AccountCreate) SetSuper(b bool) *AccountCreate {
|
||||||
|
ac.mutation.SetSuper(b)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActive sets the "active" field.
|
||||||
|
func (ac *AccountCreate) SetActive(b bool) *AccountCreate {
|
||||||
|
ac.mutation.SetActive(b)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (ac *AccountCreate) SetID(i int64) *AccountCreate {
|
||||||
|
ac.mutation.SetID(i)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddDomainIDs adds the "domains" edge to the Domain entity by IDs.
|
||||||
|
func (ac *AccountCreate) AddDomainIDs(ids ...int64) *AccountCreate {
|
||||||
|
ac.mutation.AddDomainIDs(ids...)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddDomains adds the "domains" edges to the Domain entity.
|
||||||
|
func (ac *AccountCreate) AddDomains(d ...*Domain) *AccountCreate {
|
||||||
|
ids := make([]int64, len(d))
|
||||||
|
for i := range d {
|
||||||
|
ids[i] = d[i].ID
|
||||||
|
}
|
||||||
|
return ac.AddDomainIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLogIDs adds the "logs" edge to the Logentry entity by IDs.
|
||||||
|
func (ac *AccountCreate) AddLogIDs(ids ...int64) *AccountCreate {
|
||||||
|
ac.mutation.AddLogIDs(ids...)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLogs adds the "logs" edges to the Logentry entity.
|
||||||
|
func (ac *AccountCreate) AddLogs(l ...*Logentry) *AccountCreate {
|
||||||
|
ids := make([]int64, len(l))
|
||||||
|
for i := range l {
|
||||||
|
ids[i] = l[i].ID
|
||||||
|
}
|
||||||
|
return ac.AddLogIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AccountMutation object of the builder.
|
||||||
|
func (ac *AccountCreate) Mutation() *AccountMutation {
|
||||||
|
return ac.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Account in the database.
|
||||||
|
func (ac *AccountCreate) Save(ctx context.Context) (*Account, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *Account
|
||||||
|
)
|
||||||
|
ac.defaults()
|
||||||
|
if len(ac.hooks) == 0 {
|
||||||
|
if err = ac.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
node, err = ac.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*AccountMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err = ac.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ac.mutation = mutation
|
||||||
|
if node, err = ac.sqlSave(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &node.ID
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(ac.hooks) - 1; i >= 0; i-- {
|
||||||
|
if ac.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = ac.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, ac.mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (ac *AccountCreate) SaveX(ctx context.Context) *Account {
|
||||||
|
v, err := ac.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (ac *AccountCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := ac.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ac *AccountCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := ac.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (ac *AccountCreate) defaults() {
|
||||||
|
if _, ok := ac.mutation.Created(); !ok {
|
||||||
|
v := account.DefaultCreated()
|
||||||
|
ac.mutation.SetCreated(v)
|
||||||
|
}
|
||||||
|
if _, ok := ac.mutation.Modified(); !ok {
|
||||||
|
v := account.DefaultModified()
|
||||||
|
ac.mutation.SetModified(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (ac *AccountCreate) check() error {
|
||||||
|
if _, ok := ac.mutation.Created(); !ok {
|
||||||
|
return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "Account.created"`)}
|
||||||
|
}
|
||||||
|
if _, ok := ac.mutation.Username(); !ok {
|
||||||
|
return &ValidationError{Name: "username", err: errors.New(`ent: missing required field "Account.username"`)}
|
||||||
|
}
|
||||||
|
if _, ok := ac.mutation.Password(); !ok {
|
||||||
|
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Account.password"`)}
|
||||||
|
}
|
||||||
|
if _, ok := ac.mutation.Super(); !ok {
|
||||||
|
return &ValidationError{Name: "super", err: errors.New(`ent: missing required field "Account.super"`)}
|
||||||
|
}
|
||||||
|
if _, ok := ac.mutation.Active(); !ok {
|
||||||
|
return &ValidationError{Name: "active", err: errors.New(`ent: missing required field "Account.active"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ac *AccountCreate) sqlSave(ctx context.Context) (*Account, error) {
|
||||||
|
_node, _spec := ac.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != _node.ID {
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int64(id)
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ac *AccountCreate) createSpec() (*Account, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Account{config: ac.config}
|
||||||
|
_spec = &sqlgraph.CreateSpec{
|
||||||
|
Table: account.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: account.FieldID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if id, ok := ac.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = id
|
||||||
|
}
|
||||||
|
if value, ok := ac.mutation.Created(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldCreated,
|
||||||
|
})
|
||||||
|
_node.Created = value
|
||||||
|
}
|
||||||
|
if value, ok := ac.mutation.Modified(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldModified,
|
||||||
|
})
|
||||||
|
_node.Modified = value
|
||||||
|
}
|
||||||
|
if value, ok := ac.mutation.Username(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldUsername,
|
||||||
|
})
|
||||||
|
_node.Username = value
|
||||||
|
}
|
||||||
|
if value, ok := ac.mutation.Password(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBytes,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldPassword,
|
||||||
|
})
|
||||||
|
_node.Password = value
|
||||||
|
}
|
||||||
|
if value, ok := ac.mutation.Super(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldSuper,
|
||||||
|
})
|
||||||
|
_node.Super = value
|
||||||
|
}
|
||||||
|
if value, ok := ac.mutation.Active(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldActive,
|
||||||
|
})
|
||||||
|
_node.Active = value
|
||||||
|
}
|
||||||
|
if nodes := ac.mutation.DomainsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.DomainsTable,
|
||||||
|
Columns: account.DomainsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
if nodes := ac.mutation.LogsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.LogsTable,
|
||||||
|
Columns: []string{account.LogsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountCreateBulk is the builder for creating many Account entities in bulk.
|
||||||
|
type AccountCreateBulk struct {
|
||||||
|
config
|
||||||
|
builders []*AccountCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Account entities in the database.
|
||||||
|
func (acb *AccountCreateBulk) Save(ctx context.Context) ([]*Account, error) {
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(acb.builders))
|
||||||
|
nodes := make([]*Account, len(acb.builders))
|
||||||
|
mutators := make([]Mutator, len(acb.builders))
|
||||||
|
for i := range acb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := acb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*AccountMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
var err error
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, acb.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, acb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
mutation.done = true
|
||||||
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int64(id)
|
||||||
|
}
|
||||||
|
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, acb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (acb *AccountCreateBulk) SaveX(ctx context.Context) []*Account {
|
||||||
|
v, err := acb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (acb *AccountCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := acb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (acb *AccountCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := acb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
111
ent/account_delete.go
Normal file
111
ent/account_delete.go
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AccountDelete is the builder for deleting a Account entity.
|
||||||
|
type AccountDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AccountMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AccountDelete builder.
|
||||||
|
func (ad *AccountDelete) Where(ps ...predicate.Account) *AccountDelete {
|
||||||
|
ad.mutation.Where(ps...)
|
||||||
|
return ad
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (ad *AccountDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
if len(ad.hooks) == 0 {
|
||||||
|
affected, err = ad.sqlExec(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*AccountMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
ad.mutation = mutation
|
||||||
|
affected, err = ad.sqlExec(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(ad.hooks) - 1; i >= 0; i-- {
|
||||||
|
if ad.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = ad.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, ad.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ad *AccountDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := ad.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ad *AccountDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := &sqlgraph.DeleteSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: account.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: account.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := ad.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sqlgraph.DeleteNodes(ctx, ad.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountDeleteOne is the builder for deleting a single Account entity.
|
||||||
|
type AccountDeleteOne struct {
|
||||||
|
ad *AccountDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (ado *AccountDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := ado.ad.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{account.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ado *AccountDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
ado.ad.ExecX(ctx)
|
||||||
|
}
|
1091
ent/account_query.go
Normal file
1091
ent/account_query.go
Normal file
File diff suppressed because it is too large
Load Diff
774
ent/account_update.go
Normal file
774
ent/account_update.go
Normal file
@ -0,0 +1,774 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/logentry"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AccountUpdate is the builder for updating Account entities.
|
||||||
|
type AccountUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AccountMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AccountUpdate builder.
|
||||||
|
func (au *AccountUpdate) Where(ps ...predicate.Account) *AccountUpdate {
|
||||||
|
au.mutation.Where(ps...)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModified sets the "modified" field.
|
||||||
|
func (au *AccountUpdate) SetModified(t time.Time) *AccountUpdate {
|
||||||
|
au.mutation.SetModified(t)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearModified clears the value of the "modified" field.
|
||||||
|
func (au *AccountUpdate) ClearModified() *AccountUpdate {
|
||||||
|
au.mutation.ClearModified()
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUsername sets the "username" field.
|
||||||
|
func (au *AccountUpdate) SetUsername(s string) *AccountUpdate {
|
||||||
|
au.mutation.SetUsername(s)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPassword sets the "password" field.
|
||||||
|
func (au *AccountUpdate) SetPassword(b []byte) *AccountUpdate {
|
||||||
|
au.mutation.SetPassword(b)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSuper sets the "super" field.
|
||||||
|
func (au *AccountUpdate) SetSuper(b bool) *AccountUpdate {
|
||||||
|
au.mutation.SetSuper(b)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActive sets the "active" field.
|
||||||
|
func (au *AccountUpdate) SetActive(b bool) *AccountUpdate {
|
||||||
|
au.mutation.SetActive(b)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddDomainIDs adds the "domains" edge to the Domain entity by IDs.
|
||||||
|
func (au *AccountUpdate) AddDomainIDs(ids ...int64) *AccountUpdate {
|
||||||
|
au.mutation.AddDomainIDs(ids...)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddDomains adds the "domains" edges to the Domain entity.
|
||||||
|
func (au *AccountUpdate) AddDomains(d ...*Domain) *AccountUpdate {
|
||||||
|
ids := make([]int64, len(d))
|
||||||
|
for i := range d {
|
||||||
|
ids[i] = d[i].ID
|
||||||
|
}
|
||||||
|
return au.AddDomainIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLogIDs adds the "logs" edge to the Logentry entity by IDs.
|
||||||
|
func (au *AccountUpdate) AddLogIDs(ids ...int64) *AccountUpdate {
|
||||||
|
au.mutation.AddLogIDs(ids...)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLogs adds the "logs" edges to the Logentry entity.
|
||||||
|
func (au *AccountUpdate) AddLogs(l ...*Logentry) *AccountUpdate {
|
||||||
|
ids := make([]int64, len(l))
|
||||||
|
for i := range l {
|
||||||
|
ids[i] = l[i].ID
|
||||||
|
}
|
||||||
|
return au.AddLogIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AccountMutation object of the builder.
|
||||||
|
func (au *AccountUpdate) Mutation() *AccountMutation {
|
||||||
|
return au.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomains clears all "domains" edges to the Domain entity.
|
||||||
|
func (au *AccountUpdate) ClearDomains() *AccountUpdate {
|
||||||
|
au.mutation.ClearDomains()
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveDomainIDs removes the "domains" edge to Domain entities by IDs.
|
||||||
|
func (au *AccountUpdate) RemoveDomainIDs(ids ...int64) *AccountUpdate {
|
||||||
|
au.mutation.RemoveDomainIDs(ids...)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveDomains removes "domains" edges to Domain entities.
|
||||||
|
func (au *AccountUpdate) RemoveDomains(d ...*Domain) *AccountUpdate {
|
||||||
|
ids := make([]int64, len(d))
|
||||||
|
for i := range d {
|
||||||
|
ids[i] = d[i].ID
|
||||||
|
}
|
||||||
|
return au.RemoveDomainIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLogs clears all "logs" edges to the Logentry entity.
|
||||||
|
func (au *AccountUpdate) ClearLogs() *AccountUpdate {
|
||||||
|
au.mutation.ClearLogs()
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveLogIDs removes the "logs" edge to Logentry entities by IDs.
|
||||||
|
func (au *AccountUpdate) RemoveLogIDs(ids ...int64) *AccountUpdate {
|
||||||
|
au.mutation.RemoveLogIDs(ids...)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveLogs removes "logs" edges to Logentry entities.
|
||||||
|
func (au *AccountUpdate) RemoveLogs(l ...*Logentry) *AccountUpdate {
|
||||||
|
ids := make([]int64, len(l))
|
||||||
|
for i := range l {
|
||||||
|
ids[i] = l[i].ID
|
||||||
|
}
|
||||||
|
return au.RemoveLogIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (au *AccountUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
au.defaults()
|
||||||
|
if len(au.hooks) == 0 {
|
||||||
|
affected, err = au.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*AccountMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
au.mutation = mutation
|
||||||
|
affected, err = au.sqlSave(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(au.hooks) - 1; i >= 0; i-- {
|
||||||
|
if au.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = au.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, au.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (au *AccountUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := au.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (au *AccountUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := au.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (au *AccountUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := au.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (au *AccountUpdate) defaults() {
|
||||||
|
if _, ok := au.mutation.Modified(); !ok && !au.mutation.ModifiedCleared() {
|
||||||
|
v := account.UpdateDefaultModified()
|
||||||
|
au.mutation.SetModified(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (au *AccountUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
_spec := &sqlgraph.UpdateSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: account.Table,
|
||||||
|
Columns: account.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: account.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := au.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := au.mutation.Modified(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if au.mutation.ModifiedCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Column: account.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := au.mutation.Username(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldUsername,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := au.mutation.Password(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBytes,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldPassword,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := au.mutation.Super(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldSuper,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := au.mutation.Active(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldActive,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if au.mutation.DomainsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.DomainsTable,
|
||||||
|
Columns: account.DomainsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := au.mutation.RemovedDomainsIDs(); len(nodes) > 0 && !au.mutation.DomainsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.DomainsTable,
|
||||||
|
Columns: account.DomainsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := au.mutation.DomainsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.DomainsTable,
|
||||||
|
Columns: account.DomainsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if au.mutation.LogsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.LogsTable,
|
||||||
|
Columns: []string{account.LogsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := au.mutation.RemovedLogsIDs(); len(nodes) > 0 && !au.mutation.LogsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.LogsTable,
|
||||||
|
Columns: []string{account.LogsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := au.mutation.LogsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.LogsTable,
|
||||||
|
Columns: []string{account.LogsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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, au.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{account.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountUpdateOne is the builder for updating a single Account entity.
|
||||||
|
type AccountUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AccountMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModified sets the "modified" field.
|
||||||
|
func (auo *AccountUpdateOne) SetModified(t time.Time) *AccountUpdateOne {
|
||||||
|
auo.mutation.SetModified(t)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearModified clears the value of the "modified" field.
|
||||||
|
func (auo *AccountUpdateOne) ClearModified() *AccountUpdateOne {
|
||||||
|
auo.mutation.ClearModified()
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUsername sets the "username" field.
|
||||||
|
func (auo *AccountUpdateOne) SetUsername(s string) *AccountUpdateOne {
|
||||||
|
auo.mutation.SetUsername(s)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPassword sets the "password" field.
|
||||||
|
func (auo *AccountUpdateOne) SetPassword(b []byte) *AccountUpdateOne {
|
||||||
|
auo.mutation.SetPassword(b)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSuper sets the "super" field.
|
||||||
|
func (auo *AccountUpdateOne) SetSuper(b bool) *AccountUpdateOne {
|
||||||
|
auo.mutation.SetSuper(b)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActive sets the "active" field.
|
||||||
|
func (auo *AccountUpdateOne) SetActive(b bool) *AccountUpdateOne {
|
||||||
|
auo.mutation.SetActive(b)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddDomainIDs adds the "domains" edge to the Domain entity by IDs.
|
||||||
|
func (auo *AccountUpdateOne) AddDomainIDs(ids ...int64) *AccountUpdateOne {
|
||||||
|
auo.mutation.AddDomainIDs(ids...)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddDomains adds the "domains" edges to the Domain entity.
|
||||||
|
func (auo *AccountUpdateOne) AddDomains(d ...*Domain) *AccountUpdateOne {
|
||||||
|
ids := make([]int64, len(d))
|
||||||
|
for i := range d {
|
||||||
|
ids[i] = d[i].ID
|
||||||
|
}
|
||||||
|
return auo.AddDomainIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLogIDs adds the "logs" edge to the Logentry entity by IDs.
|
||||||
|
func (auo *AccountUpdateOne) AddLogIDs(ids ...int64) *AccountUpdateOne {
|
||||||
|
auo.mutation.AddLogIDs(ids...)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLogs adds the "logs" edges to the Logentry entity.
|
||||||
|
func (auo *AccountUpdateOne) AddLogs(l ...*Logentry) *AccountUpdateOne {
|
||||||
|
ids := make([]int64, len(l))
|
||||||
|
for i := range l {
|
||||||
|
ids[i] = l[i].ID
|
||||||
|
}
|
||||||
|
return auo.AddLogIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AccountMutation object of the builder.
|
||||||
|
func (auo *AccountUpdateOne) Mutation() *AccountMutation {
|
||||||
|
return auo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomains clears all "domains" edges to the Domain entity.
|
||||||
|
func (auo *AccountUpdateOne) ClearDomains() *AccountUpdateOne {
|
||||||
|
auo.mutation.ClearDomains()
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveDomainIDs removes the "domains" edge to Domain entities by IDs.
|
||||||
|
func (auo *AccountUpdateOne) RemoveDomainIDs(ids ...int64) *AccountUpdateOne {
|
||||||
|
auo.mutation.RemoveDomainIDs(ids...)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveDomains removes "domains" edges to Domain entities.
|
||||||
|
func (auo *AccountUpdateOne) RemoveDomains(d ...*Domain) *AccountUpdateOne {
|
||||||
|
ids := make([]int64, len(d))
|
||||||
|
for i := range d {
|
||||||
|
ids[i] = d[i].ID
|
||||||
|
}
|
||||||
|
return auo.RemoveDomainIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearLogs clears all "logs" edges to the Logentry entity.
|
||||||
|
func (auo *AccountUpdateOne) ClearLogs() *AccountUpdateOne {
|
||||||
|
auo.mutation.ClearLogs()
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveLogIDs removes the "logs" edge to Logentry entities by IDs.
|
||||||
|
func (auo *AccountUpdateOne) RemoveLogIDs(ids ...int64) *AccountUpdateOne {
|
||||||
|
auo.mutation.RemoveLogIDs(ids...)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveLogs removes "logs" edges to Logentry entities.
|
||||||
|
func (auo *AccountUpdateOne) RemoveLogs(l ...*Logentry) *AccountUpdateOne {
|
||||||
|
ids := make([]int64, len(l))
|
||||||
|
for i := range l {
|
||||||
|
ids[i] = l[i].ID
|
||||||
|
}
|
||||||
|
return auo.RemoveLogIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (auo *AccountUpdateOne) Select(field string, fields ...string) *AccountUpdateOne {
|
||||||
|
auo.fields = append([]string{field}, fields...)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Account entity.
|
||||||
|
func (auo *AccountUpdateOne) Save(ctx context.Context) (*Account, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *Account
|
||||||
|
)
|
||||||
|
auo.defaults()
|
||||||
|
if len(auo.hooks) == 0 {
|
||||||
|
node, err = auo.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*AccountMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
auo.mutation = mutation
|
||||||
|
node, err = auo.sqlSave(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(auo.hooks) - 1; i >= 0; i-- {
|
||||||
|
if auo.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = auo.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, auo.mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (auo *AccountUpdateOne) SaveX(ctx context.Context) *Account {
|
||||||
|
node, err := auo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (auo *AccountUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := auo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (auo *AccountUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := auo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (auo *AccountUpdateOne) defaults() {
|
||||||
|
if _, ok := auo.mutation.Modified(); !ok && !auo.mutation.ModifiedCleared() {
|
||||||
|
v := account.UpdateDefaultModified()
|
||||||
|
auo.mutation.SetModified(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (auo *AccountUpdateOne) sqlSave(ctx context.Context) (_node *Account, err error) {
|
||||||
|
_spec := &sqlgraph.UpdateSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: account.Table,
|
||||||
|
Columns: account.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: account.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
id, ok := auo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Account.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := auo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, account.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !account.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != account.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := auo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := auo.mutation.Modified(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if auo.mutation.ModifiedCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Column: account.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := auo.mutation.Username(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldUsername,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := auo.mutation.Password(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBytes,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldPassword,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := auo.mutation.Super(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldSuper,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := auo.mutation.Active(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: account.FieldActive,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if auo.mutation.DomainsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.DomainsTable,
|
||||||
|
Columns: account.DomainsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := auo.mutation.RemovedDomainsIDs(); len(nodes) > 0 && !auo.mutation.DomainsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.DomainsTable,
|
||||||
|
Columns: account.DomainsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := auo.mutation.DomainsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.DomainsTable,
|
||||||
|
Columns: account.DomainsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if auo.mutation.LogsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.LogsTable,
|
||||||
|
Columns: []string{account.LogsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := auo.mutation.RemovedLogsIDs(); len(nodes) > 0 && !auo.mutation.LogsCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.LogsTable,
|
||||||
|
Columns: []string{account.LogsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := auo.mutation.LogsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: account.LogsTable,
|
||||||
|
Columns: []string{account.LogsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &Account{config: auo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{account.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
179
ent/alias.go
Normal file
179
ent/alias.go
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/alias"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Alias is the model entity for the Alias schema.
|
||||||
|
type Alias struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// Created holds the value of the "created" field.
|
||||||
|
Created time.Time `json:"created,omitempty"`
|
||||||
|
// Modified holds the value of the "modified" field.
|
||||||
|
Modified *time.Time `json:"modified,omitempty"`
|
||||||
|
// DomainID holds the value of the "domain_id" field.
|
||||||
|
DomainID int64 `json:"domain_id,omitempty"`
|
||||||
|
// Goto holds the value of the "goto" field.
|
||||||
|
Goto string `json:"goto,omitempty"`
|
||||||
|
// Active holds the value of the "active" field.
|
||||||
|
Active bool `json:"active,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the AliasQuery when eager-loading is set.
|
||||||
|
Edges AliasEdges `json:"edges"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AliasEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type AliasEdges struct {
|
||||||
|
// Domain holds the value of the domain edge.
|
||||||
|
Domain *Domain `json:"domain,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [1]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainOrErr returns the Domain value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e AliasEdges) DomainOrErr() (*Domain, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
if e.Domain == nil {
|
||||||
|
// The edge domain was loaded in eager-loading,
|
||||||
|
// but was not found.
|
||||||
|
return nil, &NotFoundError{label: domain.Label}
|
||||||
|
}
|
||||||
|
return e.Domain, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "domain"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Alias) scanValues(columns []string) ([]interface{}, error) {
|
||||||
|
values := make([]interface{}, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case alias.FieldActive:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case alias.FieldID, alias.FieldDomainID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case alias.FieldGoto:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case alias.FieldCreated, alias.FieldModified:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unexpected column %q for type Alias", columns[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Alias fields.
|
||||||
|
func (a *Alias) assignValues(columns []string, values []interface{}) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case alias.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
a.ID = int64(value.Int64)
|
||||||
|
case alias.FieldCreated:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
a.Created = value.Time
|
||||||
|
}
|
||||||
|
case alias.FieldModified:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field modified", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
a.Modified = new(time.Time)
|
||||||
|
*a.Modified = value.Time
|
||||||
|
}
|
||||||
|
case alias.FieldDomainID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field domain_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
a.DomainID = value.Int64
|
||||||
|
}
|
||||||
|
case alias.FieldGoto:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field goto", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
a.Goto = value.String
|
||||||
|
}
|
||||||
|
case alias.FieldActive:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field active", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
a.Active = value.Bool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryDomain queries the "domain" edge of the Alias entity.
|
||||||
|
func (a *Alias) QueryDomain() *DomainQuery {
|
||||||
|
return (&AliasClient{config: a.config}).QueryDomain(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Alias.
|
||||||
|
// Note that you need to call Alias.Unwrap() before calling this method if this Alias
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (a *Alias) Update() *AliasUpdateOne {
|
||||||
|
return (&AliasClient{config: a.config}).UpdateOne(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Alias entity that was returned from a transaction after it was closed,
|
||||||
|
// so that all future queries will be executed through the driver which created the transaction.
|
||||||
|
func (a *Alias) Unwrap() *Alias {
|
||||||
|
tx, ok := a.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: Alias is not a transactional entity")
|
||||||
|
}
|
||||||
|
a.config.driver = tx.drv
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (a *Alias) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Alias(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v", a.ID))
|
||||||
|
builder.WriteString(", created=")
|
||||||
|
builder.WriteString(a.Created.Format(time.ANSIC))
|
||||||
|
if v := a.Modified; v != nil {
|
||||||
|
builder.WriteString(", modified=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", domain_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", a.DomainID))
|
||||||
|
builder.WriteString(", goto=")
|
||||||
|
builder.WriteString(a.Goto)
|
||||||
|
builder.WriteString(", active=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", a.Active))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// AliasSlice is a parsable slice of Alias.
|
||||||
|
type AliasSlice []*Alias
|
||||||
|
|
||||||
|
func (a AliasSlice) config(cfg config) {
|
||||||
|
for _i := range a {
|
||||||
|
a[_i].config = cfg
|
||||||
|
}
|
||||||
|
}
|
64
ent/alias/alias.go
Normal file
64
ent/alias/alias.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package alias
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the alias type in the database.
|
||||||
|
Label = "alias"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreated holds the string denoting the created field in the database.
|
||||||
|
FieldCreated = "created"
|
||||||
|
// FieldModified holds the string denoting the modified field in the database.
|
||||||
|
FieldModified = "modified"
|
||||||
|
// FieldDomainID holds the string denoting the domain_id field in the database.
|
||||||
|
FieldDomainID = "domain_id"
|
||||||
|
// FieldGoto holds the string denoting the goto field in the database.
|
||||||
|
FieldGoto = "goto"
|
||||||
|
// FieldActive holds the string denoting the active field in the database.
|
||||||
|
FieldActive = "active"
|
||||||
|
// EdgeDomain holds the string denoting the domain edge name in mutations.
|
||||||
|
EdgeDomain = "domain"
|
||||||
|
// Table holds the table name of the alias in the database.
|
||||||
|
Table = "alias"
|
||||||
|
// DomainTable is the table that holds the domain relation/edge.
|
||||||
|
DomainTable = "alias"
|
||||||
|
// DomainInverseTable is the table name for the Domain entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "domain" package.
|
||||||
|
DomainInverseTable = "domains"
|
||||||
|
// DomainColumn is the table column denoting the domain relation/edge.
|
||||||
|
DomainColumn = "domain_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for alias fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreated,
|
||||||
|
FieldModified,
|
||||||
|
FieldDomainID,
|
||||||
|
FieldGoto,
|
||||||
|
FieldActive,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 (
|
||||||
|
// DefaultCreated holds the default value on creation for the "created" field.
|
||||||
|
DefaultCreated func() time.Time
|
||||||
|
// DefaultModified holds the default value on creation for the "modified" field.
|
||||||
|
DefaultModified func() time.Time
|
||||||
|
// UpdateDefaultModified holds the default value on update for the "modified" field.
|
||||||
|
UpdateDefaultModified func() time.Time
|
||||||
|
)
|
542
ent/alias/where.go
Normal file
542
ent/alias/where.go
Normal file
@ -0,0 +1,542 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package alias
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(ids) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v := make([]interface{}, len(ids))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = ids[i]
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(ids) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v := make([]interface{}, len(ids))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = ids[i]
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Created applies equality check predicate on the "created" field. It's identical to CreatedEQ.
|
||||||
|
func Created(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modified applies equality check predicate on the "modified" field. It's identical to ModifiedEQ.
|
||||||
|
func Modified(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainID applies equality check predicate on the "domain_id" field. It's identical to DomainIDEQ.
|
||||||
|
func DomainID(v int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldDomainID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Goto applies equality check predicate on the "goto" field. It's identical to GotoEQ.
|
||||||
|
func Goto(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Active applies equality check predicate on the "active" field. It's identical to ActiveEQ.
|
||||||
|
func Active(v bool) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldActive), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedEQ applies the EQ predicate on the "created" field.
|
||||||
|
func CreatedEQ(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedNEQ applies the NEQ predicate on the "created" field.
|
||||||
|
func CreatedNEQ(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedIn applies the In predicate on the "created" field.
|
||||||
|
func CreatedIn(vs ...time.Time) predicate.Alias {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldCreated), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedNotIn applies the NotIn predicate on the "created" field.
|
||||||
|
func CreatedNotIn(vs ...time.Time) predicate.Alias {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldCreated), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedGT applies the GT predicate on the "created" field.
|
||||||
|
func CreatedGT(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedGTE applies the GTE predicate on the "created" field.
|
||||||
|
func CreatedGTE(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedLT applies the LT predicate on the "created" field.
|
||||||
|
func CreatedLT(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreatedLTE applies the LTE predicate on the "created" field.
|
||||||
|
func CreatedLTE(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldCreated), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedEQ applies the EQ predicate on the "modified" field.
|
||||||
|
func ModifiedEQ(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedNEQ applies the NEQ predicate on the "modified" field.
|
||||||
|
func ModifiedNEQ(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedIn applies the In predicate on the "modified" field.
|
||||||
|
func ModifiedIn(vs ...time.Time) predicate.Alias {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldModified), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedNotIn applies the NotIn predicate on the "modified" field.
|
||||||
|
func ModifiedNotIn(vs ...time.Time) predicate.Alias {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldModified), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedGT applies the GT predicate on the "modified" field.
|
||||||
|
func ModifiedGT(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedGTE applies the GTE predicate on the "modified" field.
|
||||||
|
func ModifiedGTE(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedLT applies the LT predicate on the "modified" field.
|
||||||
|
func ModifiedLT(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedLTE applies the LTE predicate on the "modified" field.
|
||||||
|
func ModifiedLTE(v time.Time) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldModified), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedIsNil applies the IsNil predicate on the "modified" field.
|
||||||
|
func ModifiedIsNil() predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.IsNull(s.C(FieldModified)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ModifiedNotNil applies the NotNil predicate on the "modified" field.
|
||||||
|
func ModifiedNotNil() predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotNull(s.C(FieldModified)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDEQ applies the EQ predicate on the "domain_id" field.
|
||||||
|
func DomainIDEQ(v int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldDomainID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDNEQ applies the NEQ predicate on the "domain_id" field.
|
||||||
|
func DomainIDNEQ(v int64) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldDomainID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDIn applies the In predicate on the "domain_id" field.
|
||||||
|
func DomainIDIn(vs ...int64) predicate.Alias {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldDomainID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDNotIn applies the NotIn predicate on the "domain_id" field.
|
||||||
|
func DomainIDNotIn(vs ...int64) predicate.Alias {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldDomainID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDIsNil applies the IsNil predicate on the "domain_id" field.
|
||||||
|
func DomainIDIsNil() predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.IsNull(s.C(FieldDomainID)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDNotNil applies the NotNil predicate on the "domain_id" field.
|
||||||
|
func DomainIDNotNil() predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotNull(s.C(FieldDomainID)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoEQ applies the EQ predicate on the "goto" field.
|
||||||
|
func GotoEQ(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoNEQ applies the NEQ predicate on the "goto" field.
|
||||||
|
func GotoNEQ(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoIn applies the In predicate on the "goto" field.
|
||||||
|
func GotoIn(vs ...string) predicate.Alias {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldGoto), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoNotIn applies the NotIn predicate on the "goto" field.
|
||||||
|
func GotoNotIn(vs ...string) predicate.Alias {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldGoto), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoGT applies the GT predicate on the "goto" field.
|
||||||
|
func GotoGT(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoGTE applies the GTE predicate on the "goto" field.
|
||||||
|
func GotoGTE(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoLT applies the LT predicate on the "goto" field.
|
||||||
|
func GotoLT(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoLTE applies the LTE predicate on the "goto" field.
|
||||||
|
func GotoLTE(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoContains applies the Contains predicate on the "goto" field.
|
||||||
|
func GotoContains(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.Contains(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoHasPrefix applies the HasPrefix predicate on the "goto" field.
|
||||||
|
func GotoHasPrefix(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasPrefix(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoHasSuffix applies the HasSuffix predicate on the "goto" field.
|
||||||
|
func GotoHasSuffix(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasSuffix(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoEqualFold applies the EqualFold predicate on the "goto" field.
|
||||||
|
func GotoEqualFold(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EqualFold(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// GotoContainsFold applies the ContainsFold predicate on the "goto" field.
|
||||||
|
func GotoContainsFold(v string) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.ContainsFold(s.C(FieldGoto), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActiveEQ applies the EQ predicate on the "active" field.
|
||||||
|
func ActiveEQ(v bool) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldActive), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActiveNEQ applies the NEQ predicate on the "active" field.
|
||||||
|
func ActiveNEQ(v bool) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldActive), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasDomain applies the HasEdge predicate on the "domain" edge.
|
||||||
|
func HasDomain() predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(DomainTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, DomainTable, DomainColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasDomainWith applies the HasEdge predicate on the "domain" edge with a given conditions (other predicates).
|
||||||
|
func HasDomainWith(preds ...predicate.Domain) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(DomainInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, DomainTable, DomainColumn),
|
||||||
|
)
|
||||||
|
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.Alias) predicate.Alias {
|
||||||
|
return predicate.Alias(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.Alias) predicate.Alias {
|
||||||
|
return predicate.Alias(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.Alias) predicate.Alias {
|
||||||
|
return predicate.Alias(func(s *sql.Selector) {
|
||||||
|
p(s.Not())
|
||||||
|
})
|
||||||
|
}
|
351
ent/alias_create.go
Normal file
351
ent/alias_create.go
Normal file
@ -0,0 +1,351 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/alias"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AliasCreate is the builder for creating a Alias entity.
|
||||||
|
type AliasCreate struct {
|
||||||
|
config
|
||||||
|
mutation *AliasMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreated sets the "created" field.
|
||||||
|
func (ac *AliasCreate) SetCreated(t time.Time) *AliasCreate {
|
||||||
|
ac.mutation.SetCreated(t)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreated sets the "created" field if the given value is not nil.
|
||||||
|
func (ac *AliasCreate) SetNillableCreated(t *time.Time) *AliasCreate {
|
||||||
|
if t != nil {
|
||||||
|
ac.SetCreated(*t)
|
||||||
|
}
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModified sets the "modified" field.
|
||||||
|
func (ac *AliasCreate) SetModified(t time.Time) *AliasCreate {
|
||||||
|
ac.mutation.SetModified(t)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableModified sets the "modified" field if the given value is not nil.
|
||||||
|
func (ac *AliasCreate) SetNillableModified(t *time.Time) *AliasCreate {
|
||||||
|
if t != nil {
|
||||||
|
ac.SetModified(*t)
|
||||||
|
}
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomainID sets the "domain_id" field.
|
||||||
|
func (ac *AliasCreate) SetDomainID(i int64) *AliasCreate {
|
||||||
|
ac.mutation.SetDomainID(i)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
||||||
|
func (ac *AliasCreate) SetNillableDomainID(i *int64) *AliasCreate {
|
||||||
|
if i != nil {
|
||||||
|
ac.SetDomainID(*i)
|
||||||
|
}
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGoto sets the "goto" field.
|
||||||
|
func (ac *AliasCreate) SetGoto(s string) *AliasCreate {
|
||||||
|
ac.mutation.SetGoto(s)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActive sets the "active" field.
|
||||||
|
func (ac *AliasCreate) SetActive(b bool) *AliasCreate {
|
||||||
|
ac.mutation.SetActive(b)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (ac *AliasCreate) SetID(i int64) *AliasCreate {
|
||||||
|
ac.mutation.SetID(i)
|
||||||
|
return ac
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomain sets the "domain" edge to the Domain entity.
|
||||||
|
func (ac *AliasCreate) SetDomain(d *Domain) *AliasCreate {
|
||||||
|
return ac.SetDomainID(d.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AliasMutation object of the builder.
|
||||||
|
func (ac *AliasCreate) Mutation() *AliasMutation {
|
||||||
|
return ac.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Alias in the database.
|
||||||
|
func (ac *AliasCreate) Save(ctx context.Context) (*Alias, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *Alias
|
||||||
|
)
|
||||||
|
ac.defaults()
|
||||||
|
if len(ac.hooks) == 0 {
|
||||||
|
if err = ac.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
node, err = ac.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*AliasMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err = ac.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ac.mutation = mutation
|
||||||
|
if node, err = ac.sqlSave(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &node.ID
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(ac.hooks) - 1; i >= 0; i-- {
|
||||||
|
if ac.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = ac.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, ac.mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (ac *AliasCreate) SaveX(ctx context.Context) *Alias {
|
||||||
|
v, err := ac.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (ac *AliasCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := ac.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ac *AliasCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := ac.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (ac *AliasCreate) defaults() {
|
||||||
|
if _, ok := ac.mutation.Created(); !ok {
|
||||||
|
v := alias.DefaultCreated()
|
||||||
|
ac.mutation.SetCreated(v)
|
||||||
|
}
|
||||||
|
if _, ok := ac.mutation.Modified(); !ok {
|
||||||
|
v := alias.DefaultModified()
|
||||||
|
ac.mutation.SetModified(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (ac *AliasCreate) check() error {
|
||||||
|
if _, ok := ac.mutation.Created(); !ok {
|
||||||
|
return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "Alias.created"`)}
|
||||||
|
}
|
||||||
|
if _, ok := ac.mutation.Goto(); !ok {
|
||||||
|
return &ValidationError{Name: "goto", err: errors.New(`ent: missing required field "Alias.goto"`)}
|
||||||
|
}
|
||||||
|
if _, ok := ac.mutation.Active(); !ok {
|
||||||
|
return &ValidationError{Name: "active", err: errors.New(`ent: missing required field "Alias.active"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ac *AliasCreate) sqlSave(ctx context.Context) (*Alias, error) {
|
||||||
|
_node, _spec := ac.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != _node.ID {
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int64(id)
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ac *AliasCreate) createSpec() (*Alias, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Alias{config: ac.config}
|
||||||
|
_spec = &sqlgraph.CreateSpec{
|
||||||
|
Table: alias.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: alias.FieldID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if id, ok := ac.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = id
|
||||||
|
}
|
||||||
|
if value, ok := ac.mutation.Created(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: alias.FieldCreated,
|
||||||
|
})
|
||||||
|
_node.Created = value
|
||||||
|
}
|
||||||
|
if value, ok := ac.mutation.Modified(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: alias.FieldModified,
|
||||||
|
})
|
||||||
|
_node.Modified = &value
|
||||||
|
}
|
||||||
|
if value, ok := ac.mutation.Goto(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: alias.FieldGoto,
|
||||||
|
})
|
||||||
|
_node.Goto = value
|
||||||
|
}
|
||||||
|
if value, ok := ac.mutation.Active(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: alias.FieldActive,
|
||||||
|
})
|
||||||
|
_node.Active = value
|
||||||
|
}
|
||||||
|
if nodes := ac.mutation.DomainIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: alias.DomainTable,
|
||||||
|
Columns: []string{alias.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.DomainID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// AliasCreateBulk is the builder for creating many Alias entities in bulk.
|
||||||
|
type AliasCreateBulk struct {
|
||||||
|
config
|
||||||
|
builders []*AliasCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Alias entities in the database.
|
||||||
|
func (acb *AliasCreateBulk) Save(ctx context.Context) ([]*Alias, error) {
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(acb.builders))
|
||||||
|
nodes := make([]*Alias, len(acb.builders))
|
||||||
|
mutators := make([]Mutator, len(acb.builders))
|
||||||
|
for i := range acb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := acb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*AliasMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
var err error
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, acb.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, acb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
mutation.done = true
|
||||||
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int64(id)
|
||||||
|
}
|
||||||
|
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, acb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (acb *AliasCreateBulk) SaveX(ctx context.Context) []*Alias {
|
||||||
|
v, err := acb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (acb *AliasCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := acb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (acb *AliasCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := acb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
111
ent/alias_delete.go
Normal file
111
ent/alias_delete.go
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/alias"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AliasDelete is the builder for deleting a Alias entity.
|
||||||
|
type AliasDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AliasMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AliasDelete builder.
|
||||||
|
func (ad *AliasDelete) Where(ps ...predicate.Alias) *AliasDelete {
|
||||||
|
ad.mutation.Where(ps...)
|
||||||
|
return ad
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (ad *AliasDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
if len(ad.hooks) == 0 {
|
||||||
|
affected, err = ad.sqlExec(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*AliasMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
ad.mutation = mutation
|
||||||
|
affected, err = ad.sqlExec(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(ad.hooks) - 1; i >= 0; i-- {
|
||||||
|
if ad.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = ad.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, ad.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ad *AliasDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := ad.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ad *AliasDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := &sqlgraph.DeleteSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: alias.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: alias.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := ad.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sqlgraph.DeleteNodes(ctx, ad.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AliasDeleteOne is the builder for deleting a single Alias entity.
|
||||||
|
type AliasDeleteOne struct {
|
||||||
|
ad *AliasDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (ado *AliasDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := ado.ad.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ado *AliasDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
ado.ad.ExecX(ctx)
|
||||||
|
}
|
989
ent/alias_query.go
Normal file
989
ent/alias_query.go
Normal file
@ -0,0 +1,989 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/alias"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AliasQuery is the builder for querying Alias entities.
|
||||||
|
type AliasQuery struct {
|
||||||
|
config
|
||||||
|
limit *int
|
||||||
|
offset *int
|
||||||
|
unique *bool
|
||||||
|
order []OrderFunc
|
||||||
|
fields []string
|
||||||
|
predicates []predicate.Alias
|
||||||
|
// eager-loading edges.
|
||||||
|
withDomain *DomainQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the AliasQuery builder.
|
||||||
|
func (aq *AliasQuery) Where(ps ...predicate.Alias) *AliasQuery {
|
||||||
|
aq.predicates = append(aq.predicates, ps...)
|
||||||
|
return aq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit adds a limit step to the query.
|
||||||
|
func (aq *AliasQuery) Limit(limit int) *AliasQuery {
|
||||||
|
aq.limit = &limit
|
||||||
|
return aq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset adds an offset step to the query.
|
||||||
|
func (aq *AliasQuery) Offset(offset int) *AliasQuery {
|
||||||
|
aq.offset = &offset
|
||||||
|
return aq
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 (aq *AliasQuery) Unique(unique bool) *AliasQuery {
|
||||||
|
aq.unique = &unique
|
||||||
|
return aq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order adds an order step to the query.
|
||||||
|
func (aq *AliasQuery) Order(o ...OrderFunc) *AliasQuery {
|
||||||
|
aq.order = append(aq.order, o...)
|
||||||
|
return aq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryDomain chains the current query on the "domain" edge.
|
||||||
|
func (aq *AliasQuery) QueryDomain() *DomainQuery {
|
||||||
|
query := &DomainQuery{config: aq.config}
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := aq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := aq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(alias.Table, alias.FieldID, selector),
|
||||||
|
sqlgraph.To(domain.Table, domain.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, alias.DomainTable, alias.DomainColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first Alias entity from the query.
|
||||||
|
// Returns a *NotFoundError when no Alias was found.
|
||||||
|
func (aq *AliasQuery) First(ctx context.Context) (*Alias, error) {
|
||||||
|
nodes, err := aq.Limit(1).All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{alias.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (aq *AliasQuery) FirstX(ctx context.Context) *Alias {
|
||||||
|
node, err := aq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first Alias ID from the query.
|
||||||
|
// Returns a *NotFoundError when no Alias ID was found.
|
||||||
|
func (aq *AliasQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = aq.Limit(1).IDs(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (aq *AliasQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := aq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single Alias entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one Alias entity is found.
|
||||||
|
// Returns a *NotFoundError when no Alias entities are found.
|
||||||
|
func (aq *AliasQuery) Only(ctx context.Context) (*Alias, error) {
|
||||||
|
nodes, err := aq.Limit(2).All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{alias.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (aq *AliasQuery) OnlyX(ctx context.Context) *Alias {
|
||||||
|
node, err := aq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only Alias ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one Alias ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (aq *AliasQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = aq.Limit(2).IDs(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{alias.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (aq *AliasQuery) OnlyIDX(ctx context.Context) int64 {
|
||||||
|
id, err := aq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of AliasSlice.
|
||||||
|
func (aq *AliasQuery) All(ctx context.Context) ([]*Alias, error) {
|
||||||
|
if err := aq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return aq.sqlAll(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (aq *AliasQuery) AllX(ctx context.Context) []*Alias {
|
||||||
|
nodes, err := aq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of Alias IDs.
|
||||||
|
func (aq *AliasQuery) IDs(ctx context.Context) ([]int64, error) {
|
||||||
|
var ids []int64
|
||||||
|
if err := aq.Select(alias.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (aq *AliasQuery) IDsX(ctx context.Context) []int64 {
|
||||||
|
ids, err := aq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (aq *AliasQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
if err := aq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return aq.sqlCount(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (aq *AliasQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := aq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (aq *AliasQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
if err := aq.prepareQuery(ctx); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return aq.sqlExist(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (aq *AliasQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := aq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the AliasQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (aq *AliasQuery) Clone() *AliasQuery {
|
||||||
|
if aq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &AliasQuery{
|
||||||
|
config: aq.config,
|
||||||
|
limit: aq.limit,
|
||||||
|
offset: aq.offset,
|
||||||
|
order: append([]OrderFunc{}, aq.order...),
|
||||||
|
predicates: append([]predicate.Alias{}, aq.predicates...),
|
||||||
|
withDomain: aq.withDomain.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: aq.sql.Clone(),
|
||||||
|
path: aq.path,
|
||||||
|
unique: aq.unique,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithDomain tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "domain" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (aq *AliasQuery) WithDomain(opts ...func(*DomainQuery)) *AliasQuery {
|
||||||
|
query := &DomainQuery{config: aq.config}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
aq.withDomain = query
|
||||||
|
return aq
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// Created time.Time `json:"created,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Alias.Query().
|
||||||
|
// GroupBy(alias.FieldCreated).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
//
|
||||||
|
func (aq *AliasQuery) GroupBy(field string, fields ...string) *AliasGroupBy {
|
||||||
|
group := &AliasGroupBy{config: aq.config}
|
||||||
|
group.fields = append([]string{field}, fields...)
|
||||||
|
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||||
|
if err := aq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return aq.sqlQuery(ctx), nil
|
||||||
|
}
|
||||||
|
return group
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// Created time.Time `json:"created,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Alias.Query().
|
||||||
|
// Select(alias.FieldCreated).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
//
|
||||||
|
func (aq *AliasQuery) Select(fields ...string) *AliasSelect {
|
||||||
|
aq.fields = append(aq.fields, fields...)
|
||||||
|
return &AliasSelect{AliasQuery: aq}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aq *AliasQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, f := range aq.fields {
|
||||||
|
if !alias.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if aq.path != nil {
|
||||||
|
prev, err := aq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
aq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aq *AliasQuery) sqlAll(ctx context.Context) ([]*Alias, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*Alias{}
|
||||||
|
_spec = aq.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
aq.withDomain != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
|
||||||
|
node := &Alias{config: aq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
return node.scanValues(columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []interface{}) error {
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||||
|
}
|
||||||
|
node := nodes[len(nodes)-1]
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, aq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if query := aq.withDomain; query != nil {
|
||||||
|
ids := make([]int64, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64][]*Alias)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].DomainID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
query.Where(domain.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf(`unexpected foreign-key "domain_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
nodes[i].Edges.Domain = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aq *AliasQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := aq.querySpec()
|
||||||
|
_spec.Node.Columns = aq.fields
|
||||||
|
if len(aq.fields) > 0 {
|
||||||
|
_spec.Unique = aq.unique != nil && *aq.unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, aq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aq *AliasQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||||
|
n, err := aq.sqlCount(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
}
|
||||||
|
return n > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aq *AliasQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := &sqlgraph.QuerySpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: alias.Table,
|
||||||
|
Columns: alias.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: alias.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
From: aq.sql,
|
||||||
|
Unique: true,
|
||||||
|
}
|
||||||
|
if unique := aq.unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
}
|
||||||
|
if fields := aq.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, alias.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != alias.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := aq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := aq.limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := aq.offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := aq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (aq *AliasQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(aq.driver.Dialect())
|
||||||
|
t1 := builder.Table(alias.Table)
|
||||||
|
columns := aq.fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = alias.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if aq.sql != nil {
|
||||||
|
selector = aq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if aq.unique != nil && *aq.unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range aq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range aq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := aq.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 := aq.limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// AliasGroupBy is the group-by builder for Alias entities.
|
||||||
|
type AliasGroupBy struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
fns []AggregateFunc
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (agb *AliasGroupBy) Aggregate(fns ...AggregateFunc) *AliasGroupBy {
|
||||||
|
agb.fns = append(agb.fns, fns...)
|
||||||
|
return agb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the group-by query and scans the result into the given value.
|
||||||
|
func (agb *AliasGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||||
|
query, err := agb.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
agb.sql = query
|
||||||
|
return agb.sqlScan(ctx, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanX is like Scan, but panics if an error occurs.
|
||||||
|
func (agb *AliasGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||||
|
if err := agb.Scan(ctx, v); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings returns list of strings from group-by.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (agb *AliasGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||||
|
if len(agb.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: AliasGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||||
|
}
|
||||||
|
var v []string
|
||||||
|
if err := agb.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringsX is like Strings, but panics if an error occurs.
|
||||||
|
func (agb *AliasGroupBy) StringsX(ctx context.Context) []string {
|
||||||
|
v, err := agb.Strings(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a single string from a group-by query.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (agb *AliasGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||||
|
var v []string
|
||||||
|
if v, err = agb.Strings(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: AliasGroupBy.Strings returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringX is like String, but panics if an error occurs.
|
||||||
|
func (agb *AliasGroupBy) StringX(ctx context.Context) string {
|
||||||
|
v, err := agb.String(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ints returns list of ints from group-by.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (agb *AliasGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||||
|
if len(agb.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: AliasGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||||
|
}
|
||||||
|
var v []int
|
||||||
|
if err := agb.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntsX is like Ints, but panics if an error occurs.
|
||||||
|
func (agb *AliasGroupBy) IntsX(ctx context.Context) []int {
|
||||||
|
v, err := agb.Ints(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int returns a single int from a group-by query.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (agb *AliasGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||||
|
var v []int
|
||||||
|
if v, err = agb.Ints(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: AliasGroupBy.Ints returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntX is like Int, but panics if an error occurs.
|
||||||
|
func (agb *AliasGroupBy) IntX(ctx context.Context) int {
|
||||||
|
v, err := agb.Int(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64s returns list of float64s from group-by.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (agb *AliasGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||||
|
if len(agb.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: AliasGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||||
|
}
|
||||||
|
var v []float64
|
||||||
|
if err := agb.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64sX is like Float64s, but panics if an error occurs.
|
||||||
|
func (agb *AliasGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||||
|
v, err := agb.Float64s(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns a single float64 from a group-by query.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (agb *AliasGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||||
|
var v []float64
|
||||||
|
if v, err = agb.Float64s(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: AliasGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64X is like Float64, but panics if an error occurs.
|
||||||
|
func (agb *AliasGroupBy) Float64X(ctx context.Context) float64 {
|
||||||
|
v, err := agb.Float64(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bools returns list of bools from group-by.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (agb *AliasGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||||
|
if len(agb.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: AliasGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||||
|
}
|
||||||
|
var v []bool
|
||||||
|
if err := agb.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolsX is like Bools, but panics if an error occurs.
|
||||||
|
func (agb *AliasGroupBy) BoolsX(ctx context.Context) []bool {
|
||||||
|
v, err := agb.Bools(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns a single bool from a group-by query.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (agb *AliasGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||||
|
var v []bool
|
||||||
|
if v, err = agb.Bools(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: AliasGroupBy.Bools returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolX is like Bool, but panics if an error occurs.
|
||||||
|
func (agb *AliasGroupBy) BoolX(ctx context.Context) bool {
|
||||||
|
v, err := agb.Bool(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (agb *AliasGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||||
|
for _, f := range agb.fields {
|
||||||
|
if !alias.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selector := agb.sqlQuery()
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := agb.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (agb *AliasGroupBy) sqlQuery() *sql.Selector {
|
||||||
|
selector := agb.sql.Select()
|
||||||
|
aggregation := make([]string, 0, len(agb.fns))
|
||||||
|
for _, fn := range agb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
// If no columns were selected in a custom aggregation function, the default
|
||||||
|
// selection is the fields used for "group-by", and the aggregation functions.
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(agb.fields)+len(agb.fns))
|
||||||
|
for _, f := range agb.fields {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
return selector.GroupBy(selector.Columns(agb.fields...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AliasSelect is the builder for selecting fields of Alias entities.
|
||||||
|
type AliasSelect struct {
|
||||||
|
*AliasQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (as *AliasSelect) Scan(ctx context.Context, v interface{}) error {
|
||||||
|
if err := as.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
as.sql = as.AliasQuery.sqlQuery(ctx)
|
||||||
|
return as.sqlScan(ctx, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanX is like Scan, but panics if an error occurs.
|
||||||
|
func (as *AliasSelect) ScanX(ctx context.Context, v interface{}) {
|
||||||
|
if err := as.Scan(ctx, v); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||||
|
func (as *AliasSelect) Strings(ctx context.Context) ([]string, error) {
|
||||||
|
if len(as.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: AliasSelect.Strings is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []string
|
||||||
|
if err := as.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringsX is like Strings, but panics if an error occurs.
|
||||||
|
func (as *AliasSelect) StringsX(ctx context.Context) []string {
|
||||||
|
v, err := as.Strings(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||||
|
func (as *AliasSelect) String(ctx context.Context) (_ string, err error) {
|
||||||
|
var v []string
|
||||||
|
if v, err = as.Strings(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: AliasSelect.Strings returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringX is like String, but panics if an error occurs.
|
||||||
|
func (as *AliasSelect) StringX(ctx context.Context) string {
|
||||||
|
v, err := as.String(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||||
|
func (as *AliasSelect) Ints(ctx context.Context) ([]int, error) {
|
||||||
|
if len(as.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: AliasSelect.Ints is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []int
|
||||||
|
if err := as.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntsX is like Ints, but panics if an error occurs.
|
||||||
|
func (as *AliasSelect) IntsX(ctx context.Context) []int {
|
||||||
|
v, err := as.Ints(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||||
|
func (as *AliasSelect) Int(ctx context.Context) (_ int, err error) {
|
||||||
|
var v []int
|
||||||
|
if v, err = as.Ints(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: AliasSelect.Ints returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntX is like Int, but panics if an error occurs.
|
||||||
|
func (as *AliasSelect) IntX(ctx context.Context) int {
|
||||||
|
v, err := as.Int(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||||
|
func (as *AliasSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||||
|
if len(as.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: AliasSelect.Float64s is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []float64
|
||||||
|
if err := as.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64sX is like Float64s, but panics if an error occurs.
|
||||||
|
func (as *AliasSelect) Float64sX(ctx context.Context) []float64 {
|
||||||
|
v, err := as.Float64s(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||||
|
func (as *AliasSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||||
|
var v []float64
|
||||||
|
if v, err = as.Float64s(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: AliasSelect.Float64s returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64X is like Float64, but panics if an error occurs.
|
||||||
|
func (as *AliasSelect) Float64X(ctx context.Context) float64 {
|
||||||
|
v, err := as.Float64(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||||
|
func (as *AliasSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||||
|
if len(as.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: AliasSelect.Bools is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []bool
|
||||||
|
if err := as.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolsX is like Bools, but panics if an error occurs.
|
||||||
|
func (as *AliasSelect) BoolsX(ctx context.Context) []bool {
|
||||||
|
v, err := as.Bools(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||||
|
func (as *AliasSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||||
|
var v []bool
|
||||||
|
if v, err = as.Bools(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: AliasSelect.Bools returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolX is like Bool, but panics if an error occurs.
|
||||||
|
func (as *AliasSelect) BoolX(ctx context.Context) bool {
|
||||||
|
v, err := as.Bool(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (as *AliasSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := as.sql.Query()
|
||||||
|
if err := as.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
493
ent/alias_update.go
Normal file
493
ent/alias_update.go
Normal file
@ -0,0 +1,493 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/alias"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AliasUpdate is the builder for updating Alias entities.
|
||||||
|
type AliasUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AliasMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the AliasUpdate builder.
|
||||||
|
func (au *AliasUpdate) Where(ps ...predicate.Alias) *AliasUpdate {
|
||||||
|
au.mutation.Where(ps...)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModified sets the "modified" field.
|
||||||
|
func (au *AliasUpdate) SetModified(t time.Time) *AliasUpdate {
|
||||||
|
au.mutation.SetModified(t)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearModified clears the value of the "modified" field.
|
||||||
|
func (au *AliasUpdate) ClearModified() *AliasUpdate {
|
||||||
|
au.mutation.ClearModified()
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomainID sets the "domain_id" field.
|
||||||
|
func (au *AliasUpdate) SetDomainID(i int64) *AliasUpdate {
|
||||||
|
au.mutation.SetDomainID(i)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
||||||
|
func (au *AliasUpdate) SetNillableDomainID(i *int64) *AliasUpdate {
|
||||||
|
if i != nil {
|
||||||
|
au.SetDomainID(*i)
|
||||||
|
}
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomainID clears the value of the "domain_id" field.
|
||||||
|
func (au *AliasUpdate) ClearDomainID() *AliasUpdate {
|
||||||
|
au.mutation.ClearDomainID()
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGoto sets the "goto" field.
|
||||||
|
func (au *AliasUpdate) SetGoto(s string) *AliasUpdate {
|
||||||
|
au.mutation.SetGoto(s)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActive sets the "active" field.
|
||||||
|
func (au *AliasUpdate) SetActive(b bool) *AliasUpdate {
|
||||||
|
au.mutation.SetActive(b)
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomain sets the "domain" edge to the Domain entity.
|
||||||
|
func (au *AliasUpdate) SetDomain(d *Domain) *AliasUpdate {
|
||||||
|
return au.SetDomainID(d.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AliasMutation object of the builder.
|
||||||
|
func (au *AliasUpdate) Mutation() *AliasMutation {
|
||||||
|
return au.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomain clears the "domain" edge to the Domain entity.
|
||||||
|
func (au *AliasUpdate) ClearDomain() *AliasUpdate {
|
||||||
|
au.mutation.ClearDomain()
|
||||||
|
return au
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (au *AliasUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
au.defaults()
|
||||||
|
if len(au.hooks) == 0 {
|
||||||
|
affected, err = au.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*AliasMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
au.mutation = mutation
|
||||||
|
affected, err = au.sqlSave(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(au.hooks) - 1; i >= 0; i-- {
|
||||||
|
if au.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = au.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, au.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (au *AliasUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := au.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (au *AliasUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := au.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (au *AliasUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := au.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (au *AliasUpdate) defaults() {
|
||||||
|
if _, ok := au.mutation.Modified(); !ok && !au.mutation.ModifiedCleared() {
|
||||||
|
v := alias.UpdateDefaultModified()
|
||||||
|
au.mutation.SetModified(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (au *AliasUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
_spec := &sqlgraph.UpdateSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: alias.Table,
|
||||||
|
Columns: alias.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: alias.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := au.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := au.mutation.Modified(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: alias.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if au.mutation.ModifiedCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Column: alias.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := au.mutation.Goto(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: alias.FieldGoto,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := au.mutation.Active(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: alias.FieldActive,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if au.mutation.DomainCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: alias.DomainTable,
|
||||||
|
Columns: []string{alias.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := au.mutation.DomainIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: alias.DomainTable,
|
||||||
|
Columns: []string{alias.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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, au.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AliasUpdateOne is the builder for updating a single Alias entity.
|
||||||
|
type AliasUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *AliasMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModified sets the "modified" field.
|
||||||
|
func (auo *AliasUpdateOne) SetModified(t time.Time) *AliasUpdateOne {
|
||||||
|
auo.mutation.SetModified(t)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearModified clears the value of the "modified" field.
|
||||||
|
func (auo *AliasUpdateOne) ClearModified() *AliasUpdateOne {
|
||||||
|
auo.mutation.ClearModified()
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomainID sets the "domain_id" field.
|
||||||
|
func (auo *AliasUpdateOne) SetDomainID(i int64) *AliasUpdateOne {
|
||||||
|
auo.mutation.SetDomainID(i)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
||||||
|
func (auo *AliasUpdateOne) SetNillableDomainID(i *int64) *AliasUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
auo.SetDomainID(*i)
|
||||||
|
}
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomainID clears the value of the "domain_id" field.
|
||||||
|
func (auo *AliasUpdateOne) ClearDomainID() *AliasUpdateOne {
|
||||||
|
auo.mutation.ClearDomainID()
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGoto sets the "goto" field.
|
||||||
|
func (auo *AliasUpdateOne) SetGoto(s string) *AliasUpdateOne {
|
||||||
|
auo.mutation.SetGoto(s)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActive sets the "active" field.
|
||||||
|
func (auo *AliasUpdateOne) SetActive(b bool) *AliasUpdateOne {
|
||||||
|
auo.mutation.SetActive(b)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomain sets the "domain" edge to the Domain entity.
|
||||||
|
func (auo *AliasUpdateOne) SetDomain(d *Domain) *AliasUpdateOne {
|
||||||
|
return auo.SetDomainID(d.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the AliasMutation object of the builder.
|
||||||
|
func (auo *AliasUpdateOne) Mutation() *AliasMutation {
|
||||||
|
return auo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomain clears the "domain" edge to the Domain entity.
|
||||||
|
func (auo *AliasUpdateOne) ClearDomain() *AliasUpdateOne {
|
||||||
|
auo.mutation.ClearDomain()
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (auo *AliasUpdateOne) Select(field string, fields ...string) *AliasUpdateOne {
|
||||||
|
auo.fields = append([]string{field}, fields...)
|
||||||
|
return auo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Alias entity.
|
||||||
|
func (auo *AliasUpdateOne) Save(ctx context.Context) (*Alias, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *Alias
|
||||||
|
)
|
||||||
|
auo.defaults()
|
||||||
|
if len(auo.hooks) == 0 {
|
||||||
|
node, err = auo.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*AliasMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
auo.mutation = mutation
|
||||||
|
node, err = auo.sqlSave(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(auo.hooks) - 1; i >= 0; i-- {
|
||||||
|
if auo.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = auo.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, auo.mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (auo *AliasUpdateOne) SaveX(ctx context.Context) *Alias {
|
||||||
|
node, err := auo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (auo *AliasUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := auo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (auo *AliasUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := auo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (auo *AliasUpdateOne) defaults() {
|
||||||
|
if _, ok := auo.mutation.Modified(); !ok && !auo.mutation.ModifiedCleared() {
|
||||||
|
v := alias.UpdateDefaultModified()
|
||||||
|
auo.mutation.SetModified(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (auo *AliasUpdateOne) sqlSave(ctx context.Context) (_node *Alias, err error) {
|
||||||
|
_spec := &sqlgraph.UpdateSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: alias.Table,
|
||||||
|
Columns: alias.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: alias.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
id, ok := auo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Alias.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := auo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, alias.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !alias.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != alias.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := auo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := auo.mutation.Modified(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: alias.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if auo.mutation.ModifiedCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Column: alias.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := auo.mutation.Goto(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: alias.FieldGoto,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := auo.mutation.Active(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: alias.FieldActive,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if auo.mutation.DomainCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: alias.DomainTable,
|
||||||
|
Columns: []string{alias.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := auo.mutation.DomainIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: alias.DomainTable,
|
||||||
|
Columns: []string{alias.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &Alias{config: auo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{alias.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
762
ent/client.go
Normal file
762
ent/client.go
Normal file
@ -0,0 +1,762 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/migrate"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"code.icod.de/postfix/manager/ent/alias"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/logentry"
|
||||||
|
"code.icod.de/postfix/manager/ent/mailbox"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Client is the client that holds all ent builders.
|
||||||
|
type Client struct {
|
||||||
|
config
|
||||||
|
// Schema is the client for creating, migrating and dropping schema.
|
||||||
|
Schema *migrate.Schema
|
||||||
|
// Account is the client for interacting with the Account builders.
|
||||||
|
Account *AccountClient
|
||||||
|
// Alias is the client for interacting with the Alias builders.
|
||||||
|
Alias *AliasClient
|
||||||
|
// Domain is the client for interacting with the Domain builders.
|
||||||
|
Domain *DomainClient
|
||||||
|
// Logentry is the client for interacting with the Logentry builders.
|
||||||
|
Logentry *LogentryClient
|
||||||
|
// Mailbox is the client for interacting with the Mailbox builders.
|
||||||
|
Mailbox *MailboxClient
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient creates a new client configured with the given options.
|
||||||
|
func NewClient(opts ...Option) *Client {
|
||||||
|
cfg := config{log: log.Println, hooks: &hooks{}}
|
||||||
|
cfg.options(opts...)
|
||||||
|
client := &Client{config: cfg}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) init() {
|
||||||
|
c.Schema = migrate.NewSchema(c.driver)
|
||||||
|
c.Account = NewAccountClient(c.config)
|
||||||
|
c.Alias = NewAliasClient(c.config)
|
||||||
|
c.Domain = NewDomainClient(c.config)
|
||||||
|
c.Logentry = NewLogentryClient(c.config)
|
||||||
|
c.Mailbox = NewMailboxClient(c.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open opens a database/sql.DB specified by the driver name and
|
||||||
|
// the data source name, and returns a new client attached to it.
|
||||||
|
// Optional parameters can be added for configuring the client.
|
||||||
|
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
|
||||||
|
switch driverName {
|
||||||
|
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
|
||||||
|
drv, err := sql.Open(driverName, dataSourceName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewClient(append(options, Driver(drv))...), nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unsupported driver: %q", driverName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx returns a new transactional client. The provided context
|
||||||
|
// is used until the transaction is committed or rolled back.
|
||||||
|
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
|
||||||
|
}
|
||||||
|
tx, err := newTx(ctx, c.driver)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = tx
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
Account: NewAccountClient(cfg),
|
||||||
|
Alias: NewAliasClient(cfg),
|
||||||
|
Domain: NewDomainClient(cfg),
|
||||||
|
Logentry: NewLogentryClient(cfg),
|
||||||
|
Mailbox: NewMailboxClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BeginTx returns a transactional client with specified options.
|
||||||
|
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
|
||||||
|
if _, ok := c.driver.(*txDriver); ok {
|
||||||
|
return nil, fmt.Errorf("ent: cannot start a transaction within a transaction")
|
||||||
|
}
|
||||||
|
tx, err := c.driver.(interface {
|
||||||
|
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
|
||||||
|
}).BeginTx(ctx, opts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = &txDriver{tx: tx, drv: c.driver}
|
||||||
|
return &Tx{
|
||||||
|
ctx: ctx,
|
||||||
|
config: cfg,
|
||||||
|
Account: NewAccountClient(cfg),
|
||||||
|
Alias: NewAliasClient(cfg),
|
||||||
|
Domain: NewDomainClient(cfg),
|
||||||
|
Logentry: NewLogentryClient(cfg),
|
||||||
|
Mailbox: NewMailboxClient(cfg),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||||
|
//
|
||||||
|
// client.Debug().
|
||||||
|
// Account.
|
||||||
|
// Query().
|
||||||
|
// Count(ctx)
|
||||||
|
//
|
||||||
|
func (c *Client) Debug() *Client {
|
||||||
|
if c.debug {
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
cfg := c.config
|
||||||
|
cfg.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
client := &Client{config: cfg}
|
||||||
|
client.init()
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close closes the database connection and prevents new queries from starting.
|
||||||
|
func (c *Client) Close() error {
|
||||||
|
return c.driver.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.Account.Use(hooks...)
|
||||||
|
c.Alias.Use(hooks...)
|
||||||
|
c.Domain.Use(hooks...)
|
||||||
|
c.Logentry.Use(hooks...)
|
||||||
|
c.Mailbox.Use(hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountClient is a client for the Account schema.
|
||||||
|
type AccountClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAccountClient returns a client for the Account from the given config.
|
||||||
|
func NewAccountClient(c config) *AccountClient {
|
||||||
|
return &AccountClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `account.Hooks(f(g(h())))`.
|
||||||
|
func (c *AccountClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Account = append(c.hooks.Account, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a create builder for Account.
|
||||||
|
func (c *AccountClient) Create() *AccountCreate {
|
||||||
|
mutation := newAccountMutation(c.config, OpCreate)
|
||||||
|
return &AccountCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Account entities.
|
||||||
|
func (c *AccountClient) CreateBulk(builders ...*AccountCreate) *AccountCreateBulk {
|
||||||
|
return &AccountCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Account.
|
||||||
|
func (c *AccountClient) Update() *AccountUpdate {
|
||||||
|
mutation := newAccountMutation(c.config, OpUpdate)
|
||||||
|
return &AccountUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *AccountClient) UpdateOne(a *Account) *AccountUpdateOne {
|
||||||
|
mutation := newAccountMutation(c.config, OpUpdateOne, withAccount(a))
|
||||||
|
return &AccountUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *AccountClient) UpdateOneID(id int64) *AccountUpdateOne {
|
||||||
|
mutation := newAccountMutation(c.config, OpUpdateOne, withAccountID(id))
|
||||||
|
return &AccountUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Account.
|
||||||
|
func (c *AccountClient) Delete() *AccountDelete {
|
||||||
|
mutation := newAccountMutation(c.config, OpDelete)
|
||||||
|
return &AccountDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a delete builder for the given entity.
|
||||||
|
func (c *AccountClient) DeleteOne(a *Account) *AccountDeleteOne {
|
||||||
|
return c.DeleteOneID(a.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a delete builder for the given id.
|
||||||
|
func (c *AccountClient) DeleteOneID(id int64) *AccountDeleteOne {
|
||||||
|
builder := c.Delete().Where(account.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &AccountDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Account.
|
||||||
|
func (c *AccountClient) Query() *AccountQuery {
|
||||||
|
return &AccountQuery{
|
||||||
|
config: c.config,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Account entity by its id.
|
||||||
|
func (c *AccountClient) Get(ctx context.Context, id int64) (*Account, error) {
|
||||||
|
return c.Query().Where(account.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *AccountClient) GetX(ctx context.Context, id int64) *Account {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryDomains queries the domains edge of a Account.
|
||||||
|
func (c *AccountClient) QueryDomains(a *Account) *DomainQuery {
|
||||||
|
query := &DomainQuery{config: c.config}
|
||||||
|
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := a.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(account.Table, account.FieldID, id),
|
||||||
|
sqlgraph.To(domain.Table, domain.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, false, account.DomainsTable, account.DomainsPrimaryKey...),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(a.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryLogs queries the logs edge of a Account.
|
||||||
|
func (c *AccountClient) QueryLogs(a *Account) *LogentryQuery {
|
||||||
|
query := &LogentryQuery{config: c.config}
|
||||||
|
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := a.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(account.Table, account.FieldID, id),
|
||||||
|
sqlgraph.To(logentry.Table, logentry.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, account.LogsTable, account.LogsColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(a.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *AccountClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Account
|
||||||
|
}
|
||||||
|
|
||||||
|
// AliasClient is a client for the Alias schema.
|
||||||
|
type AliasClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewAliasClient returns a client for the Alias from the given config.
|
||||||
|
func NewAliasClient(c config) *AliasClient {
|
||||||
|
return &AliasClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `alias.Hooks(f(g(h())))`.
|
||||||
|
func (c *AliasClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Alias = append(c.hooks.Alias, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a create builder for Alias.
|
||||||
|
func (c *AliasClient) Create() *AliasCreate {
|
||||||
|
mutation := newAliasMutation(c.config, OpCreate)
|
||||||
|
return &AliasCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Alias entities.
|
||||||
|
func (c *AliasClient) CreateBulk(builders ...*AliasCreate) *AliasCreateBulk {
|
||||||
|
return &AliasCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Alias.
|
||||||
|
func (c *AliasClient) Update() *AliasUpdate {
|
||||||
|
mutation := newAliasMutation(c.config, OpUpdate)
|
||||||
|
return &AliasUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *AliasClient) UpdateOne(a *Alias) *AliasUpdateOne {
|
||||||
|
mutation := newAliasMutation(c.config, OpUpdateOne, withAlias(a))
|
||||||
|
return &AliasUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *AliasClient) UpdateOneID(id int64) *AliasUpdateOne {
|
||||||
|
mutation := newAliasMutation(c.config, OpUpdateOne, withAliasID(id))
|
||||||
|
return &AliasUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Alias.
|
||||||
|
func (c *AliasClient) Delete() *AliasDelete {
|
||||||
|
mutation := newAliasMutation(c.config, OpDelete)
|
||||||
|
return &AliasDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a delete builder for the given entity.
|
||||||
|
func (c *AliasClient) DeleteOne(a *Alias) *AliasDeleteOne {
|
||||||
|
return c.DeleteOneID(a.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a delete builder for the given id.
|
||||||
|
func (c *AliasClient) DeleteOneID(id int64) *AliasDeleteOne {
|
||||||
|
builder := c.Delete().Where(alias.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &AliasDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Alias.
|
||||||
|
func (c *AliasClient) Query() *AliasQuery {
|
||||||
|
return &AliasQuery{
|
||||||
|
config: c.config,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Alias entity by its id.
|
||||||
|
func (c *AliasClient) Get(ctx context.Context, id int64) (*Alias, error) {
|
||||||
|
return c.Query().Where(alias.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *AliasClient) GetX(ctx context.Context, id int64) *Alias {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryDomain queries the domain edge of a Alias.
|
||||||
|
func (c *AliasClient) QueryDomain(a *Alias) *DomainQuery {
|
||||||
|
query := &DomainQuery{config: c.config}
|
||||||
|
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := a.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(alias.Table, alias.FieldID, id),
|
||||||
|
sqlgraph.To(domain.Table, domain.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, alias.DomainTable, alias.DomainColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(a.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *AliasClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Alias
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainClient is a client for the Domain schema.
|
||||||
|
type DomainClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewDomainClient returns a client for the Domain from the given config.
|
||||||
|
func NewDomainClient(c config) *DomainClient {
|
||||||
|
return &DomainClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `domain.Hooks(f(g(h())))`.
|
||||||
|
func (c *DomainClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Domain = append(c.hooks.Domain, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a create builder for Domain.
|
||||||
|
func (c *DomainClient) Create() *DomainCreate {
|
||||||
|
mutation := newDomainMutation(c.config, OpCreate)
|
||||||
|
return &DomainCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Domain entities.
|
||||||
|
func (c *DomainClient) CreateBulk(builders ...*DomainCreate) *DomainCreateBulk {
|
||||||
|
return &DomainCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Domain.
|
||||||
|
func (c *DomainClient) Update() *DomainUpdate {
|
||||||
|
mutation := newDomainMutation(c.config, OpUpdate)
|
||||||
|
return &DomainUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *DomainClient) UpdateOne(d *Domain) *DomainUpdateOne {
|
||||||
|
mutation := newDomainMutation(c.config, OpUpdateOne, withDomain(d))
|
||||||
|
return &DomainUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *DomainClient) UpdateOneID(id int64) *DomainUpdateOne {
|
||||||
|
mutation := newDomainMutation(c.config, OpUpdateOne, withDomainID(id))
|
||||||
|
return &DomainUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Domain.
|
||||||
|
func (c *DomainClient) Delete() *DomainDelete {
|
||||||
|
mutation := newDomainMutation(c.config, OpDelete)
|
||||||
|
return &DomainDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a delete builder for the given entity.
|
||||||
|
func (c *DomainClient) DeleteOne(d *Domain) *DomainDeleteOne {
|
||||||
|
return c.DeleteOneID(d.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a delete builder for the given id.
|
||||||
|
func (c *DomainClient) DeleteOneID(id int64) *DomainDeleteOne {
|
||||||
|
builder := c.Delete().Where(domain.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &DomainDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Domain.
|
||||||
|
func (c *DomainClient) Query() *DomainQuery {
|
||||||
|
return &DomainQuery{
|
||||||
|
config: c.config,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Domain entity by its id.
|
||||||
|
func (c *DomainClient) Get(ctx context.Context, id int64) (*Domain, error) {
|
||||||
|
return c.Query().Where(domain.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *DomainClient) GetX(ctx context.Context, id int64) *Domain {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryMailboxes queries the mailboxes edge of a Domain.
|
||||||
|
func (c *DomainClient) QueryMailboxes(d *Domain) *MailboxQuery {
|
||||||
|
query := &MailboxQuery{config: c.config}
|
||||||
|
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := d.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(domain.Table, domain.FieldID, id),
|
||||||
|
sqlgraph.To(mailbox.Table, mailbox.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, domain.MailboxesTable, domain.MailboxesColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(d.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAliases queries the aliases edge of a Domain.
|
||||||
|
func (c *DomainClient) QueryAliases(d *Domain) *AliasQuery {
|
||||||
|
query := &AliasQuery{config: c.config}
|
||||||
|
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := d.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(domain.Table, domain.FieldID, id),
|
||||||
|
sqlgraph.To(alias.Table, alias.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, domain.AliasesTable, domain.AliasesColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(d.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryLogs queries the logs edge of a Domain.
|
||||||
|
func (c *DomainClient) QueryLogs(d *Domain) *LogentryQuery {
|
||||||
|
query := &LogentryQuery{config: c.config}
|
||||||
|
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := d.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(domain.Table, domain.FieldID, id),
|
||||||
|
sqlgraph.To(logentry.Table, logentry.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.O2M, false, domain.LogsTable, domain.LogsColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(d.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAccounts queries the accounts edge of a Domain.
|
||||||
|
func (c *DomainClient) QueryAccounts(d *Domain) *AccountQuery {
|
||||||
|
query := &AccountQuery{config: c.config}
|
||||||
|
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := d.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(domain.Table, domain.FieldID, id),
|
||||||
|
sqlgraph.To(account.Table, account.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2M, true, domain.AccountsTable, domain.AccountsPrimaryKey...),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(d.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *DomainClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Domain
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogentryClient is a client for the Logentry schema.
|
||||||
|
type LogentryClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewLogentryClient returns a client for the Logentry from the given config.
|
||||||
|
func NewLogentryClient(c config) *LogentryClient {
|
||||||
|
return &LogentryClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `logentry.Hooks(f(g(h())))`.
|
||||||
|
func (c *LogentryClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Logentry = append(c.hooks.Logentry, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a create builder for Logentry.
|
||||||
|
func (c *LogentryClient) Create() *LogentryCreate {
|
||||||
|
mutation := newLogentryMutation(c.config, OpCreate)
|
||||||
|
return &LogentryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Logentry entities.
|
||||||
|
func (c *LogentryClient) CreateBulk(builders ...*LogentryCreate) *LogentryCreateBulk {
|
||||||
|
return &LogentryCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Logentry.
|
||||||
|
func (c *LogentryClient) Update() *LogentryUpdate {
|
||||||
|
mutation := newLogentryMutation(c.config, OpUpdate)
|
||||||
|
return &LogentryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *LogentryClient) UpdateOne(l *Logentry) *LogentryUpdateOne {
|
||||||
|
mutation := newLogentryMutation(c.config, OpUpdateOne, withLogentry(l))
|
||||||
|
return &LogentryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *LogentryClient) UpdateOneID(id int64) *LogentryUpdateOne {
|
||||||
|
mutation := newLogentryMutation(c.config, OpUpdateOne, withLogentryID(id))
|
||||||
|
return &LogentryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Logentry.
|
||||||
|
func (c *LogentryClient) Delete() *LogentryDelete {
|
||||||
|
mutation := newLogentryMutation(c.config, OpDelete)
|
||||||
|
return &LogentryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a delete builder for the given entity.
|
||||||
|
func (c *LogentryClient) DeleteOne(l *Logentry) *LogentryDeleteOne {
|
||||||
|
return c.DeleteOneID(l.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a delete builder for the given id.
|
||||||
|
func (c *LogentryClient) DeleteOneID(id int64) *LogentryDeleteOne {
|
||||||
|
builder := c.Delete().Where(logentry.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &LogentryDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Logentry.
|
||||||
|
func (c *LogentryClient) Query() *LogentryQuery {
|
||||||
|
return &LogentryQuery{
|
||||||
|
config: c.config,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Logentry entity by its id.
|
||||||
|
func (c *LogentryClient) Get(ctx context.Context, id int64) (*Logentry, error) {
|
||||||
|
return c.Query().Where(logentry.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *LogentryClient) GetX(ctx context.Context, id int64) *Logentry {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAccount queries the account edge of a Logentry.
|
||||||
|
func (c *LogentryClient) QueryAccount(l *Logentry) *AccountQuery {
|
||||||
|
query := &AccountQuery{config: c.config}
|
||||||
|
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := l.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(logentry.Table, logentry.FieldID, id),
|
||||||
|
sqlgraph.To(account.Table, account.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, logentry.AccountTable, logentry.AccountColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(l.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryDomain queries the domain edge of a Logentry.
|
||||||
|
func (c *LogentryClient) QueryDomain(l *Logentry) *DomainQuery {
|
||||||
|
query := &DomainQuery{config: c.config}
|
||||||
|
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := l.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(logentry.Table, logentry.FieldID, id),
|
||||||
|
sqlgraph.To(domain.Table, domain.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, logentry.DomainTable, logentry.DomainColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(l.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *LogentryClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Logentry
|
||||||
|
}
|
||||||
|
|
||||||
|
// MailboxClient is a client for the Mailbox schema.
|
||||||
|
type MailboxClient struct {
|
||||||
|
config
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewMailboxClient returns a client for the Mailbox from the given config.
|
||||||
|
func NewMailboxClient(c config) *MailboxClient {
|
||||||
|
return &MailboxClient{config: c}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use adds a list of mutation hooks to the hooks stack.
|
||||||
|
// A call to `Use(f, g, h)` equals to `mailbox.Hooks(f(g(h())))`.
|
||||||
|
func (c *MailboxClient) Use(hooks ...Hook) {
|
||||||
|
c.hooks.Mailbox = append(c.hooks.Mailbox, hooks...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create returns a create builder for Mailbox.
|
||||||
|
func (c *MailboxClient) Create() *MailboxCreate {
|
||||||
|
mutation := newMailboxMutation(c.config, OpCreate)
|
||||||
|
return &MailboxCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateBulk returns a builder for creating a bulk of Mailbox entities.
|
||||||
|
func (c *MailboxClient) CreateBulk(builders ...*MailboxCreate) *MailboxCreateBulk {
|
||||||
|
return &MailboxCreateBulk{config: c.config, builders: builders}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns an update builder for Mailbox.
|
||||||
|
func (c *MailboxClient) Update() *MailboxUpdate {
|
||||||
|
mutation := newMailboxMutation(c.config, OpUpdate)
|
||||||
|
return &MailboxUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOne returns an update builder for the given entity.
|
||||||
|
func (c *MailboxClient) UpdateOne(m *Mailbox) *MailboxUpdateOne {
|
||||||
|
mutation := newMailboxMutation(c.config, OpUpdateOne, withMailbox(m))
|
||||||
|
return &MailboxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateOneID returns an update builder for the given id.
|
||||||
|
func (c *MailboxClient) UpdateOneID(id int64) *MailboxUpdateOne {
|
||||||
|
mutation := newMailboxMutation(c.config, OpUpdateOne, withMailboxID(id))
|
||||||
|
return &MailboxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete returns a delete builder for Mailbox.
|
||||||
|
func (c *MailboxClient) Delete() *MailboxDelete {
|
||||||
|
mutation := newMailboxMutation(c.config, OpDelete)
|
||||||
|
return &MailboxDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOne returns a delete builder for the given entity.
|
||||||
|
func (c *MailboxClient) DeleteOne(m *Mailbox) *MailboxDeleteOne {
|
||||||
|
return c.DeleteOneID(m.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOneID returns a delete builder for the given id.
|
||||||
|
func (c *MailboxClient) DeleteOneID(id int64) *MailboxDeleteOne {
|
||||||
|
builder := c.Delete().Where(mailbox.ID(id))
|
||||||
|
builder.mutation.id = &id
|
||||||
|
builder.mutation.op = OpDeleteOne
|
||||||
|
return &MailboxDeleteOne{builder}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query returns a query builder for Mailbox.
|
||||||
|
func (c *MailboxClient) Query() *MailboxQuery {
|
||||||
|
return &MailboxQuery{
|
||||||
|
config: c.config,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get returns a Mailbox entity by its id.
|
||||||
|
func (c *MailboxClient) Get(ctx context.Context, id int64) (*Mailbox, error) {
|
||||||
|
return c.Query().Where(mailbox.ID(id)).Only(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetX is like Get, but panics if an error occurs.
|
||||||
|
func (c *MailboxClient) GetX(ctx context.Context, id int64) *Mailbox {
|
||||||
|
obj, err := c.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryDomain queries the domain edge of a Mailbox.
|
||||||
|
func (c *MailboxClient) QueryDomain(m *Mailbox) *DomainQuery {
|
||||||
|
query := &DomainQuery{config: c.config}
|
||||||
|
query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) {
|
||||||
|
id := m.ID
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(mailbox.Table, mailbox.FieldID, id),
|
||||||
|
sqlgraph.To(domain.Table, domain.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, mailbox.DomainTable, mailbox.DomainColumn),
|
||||||
|
)
|
||||||
|
fromV = sqlgraph.Neighbors(m.driver.Dialect(), step)
|
||||||
|
return fromV, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks returns the client hooks.
|
||||||
|
func (c *MailboxClient) Hooks() []Hook {
|
||||||
|
return c.hooks.Mailbox
|
||||||
|
}
|
63
ent/config.go
Normal file
63
ent/config.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Option function to configure the client.
|
||||||
|
type Option func(*config)
|
||||||
|
|
||||||
|
// Config is the configuration for the client and its builder.
|
||||||
|
type config struct {
|
||||||
|
// driver used for executing database requests.
|
||||||
|
driver dialect.Driver
|
||||||
|
// debug enable a debug logging.
|
||||||
|
debug bool
|
||||||
|
// log used for logging on debug mode.
|
||||||
|
log func(...interface{})
|
||||||
|
// hooks to execute on mutations.
|
||||||
|
hooks *hooks
|
||||||
|
}
|
||||||
|
|
||||||
|
// hooks per client, for fast access.
|
||||||
|
type hooks struct {
|
||||||
|
Account []ent.Hook
|
||||||
|
Alias []ent.Hook
|
||||||
|
Domain []ent.Hook
|
||||||
|
Logentry []ent.Hook
|
||||||
|
Mailbox []ent.Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// Options applies the options on the config object.
|
||||||
|
func (c *config) options(opts ...Option) {
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(c)
|
||||||
|
}
|
||||||
|
if c.debug {
|
||||||
|
c.driver = dialect.Debug(c.driver, c.log)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug enables debug logging on the ent.Driver.
|
||||||
|
func Debug() Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.debug = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log sets the logging function for debug mode.
|
||||||
|
func Log(fn func(...interface{})) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.log = fn
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Driver configures the client driver.
|
||||||
|
func Driver(driver dialect.Driver) Option {
|
||||||
|
return func(c *config) {
|
||||||
|
c.driver = driver
|
||||||
|
}
|
||||||
|
}
|
33
ent/context.go
Normal file
33
ent/context.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
type clientCtxKey struct{}
|
||||||
|
|
||||||
|
// FromContext returns a Client stored inside a context, or nil if there isn't one.
|
||||||
|
func FromContext(ctx context.Context) *Client {
|
||||||
|
c, _ := ctx.Value(clientCtxKey{}).(*Client)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewContext returns a new context with the given Client attached.
|
||||||
|
func NewContext(parent context.Context, c *Client) context.Context {
|
||||||
|
return context.WithValue(parent, clientCtxKey{}, c)
|
||||||
|
}
|
||||||
|
|
||||||
|
type txCtxKey struct{}
|
||||||
|
|
||||||
|
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
|
||||||
|
func TxFromContext(ctx context.Context) *Tx {
|
||||||
|
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTxContext returns a new context with the given Tx attached.
|
||||||
|
func NewTxContext(parent context.Context, tx *Tx) context.Context {
|
||||||
|
return context.WithValue(parent, txCtxKey{}, tx)
|
||||||
|
}
|
284
ent/domain.go
Normal file
284
ent/domain.go
Normal file
@ -0,0 +1,284 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Domain is the model entity for the Domain schema.
|
||||||
|
type Domain struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// Created holds the value of the "created" field.
|
||||||
|
Created time.Time `json:"created,omitempty"`
|
||||||
|
// Modified holds the value of the "modified" field.
|
||||||
|
Modified *time.Time `json:"modified,omitempty"`
|
||||||
|
// Domain holds the value of the "domain" field.
|
||||||
|
Domain string `json:"domain,omitempty"`
|
||||||
|
// Description holds the value of the "description" field.
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
|
// MaxAliases holds the value of the "max_aliases" field.
|
||||||
|
MaxAliases int64 `json:"max_aliases,omitempty"`
|
||||||
|
// MaxMailboxes holds the value of the "max_mailboxes" field.
|
||||||
|
MaxMailboxes int64 `json:"max_mailboxes,omitempty"`
|
||||||
|
// MaxQuota holds the value of the "max_quota" field.
|
||||||
|
MaxQuota int64 `json:"max_quota,omitempty"`
|
||||||
|
// Quota holds the value of the "quota" field.
|
||||||
|
Quota int64 `json:"quota,omitempty"`
|
||||||
|
// Transport holds the value of the "transport" field.
|
||||||
|
Transport string `json:"transport,omitempty"`
|
||||||
|
// BackupMx holds the value of the "backup_mx" field.
|
||||||
|
BackupMx bool `json:"backup_mx,omitempty"`
|
||||||
|
// Active holds the value of the "active" field.
|
||||||
|
Active bool `json:"active,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the DomainQuery when eager-loading is set.
|
||||||
|
Edges DomainEdges `json:"edges"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type DomainEdges struct {
|
||||||
|
// Mailboxes holds the value of the mailboxes edge.
|
||||||
|
Mailboxes []*Mailbox `json:"mailboxes,omitempty"`
|
||||||
|
// Aliases holds the value of the aliases edge.
|
||||||
|
Aliases []*Alias `json:"aliases,omitempty"`
|
||||||
|
// Logs holds the value of the logs edge.
|
||||||
|
Logs []*Logentry `json:"logs,omitempty"`
|
||||||
|
// Accounts holds the value of the accounts edge.
|
||||||
|
Accounts []*Account `json:"accounts,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [4]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// MailboxesOrErr returns the Mailboxes value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e DomainEdges) MailboxesOrErr() ([]*Mailbox, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
return e.Mailboxes, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "mailboxes"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AliasesOrErr returns the Aliases value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e DomainEdges) AliasesOrErr() ([]*Alias, error) {
|
||||||
|
if e.loadedTypes[1] {
|
||||||
|
return e.Aliases, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "aliases"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogsOrErr returns the Logs value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e DomainEdges) LogsOrErr() ([]*Logentry, error) {
|
||||||
|
if e.loadedTypes[2] {
|
||||||
|
return e.Logs, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "logs"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountsOrErr returns the Accounts value or an error if the edge
|
||||||
|
// was not loaded in eager-loading.
|
||||||
|
func (e DomainEdges) AccountsOrErr() ([]*Account, error) {
|
||||||
|
if e.loadedTypes[3] {
|
||||||
|
return e.Accounts, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "accounts"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Domain) scanValues(columns []string) ([]interface{}, error) {
|
||||||
|
values := make([]interface{}, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case domain.FieldBackupMx, domain.FieldActive:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case domain.FieldID, domain.FieldMaxAliases, domain.FieldMaxMailboxes, domain.FieldMaxQuota, domain.FieldQuota:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case domain.FieldDomain, domain.FieldDescription, domain.FieldTransport:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case domain.FieldCreated, domain.FieldModified:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unexpected column %q for type Domain", columns[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Domain fields.
|
||||||
|
func (d *Domain) assignValues(columns []string, values []interface{}) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case domain.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
d.ID = int64(value.Int64)
|
||||||
|
case domain.FieldCreated:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.Created = value.Time
|
||||||
|
}
|
||||||
|
case domain.FieldModified:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field modified", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.Modified = new(time.Time)
|
||||||
|
*d.Modified = value.Time
|
||||||
|
}
|
||||||
|
case domain.FieldDomain:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field domain", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.Domain = value.String
|
||||||
|
}
|
||||||
|
case domain.FieldDescription:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field description", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.Description = new(string)
|
||||||
|
*d.Description = value.String
|
||||||
|
}
|
||||||
|
case domain.FieldMaxAliases:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field max_aliases", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.MaxAliases = value.Int64
|
||||||
|
}
|
||||||
|
case domain.FieldMaxMailboxes:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field max_mailboxes", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.MaxMailboxes = value.Int64
|
||||||
|
}
|
||||||
|
case domain.FieldMaxQuota:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field max_quota", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.MaxQuota = value.Int64
|
||||||
|
}
|
||||||
|
case domain.FieldQuota:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field quota", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.Quota = value.Int64
|
||||||
|
}
|
||||||
|
case domain.FieldTransport:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field transport", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.Transport = value.String
|
||||||
|
}
|
||||||
|
case domain.FieldBackupMx:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field backup_mx", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.BackupMx = value.Bool
|
||||||
|
}
|
||||||
|
case domain.FieldActive:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field active", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
d.Active = value.Bool
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryMailboxes queries the "mailboxes" edge of the Domain entity.
|
||||||
|
func (d *Domain) QueryMailboxes() *MailboxQuery {
|
||||||
|
return (&DomainClient{config: d.config}).QueryMailboxes(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAliases queries the "aliases" edge of the Domain entity.
|
||||||
|
func (d *Domain) QueryAliases() *AliasQuery {
|
||||||
|
return (&DomainClient{config: d.config}).QueryAliases(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryLogs queries the "logs" edge of the Domain entity.
|
||||||
|
func (d *Domain) QueryLogs() *LogentryQuery {
|
||||||
|
return (&DomainClient{config: d.config}).QueryLogs(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAccounts queries the "accounts" edge of the Domain entity.
|
||||||
|
func (d *Domain) QueryAccounts() *AccountQuery {
|
||||||
|
return (&DomainClient{config: d.config}).QueryAccounts(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Domain.
|
||||||
|
// Note that you need to call Domain.Unwrap() before calling this method if this Domain
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (d *Domain) Update() *DomainUpdateOne {
|
||||||
|
return (&DomainClient{config: d.config}).UpdateOne(d)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Domain 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 (d *Domain) Unwrap() *Domain {
|
||||||
|
tx, ok := d.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: Domain is not a transactional entity")
|
||||||
|
}
|
||||||
|
d.config.driver = tx.drv
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (d *Domain) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Domain(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v", d.ID))
|
||||||
|
builder.WriteString(", created=")
|
||||||
|
builder.WriteString(d.Created.Format(time.ANSIC))
|
||||||
|
if v := d.Modified; v != nil {
|
||||||
|
builder.WriteString(", modified=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", domain=")
|
||||||
|
builder.WriteString(d.Domain)
|
||||||
|
if v := d.Description; v != nil {
|
||||||
|
builder.WriteString(", description=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", max_aliases=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", d.MaxAliases))
|
||||||
|
builder.WriteString(", max_mailboxes=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", d.MaxMailboxes))
|
||||||
|
builder.WriteString(", max_quota=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", d.MaxQuota))
|
||||||
|
builder.WriteString(", quota=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", d.Quota))
|
||||||
|
builder.WriteString(", transport=")
|
||||||
|
builder.WriteString(d.Transport)
|
||||||
|
builder.WriteString(", backup_mx=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", d.BackupMx))
|
||||||
|
builder.WriteString(", active=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", d.Active))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Domains is a parsable slice of Domain.
|
||||||
|
type Domains []*Domain
|
||||||
|
|
||||||
|
func (d Domains) config(cfg config) {
|
||||||
|
for _i := range d {
|
||||||
|
d[_i].config = cfg
|
||||||
|
}
|
||||||
|
}
|
113
ent/domain/domain.go
Normal file
113
ent/domain/domain.go
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package domain
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the domain type in the database.
|
||||||
|
Label = "domain"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldCreated holds the string denoting the created field in the database.
|
||||||
|
FieldCreated = "created"
|
||||||
|
// FieldModified holds the string denoting the modified field in the database.
|
||||||
|
FieldModified = "modified"
|
||||||
|
// FieldDomain holds the string denoting the domain field in the database.
|
||||||
|
FieldDomain = "domain"
|
||||||
|
// FieldDescription holds the string denoting the description field in the database.
|
||||||
|
FieldDescription = "description"
|
||||||
|
// FieldMaxAliases holds the string denoting the max_aliases field in the database.
|
||||||
|
FieldMaxAliases = "max_aliases"
|
||||||
|
// FieldMaxMailboxes holds the string denoting the max_mailboxes field in the database.
|
||||||
|
FieldMaxMailboxes = "max_mailboxes"
|
||||||
|
// FieldMaxQuota holds the string denoting the max_quota field in the database.
|
||||||
|
FieldMaxQuota = "max_quota"
|
||||||
|
// FieldQuota holds the string denoting the quota field in the database.
|
||||||
|
FieldQuota = "quota"
|
||||||
|
// FieldTransport holds the string denoting the transport field in the database.
|
||||||
|
FieldTransport = "transport"
|
||||||
|
// FieldBackupMx holds the string denoting the backup_mx field in the database.
|
||||||
|
FieldBackupMx = "backup_mx"
|
||||||
|
// FieldActive holds the string denoting the active field in the database.
|
||||||
|
FieldActive = "active"
|
||||||
|
// EdgeMailboxes holds the string denoting the mailboxes edge name in mutations.
|
||||||
|
EdgeMailboxes = "mailboxes"
|
||||||
|
// EdgeAliases holds the string denoting the aliases edge name in mutations.
|
||||||
|
EdgeAliases = "aliases"
|
||||||
|
// EdgeLogs holds the string denoting the logs edge name in mutations.
|
||||||
|
EdgeLogs = "logs"
|
||||||
|
// EdgeAccounts holds the string denoting the accounts edge name in mutations.
|
||||||
|
EdgeAccounts = "accounts"
|
||||||
|
// Table holds the table name of the domain in the database.
|
||||||
|
Table = "domains"
|
||||||
|
// MailboxesTable is the table that holds the mailboxes relation/edge.
|
||||||
|
MailboxesTable = "mailboxes"
|
||||||
|
// MailboxesInverseTable is the table name for the Mailbox entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "mailbox" package.
|
||||||
|
MailboxesInverseTable = "mailboxes"
|
||||||
|
// MailboxesColumn is the table column denoting the mailboxes relation/edge.
|
||||||
|
MailboxesColumn = "domain_id"
|
||||||
|
// AliasesTable is the table that holds the aliases relation/edge.
|
||||||
|
AliasesTable = "alias"
|
||||||
|
// AliasesInverseTable is the table name for the Alias entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "alias" package.
|
||||||
|
AliasesInverseTable = "alias"
|
||||||
|
// AliasesColumn is the table column denoting the aliases relation/edge.
|
||||||
|
AliasesColumn = "domain_id"
|
||||||
|
// LogsTable is the table that holds the logs relation/edge.
|
||||||
|
LogsTable = "logentries"
|
||||||
|
// LogsInverseTable is the table name for the Logentry entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "logentry" package.
|
||||||
|
LogsInverseTable = "logentries"
|
||||||
|
// LogsColumn is the table column denoting the logs relation/edge.
|
||||||
|
LogsColumn = "domain_id"
|
||||||
|
// AccountsTable is the table that holds the accounts relation/edge. The primary key declared below.
|
||||||
|
AccountsTable = "account_domains"
|
||||||
|
// AccountsInverseTable is the table name for the Account entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "account" package.
|
||||||
|
AccountsInverseTable = "accounts"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for domain fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldCreated,
|
||||||
|
FieldModified,
|
||||||
|
FieldDomain,
|
||||||
|
FieldDescription,
|
||||||
|
FieldMaxAliases,
|
||||||
|
FieldMaxMailboxes,
|
||||||
|
FieldMaxQuota,
|
||||||
|
FieldQuota,
|
||||||
|
FieldTransport,
|
||||||
|
FieldBackupMx,
|
||||||
|
FieldActive,
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
// AccountsPrimaryKey and AccountsColumn2 are the table columns denoting the
|
||||||
|
// primary key for the accounts relation (M2M).
|
||||||
|
AccountsPrimaryKey = []string{"account_id", "domain_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 (
|
||||||
|
// DefaultCreated holds the default value on creation for the "created" field.
|
||||||
|
DefaultCreated func() time.Time
|
||||||
|
// DefaultModified holds the default value on creation for the "modified" field.
|
||||||
|
DefaultModified func() time.Time
|
||||||
|
// UpdateDefaultModified holds the default value on update for the "modified" field.
|
||||||
|
UpdateDefaultModified func() time.Time
|
||||||
|
)
|
1160
ent/domain/where.go
Normal file
1160
ent/domain/where.go
Normal file
File diff suppressed because it is too large
Load Diff
575
ent/domain_create.go
Normal file
575
ent/domain_create.go
Normal file
@ -0,0 +1,575 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"code.icod.de/postfix/manager/ent/alias"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/logentry"
|
||||||
|
"code.icod.de/postfix/manager/ent/mailbox"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DomainCreate is the builder for creating a Domain entity.
|
||||||
|
type DomainCreate struct {
|
||||||
|
config
|
||||||
|
mutation *DomainMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreated sets the "created" field.
|
||||||
|
func (dc *DomainCreate) SetCreated(t time.Time) *DomainCreate {
|
||||||
|
dc.mutation.SetCreated(t)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreated sets the "created" field if the given value is not nil.
|
||||||
|
func (dc *DomainCreate) SetNillableCreated(t *time.Time) *DomainCreate {
|
||||||
|
if t != nil {
|
||||||
|
dc.SetCreated(*t)
|
||||||
|
}
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModified sets the "modified" field.
|
||||||
|
func (dc *DomainCreate) SetModified(t time.Time) *DomainCreate {
|
||||||
|
dc.mutation.SetModified(t)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableModified sets the "modified" field if the given value is not nil.
|
||||||
|
func (dc *DomainCreate) SetNillableModified(t *time.Time) *DomainCreate {
|
||||||
|
if t != nil {
|
||||||
|
dc.SetModified(*t)
|
||||||
|
}
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomain sets the "domain" field.
|
||||||
|
func (dc *DomainCreate) SetDomain(s string) *DomainCreate {
|
||||||
|
dc.mutation.SetDomain(s)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDescription sets the "description" field.
|
||||||
|
func (dc *DomainCreate) SetDescription(s string) *DomainCreate {
|
||||||
|
dc.mutation.SetDescription(s)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDescription sets the "description" field if the given value is not nil.
|
||||||
|
func (dc *DomainCreate) SetNillableDescription(s *string) *DomainCreate {
|
||||||
|
if s != nil {
|
||||||
|
dc.SetDescription(*s)
|
||||||
|
}
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaxAliases sets the "max_aliases" field.
|
||||||
|
func (dc *DomainCreate) SetMaxAliases(i int64) *DomainCreate {
|
||||||
|
dc.mutation.SetMaxAliases(i)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaxMailboxes sets the "max_mailboxes" field.
|
||||||
|
func (dc *DomainCreate) SetMaxMailboxes(i int64) *DomainCreate {
|
||||||
|
dc.mutation.SetMaxMailboxes(i)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaxQuota sets the "max_quota" field.
|
||||||
|
func (dc *DomainCreate) SetMaxQuota(i int64) *DomainCreate {
|
||||||
|
dc.mutation.SetMaxQuota(i)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetQuota sets the "quota" field.
|
||||||
|
func (dc *DomainCreate) SetQuota(i int64) *DomainCreate {
|
||||||
|
dc.mutation.SetQuota(i)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTransport sets the "transport" field.
|
||||||
|
func (dc *DomainCreate) SetTransport(s string) *DomainCreate {
|
||||||
|
dc.mutation.SetTransport(s)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBackupMx sets the "backup_mx" field.
|
||||||
|
func (dc *DomainCreate) SetBackupMx(b bool) *DomainCreate {
|
||||||
|
dc.mutation.SetBackupMx(b)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActive sets the "active" field.
|
||||||
|
func (dc *DomainCreate) SetActive(b bool) *DomainCreate {
|
||||||
|
dc.mutation.SetActive(b)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (dc *DomainCreate) SetID(i int64) *DomainCreate {
|
||||||
|
dc.mutation.SetID(i)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddMailboxIDs adds the "mailboxes" edge to the Mailbox entity by IDs.
|
||||||
|
func (dc *DomainCreate) AddMailboxIDs(ids ...int64) *DomainCreate {
|
||||||
|
dc.mutation.AddMailboxIDs(ids...)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddMailboxes adds the "mailboxes" edges to the Mailbox entity.
|
||||||
|
func (dc *DomainCreate) AddMailboxes(m ...*Mailbox) *DomainCreate {
|
||||||
|
ids := make([]int64, len(m))
|
||||||
|
for i := range m {
|
||||||
|
ids[i] = m[i].ID
|
||||||
|
}
|
||||||
|
return dc.AddMailboxIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAliasIDs adds the "aliases" edge to the Alias entity by IDs.
|
||||||
|
func (dc *DomainCreate) AddAliasIDs(ids ...int64) *DomainCreate {
|
||||||
|
dc.mutation.AddAliasIDs(ids...)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAliases adds the "aliases" edges to the Alias entity.
|
||||||
|
func (dc *DomainCreate) AddAliases(a ...*Alias) *DomainCreate {
|
||||||
|
ids := make([]int64, len(a))
|
||||||
|
for i := range a {
|
||||||
|
ids[i] = a[i].ID
|
||||||
|
}
|
||||||
|
return dc.AddAliasIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLogIDs adds the "logs" edge to the Logentry entity by IDs.
|
||||||
|
func (dc *DomainCreate) AddLogIDs(ids ...int64) *DomainCreate {
|
||||||
|
dc.mutation.AddLogIDs(ids...)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddLogs adds the "logs" edges to the Logentry entity.
|
||||||
|
func (dc *DomainCreate) AddLogs(l ...*Logentry) *DomainCreate {
|
||||||
|
ids := make([]int64, len(l))
|
||||||
|
for i := range l {
|
||||||
|
ids[i] = l[i].ID
|
||||||
|
}
|
||||||
|
return dc.AddLogIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAccountIDs adds the "accounts" edge to the Account entity by IDs.
|
||||||
|
func (dc *DomainCreate) AddAccountIDs(ids ...int64) *DomainCreate {
|
||||||
|
dc.mutation.AddAccountIDs(ids...)
|
||||||
|
return dc
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddAccounts adds the "accounts" edges to the Account entity.
|
||||||
|
func (dc *DomainCreate) AddAccounts(a ...*Account) *DomainCreate {
|
||||||
|
ids := make([]int64, len(a))
|
||||||
|
for i := range a {
|
||||||
|
ids[i] = a[i].ID
|
||||||
|
}
|
||||||
|
return dc.AddAccountIDs(ids...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the DomainMutation object of the builder.
|
||||||
|
func (dc *DomainCreate) Mutation() *DomainMutation {
|
||||||
|
return dc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Domain in the database.
|
||||||
|
func (dc *DomainCreate) Save(ctx context.Context) (*Domain, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *Domain
|
||||||
|
)
|
||||||
|
dc.defaults()
|
||||||
|
if len(dc.hooks) == 0 {
|
||||||
|
if err = dc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
node, err = dc.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*DomainMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err = dc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
dc.mutation = mutation
|
||||||
|
if node, err = dc.sqlSave(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &node.ID
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(dc.hooks) - 1; i >= 0; i-- {
|
||||||
|
if dc.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = dc.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, dc.mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (dc *DomainCreate) SaveX(ctx context.Context) *Domain {
|
||||||
|
v, err := dc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (dc *DomainCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := dc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (dc *DomainCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := dc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (dc *DomainCreate) defaults() {
|
||||||
|
if _, ok := dc.mutation.Created(); !ok {
|
||||||
|
v := domain.DefaultCreated()
|
||||||
|
dc.mutation.SetCreated(v)
|
||||||
|
}
|
||||||
|
if _, ok := dc.mutation.Modified(); !ok {
|
||||||
|
v := domain.DefaultModified()
|
||||||
|
dc.mutation.SetModified(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (dc *DomainCreate) check() error {
|
||||||
|
if _, ok := dc.mutation.Created(); !ok {
|
||||||
|
return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "Domain.created"`)}
|
||||||
|
}
|
||||||
|
if _, ok := dc.mutation.Domain(); !ok {
|
||||||
|
return &ValidationError{Name: "domain", err: errors.New(`ent: missing required field "Domain.domain"`)}
|
||||||
|
}
|
||||||
|
if _, ok := dc.mutation.MaxAliases(); !ok {
|
||||||
|
return &ValidationError{Name: "max_aliases", err: errors.New(`ent: missing required field "Domain.max_aliases"`)}
|
||||||
|
}
|
||||||
|
if _, ok := dc.mutation.MaxMailboxes(); !ok {
|
||||||
|
return &ValidationError{Name: "max_mailboxes", err: errors.New(`ent: missing required field "Domain.max_mailboxes"`)}
|
||||||
|
}
|
||||||
|
if _, ok := dc.mutation.MaxQuota(); !ok {
|
||||||
|
return &ValidationError{Name: "max_quota", err: errors.New(`ent: missing required field "Domain.max_quota"`)}
|
||||||
|
}
|
||||||
|
if _, ok := dc.mutation.Quota(); !ok {
|
||||||
|
return &ValidationError{Name: "quota", err: errors.New(`ent: missing required field "Domain.quota"`)}
|
||||||
|
}
|
||||||
|
if _, ok := dc.mutation.Transport(); !ok {
|
||||||
|
return &ValidationError{Name: "transport", err: errors.New(`ent: missing required field "Domain.transport"`)}
|
||||||
|
}
|
||||||
|
if _, ok := dc.mutation.BackupMx(); !ok {
|
||||||
|
return &ValidationError{Name: "backup_mx", err: errors.New(`ent: missing required field "Domain.backup_mx"`)}
|
||||||
|
}
|
||||||
|
if _, ok := dc.mutation.Active(); !ok {
|
||||||
|
return &ValidationError{Name: "active", err: errors.New(`ent: missing required field "Domain.active"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dc *DomainCreate) sqlSave(ctx context.Context) (*Domain, error) {
|
||||||
|
_node, _spec := dc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, dc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != _node.ID {
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int64(id)
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dc *DomainCreate) createSpec() (*Domain, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Domain{config: dc.config}
|
||||||
|
_spec = &sqlgraph.CreateSpec{
|
||||||
|
Table: domain.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if id, ok := dc.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = id
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.Created(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldCreated,
|
||||||
|
})
|
||||||
|
_node.Created = value
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.Modified(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldModified,
|
||||||
|
})
|
||||||
|
_node.Modified = &value
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.Domain(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldDomain,
|
||||||
|
})
|
||||||
|
_node.Domain = value
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.Description(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldDescription,
|
||||||
|
})
|
||||||
|
_node.Description = &value
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.MaxAliases(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldMaxAliases,
|
||||||
|
})
|
||||||
|
_node.MaxAliases = value
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.MaxMailboxes(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldMaxMailboxes,
|
||||||
|
})
|
||||||
|
_node.MaxMailboxes = value
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.MaxQuota(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldMaxQuota,
|
||||||
|
})
|
||||||
|
_node.MaxQuota = value
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.Quota(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldQuota,
|
||||||
|
})
|
||||||
|
_node.Quota = value
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.Transport(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldTransport,
|
||||||
|
})
|
||||||
|
_node.Transport = value
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.BackupMx(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldBackupMx,
|
||||||
|
})
|
||||||
|
_node.BackupMx = value
|
||||||
|
}
|
||||||
|
if value, ok := dc.mutation.Active(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: domain.FieldActive,
|
||||||
|
})
|
||||||
|
_node.Active = value
|
||||||
|
}
|
||||||
|
if nodes := dc.mutation.MailboxesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: domain.MailboxesTable,
|
||||||
|
Columns: []string{domain.MailboxesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: mailbox.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
if nodes := dc.mutation.AliasesIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: domain.AliasesTable,
|
||||||
|
Columns: []string{domain.AliasesColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: alias.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
if nodes := dc.mutation.LogsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.O2M,
|
||||||
|
Inverse: false,
|
||||||
|
Table: domain.LogsTable,
|
||||||
|
Columns: []string{domain.LogsColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
if nodes := dc.mutation.AccountsIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2M,
|
||||||
|
Inverse: true,
|
||||||
|
Table: domain.AccountsTable,
|
||||||
|
Columns: domain.AccountsPrimaryKey,
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: account.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainCreateBulk is the builder for creating many Domain entities in bulk.
|
||||||
|
type DomainCreateBulk struct {
|
||||||
|
config
|
||||||
|
builders []*DomainCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Domain entities in the database.
|
||||||
|
func (dcb *DomainCreateBulk) Save(ctx context.Context) ([]*Domain, error) {
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(dcb.builders))
|
||||||
|
nodes := make([]*Domain, len(dcb.builders))
|
||||||
|
mutators := make([]Mutator, len(dcb.builders))
|
||||||
|
for i := range dcb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := dcb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*DomainMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
var err error
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, dcb.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, dcb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
mutation.done = true
|
||||||
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int64(id)
|
||||||
|
}
|
||||||
|
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, dcb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (dcb *DomainCreateBulk) SaveX(ctx context.Context) []*Domain {
|
||||||
|
v, err := dcb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (dcb *DomainCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := dcb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (dcb *DomainCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := dcb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
111
ent/domain_delete.go
Normal file
111
ent/domain_delete.go
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DomainDelete is the builder for deleting a Domain entity.
|
||||||
|
type DomainDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *DomainMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the DomainDelete builder.
|
||||||
|
func (dd *DomainDelete) Where(ps ...predicate.Domain) *DomainDelete {
|
||||||
|
dd.mutation.Where(ps...)
|
||||||
|
return dd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (dd *DomainDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
if len(dd.hooks) == 0 {
|
||||||
|
affected, err = dd.sqlExec(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*DomainMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
dd.mutation = mutation
|
||||||
|
affected, err = dd.sqlExec(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(dd.hooks) - 1; i >= 0; i-- {
|
||||||
|
if dd.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = dd.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, dd.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (dd *DomainDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := dd.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dd *DomainDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := &sqlgraph.DeleteSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: domain.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := dd.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sqlgraph.DeleteNodes(ctx, dd.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainDeleteOne is the builder for deleting a single Domain entity.
|
||||||
|
type DomainDeleteOne struct {
|
||||||
|
dd *DomainDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (ddo *DomainDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := ddo.dd.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{domain.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ddo *DomainDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
ddo.dd.ExecX(ctx)
|
||||||
|
}
|
1215
ent/domain_query.go
Normal file
1215
ent/domain_query.go
Normal file
File diff suppressed because it is too large
Load Diff
1418
ent/domain_update.go
Normal file
1418
ent/domain_update.go
Normal file
File diff suppressed because it is too large
Load Diff
267
ent/ent.go
Normal file
267
ent/ent.go
Normal file
@ -0,0 +1,267 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"code.icod.de/postfix/manager/ent/alias"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/logentry"
|
||||||
|
"code.icod.de/postfix/manager/ent/mailbox"
|
||||||
|
"entgo.io/ent"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ent aliases to avoid import conflicts in user's code.
|
||||||
|
type (
|
||||||
|
Op = ent.Op
|
||||||
|
Hook = ent.Hook
|
||||||
|
Value = ent.Value
|
||||||
|
Query = ent.Query
|
||||||
|
Policy = ent.Policy
|
||||||
|
Mutator = ent.Mutator
|
||||||
|
Mutation = ent.Mutation
|
||||||
|
MutateFunc = ent.MutateFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
// OrderFunc applies an ordering on the sql selector.
|
||||||
|
type OrderFunc func(*sql.Selector)
|
||||||
|
|
||||||
|
// columnChecker returns a function indicates if the column exists in the given column.
|
||||||
|
func columnChecker(table string) func(string) error {
|
||||||
|
checks := map[string]func(string) bool{
|
||||||
|
account.Table: account.ValidColumn,
|
||||||
|
alias.Table: alias.ValidColumn,
|
||||||
|
domain.Table: domain.ValidColumn,
|
||||||
|
logentry.Table: logentry.ValidColumn,
|
||||||
|
mailbox.Table: mailbox.ValidColumn,
|
||||||
|
}
|
||||||
|
check, ok := checks[table]
|
||||||
|
if !ok {
|
||||||
|
return func(string) error {
|
||||||
|
return fmt.Errorf("unknown table %q", table)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return func(column string) error {
|
||||||
|
if !check(column) {
|
||||||
|
return fmt.Errorf("unknown column %q for table %q", column, table)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Asc applies the given fields in ASC order.
|
||||||
|
func Asc(fields ...string) OrderFunc {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
check := columnChecker(s.TableName())
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := check(f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Asc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desc applies the given fields in DESC order.
|
||||||
|
func Desc(fields ...string) OrderFunc {
|
||||||
|
return func(s *sql.Selector) {
|
||||||
|
check := columnChecker(s.TableName())
|
||||||
|
for _, f := range fields {
|
||||||
|
if err := check(f); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
}
|
||||||
|
s.OrderBy(sql.Desc(s.C(f)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
|
||||||
|
type AggregateFunc func(*sql.Selector) string
|
||||||
|
|
||||||
|
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
|
||||||
|
//
|
||||||
|
// GroupBy(field1, field2).
|
||||||
|
// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
//
|
||||||
|
func As(fn AggregateFunc, end string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.As(fn(s), end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count applies the "count" aggregation function on each group.
|
||||||
|
func Count() AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
return sql.Count("*")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Max applies the "max" aggregation function on the given field of each group.
|
||||||
|
func Max(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
check := columnChecker(s.TableName())
|
||||||
|
if err := check(field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Max(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mean applies the "mean" aggregation function on the given field of each group.
|
||||||
|
func Mean(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
check := columnChecker(s.TableName())
|
||||||
|
if err := check(field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Avg(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Min applies the "min" aggregation function on the given field of each group.
|
||||||
|
func Min(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
check := columnChecker(s.TableName())
|
||||||
|
if err := check(field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Min(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sum applies the "sum" aggregation function on the given field of each group.
|
||||||
|
func Sum(field string) AggregateFunc {
|
||||||
|
return func(s *sql.Selector) string {
|
||||||
|
check := columnChecker(s.TableName())
|
||||||
|
if err := check(field); err != nil {
|
||||||
|
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)})
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sql.Sum(s.C(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidationError returns when validating a field or edge fails.
|
||||||
|
type ValidationError struct {
|
||||||
|
Name string // Field or edge name.
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *ValidationError) Error() string {
|
||||||
|
return e.err.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ValidationError) Unwrap() error {
|
||||||
|
return e.err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValidationError returns a boolean indicating whether the error is a validation error.
|
||||||
|
func IsValidationError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ValidationError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
|
||||||
|
type NotFoundError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotFoundError) Error() string {
|
||||||
|
return "ent: " + e.label + " not found"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotFound returns a boolean indicating whether the error is a not found error.
|
||||||
|
func IsNotFound(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotFoundError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaskNotFound masks not found error.
|
||||||
|
func MaskNotFound(err error) error {
|
||||||
|
if IsNotFound(err) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
|
||||||
|
type NotSingularError struct {
|
||||||
|
label string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotSingularError) Error() string {
|
||||||
|
return "ent: " + e.label + " not singular"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
|
||||||
|
func IsNotSingular(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotSingularError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NotLoadedError returns when trying to get a node that was not loaded by the query.
|
||||||
|
type NotLoadedError struct {
|
||||||
|
edge string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e *NotLoadedError) Error() string {
|
||||||
|
return "ent: " + e.edge + " edge was not loaded"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
|
||||||
|
func IsNotLoaded(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *NotLoadedError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ConstraintError returns when trying to create/update one or more entities and
|
||||||
|
// one or more of their constraints failed. For example, violation of edge or
|
||||||
|
// field uniqueness.
|
||||||
|
type ConstraintError struct {
|
||||||
|
msg string
|
||||||
|
wrap error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error implements the error interface.
|
||||||
|
func (e ConstraintError) Error() string {
|
||||||
|
return "ent: constraint failed: " + e.msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap implements the errors.Wrapper interface.
|
||||||
|
func (e *ConstraintError) Unwrap() error {
|
||||||
|
return e.wrap
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
|
||||||
|
func IsConstraintError(err error) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
var e *ConstraintError
|
||||||
|
return errors.As(err, &e)
|
||||||
|
}
|
78
ent/enttest/enttest.go
Normal file
78
ent/enttest/enttest.go
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package enttest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent"
|
||||||
|
// required by schema hooks.
|
||||||
|
_ "code.icod.de/postfix/manager/ent/runtime"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// TestingT is the interface that is shared between
|
||||||
|
// testing.T and testing.B and used by enttest.
|
||||||
|
TestingT interface {
|
||||||
|
FailNow()
|
||||||
|
Error(...interface{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Option configures client creation.
|
||||||
|
Option func(*options)
|
||||||
|
|
||||||
|
options struct {
|
||||||
|
opts []ent.Option
|
||||||
|
migrateOpts []schema.MigrateOption
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// WithOptions forwards options to client creation.
|
||||||
|
func WithOptions(opts ...ent.Option) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.opts = append(o.opts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithMigrateOptions forwards options to auto migration.
|
||||||
|
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
|
||||||
|
return func(o *options) {
|
||||||
|
o.migrateOpts = append(o.migrateOpts, opts...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newOptions(opts []Option) *options {
|
||||||
|
o := &options{}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(o)
|
||||||
|
}
|
||||||
|
return o
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open calls ent.Open and auto-run migration.
|
||||||
|
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c, err := ent.Open(driverName, dataSourceName, o.opts...)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClient calls ent.NewClient and auto-run migration.
|
||||||
|
func NewClient(t TestingT, opts ...Option) *ent.Client {
|
||||||
|
o := newOptions(opts)
|
||||||
|
c := ent.NewClient(o.opts...)
|
||||||
|
if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
t.FailNow()
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
256
ent/hook/hook.go
Normal file
256
ent/hook/hook.go
Normal file
@ -0,0 +1,256 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package hook
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The AccountFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Account mutator.
|
||||||
|
type AccountFunc func(context.Context, *ent.AccountMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f AccountFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
mv, ok := m.(*ent.AccountMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AccountMutation", m)
|
||||||
|
}
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The AliasFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Alias mutator.
|
||||||
|
type AliasFunc func(context.Context, *ent.AliasMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f AliasFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
mv, ok := m.(*ent.AliasMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AliasMutation", m)
|
||||||
|
}
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The DomainFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Domain mutator.
|
||||||
|
type DomainFunc func(context.Context, *ent.DomainMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f DomainFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
mv, ok := m.(*ent.DomainMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DomainMutation", m)
|
||||||
|
}
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The LogentryFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Logentry mutator.
|
||||||
|
type LogentryFunc func(context.Context, *ent.LogentryMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f LogentryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
mv, ok := m.(*ent.LogentryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LogentryMutation", m)
|
||||||
|
}
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The MailboxFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as Mailbox mutator.
|
||||||
|
type MailboxFunc func(context.Context, *ent.MailboxMutation) (ent.Value, error)
|
||||||
|
|
||||||
|
// Mutate calls f(ctx, m).
|
||||||
|
func (f MailboxFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
mv, ok := m.(*ent.MailboxMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MailboxMutation", m)
|
||||||
|
}
|
||||||
|
return f(ctx, mv)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Condition is a hook condition function.
|
||||||
|
type Condition func(context.Context, ent.Mutation) bool
|
||||||
|
|
||||||
|
// And groups conditions with the AND operator.
|
||||||
|
func And(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m ent.Mutation) bool {
|
||||||
|
if !first(ctx, m) || !second(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if !cond(ctx, m) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Or groups conditions with the OR operator.
|
||||||
|
func Or(first, second Condition, rest ...Condition) Condition {
|
||||||
|
return func(ctx context.Context, m ent.Mutation) bool {
|
||||||
|
if first(ctx, m) || second(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, cond := range rest {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not negates a given condition.
|
||||||
|
func Not(cond Condition) Condition {
|
||||||
|
return func(ctx context.Context, m ent.Mutation) bool {
|
||||||
|
return !cond(ctx, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasOp is a condition testing mutation operation.
|
||||||
|
func HasOp(op ent.Op) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
return m.Op().Is(op)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAddedFields is a condition validating `.AddedField` on fields.
|
||||||
|
func HasAddedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.AddedField(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasClearedFields is a condition validating `.FieldCleared` on fields.
|
||||||
|
func HasClearedFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if exists := m.FieldCleared(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasFields is a condition validating `.Field` on fields.
|
||||||
|
func HasFields(field string, fields ...string) Condition {
|
||||||
|
return func(_ context.Context, m ent.Mutation) bool {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, field := range fields {
|
||||||
|
if _, exists := m.Field(field); !exists {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If executes the given hook under condition.
|
||||||
|
//
|
||||||
|
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
|
||||||
|
//
|
||||||
|
func If(hk ent.Hook, cond Condition) ent.Hook {
|
||||||
|
return func(next ent.Mutator) ent.Mutator {
|
||||||
|
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||||
|
if cond(ctx, m) {
|
||||||
|
return hk(next).Mutate(ctx, m)
|
||||||
|
}
|
||||||
|
return next.Mutate(ctx, m)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// On executes the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.On(Log, ent.Delete|ent.Create)
|
||||||
|
//
|
||||||
|
func On(hk ent.Hook, op ent.Op) ent.Hook {
|
||||||
|
return If(hk, HasOp(op))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unless skips the given hook only for the given operation.
|
||||||
|
//
|
||||||
|
// hook.Unless(Log, ent.Update|ent.UpdateOne)
|
||||||
|
//
|
||||||
|
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
|
||||||
|
return If(hk, Not(HasOp(op)))
|
||||||
|
}
|
||||||
|
|
||||||
|
// FixedError is a hook returning a fixed error.
|
||||||
|
func FixedError(err error) ent.Hook {
|
||||||
|
return func(ent.Mutator) ent.Mutator {
|
||||||
|
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
|
||||||
|
return nil, err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reject returns a hook that rejects all operations that match op.
|
||||||
|
//
|
||||||
|
// func (T) Hooks() []ent.Hook {
|
||||||
|
// return []ent.Hook{
|
||||||
|
// Reject(ent.Delete|ent.Update),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
func Reject(op ent.Op) ent.Hook {
|
||||||
|
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
|
||||||
|
return On(hk, op)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chain acts as a list of hooks and is effectively immutable.
|
||||||
|
// Once created, it will always hold the same set of hooks in the same order.
|
||||||
|
type Chain struct {
|
||||||
|
hooks []ent.Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewChain creates a new chain of hooks.
|
||||||
|
func NewChain(hooks ...ent.Hook) Chain {
|
||||||
|
return Chain{append([]ent.Hook(nil), hooks...)}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hook chains the list of hooks and returns the final hook.
|
||||||
|
func (c Chain) Hook() ent.Hook {
|
||||||
|
return func(mutator ent.Mutator) ent.Mutator {
|
||||||
|
for i := len(c.hooks) - 1; i >= 0; i-- {
|
||||||
|
mutator = c.hooks[i](mutator)
|
||||||
|
}
|
||||||
|
return mutator
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append extends a chain, adding the specified hook
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Append(hooks ...ent.Hook) Chain {
|
||||||
|
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
|
||||||
|
newHooks = append(newHooks, c.hooks...)
|
||||||
|
newHooks = append(newHooks, hooks...)
|
||||||
|
return Chain{newHooks}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extend extends a chain, adding the specified chain
|
||||||
|
// as the last ones in the mutation flow.
|
||||||
|
func (c Chain) Extend(chain Chain) Chain {
|
||||||
|
return c.Append(chain.hooks...)
|
||||||
|
}
|
199
ent/logentry.go
Normal file
199
ent/logentry.go
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/logentry"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Logentry is the model entity for the Logentry schema.
|
||||||
|
type Logentry struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// Timestamp holds the value of the "timestamp" field.
|
||||||
|
Timestamp time.Time `json:"timestamp,omitempty"`
|
||||||
|
// Action holds the value of the "action" field.
|
||||||
|
Action string `json:"action,omitempty"`
|
||||||
|
// Data holds the value of the "data" field.
|
||||||
|
Data *string `json:"data,omitempty"`
|
||||||
|
// AccountID holds the value of the "account_id" field.
|
||||||
|
AccountID int64 `json:"account_id,omitempty"`
|
||||||
|
// DomainID holds the value of the "domain_id" field.
|
||||||
|
DomainID int64 `json:"domain_id,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the LogentryQuery when eager-loading is set.
|
||||||
|
Edges LogentryEdges `json:"edges"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogentryEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type LogentryEdges struct {
|
||||||
|
// Account holds the value of the account edge.
|
||||||
|
Account *Account `json:"account,omitempty"`
|
||||||
|
// Domain holds the value of the domain edge.
|
||||||
|
Domain *Domain `json:"domain,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [2]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountOrErr returns the Account value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e LogentryEdges) AccountOrErr() (*Account, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
if e.Account == nil {
|
||||||
|
// The edge account was loaded in eager-loading,
|
||||||
|
// but was not found.
|
||||||
|
return nil, &NotFoundError{label: account.Label}
|
||||||
|
}
|
||||||
|
return e.Account, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "account"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainOrErr returns the Domain value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e LogentryEdges) DomainOrErr() (*Domain, error) {
|
||||||
|
if e.loadedTypes[1] {
|
||||||
|
if e.Domain == nil {
|
||||||
|
// The edge domain was loaded in eager-loading,
|
||||||
|
// but was not found.
|
||||||
|
return nil, &NotFoundError{label: domain.Label}
|
||||||
|
}
|
||||||
|
return e.Domain, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "domain"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Logentry) scanValues(columns []string) ([]interface{}, error) {
|
||||||
|
values := make([]interface{}, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case logentry.FieldID, logentry.FieldAccountID, logentry.FieldDomainID:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case logentry.FieldAction, logentry.FieldData:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case logentry.FieldTimestamp:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unexpected column %q for type Logentry", columns[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Logentry fields.
|
||||||
|
func (l *Logentry) assignValues(columns []string, values []interface{}) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case logentry.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
l.ID = int64(value.Int64)
|
||||||
|
case logentry.FieldTimestamp:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field timestamp", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
l.Timestamp = value.Time
|
||||||
|
}
|
||||||
|
case logentry.FieldAction:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field action", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
l.Action = value.String
|
||||||
|
}
|
||||||
|
case logentry.FieldData:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field data", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
l.Data = new(string)
|
||||||
|
*l.Data = value.String
|
||||||
|
}
|
||||||
|
case logentry.FieldAccountID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field account_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
l.AccountID = value.Int64
|
||||||
|
}
|
||||||
|
case logentry.FieldDomainID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field domain_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
l.DomainID = value.Int64
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryAccount queries the "account" edge of the Logentry entity.
|
||||||
|
func (l *Logentry) QueryAccount() *AccountQuery {
|
||||||
|
return (&LogentryClient{config: l.config}).QueryAccount(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryDomain queries the "domain" edge of the Logentry entity.
|
||||||
|
func (l *Logentry) QueryDomain() *DomainQuery {
|
||||||
|
return (&LogentryClient{config: l.config}).QueryDomain(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Logentry.
|
||||||
|
// Note that you need to call Logentry.Unwrap() before calling this method if this Logentry
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (l *Logentry) Update() *LogentryUpdateOne {
|
||||||
|
return (&LogentryClient{config: l.config}).UpdateOne(l)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Logentry 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 (l *Logentry) Unwrap() *Logentry {
|
||||||
|
tx, ok := l.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: Logentry is not a transactional entity")
|
||||||
|
}
|
||||||
|
l.config.driver = tx.drv
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (l *Logentry) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Logentry(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v", l.ID))
|
||||||
|
builder.WriteString(", timestamp=")
|
||||||
|
builder.WriteString(l.Timestamp.Format(time.ANSIC))
|
||||||
|
builder.WriteString(", action=")
|
||||||
|
builder.WriteString(l.Action)
|
||||||
|
if v := l.Data; v != nil {
|
||||||
|
builder.WriteString(", data=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", account_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", l.AccountID))
|
||||||
|
builder.WriteString(", domain_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", l.DomainID))
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logentries is a parsable slice of Logentry.
|
||||||
|
type Logentries []*Logentry
|
||||||
|
|
||||||
|
func (l Logentries) config(cfg config) {
|
||||||
|
for _i := range l {
|
||||||
|
l[_i].config = cfg
|
||||||
|
}
|
||||||
|
}
|
69
ent/logentry/logentry.go
Normal file
69
ent/logentry/logentry.go
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package logentry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the logentry type in the database.
|
||||||
|
Label = "logentry"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldTimestamp holds the string denoting the timestamp field in the database.
|
||||||
|
FieldTimestamp = "timestamp"
|
||||||
|
// FieldAction holds the string denoting the action field in the database.
|
||||||
|
FieldAction = "action"
|
||||||
|
// FieldData holds the string denoting the data field in the database.
|
||||||
|
FieldData = "data"
|
||||||
|
// FieldAccountID holds the string denoting the account_id field in the database.
|
||||||
|
FieldAccountID = "account_id"
|
||||||
|
// FieldDomainID holds the string denoting the domain_id field in the database.
|
||||||
|
FieldDomainID = "domain_id"
|
||||||
|
// EdgeAccount holds the string denoting the account edge name in mutations.
|
||||||
|
EdgeAccount = "account"
|
||||||
|
// EdgeDomain holds the string denoting the domain edge name in mutations.
|
||||||
|
EdgeDomain = "domain"
|
||||||
|
// Table holds the table name of the logentry in the database.
|
||||||
|
Table = "logentries"
|
||||||
|
// AccountTable is the table that holds the account relation/edge.
|
||||||
|
AccountTable = "logentries"
|
||||||
|
// AccountInverseTable is the table name for the Account entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "account" package.
|
||||||
|
AccountInverseTable = "accounts"
|
||||||
|
// AccountColumn is the table column denoting the account relation/edge.
|
||||||
|
AccountColumn = "account_id"
|
||||||
|
// DomainTable is the table that holds the domain relation/edge.
|
||||||
|
DomainTable = "logentries"
|
||||||
|
// DomainInverseTable is the table name for the Domain entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "domain" package.
|
||||||
|
DomainInverseTable = "domains"
|
||||||
|
// DomainColumn is the table column denoting the domain relation/edge.
|
||||||
|
DomainColumn = "domain_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for logentry fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldTimestamp,
|
||||||
|
FieldAction,
|
||||||
|
FieldData,
|
||||||
|
FieldAccountID,
|
||||||
|
FieldDomainID,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 (
|
||||||
|
// DefaultTimestamp holds the default value on creation for the "timestamp" field.
|
||||||
|
DefaultTimestamp func() time.Time
|
||||||
|
)
|
653
ent/logentry/where.go
Normal file
653
ent/logentry/where.go
Normal file
@ -0,0 +1,653 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package logentry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ID filters vertices based on their ID field.
|
||||||
|
func ID(id int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDEQ applies the EQ predicate on the ID field.
|
||||||
|
func IDEQ(id int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNEQ applies the NEQ predicate on the ID field.
|
||||||
|
func IDNEQ(id int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDIn applies the In predicate on the ID field.
|
||||||
|
func IDIn(ids ...int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(ids) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v := make([]interface{}, len(ids))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = ids[i]
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDNotIn applies the NotIn predicate on the ID field.
|
||||||
|
func IDNotIn(ids ...int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(ids) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
v := make([]interface{}, len(ids))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = ids[i]
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGT applies the GT predicate on the ID field.
|
||||||
|
func IDGT(id int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDGTE applies the GTE predicate on the ID field.
|
||||||
|
func IDGTE(id int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLT applies the LT predicate on the ID field.
|
||||||
|
func IDLT(id int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDLTE applies the LTE predicate on the ID field.
|
||||||
|
func IDLTE(id int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldID), id))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Timestamp applies equality check predicate on the "timestamp" field. It's identical to TimestampEQ.
|
||||||
|
func Timestamp(v time.Time) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldTimestamp), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Action applies equality check predicate on the "action" field. It's identical to ActionEQ.
|
||||||
|
func Action(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Data applies equality check predicate on the "data" field. It's identical to DataEQ.
|
||||||
|
func Data(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountID applies equality check predicate on the "account_id" field. It's identical to AccountIDEQ.
|
||||||
|
func AccountID(v int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldAccountID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainID applies equality check predicate on the "domain_id" field. It's identical to DomainIDEQ.
|
||||||
|
func DomainID(v int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldDomainID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimestampEQ applies the EQ predicate on the "timestamp" field.
|
||||||
|
func TimestampEQ(v time.Time) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldTimestamp), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimestampNEQ applies the NEQ predicate on the "timestamp" field.
|
||||||
|
func TimestampNEQ(v time.Time) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldTimestamp), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimestampIn applies the In predicate on the "timestamp" field.
|
||||||
|
func TimestampIn(vs ...time.Time) predicate.Logentry {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldTimestamp), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimestampNotIn applies the NotIn predicate on the "timestamp" field.
|
||||||
|
func TimestampNotIn(vs ...time.Time) predicate.Logentry {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldTimestamp), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimestampGT applies the GT predicate on the "timestamp" field.
|
||||||
|
func TimestampGT(v time.Time) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldTimestamp), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimestampGTE applies the GTE predicate on the "timestamp" field.
|
||||||
|
func TimestampGTE(v time.Time) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldTimestamp), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimestampLT applies the LT predicate on the "timestamp" field.
|
||||||
|
func TimestampLT(v time.Time) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldTimestamp), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// TimestampLTE applies the LTE predicate on the "timestamp" field.
|
||||||
|
func TimestampLTE(v time.Time) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldTimestamp), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionEQ applies the EQ predicate on the "action" field.
|
||||||
|
func ActionEQ(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionNEQ applies the NEQ predicate on the "action" field.
|
||||||
|
func ActionNEQ(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionIn applies the In predicate on the "action" field.
|
||||||
|
func ActionIn(vs ...string) predicate.Logentry {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldAction), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionNotIn applies the NotIn predicate on the "action" field.
|
||||||
|
func ActionNotIn(vs ...string) predicate.Logentry {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldAction), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionGT applies the GT predicate on the "action" field.
|
||||||
|
func ActionGT(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionGTE applies the GTE predicate on the "action" field.
|
||||||
|
func ActionGTE(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionLT applies the LT predicate on the "action" field.
|
||||||
|
func ActionLT(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionLTE applies the LTE predicate on the "action" field.
|
||||||
|
func ActionLTE(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionContains applies the Contains predicate on the "action" field.
|
||||||
|
func ActionContains(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.Contains(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionHasPrefix applies the HasPrefix predicate on the "action" field.
|
||||||
|
func ActionHasPrefix(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasPrefix(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionHasSuffix applies the HasSuffix predicate on the "action" field.
|
||||||
|
func ActionHasSuffix(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasSuffix(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionEqualFold applies the EqualFold predicate on the "action" field.
|
||||||
|
func ActionEqualFold(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EqualFold(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ActionContainsFold applies the ContainsFold predicate on the "action" field.
|
||||||
|
func ActionContainsFold(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.ContainsFold(s.C(FieldAction), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataEQ applies the EQ predicate on the "data" field.
|
||||||
|
func DataEQ(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataNEQ applies the NEQ predicate on the "data" field.
|
||||||
|
func DataNEQ(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataIn applies the In predicate on the "data" field.
|
||||||
|
func DataIn(vs ...string) predicate.Logentry {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldData), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataNotIn applies the NotIn predicate on the "data" field.
|
||||||
|
func DataNotIn(vs ...string) predicate.Logentry {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldData), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataGT applies the GT predicate on the "data" field.
|
||||||
|
func DataGT(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GT(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataGTE applies the GTE predicate on the "data" field.
|
||||||
|
func DataGTE(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.GTE(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataLT applies the LT predicate on the "data" field.
|
||||||
|
func DataLT(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LT(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataLTE applies the LTE predicate on the "data" field.
|
||||||
|
func DataLTE(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.LTE(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataContains applies the Contains predicate on the "data" field.
|
||||||
|
func DataContains(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.Contains(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataHasPrefix applies the HasPrefix predicate on the "data" field.
|
||||||
|
func DataHasPrefix(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasPrefix(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataHasSuffix applies the HasSuffix predicate on the "data" field.
|
||||||
|
func DataHasSuffix(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.HasSuffix(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataIsNil applies the IsNil predicate on the "data" field.
|
||||||
|
func DataIsNil() predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.IsNull(s.C(FieldData)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataNotNil applies the NotNil predicate on the "data" field.
|
||||||
|
func DataNotNil() predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotNull(s.C(FieldData)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataEqualFold applies the EqualFold predicate on the "data" field.
|
||||||
|
func DataEqualFold(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EqualFold(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataContainsFold applies the ContainsFold predicate on the "data" field.
|
||||||
|
func DataContainsFold(v string) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.ContainsFold(s.C(FieldData), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountIDEQ applies the EQ predicate on the "account_id" field.
|
||||||
|
func AccountIDEQ(v int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldAccountID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountIDNEQ applies the NEQ predicate on the "account_id" field.
|
||||||
|
func AccountIDNEQ(v int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldAccountID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountIDIn applies the In predicate on the "account_id" field.
|
||||||
|
func AccountIDIn(vs ...int64) predicate.Logentry {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldAccountID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountIDNotIn applies the NotIn predicate on the "account_id" field.
|
||||||
|
func AccountIDNotIn(vs ...int64) predicate.Logentry {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldAccountID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountIDIsNil applies the IsNil predicate on the "account_id" field.
|
||||||
|
func AccountIDIsNil() predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.IsNull(s.C(FieldAccountID)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AccountIDNotNil applies the NotNil predicate on the "account_id" field.
|
||||||
|
func AccountIDNotNil() predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotNull(s.C(FieldAccountID)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDEQ applies the EQ predicate on the "domain_id" field.
|
||||||
|
func DomainIDEQ(v int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.EQ(s.C(FieldDomainID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDNEQ applies the NEQ predicate on the "domain_id" field.
|
||||||
|
func DomainIDNEQ(v int64) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NEQ(s.C(FieldDomainID), v))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDIn applies the In predicate on the "domain_id" field.
|
||||||
|
func DomainIDIn(vs ...int64) predicate.Logentry {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.In(s.C(FieldDomainID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDNotIn applies the NotIn predicate on the "domain_id" field.
|
||||||
|
func DomainIDNotIn(vs ...int64) predicate.Logentry {
|
||||||
|
v := make([]interface{}, len(vs))
|
||||||
|
for i := range v {
|
||||||
|
v[i] = vs[i]
|
||||||
|
}
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
// if not arguments were provided, append the FALSE constants,
|
||||||
|
// since we can't apply "IN ()". This will make this predicate falsy.
|
||||||
|
if len(v) == 0 {
|
||||||
|
s.Where(sql.False())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s.Where(sql.NotIn(s.C(FieldDomainID), v...))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDIsNil applies the IsNil predicate on the "domain_id" field.
|
||||||
|
func DomainIDIsNil() predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.IsNull(s.C(FieldDomainID)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainIDNotNil applies the NotNil predicate on the "domain_id" field.
|
||||||
|
func DomainIDNotNil() predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
s.Where(sql.NotNull(s.C(FieldDomainID)))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAccount applies the HasEdge predicate on the "account" edge.
|
||||||
|
func HasAccount() predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(AccountTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, AccountTable, AccountColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasAccountWith applies the HasEdge predicate on the "account" edge with a given conditions (other predicates).
|
||||||
|
func HasAccountWith(preds ...predicate.Account) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(AccountInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, AccountTable, AccountColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||||
|
for _, p := range preds {
|
||||||
|
p(s)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasDomain applies the HasEdge predicate on the "domain" edge.
|
||||||
|
func HasDomain() predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(DomainTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, DomainTable, DomainColumn),
|
||||||
|
)
|
||||||
|
sqlgraph.HasNeighbors(s, step)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasDomainWith applies the HasEdge predicate on the "domain" edge with a given conditions (other predicates).
|
||||||
|
func HasDomainWith(preds ...predicate.Domain) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(Table, FieldID),
|
||||||
|
sqlgraph.To(DomainInverseTable, FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, DomainTable, DomainColumn),
|
||||||
|
)
|
||||||
|
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.Logentry) predicate.Logentry {
|
||||||
|
return predicate.Logentry(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.Logentry) predicate.Logentry {
|
||||||
|
return predicate.Logentry(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.Logentry) predicate.Logentry {
|
||||||
|
return predicate.Logentry(func(s *sql.Selector) {
|
||||||
|
p(s.Not())
|
||||||
|
})
|
||||||
|
}
|
370
ent/logentry_create.go
Normal file
370
ent/logentry_create.go
Normal file
@ -0,0 +1,370 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/logentry"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LogentryCreate is the builder for creating a Logentry entity.
|
||||||
|
type LogentryCreate struct {
|
||||||
|
config
|
||||||
|
mutation *LogentryMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetTimestamp sets the "timestamp" field.
|
||||||
|
func (lc *LogentryCreate) SetTimestamp(t time.Time) *LogentryCreate {
|
||||||
|
lc.mutation.SetTimestamp(t)
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableTimestamp sets the "timestamp" field if the given value is not nil.
|
||||||
|
func (lc *LogentryCreate) SetNillableTimestamp(t *time.Time) *LogentryCreate {
|
||||||
|
if t != nil {
|
||||||
|
lc.SetTimestamp(*t)
|
||||||
|
}
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAction sets the "action" field.
|
||||||
|
func (lc *LogentryCreate) SetAction(s string) *LogentryCreate {
|
||||||
|
lc.mutation.SetAction(s)
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetData sets the "data" field.
|
||||||
|
func (lc *LogentryCreate) SetData(s string) *LogentryCreate {
|
||||||
|
lc.mutation.SetData(s)
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableData sets the "data" field if the given value is not nil.
|
||||||
|
func (lc *LogentryCreate) SetNillableData(s *string) *LogentryCreate {
|
||||||
|
if s != nil {
|
||||||
|
lc.SetData(*s)
|
||||||
|
}
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAccountID sets the "account_id" field.
|
||||||
|
func (lc *LogentryCreate) SetAccountID(i int64) *LogentryCreate {
|
||||||
|
lc.mutation.SetAccountID(i)
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
|
||||||
|
func (lc *LogentryCreate) SetNillableAccountID(i *int64) *LogentryCreate {
|
||||||
|
if i != nil {
|
||||||
|
lc.SetAccountID(*i)
|
||||||
|
}
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomainID sets the "domain_id" field.
|
||||||
|
func (lc *LogentryCreate) SetDomainID(i int64) *LogentryCreate {
|
||||||
|
lc.mutation.SetDomainID(i)
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
||||||
|
func (lc *LogentryCreate) SetNillableDomainID(i *int64) *LogentryCreate {
|
||||||
|
if i != nil {
|
||||||
|
lc.SetDomainID(*i)
|
||||||
|
}
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (lc *LogentryCreate) SetID(i int64) *LogentryCreate {
|
||||||
|
lc.mutation.SetID(i)
|
||||||
|
return lc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAccount sets the "account" edge to the Account entity.
|
||||||
|
func (lc *LogentryCreate) SetAccount(a *Account) *LogentryCreate {
|
||||||
|
return lc.SetAccountID(a.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomain sets the "domain" edge to the Domain entity.
|
||||||
|
func (lc *LogentryCreate) SetDomain(d *Domain) *LogentryCreate {
|
||||||
|
return lc.SetDomainID(d.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the LogentryMutation object of the builder.
|
||||||
|
func (lc *LogentryCreate) Mutation() *LogentryMutation {
|
||||||
|
return lc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Logentry in the database.
|
||||||
|
func (lc *LogentryCreate) Save(ctx context.Context) (*Logentry, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *Logentry
|
||||||
|
)
|
||||||
|
lc.defaults()
|
||||||
|
if len(lc.hooks) == 0 {
|
||||||
|
if err = lc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
node, err = lc.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*LogentryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err = lc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
lc.mutation = mutation
|
||||||
|
if node, err = lc.sqlSave(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &node.ID
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(lc.hooks) - 1; i >= 0; i-- {
|
||||||
|
if lc.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = lc.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, lc.mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (lc *LogentryCreate) SaveX(ctx context.Context) *Logentry {
|
||||||
|
v, err := lc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (lc *LogentryCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := lc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (lc *LogentryCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := lc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (lc *LogentryCreate) defaults() {
|
||||||
|
if _, ok := lc.mutation.Timestamp(); !ok {
|
||||||
|
v := logentry.DefaultTimestamp()
|
||||||
|
lc.mutation.SetTimestamp(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (lc *LogentryCreate) check() error {
|
||||||
|
if _, ok := lc.mutation.Timestamp(); !ok {
|
||||||
|
return &ValidationError{Name: "timestamp", err: errors.New(`ent: missing required field "Logentry.timestamp"`)}
|
||||||
|
}
|
||||||
|
if _, ok := lc.mutation.Action(); !ok {
|
||||||
|
return &ValidationError{Name: "action", err: errors.New(`ent: missing required field "Logentry.action"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lc *LogentryCreate) sqlSave(ctx context.Context) (*Logentry, error) {
|
||||||
|
_node, _spec := lc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, lc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != _node.ID {
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int64(id)
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lc *LogentryCreate) createSpec() (*Logentry, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Logentry{config: lc.config}
|
||||||
|
_spec = &sqlgraph.CreateSpec{
|
||||||
|
Table: logentry.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if id, ok := lc.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = id
|
||||||
|
}
|
||||||
|
if value, ok := lc.mutation.Timestamp(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: logentry.FieldTimestamp,
|
||||||
|
})
|
||||||
|
_node.Timestamp = value
|
||||||
|
}
|
||||||
|
if value, ok := lc.mutation.Action(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: logentry.FieldAction,
|
||||||
|
})
|
||||||
|
_node.Action = value
|
||||||
|
}
|
||||||
|
if value, ok := lc.mutation.Data(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: logentry.FieldData,
|
||||||
|
})
|
||||||
|
_node.Data = &value
|
||||||
|
}
|
||||||
|
if nodes := lc.mutation.AccountIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: logentry.AccountTable,
|
||||||
|
Columns: []string{logentry.AccountColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: account.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.AccountID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
if nodes := lc.mutation.DomainIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: logentry.DomainTable,
|
||||||
|
Columns: []string{logentry.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.DomainID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogentryCreateBulk is the builder for creating many Logentry entities in bulk.
|
||||||
|
type LogentryCreateBulk struct {
|
||||||
|
config
|
||||||
|
builders []*LogentryCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Logentry entities in the database.
|
||||||
|
func (lcb *LogentryCreateBulk) Save(ctx context.Context) ([]*Logentry, error) {
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(lcb.builders))
|
||||||
|
nodes := make([]*Logentry, len(lcb.builders))
|
||||||
|
mutators := make([]Mutator, len(lcb.builders))
|
||||||
|
for i := range lcb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := lcb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*LogentryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
var err error
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, lcb.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, lcb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
mutation.done = true
|
||||||
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int64(id)
|
||||||
|
}
|
||||||
|
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, lcb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (lcb *LogentryCreateBulk) SaveX(ctx context.Context) []*Logentry {
|
||||||
|
v, err := lcb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (lcb *LogentryCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := lcb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (lcb *LogentryCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := lcb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
111
ent/logentry_delete.go
Normal file
111
ent/logentry_delete.go
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/logentry"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LogentryDelete is the builder for deleting a Logentry entity.
|
||||||
|
type LogentryDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *LogentryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the LogentryDelete builder.
|
||||||
|
func (ld *LogentryDelete) Where(ps ...predicate.Logentry) *LogentryDelete {
|
||||||
|
ld.mutation.Where(ps...)
|
||||||
|
return ld
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (ld *LogentryDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
if len(ld.hooks) == 0 {
|
||||||
|
affected, err = ld.sqlExec(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*LogentryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
ld.mutation = mutation
|
||||||
|
affected, err = ld.sqlExec(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(ld.hooks) - 1; i >= 0; i-- {
|
||||||
|
if ld.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = ld.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, ld.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ld *LogentryDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := ld.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ld *LogentryDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := &sqlgraph.DeleteSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: logentry.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := ld.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sqlgraph.DeleteNodes(ctx, ld.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogentryDeleteOne is the builder for deleting a single Logentry entity.
|
||||||
|
type LogentryDeleteOne struct {
|
||||||
|
ld *LogentryDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (ldo *LogentryDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := ldo.ld.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{logentry.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (ldo *LogentryDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
ldo.ld.ExecX(ctx)
|
||||||
|
}
|
1052
ent/logentry_query.go
Normal file
1052
ent/logentry_query.go
Normal file
File diff suppressed because it is too large
Load Diff
597
ent/logentry_update.go
Normal file
597
ent/logentry_update.go
Normal file
@ -0,0 +1,597 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/logentry"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// LogentryUpdate is the builder for updating Logentry entities.
|
||||||
|
type LogentryUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *LogentryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the LogentryUpdate builder.
|
||||||
|
func (lu *LogentryUpdate) Where(ps ...predicate.Logentry) *LogentryUpdate {
|
||||||
|
lu.mutation.Where(ps...)
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAction sets the "action" field.
|
||||||
|
func (lu *LogentryUpdate) SetAction(s string) *LogentryUpdate {
|
||||||
|
lu.mutation.SetAction(s)
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetData sets the "data" field.
|
||||||
|
func (lu *LogentryUpdate) SetData(s string) *LogentryUpdate {
|
||||||
|
lu.mutation.SetData(s)
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableData sets the "data" field if the given value is not nil.
|
||||||
|
func (lu *LogentryUpdate) SetNillableData(s *string) *LogentryUpdate {
|
||||||
|
if s != nil {
|
||||||
|
lu.SetData(*s)
|
||||||
|
}
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearData clears the value of the "data" field.
|
||||||
|
func (lu *LogentryUpdate) ClearData() *LogentryUpdate {
|
||||||
|
lu.mutation.ClearData()
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAccountID sets the "account_id" field.
|
||||||
|
func (lu *LogentryUpdate) SetAccountID(i int64) *LogentryUpdate {
|
||||||
|
lu.mutation.SetAccountID(i)
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
|
||||||
|
func (lu *LogentryUpdate) SetNillableAccountID(i *int64) *LogentryUpdate {
|
||||||
|
if i != nil {
|
||||||
|
lu.SetAccountID(*i)
|
||||||
|
}
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAccountID clears the value of the "account_id" field.
|
||||||
|
func (lu *LogentryUpdate) ClearAccountID() *LogentryUpdate {
|
||||||
|
lu.mutation.ClearAccountID()
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomainID sets the "domain_id" field.
|
||||||
|
func (lu *LogentryUpdate) SetDomainID(i int64) *LogentryUpdate {
|
||||||
|
lu.mutation.SetDomainID(i)
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
||||||
|
func (lu *LogentryUpdate) SetNillableDomainID(i *int64) *LogentryUpdate {
|
||||||
|
if i != nil {
|
||||||
|
lu.SetDomainID(*i)
|
||||||
|
}
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomainID clears the value of the "domain_id" field.
|
||||||
|
func (lu *LogentryUpdate) ClearDomainID() *LogentryUpdate {
|
||||||
|
lu.mutation.ClearDomainID()
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAccount sets the "account" edge to the Account entity.
|
||||||
|
func (lu *LogentryUpdate) SetAccount(a *Account) *LogentryUpdate {
|
||||||
|
return lu.SetAccountID(a.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomain sets the "domain" edge to the Domain entity.
|
||||||
|
func (lu *LogentryUpdate) SetDomain(d *Domain) *LogentryUpdate {
|
||||||
|
return lu.SetDomainID(d.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the LogentryMutation object of the builder.
|
||||||
|
func (lu *LogentryUpdate) Mutation() *LogentryMutation {
|
||||||
|
return lu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAccount clears the "account" edge to the Account entity.
|
||||||
|
func (lu *LogentryUpdate) ClearAccount() *LogentryUpdate {
|
||||||
|
lu.mutation.ClearAccount()
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomain clears the "domain" edge to the Domain entity.
|
||||||
|
func (lu *LogentryUpdate) ClearDomain() *LogentryUpdate {
|
||||||
|
lu.mutation.ClearDomain()
|
||||||
|
return lu
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (lu *LogentryUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
if len(lu.hooks) == 0 {
|
||||||
|
affected, err = lu.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*LogentryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
lu.mutation = mutation
|
||||||
|
affected, err = lu.sqlSave(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(lu.hooks) - 1; i >= 0; i-- {
|
||||||
|
if lu.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = lu.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, lu.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (lu *LogentryUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := lu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (lu *LogentryUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := lu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (lu *LogentryUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := lu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lu *LogentryUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
_spec := &sqlgraph.UpdateSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: logentry.Table,
|
||||||
|
Columns: logentry.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := lu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := lu.mutation.Action(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: logentry.FieldAction,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := lu.mutation.Data(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: logentry.FieldData,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if lu.mutation.DataCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Column: logentry.FieldData,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if lu.mutation.AccountCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: logentry.AccountTable,
|
||||||
|
Columns: []string{logentry.AccountColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: account.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := lu.mutation.AccountIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: logentry.AccountTable,
|
||||||
|
Columns: []string{logentry.AccountColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: account.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if lu.mutation.DomainCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: logentry.DomainTable,
|
||||||
|
Columns: []string{logentry.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := lu.mutation.DomainIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: logentry.DomainTable,
|
||||||
|
Columns: []string{logentry.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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, lu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{logentry.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogentryUpdateOne is the builder for updating a single Logentry entity.
|
||||||
|
type LogentryUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *LogentryMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAction sets the "action" field.
|
||||||
|
func (luo *LogentryUpdateOne) SetAction(s string) *LogentryUpdateOne {
|
||||||
|
luo.mutation.SetAction(s)
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetData sets the "data" field.
|
||||||
|
func (luo *LogentryUpdateOne) SetData(s string) *LogentryUpdateOne {
|
||||||
|
luo.mutation.SetData(s)
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableData sets the "data" field if the given value is not nil.
|
||||||
|
func (luo *LogentryUpdateOne) SetNillableData(s *string) *LogentryUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
luo.SetData(*s)
|
||||||
|
}
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearData clears the value of the "data" field.
|
||||||
|
func (luo *LogentryUpdateOne) ClearData() *LogentryUpdateOne {
|
||||||
|
luo.mutation.ClearData()
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAccountID sets the "account_id" field.
|
||||||
|
func (luo *LogentryUpdateOne) SetAccountID(i int64) *LogentryUpdateOne {
|
||||||
|
luo.mutation.SetAccountID(i)
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableAccountID sets the "account_id" field if the given value is not nil.
|
||||||
|
func (luo *LogentryUpdateOne) SetNillableAccountID(i *int64) *LogentryUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
luo.SetAccountID(*i)
|
||||||
|
}
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAccountID clears the value of the "account_id" field.
|
||||||
|
func (luo *LogentryUpdateOne) ClearAccountID() *LogentryUpdateOne {
|
||||||
|
luo.mutation.ClearAccountID()
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomainID sets the "domain_id" field.
|
||||||
|
func (luo *LogentryUpdateOne) SetDomainID(i int64) *LogentryUpdateOne {
|
||||||
|
luo.mutation.SetDomainID(i)
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
||||||
|
func (luo *LogentryUpdateOne) SetNillableDomainID(i *int64) *LogentryUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
luo.SetDomainID(*i)
|
||||||
|
}
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomainID clears the value of the "domain_id" field.
|
||||||
|
func (luo *LogentryUpdateOne) ClearDomainID() *LogentryUpdateOne {
|
||||||
|
luo.mutation.ClearDomainID()
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAccount sets the "account" edge to the Account entity.
|
||||||
|
func (luo *LogentryUpdateOne) SetAccount(a *Account) *LogentryUpdateOne {
|
||||||
|
return luo.SetAccountID(a.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomain sets the "domain" edge to the Domain entity.
|
||||||
|
func (luo *LogentryUpdateOne) SetDomain(d *Domain) *LogentryUpdateOne {
|
||||||
|
return luo.SetDomainID(d.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the LogentryMutation object of the builder.
|
||||||
|
func (luo *LogentryUpdateOne) Mutation() *LogentryMutation {
|
||||||
|
return luo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearAccount clears the "account" edge to the Account entity.
|
||||||
|
func (luo *LogentryUpdateOne) ClearAccount() *LogentryUpdateOne {
|
||||||
|
luo.mutation.ClearAccount()
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomain clears the "domain" edge to the Domain entity.
|
||||||
|
func (luo *LogentryUpdateOne) ClearDomain() *LogentryUpdateOne {
|
||||||
|
luo.mutation.ClearDomain()
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (luo *LogentryUpdateOne) Select(field string, fields ...string) *LogentryUpdateOne {
|
||||||
|
luo.fields = append([]string{field}, fields...)
|
||||||
|
return luo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Logentry entity.
|
||||||
|
func (luo *LogentryUpdateOne) Save(ctx context.Context) (*Logentry, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *Logentry
|
||||||
|
)
|
||||||
|
if len(luo.hooks) == 0 {
|
||||||
|
node, err = luo.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*LogentryMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
luo.mutation = mutation
|
||||||
|
node, err = luo.sqlSave(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(luo.hooks) - 1; i >= 0; i-- {
|
||||||
|
if luo.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = luo.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, luo.mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (luo *LogentryUpdateOne) SaveX(ctx context.Context) *Logentry {
|
||||||
|
node, err := luo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (luo *LogentryUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := luo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (luo *LogentryUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := luo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (luo *LogentryUpdateOne) sqlSave(ctx context.Context) (_node *Logentry, err error) {
|
||||||
|
_spec := &sqlgraph.UpdateSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: logentry.Table,
|
||||||
|
Columns: logentry.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: logentry.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
id, ok := luo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Logentry.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := luo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, logentry.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !logentry.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != logentry.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := luo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := luo.mutation.Action(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: logentry.FieldAction,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := luo.mutation.Data(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: logentry.FieldData,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if luo.mutation.DataCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Column: logentry.FieldData,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if luo.mutation.AccountCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: logentry.AccountTable,
|
||||||
|
Columns: []string{logentry.AccountColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: account.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := luo.mutation.AccountIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: logentry.AccountTable,
|
||||||
|
Columns: []string{logentry.AccountColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: account.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
if luo.mutation.DomainCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: logentry.DomainTable,
|
||||||
|
Columns: []string{logentry.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := luo.mutation.DomainIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: logentry.DomainTable,
|
||||||
|
Columns: []string{logentry.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &Logentry{config: luo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, luo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{logentry.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
276
ent/mailbox.go
Normal file
276
ent/mailbox.go
Normal file
@ -0,0 +1,276 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/mailbox"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Mailbox is the model entity for the Mailbox schema.
|
||||||
|
type Mailbox struct {
|
||||||
|
config `json:"-"`
|
||||||
|
// ID of the ent.
|
||||||
|
ID int64 `json:"id,omitempty"`
|
||||||
|
// Active holds the value of the "active" field.
|
||||||
|
Active bool `json:"active,omitempty"`
|
||||||
|
// Created holds the value of the "created" field.
|
||||||
|
Created time.Time `json:"created,omitempty"`
|
||||||
|
// Modified holds the value of the "modified" field.
|
||||||
|
Modified *time.Time `json:"modified,omitempty"`
|
||||||
|
// DomainID holds the value of the "domain_id" field.
|
||||||
|
DomainID int64 `json:"domain_id,omitempty"`
|
||||||
|
// Username holds the value of the "username" field.
|
||||||
|
Username string `json:"username,omitempty"`
|
||||||
|
// Password holds the value of the "password" field.
|
||||||
|
Password []byte `json:"password,omitempty"`
|
||||||
|
// Name holds the value of the "name" field.
|
||||||
|
Name *string `json:"name,omitempty"`
|
||||||
|
// Quota holds the value of the "quota" field.
|
||||||
|
Quota int64 `json:"quota,omitempty"`
|
||||||
|
// LocalPart holds the value of the "local_part" field.
|
||||||
|
LocalPart string `json:"local_part,omitempty"`
|
||||||
|
// Homedir holds the value of the "homedir" field.
|
||||||
|
Homedir *string `json:"homedir,omitempty"`
|
||||||
|
// Maildir holds the value of the "maildir" field.
|
||||||
|
Maildir *string `json:"maildir,omitempty"`
|
||||||
|
// UID holds the value of the "uid" field.
|
||||||
|
UID *int32 `json:"uid,omitempty"`
|
||||||
|
// Gid holds the value of the "gid" field.
|
||||||
|
Gid *int32 `json:"gid,omitempty"`
|
||||||
|
// Edges holds the relations/edges for other nodes in the graph.
|
||||||
|
// The values are being populated by the MailboxQuery when eager-loading is set.
|
||||||
|
Edges MailboxEdges `json:"edges"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MailboxEdges holds the relations/edges for other nodes in the graph.
|
||||||
|
type MailboxEdges struct {
|
||||||
|
// Domain holds the value of the domain edge.
|
||||||
|
Domain *Domain `json:"domain,omitempty"`
|
||||||
|
// loadedTypes holds the information for reporting if a
|
||||||
|
// type was loaded (or requested) in eager-loading or not.
|
||||||
|
loadedTypes [1]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// DomainOrErr returns the Domain value or an error if the edge
|
||||||
|
// was not loaded in eager-loading, or loaded but was not found.
|
||||||
|
func (e MailboxEdges) DomainOrErr() (*Domain, error) {
|
||||||
|
if e.loadedTypes[0] {
|
||||||
|
if e.Domain == nil {
|
||||||
|
// The edge domain was loaded in eager-loading,
|
||||||
|
// but was not found.
|
||||||
|
return nil, &NotFoundError{label: domain.Label}
|
||||||
|
}
|
||||||
|
return e.Domain, nil
|
||||||
|
}
|
||||||
|
return nil, &NotLoadedError{edge: "domain"}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scanValues returns the types for scanning values from sql.Rows.
|
||||||
|
func (*Mailbox) scanValues(columns []string) ([]interface{}, error) {
|
||||||
|
values := make([]interface{}, len(columns))
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case mailbox.FieldPassword:
|
||||||
|
values[i] = new([]byte)
|
||||||
|
case mailbox.FieldActive:
|
||||||
|
values[i] = new(sql.NullBool)
|
||||||
|
case mailbox.FieldID, mailbox.FieldDomainID, mailbox.FieldQuota, mailbox.FieldUID, mailbox.FieldGid:
|
||||||
|
values[i] = new(sql.NullInt64)
|
||||||
|
case mailbox.FieldUsername, mailbox.FieldName, mailbox.FieldLocalPart, mailbox.FieldHomedir, mailbox.FieldMaildir:
|
||||||
|
values[i] = new(sql.NullString)
|
||||||
|
case mailbox.FieldCreated, mailbox.FieldModified:
|
||||||
|
values[i] = new(sql.NullTime)
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unexpected column %q for type Mailbox", columns[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return values, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||||
|
// to the Mailbox fields.
|
||||||
|
func (m *Mailbox) assignValues(columns []string, values []interface{}) error {
|
||||||
|
if m, n := len(values), len(columns); m < n {
|
||||||
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||||
|
}
|
||||||
|
for i := range columns {
|
||||||
|
switch columns[i] {
|
||||||
|
case mailbox.FieldID:
|
||||||
|
value, ok := values[i].(*sql.NullInt64)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field id", value)
|
||||||
|
}
|
||||||
|
m.ID = int64(value.Int64)
|
||||||
|
case mailbox.FieldActive:
|
||||||
|
if value, ok := values[i].(*sql.NullBool); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field active", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.Active = value.Bool
|
||||||
|
}
|
||||||
|
case mailbox.FieldCreated:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field created", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.Created = value.Time
|
||||||
|
}
|
||||||
|
case mailbox.FieldModified:
|
||||||
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field modified", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.Modified = new(time.Time)
|
||||||
|
*m.Modified = value.Time
|
||||||
|
}
|
||||||
|
case mailbox.FieldDomainID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field domain_id", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.DomainID = value.Int64
|
||||||
|
}
|
||||||
|
case mailbox.FieldUsername:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field username", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.Username = value.String
|
||||||
|
}
|
||||||
|
case mailbox.FieldPassword:
|
||||||
|
if value, ok := values[i].(*[]byte); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field password", values[i])
|
||||||
|
} else if value != nil {
|
||||||
|
m.Password = *value
|
||||||
|
}
|
||||||
|
case mailbox.FieldName:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field name", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.Name = new(string)
|
||||||
|
*m.Name = value.String
|
||||||
|
}
|
||||||
|
case mailbox.FieldQuota:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field quota", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.Quota = value.Int64
|
||||||
|
}
|
||||||
|
case mailbox.FieldLocalPart:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field local_part", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.LocalPart = value.String
|
||||||
|
}
|
||||||
|
case mailbox.FieldHomedir:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field homedir", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.Homedir = new(string)
|
||||||
|
*m.Homedir = value.String
|
||||||
|
}
|
||||||
|
case mailbox.FieldMaildir:
|
||||||
|
if value, ok := values[i].(*sql.NullString); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field maildir", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.Maildir = new(string)
|
||||||
|
*m.Maildir = value.String
|
||||||
|
}
|
||||||
|
case mailbox.FieldUID:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field uid", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.UID = new(int32)
|
||||||
|
*m.UID = int32(value.Int64)
|
||||||
|
}
|
||||||
|
case mailbox.FieldGid:
|
||||||
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||||
|
return fmt.Errorf("unexpected type %T for field gid", values[i])
|
||||||
|
} else if value.Valid {
|
||||||
|
m.Gid = new(int32)
|
||||||
|
*m.Gid = int32(value.Int64)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryDomain queries the "domain" edge of the Mailbox entity.
|
||||||
|
func (m *Mailbox) QueryDomain() *DomainQuery {
|
||||||
|
return (&MailboxClient{config: m.config}).QueryDomain(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update returns a builder for updating this Mailbox.
|
||||||
|
// Note that you need to call Mailbox.Unwrap() before calling this method if this Mailbox
|
||||||
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||||
|
func (m *Mailbox) Update() *MailboxUpdateOne {
|
||||||
|
return (&MailboxClient{config: m.config}).UpdateOne(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwrap unwraps the Mailbox 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 (m *Mailbox) Unwrap() *Mailbox {
|
||||||
|
tx, ok := m.config.driver.(*txDriver)
|
||||||
|
if !ok {
|
||||||
|
panic("ent: Mailbox is not a transactional entity")
|
||||||
|
}
|
||||||
|
m.config.driver = tx.drv
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the fmt.Stringer.
|
||||||
|
func (m *Mailbox) String() string {
|
||||||
|
var builder strings.Builder
|
||||||
|
builder.WriteString("Mailbox(")
|
||||||
|
builder.WriteString(fmt.Sprintf("id=%v", m.ID))
|
||||||
|
builder.WriteString(", active=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", m.Active))
|
||||||
|
builder.WriteString(", created=")
|
||||||
|
builder.WriteString(m.Created.Format(time.ANSIC))
|
||||||
|
if v := m.Modified; v != nil {
|
||||||
|
builder.WriteString(", modified=")
|
||||||
|
builder.WriteString(v.Format(time.ANSIC))
|
||||||
|
}
|
||||||
|
builder.WriteString(", domain_id=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", m.DomainID))
|
||||||
|
builder.WriteString(", username=")
|
||||||
|
builder.WriteString(m.Username)
|
||||||
|
builder.WriteString(", password=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", m.Password))
|
||||||
|
if v := m.Name; v != nil {
|
||||||
|
builder.WriteString(", name=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
builder.WriteString(", quota=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", m.Quota))
|
||||||
|
builder.WriteString(", local_part=")
|
||||||
|
builder.WriteString(m.LocalPart)
|
||||||
|
if v := m.Homedir; v != nil {
|
||||||
|
builder.WriteString(", homedir=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
if v := m.Maildir; v != nil {
|
||||||
|
builder.WriteString(", maildir=")
|
||||||
|
builder.WriteString(*v)
|
||||||
|
}
|
||||||
|
if v := m.UID; v != nil {
|
||||||
|
builder.WriteString(", uid=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||||
|
}
|
||||||
|
if v := m.Gid; v != nil {
|
||||||
|
builder.WriteString(", gid=")
|
||||||
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
||||||
|
}
|
||||||
|
builder.WriteByte(')')
|
||||||
|
return builder.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mailboxes is a parsable slice of Mailbox.
|
||||||
|
type Mailboxes []*Mailbox
|
||||||
|
|
||||||
|
func (m Mailboxes) config(cfg config) {
|
||||||
|
for _i := range m {
|
||||||
|
m[_i].config = cfg
|
||||||
|
}
|
||||||
|
}
|
88
ent/mailbox/mailbox.go
Normal file
88
ent/mailbox/mailbox.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package mailbox
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Label holds the string label denoting the mailbox type in the database.
|
||||||
|
Label = "mailbox"
|
||||||
|
// FieldID holds the string denoting the id field in the database.
|
||||||
|
FieldID = "id"
|
||||||
|
// FieldActive holds the string denoting the active field in the database.
|
||||||
|
FieldActive = "active"
|
||||||
|
// FieldCreated holds the string denoting the created field in the database.
|
||||||
|
FieldCreated = "created"
|
||||||
|
// FieldModified holds the string denoting the modified field in the database.
|
||||||
|
FieldModified = "modified"
|
||||||
|
// FieldDomainID holds the string denoting the domain_id field in the database.
|
||||||
|
FieldDomainID = "domain_id"
|
||||||
|
// FieldUsername holds the string denoting the username field in the database.
|
||||||
|
FieldUsername = "username"
|
||||||
|
// FieldPassword holds the string denoting the password field in the database.
|
||||||
|
FieldPassword = "password"
|
||||||
|
// FieldName holds the string denoting the name field in the database.
|
||||||
|
FieldName = "name"
|
||||||
|
// FieldQuota holds the string denoting the quota field in the database.
|
||||||
|
FieldQuota = "quota"
|
||||||
|
// FieldLocalPart holds the string denoting the local_part field in the database.
|
||||||
|
FieldLocalPart = "local_part"
|
||||||
|
// FieldHomedir holds the string denoting the homedir field in the database.
|
||||||
|
FieldHomedir = "homedir"
|
||||||
|
// FieldMaildir holds the string denoting the maildir field in the database.
|
||||||
|
FieldMaildir = "maildir"
|
||||||
|
// FieldUID holds the string denoting the uid field in the database.
|
||||||
|
FieldUID = "uid"
|
||||||
|
// FieldGid holds the string denoting the gid field in the database.
|
||||||
|
FieldGid = "gid"
|
||||||
|
// EdgeDomain holds the string denoting the domain edge name in mutations.
|
||||||
|
EdgeDomain = "domain"
|
||||||
|
// Table holds the table name of the mailbox in the database.
|
||||||
|
Table = "mailboxes"
|
||||||
|
// DomainTable is the table that holds the domain relation/edge.
|
||||||
|
DomainTable = "mailboxes"
|
||||||
|
// DomainInverseTable is the table name for the Domain entity.
|
||||||
|
// It exists in this package in order to avoid circular dependency with the "domain" package.
|
||||||
|
DomainInverseTable = "domains"
|
||||||
|
// DomainColumn is the table column denoting the domain relation/edge.
|
||||||
|
DomainColumn = "domain_id"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Columns holds all SQL columns for mailbox fields.
|
||||||
|
var Columns = []string{
|
||||||
|
FieldID,
|
||||||
|
FieldActive,
|
||||||
|
FieldCreated,
|
||||||
|
FieldModified,
|
||||||
|
FieldDomainID,
|
||||||
|
FieldUsername,
|
||||||
|
FieldPassword,
|
||||||
|
FieldName,
|
||||||
|
FieldQuota,
|
||||||
|
FieldLocalPart,
|
||||||
|
FieldHomedir,
|
||||||
|
FieldMaildir,
|
||||||
|
FieldUID,
|
||||||
|
FieldGid,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 (
|
||||||
|
// DefaultCreated holds the default value on creation for the "created" field.
|
||||||
|
DefaultCreated func() time.Time
|
||||||
|
// DefaultModified holds the default value on creation for the "modified" field.
|
||||||
|
DefaultModified func() time.Time
|
||||||
|
// UpdateDefaultModified holds the default value on update for the "modified" field.
|
||||||
|
UpdateDefaultModified func() time.Time
|
||||||
|
)
|
1416
ent/mailbox/where.go
Normal file
1416
ent/mailbox/where.go
Normal file
File diff suppressed because it is too large
Load Diff
512
ent/mailbox_create.go
Normal file
512
ent/mailbox_create.go
Normal file
@ -0,0 +1,512 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/mailbox"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MailboxCreate is the builder for creating a Mailbox entity.
|
||||||
|
type MailboxCreate struct {
|
||||||
|
config
|
||||||
|
mutation *MailboxMutation
|
||||||
|
hooks []Hook
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActive sets the "active" field.
|
||||||
|
func (mc *MailboxCreate) SetActive(b bool) *MailboxCreate {
|
||||||
|
mc.mutation.SetActive(b)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetCreated sets the "created" field.
|
||||||
|
func (mc *MailboxCreate) SetCreated(t time.Time) *MailboxCreate {
|
||||||
|
mc.mutation.SetCreated(t)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableCreated sets the "created" field if the given value is not nil.
|
||||||
|
func (mc *MailboxCreate) SetNillableCreated(t *time.Time) *MailboxCreate {
|
||||||
|
if t != nil {
|
||||||
|
mc.SetCreated(*t)
|
||||||
|
}
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModified sets the "modified" field.
|
||||||
|
func (mc *MailboxCreate) SetModified(t time.Time) *MailboxCreate {
|
||||||
|
mc.mutation.SetModified(t)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableModified sets the "modified" field if the given value is not nil.
|
||||||
|
func (mc *MailboxCreate) SetNillableModified(t *time.Time) *MailboxCreate {
|
||||||
|
if t != nil {
|
||||||
|
mc.SetModified(*t)
|
||||||
|
}
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomainID sets the "domain_id" field.
|
||||||
|
func (mc *MailboxCreate) SetDomainID(i int64) *MailboxCreate {
|
||||||
|
mc.mutation.SetDomainID(i)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
||||||
|
func (mc *MailboxCreate) SetNillableDomainID(i *int64) *MailboxCreate {
|
||||||
|
if i != nil {
|
||||||
|
mc.SetDomainID(*i)
|
||||||
|
}
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUsername sets the "username" field.
|
||||||
|
func (mc *MailboxCreate) SetUsername(s string) *MailboxCreate {
|
||||||
|
mc.mutation.SetUsername(s)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPassword sets the "password" field.
|
||||||
|
func (mc *MailboxCreate) SetPassword(b []byte) *MailboxCreate {
|
||||||
|
mc.mutation.SetPassword(b)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (mc *MailboxCreate) SetName(s string) *MailboxCreate {
|
||||||
|
mc.mutation.SetName(s)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (mc *MailboxCreate) SetNillableName(s *string) *MailboxCreate {
|
||||||
|
if s != nil {
|
||||||
|
mc.SetName(*s)
|
||||||
|
}
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetQuota sets the "quota" field.
|
||||||
|
func (mc *MailboxCreate) SetQuota(i int64) *MailboxCreate {
|
||||||
|
mc.mutation.SetQuota(i)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLocalPart sets the "local_part" field.
|
||||||
|
func (mc *MailboxCreate) SetLocalPart(s string) *MailboxCreate {
|
||||||
|
mc.mutation.SetLocalPart(s)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHomedir sets the "homedir" field.
|
||||||
|
func (mc *MailboxCreate) SetHomedir(s string) *MailboxCreate {
|
||||||
|
mc.mutation.SetHomedir(s)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableHomedir sets the "homedir" field if the given value is not nil.
|
||||||
|
func (mc *MailboxCreate) SetNillableHomedir(s *string) *MailboxCreate {
|
||||||
|
if s != nil {
|
||||||
|
mc.SetHomedir(*s)
|
||||||
|
}
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaildir sets the "maildir" field.
|
||||||
|
func (mc *MailboxCreate) SetMaildir(s string) *MailboxCreate {
|
||||||
|
mc.mutation.SetMaildir(s)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableMaildir sets the "maildir" field if the given value is not nil.
|
||||||
|
func (mc *MailboxCreate) SetNillableMaildir(s *string) *MailboxCreate {
|
||||||
|
if s != nil {
|
||||||
|
mc.SetMaildir(*s)
|
||||||
|
}
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUID sets the "uid" field.
|
||||||
|
func (mc *MailboxCreate) SetUID(i int32) *MailboxCreate {
|
||||||
|
mc.mutation.SetUID(i)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUID sets the "uid" field if the given value is not nil.
|
||||||
|
func (mc *MailboxCreate) SetNillableUID(i *int32) *MailboxCreate {
|
||||||
|
if i != nil {
|
||||||
|
mc.SetUID(*i)
|
||||||
|
}
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGid sets the "gid" field.
|
||||||
|
func (mc *MailboxCreate) SetGid(i int32) *MailboxCreate {
|
||||||
|
mc.mutation.SetGid(i)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableGid sets the "gid" field if the given value is not nil.
|
||||||
|
func (mc *MailboxCreate) SetNillableGid(i *int32) *MailboxCreate {
|
||||||
|
if i != nil {
|
||||||
|
mc.SetGid(*i)
|
||||||
|
}
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetID sets the "id" field.
|
||||||
|
func (mc *MailboxCreate) SetID(i int64) *MailboxCreate {
|
||||||
|
mc.mutation.SetID(i)
|
||||||
|
return mc
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomain sets the "domain" edge to the Domain entity.
|
||||||
|
func (mc *MailboxCreate) SetDomain(d *Domain) *MailboxCreate {
|
||||||
|
return mc.SetDomainID(d.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the MailboxMutation object of the builder.
|
||||||
|
func (mc *MailboxCreate) Mutation() *MailboxMutation {
|
||||||
|
return mc.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Mailbox in the database.
|
||||||
|
func (mc *MailboxCreate) Save(ctx context.Context) (*Mailbox, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *Mailbox
|
||||||
|
)
|
||||||
|
mc.defaults()
|
||||||
|
if len(mc.hooks) == 0 {
|
||||||
|
if err = mc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
node, err = mc.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*MailboxMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err = mc.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mc.mutation = mutation
|
||||||
|
if node, err = mc.sqlSave(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &node.ID
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(mc.hooks) - 1; i >= 0; i-- {
|
||||||
|
if mc.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = mc.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, mc.mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX calls Save and panics if Save returns an error.
|
||||||
|
func (mc *MailboxCreate) SaveX(ctx context.Context) *Mailbox {
|
||||||
|
v, err := mc.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (mc *MailboxCreate) Exec(ctx context.Context) error {
|
||||||
|
_, err := mc.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (mc *MailboxCreate) ExecX(ctx context.Context) {
|
||||||
|
if err := mc.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (mc *MailboxCreate) defaults() {
|
||||||
|
if _, ok := mc.mutation.Created(); !ok {
|
||||||
|
v := mailbox.DefaultCreated()
|
||||||
|
mc.mutation.SetCreated(v)
|
||||||
|
}
|
||||||
|
if _, ok := mc.mutation.Modified(); !ok {
|
||||||
|
v := mailbox.DefaultModified()
|
||||||
|
mc.mutation.SetModified(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check runs all checks and user-defined validators on the builder.
|
||||||
|
func (mc *MailboxCreate) check() error {
|
||||||
|
if _, ok := mc.mutation.Active(); !ok {
|
||||||
|
return &ValidationError{Name: "active", err: errors.New(`ent: missing required field "Mailbox.active"`)}
|
||||||
|
}
|
||||||
|
if _, ok := mc.mutation.Created(); !ok {
|
||||||
|
return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "Mailbox.created"`)}
|
||||||
|
}
|
||||||
|
if _, ok := mc.mutation.Username(); !ok {
|
||||||
|
return &ValidationError{Name: "username", err: errors.New(`ent: missing required field "Mailbox.username"`)}
|
||||||
|
}
|
||||||
|
if _, ok := mc.mutation.Password(); !ok {
|
||||||
|
return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Mailbox.password"`)}
|
||||||
|
}
|
||||||
|
if _, ok := mc.mutation.Quota(); !ok {
|
||||||
|
return &ValidationError{Name: "quota", err: errors.New(`ent: missing required field "Mailbox.quota"`)}
|
||||||
|
}
|
||||||
|
if _, ok := mc.mutation.LocalPart(); !ok {
|
||||||
|
return &ValidationError{Name: "local_part", err: errors.New(`ent: missing required field "Mailbox.local_part"`)}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mc *MailboxCreate) sqlSave(ctx context.Context) (*Mailbox, error) {
|
||||||
|
_node, _spec := mc.createSpec()
|
||||||
|
if err := sqlgraph.CreateNode(ctx, mc.driver, _spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _spec.ID.Value != _node.ID {
|
||||||
|
id := _spec.ID.Value.(int64)
|
||||||
|
_node.ID = int64(id)
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mc *MailboxCreate) createSpec() (*Mailbox, *sqlgraph.CreateSpec) {
|
||||||
|
var (
|
||||||
|
_node = &Mailbox{config: mc.config}
|
||||||
|
_spec = &sqlgraph.CreateSpec{
|
||||||
|
Table: mailbox.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: mailbox.FieldID,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if id, ok := mc.mutation.ID(); ok {
|
||||||
|
_node.ID = id
|
||||||
|
_spec.ID.Value = id
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.Active(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldActive,
|
||||||
|
})
|
||||||
|
_node.Active = value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.Created(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldCreated,
|
||||||
|
})
|
||||||
|
_node.Created = value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.Modified(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldModified,
|
||||||
|
})
|
||||||
|
_node.Modified = &value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.Username(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldUsername,
|
||||||
|
})
|
||||||
|
_node.Username = value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.Password(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBytes,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldPassword,
|
||||||
|
})
|
||||||
|
_node.Password = value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.Name(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldName,
|
||||||
|
})
|
||||||
|
_node.Name = &value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.Quota(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldQuota,
|
||||||
|
})
|
||||||
|
_node.Quota = value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.LocalPart(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldLocalPart,
|
||||||
|
})
|
||||||
|
_node.LocalPart = value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.Homedir(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldHomedir,
|
||||||
|
})
|
||||||
|
_node.Homedir = &value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.Maildir(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldMaildir,
|
||||||
|
})
|
||||||
|
_node.Maildir = &value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.UID(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldUID,
|
||||||
|
})
|
||||||
|
_node.UID = &value
|
||||||
|
}
|
||||||
|
if value, ok := mc.mutation.Gid(); ok {
|
||||||
|
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldGid,
|
||||||
|
})
|
||||||
|
_node.Gid = &value
|
||||||
|
}
|
||||||
|
if nodes := mc.mutation.DomainIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: mailbox.DomainTable,
|
||||||
|
Columns: []string{mailbox.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_node.DomainID = nodes[0]
|
||||||
|
_spec.Edges = append(_spec.Edges, edge)
|
||||||
|
}
|
||||||
|
return _node, _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
// MailboxCreateBulk is the builder for creating many Mailbox entities in bulk.
|
||||||
|
type MailboxCreateBulk struct {
|
||||||
|
config
|
||||||
|
builders []*MailboxCreate
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save creates the Mailbox entities in the database.
|
||||||
|
func (mcb *MailboxCreateBulk) Save(ctx context.Context) ([]*Mailbox, error) {
|
||||||
|
specs := make([]*sqlgraph.CreateSpec, len(mcb.builders))
|
||||||
|
nodes := make([]*Mailbox, len(mcb.builders))
|
||||||
|
mutators := make([]Mutator, len(mcb.builders))
|
||||||
|
for i := range mcb.builders {
|
||||||
|
func(i int, root context.Context) {
|
||||||
|
builder := mcb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*MailboxMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
if err := builder.check(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
builder.mutation = mutation
|
||||||
|
nodes[i], specs[i] = builder.createSpec()
|
||||||
|
var err error
|
||||||
|
if i < len(mutators)-1 {
|
||||||
|
_, err = mutators[i+1].Mutate(root, mcb.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, mcb.driver, spec); err != nil {
|
||||||
|
if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
mutation.id = &nodes[i].ID
|
||||||
|
mutation.done = true
|
||||||
|
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||||
|
id := specs[i].ID.Value.(int64)
|
||||||
|
nodes[i].ID = int64(id)
|
||||||
|
}
|
||||||
|
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, mcb.builders[0].mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (mcb *MailboxCreateBulk) SaveX(ctx context.Context) []*Mailbox {
|
||||||
|
v, err := mcb.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (mcb *MailboxCreateBulk) Exec(ctx context.Context) error {
|
||||||
|
_, err := mcb.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (mcb *MailboxCreateBulk) ExecX(ctx context.Context) {
|
||||||
|
if err := mcb.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
111
ent/mailbox_delete.go
Normal file
111
ent/mailbox_delete.go
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/mailbox"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MailboxDelete is the builder for deleting a Mailbox entity.
|
||||||
|
type MailboxDelete struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *MailboxMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the MailboxDelete builder.
|
||||||
|
func (md *MailboxDelete) Where(ps ...predicate.Mailbox) *MailboxDelete {
|
||||||
|
md.mutation.Where(ps...)
|
||||||
|
return md
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||||
|
func (md *MailboxDelete) Exec(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
if len(md.hooks) == 0 {
|
||||||
|
affected, err = md.sqlExec(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*MailboxMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
md.mutation = mutation
|
||||||
|
affected, err = md.sqlExec(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(md.hooks) - 1; i >= 0; i-- {
|
||||||
|
if md.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = md.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, md.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (md *MailboxDelete) ExecX(ctx context.Context) int {
|
||||||
|
n, err := md.Exec(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (md *MailboxDelete) sqlExec(ctx context.Context) (int, error) {
|
||||||
|
_spec := &sqlgraph.DeleteSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: mailbox.Table,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: mailbox.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := md.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sqlgraph.DeleteNodes(ctx, md.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MailboxDeleteOne is the builder for deleting a single Mailbox entity.
|
||||||
|
type MailboxDeleteOne struct {
|
||||||
|
md *MailboxDelete
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the deletion query.
|
||||||
|
func (mdo *MailboxDeleteOne) Exec(ctx context.Context) error {
|
||||||
|
n, err := mdo.md.Exec(ctx)
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
return err
|
||||||
|
case n == 0:
|
||||||
|
return &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (mdo *MailboxDeleteOne) ExecX(ctx context.Context) {
|
||||||
|
mdo.md.ExecX(ctx)
|
||||||
|
}
|
989
ent/mailbox_query.go
Normal file
989
ent/mailbox_query.go
Normal file
@ -0,0 +1,989 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/mailbox"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MailboxQuery is the builder for querying Mailbox entities.
|
||||||
|
type MailboxQuery struct {
|
||||||
|
config
|
||||||
|
limit *int
|
||||||
|
offset *int
|
||||||
|
unique *bool
|
||||||
|
order []OrderFunc
|
||||||
|
fields []string
|
||||||
|
predicates []predicate.Mailbox
|
||||||
|
// eager-loading edges.
|
||||||
|
withDomain *DomainQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where adds a new predicate for the MailboxQuery builder.
|
||||||
|
func (mq *MailboxQuery) Where(ps ...predicate.Mailbox) *MailboxQuery {
|
||||||
|
mq.predicates = append(mq.predicates, ps...)
|
||||||
|
return mq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limit adds a limit step to the query.
|
||||||
|
func (mq *MailboxQuery) Limit(limit int) *MailboxQuery {
|
||||||
|
mq.limit = &limit
|
||||||
|
return mq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Offset adds an offset step to the query.
|
||||||
|
func (mq *MailboxQuery) Offset(offset int) *MailboxQuery {
|
||||||
|
mq.offset = &offset
|
||||||
|
return mq
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 (mq *MailboxQuery) Unique(unique bool) *MailboxQuery {
|
||||||
|
mq.unique = &unique
|
||||||
|
return mq
|
||||||
|
}
|
||||||
|
|
||||||
|
// Order adds an order step to the query.
|
||||||
|
func (mq *MailboxQuery) Order(o ...OrderFunc) *MailboxQuery {
|
||||||
|
mq.order = append(mq.order, o...)
|
||||||
|
return mq
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryDomain chains the current query on the "domain" edge.
|
||||||
|
func (mq *MailboxQuery) QueryDomain() *DomainQuery {
|
||||||
|
query := &DomainQuery{config: mq.config}
|
||||||
|
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||||
|
if err := mq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selector := mq.sqlQuery(ctx)
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
step := sqlgraph.NewStep(
|
||||||
|
sqlgraph.From(mailbox.Table, mailbox.FieldID, selector),
|
||||||
|
sqlgraph.To(domain.Table, domain.FieldID),
|
||||||
|
sqlgraph.Edge(sqlgraph.M2O, true, mailbox.DomainTable, mailbox.DomainColumn),
|
||||||
|
)
|
||||||
|
fromU = sqlgraph.SetNeighbors(mq.driver.Dialect(), step)
|
||||||
|
return fromU, nil
|
||||||
|
}
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// First returns the first Mailbox entity from the query.
|
||||||
|
// Returns a *NotFoundError when no Mailbox was found.
|
||||||
|
func (mq *MailboxQuery) First(ctx context.Context) (*Mailbox, error) {
|
||||||
|
nodes, err := mq.Limit(1).All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nil, &NotFoundError{mailbox.Label}
|
||||||
|
}
|
||||||
|
return nodes[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstX is like First, but panics if an error occurs.
|
||||||
|
func (mq *MailboxQuery) FirstX(ctx context.Context) *Mailbox {
|
||||||
|
node, err := mq.First(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstID returns the first Mailbox ID from the query.
|
||||||
|
// Returns a *NotFoundError when no Mailbox ID was found.
|
||||||
|
func (mq *MailboxQuery) FirstID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = mq.Limit(1).IDs(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(ids) == 0 {
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return ids[0], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||||
|
func (mq *MailboxQuery) FirstIDX(ctx context.Context) int64 {
|
||||||
|
id, err := mq.FirstID(ctx)
|
||||||
|
if err != nil && !IsNotFound(err) {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only returns a single Mailbox entity found by the query, ensuring it only returns one.
|
||||||
|
// Returns a *NotSingularError when more than one Mailbox entity is found.
|
||||||
|
// Returns a *NotFoundError when no Mailbox entities are found.
|
||||||
|
func (mq *MailboxQuery) Only(ctx context.Context) (*Mailbox, error) {
|
||||||
|
nodes, err := mq.Limit(2).All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
switch len(nodes) {
|
||||||
|
case 1:
|
||||||
|
return nodes[0], nil
|
||||||
|
case 0:
|
||||||
|
return nil, &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
return nil, &NotSingularError{mailbox.Label}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyX is like Only, but panics if an error occurs.
|
||||||
|
func (mq *MailboxQuery) OnlyX(ctx context.Context) *Mailbox {
|
||||||
|
node, err := mq.Only(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyID is like Only, but returns the only Mailbox ID in the query.
|
||||||
|
// Returns a *NotSingularError when more than one Mailbox ID is found.
|
||||||
|
// Returns a *NotFoundError when no entities are found.
|
||||||
|
func (mq *MailboxQuery) OnlyID(ctx context.Context) (id int64, err error) {
|
||||||
|
var ids []int64
|
||||||
|
if ids, err = mq.Limit(2).IDs(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(ids) {
|
||||||
|
case 1:
|
||||||
|
id = ids[0]
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
err = &NotSingularError{mailbox.Label}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||||
|
func (mq *MailboxQuery) OnlyIDX(ctx context.Context) int64 {
|
||||||
|
id, err := mq.OnlyID(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return id
|
||||||
|
}
|
||||||
|
|
||||||
|
// All executes the query and returns a list of Mailboxes.
|
||||||
|
func (mq *MailboxQuery) All(ctx context.Context) ([]*Mailbox, error) {
|
||||||
|
if err := mq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return mq.sqlAll(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AllX is like All, but panics if an error occurs.
|
||||||
|
func (mq *MailboxQuery) AllX(ctx context.Context) []*Mailbox {
|
||||||
|
nodes, err := mq.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return nodes
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDs executes the query and returns a list of Mailbox IDs.
|
||||||
|
func (mq *MailboxQuery) IDs(ctx context.Context) ([]int64, error) {
|
||||||
|
var ids []int64
|
||||||
|
if err := mq.Select(mailbox.FieldID).Scan(ctx, &ids); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ids, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDsX is like IDs, but panics if an error occurs.
|
||||||
|
func (mq *MailboxQuery) IDsX(ctx context.Context) []int64 {
|
||||||
|
ids, err := mq.IDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
// Count returns the count of the given query.
|
||||||
|
func (mq *MailboxQuery) Count(ctx context.Context) (int, error) {
|
||||||
|
if err := mq.prepareQuery(ctx); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return mq.sqlCount(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CountX is like Count, but panics if an error occurs.
|
||||||
|
func (mq *MailboxQuery) CountX(ctx context.Context) int {
|
||||||
|
count, err := mq.Count(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exist returns true if the query has elements in the graph.
|
||||||
|
func (mq *MailboxQuery) Exist(ctx context.Context) (bool, error) {
|
||||||
|
if err := mq.prepareQuery(ctx); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return mq.sqlExist(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistX is like Exist, but panics if an error occurs.
|
||||||
|
func (mq *MailboxQuery) ExistX(ctx context.Context) bool {
|
||||||
|
exist, err := mq.Exist(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return exist
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clone returns a duplicate of the MailboxQuery builder, including all associated steps. It can be
|
||||||
|
// used to prepare common query builders and use them differently after the clone is made.
|
||||||
|
func (mq *MailboxQuery) Clone() *MailboxQuery {
|
||||||
|
if mq == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return &MailboxQuery{
|
||||||
|
config: mq.config,
|
||||||
|
limit: mq.limit,
|
||||||
|
offset: mq.offset,
|
||||||
|
order: append([]OrderFunc{}, mq.order...),
|
||||||
|
predicates: append([]predicate.Mailbox{}, mq.predicates...),
|
||||||
|
withDomain: mq.withDomain.Clone(),
|
||||||
|
// clone intermediate query.
|
||||||
|
sql: mq.sql.Clone(),
|
||||||
|
path: mq.path,
|
||||||
|
unique: mq.unique,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithDomain tells the query-builder to eager-load the nodes that are connected to
|
||||||
|
// the "domain" edge. The optional arguments are used to configure the query builder of the edge.
|
||||||
|
func (mq *MailboxQuery) WithDomain(opts ...func(*DomainQuery)) *MailboxQuery {
|
||||||
|
query := &DomainQuery{config: mq.config}
|
||||||
|
for _, opt := range opts {
|
||||||
|
opt(query)
|
||||||
|
}
|
||||||
|
mq.withDomain = query
|
||||||
|
return mq
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// Active bool `json:"active,omitempty"`
|
||||||
|
// Count int `json:"count,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Mailbox.Query().
|
||||||
|
// GroupBy(mailbox.FieldActive).
|
||||||
|
// Aggregate(ent.Count()).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
//
|
||||||
|
func (mq *MailboxQuery) GroupBy(field string, fields ...string) *MailboxGroupBy {
|
||||||
|
group := &MailboxGroupBy{config: mq.config}
|
||||||
|
group.fields = append([]string{field}, fields...)
|
||||||
|
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||||
|
if err := mq.prepareQuery(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return mq.sqlQuery(ctx), nil
|
||||||
|
}
|
||||||
|
return group
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 {
|
||||||
|
// Active bool `json:"active,omitempty"`
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// client.Mailbox.Query().
|
||||||
|
// Select(mailbox.FieldActive).
|
||||||
|
// Scan(ctx, &v)
|
||||||
|
//
|
||||||
|
func (mq *MailboxQuery) Select(fields ...string) *MailboxSelect {
|
||||||
|
mq.fields = append(mq.fields, fields...)
|
||||||
|
return &MailboxSelect{MailboxQuery: mq}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mq *MailboxQuery) prepareQuery(ctx context.Context) error {
|
||||||
|
for _, f := range mq.fields {
|
||||||
|
if !mailbox.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if mq.path != nil {
|
||||||
|
prev, err := mq.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
mq.sql = prev
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mq *MailboxQuery) sqlAll(ctx context.Context) ([]*Mailbox, error) {
|
||||||
|
var (
|
||||||
|
nodes = []*Mailbox{}
|
||||||
|
_spec = mq.querySpec()
|
||||||
|
loadedTypes = [1]bool{
|
||||||
|
mq.withDomain != nil,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
|
||||||
|
node := &Mailbox{config: mq.config}
|
||||||
|
nodes = append(nodes, node)
|
||||||
|
return node.scanValues(columns)
|
||||||
|
}
|
||||||
|
_spec.Assign = func(columns []string, values []interface{}) error {
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||||
|
}
|
||||||
|
node := nodes[len(nodes)-1]
|
||||||
|
node.Edges.loadedTypes = loadedTypes
|
||||||
|
return node.assignValues(columns, values)
|
||||||
|
}
|
||||||
|
if err := sqlgraph.QueryNodes(ctx, mq.driver, _spec); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(nodes) == 0 {
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if query := mq.withDomain; query != nil {
|
||||||
|
ids := make([]int64, 0, len(nodes))
|
||||||
|
nodeids := make(map[int64][]*Mailbox)
|
||||||
|
for i := range nodes {
|
||||||
|
fk := nodes[i].DomainID
|
||||||
|
if _, ok := nodeids[fk]; !ok {
|
||||||
|
ids = append(ids, fk)
|
||||||
|
}
|
||||||
|
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||||
|
}
|
||||||
|
query.Where(domain.IDIn(ids...))
|
||||||
|
neighbors, err := query.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, n := range neighbors {
|
||||||
|
nodes, ok := nodeids[n.ID]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf(`unexpected foreign-key "domain_id" returned %v`, n.ID)
|
||||||
|
}
|
||||||
|
for i := range nodes {
|
||||||
|
nodes[i].Edges.Domain = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nodes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mq *MailboxQuery) sqlCount(ctx context.Context) (int, error) {
|
||||||
|
_spec := mq.querySpec()
|
||||||
|
_spec.Node.Columns = mq.fields
|
||||||
|
if len(mq.fields) > 0 {
|
||||||
|
_spec.Unique = mq.unique != nil && *mq.unique
|
||||||
|
}
|
||||||
|
return sqlgraph.CountNodes(ctx, mq.driver, _spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mq *MailboxQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||||
|
n, err := mq.sqlCount(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||||
|
}
|
||||||
|
return n > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mq *MailboxQuery) querySpec() *sqlgraph.QuerySpec {
|
||||||
|
_spec := &sqlgraph.QuerySpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: mailbox.Table,
|
||||||
|
Columns: mailbox.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: mailbox.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
From: mq.sql,
|
||||||
|
Unique: true,
|
||||||
|
}
|
||||||
|
if unique := mq.unique; unique != nil {
|
||||||
|
_spec.Unique = *unique
|
||||||
|
}
|
||||||
|
if fields := mq.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, mailbox.FieldID)
|
||||||
|
for i := range fields {
|
||||||
|
if fields[i] != mailbox.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := mq.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if limit := mq.limit; limit != nil {
|
||||||
|
_spec.Limit = *limit
|
||||||
|
}
|
||||||
|
if offset := mq.offset; offset != nil {
|
||||||
|
_spec.Offset = *offset
|
||||||
|
}
|
||||||
|
if ps := mq.order; len(ps) > 0 {
|
||||||
|
_spec.Order = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _spec
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mq *MailboxQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||||
|
builder := sql.Dialect(mq.driver.Dialect())
|
||||||
|
t1 := builder.Table(mailbox.Table)
|
||||||
|
columns := mq.fields
|
||||||
|
if len(columns) == 0 {
|
||||||
|
columns = mailbox.Columns
|
||||||
|
}
|
||||||
|
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||||
|
if mq.sql != nil {
|
||||||
|
selector = mq.sql
|
||||||
|
selector.Select(selector.Columns(columns...)...)
|
||||||
|
}
|
||||||
|
if mq.unique != nil && *mq.unique {
|
||||||
|
selector.Distinct()
|
||||||
|
}
|
||||||
|
for _, p := range mq.predicates {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
for _, p := range mq.order {
|
||||||
|
p(selector)
|
||||||
|
}
|
||||||
|
if offset := mq.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 := mq.limit; limit != nil {
|
||||||
|
selector.Limit(*limit)
|
||||||
|
}
|
||||||
|
return selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// MailboxGroupBy is the group-by builder for Mailbox entities.
|
||||||
|
type MailboxGroupBy struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
fns []AggregateFunc
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
path func(context.Context) (*sql.Selector, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aggregate adds the given aggregation functions to the group-by query.
|
||||||
|
func (mgb *MailboxGroupBy) Aggregate(fns ...AggregateFunc) *MailboxGroupBy {
|
||||||
|
mgb.fns = append(mgb.fns, fns...)
|
||||||
|
return mgb
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the group-by query and scans the result into the given value.
|
||||||
|
func (mgb *MailboxGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||||
|
query, err := mgb.path(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
mgb.sql = query
|
||||||
|
return mgb.sqlScan(ctx, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanX is like Scan, but panics if an error occurs.
|
||||||
|
func (mgb *MailboxGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||||
|
if err := mgb.Scan(ctx, v); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings returns list of strings from group-by.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (mgb *MailboxGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||||
|
if len(mgb.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: MailboxGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||||
|
}
|
||||||
|
var v []string
|
||||||
|
if err := mgb.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringsX is like Strings, but panics if an error occurs.
|
||||||
|
func (mgb *MailboxGroupBy) StringsX(ctx context.Context) []string {
|
||||||
|
v, err := mgb.Strings(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a single string from a group-by query.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (mgb *MailboxGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||||
|
var v []string
|
||||||
|
if v, err = mgb.Strings(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: MailboxGroupBy.Strings returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringX is like String, but panics if an error occurs.
|
||||||
|
func (mgb *MailboxGroupBy) StringX(ctx context.Context) string {
|
||||||
|
v, err := mgb.String(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ints returns list of ints from group-by.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (mgb *MailboxGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||||
|
if len(mgb.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: MailboxGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||||
|
}
|
||||||
|
var v []int
|
||||||
|
if err := mgb.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntsX is like Ints, but panics if an error occurs.
|
||||||
|
func (mgb *MailboxGroupBy) IntsX(ctx context.Context) []int {
|
||||||
|
v, err := mgb.Ints(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int returns a single int from a group-by query.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (mgb *MailboxGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||||
|
var v []int
|
||||||
|
if v, err = mgb.Ints(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: MailboxGroupBy.Ints returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntX is like Int, but panics if an error occurs.
|
||||||
|
func (mgb *MailboxGroupBy) IntX(ctx context.Context) int {
|
||||||
|
v, err := mgb.Int(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64s returns list of float64s from group-by.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (mgb *MailboxGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||||
|
if len(mgb.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: MailboxGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||||
|
}
|
||||||
|
var v []float64
|
||||||
|
if err := mgb.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64sX is like Float64s, but panics if an error occurs.
|
||||||
|
func (mgb *MailboxGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||||
|
v, err := mgb.Float64s(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns a single float64 from a group-by query.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (mgb *MailboxGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||||
|
var v []float64
|
||||||
|
if v, err = mgb.Float64s(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: MailboxGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64X is like Float64, but panics if an error occurs.
|
||||||
|
func (mgb *MailboxGroupBy) Float64X(ctx context.Context) float64 {
|
||||||
|
v, err := mgb.Float64(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bools returns list of bools from group-by.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (mgb *MailboxGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||||
|
if len(mgb.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: MailboxGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||||
|
}
|
||||||
|
var v []bool
|
||||||
|
if err := mgb.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolsX is like Bools, but panics if an error occurs.
|
||||||
|
func (mgb *MailboxGroupBy) BoolsX(ctx context.Context) []bool {
|
||||||
|
v, err := mgb.Bools(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns a single bool from a group-by query.
|
||||||
|
// It is only allowed when executing a group-by query with one field.
|
||||||
|
func (mgb *MailboxGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||||
|
var v []bool
|
||||||
|
if v, err = mgb.Bools(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: MailboxGroupBy.Bools returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolX is like Bool, but panics if an error occurs.
|
||||||
|
func (mgb *MailboxGroupBy) BoolX(ctx context.Context) bool {
|
||||||
|
v, err := mgb.Bool(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mgb *MailboxGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||||
|
for _, f := range mgb.fields {
|
||||||
|
if !mailbox.ValidColumn(f) {
|
||||||
|
return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selector := mgb.sqlQuery()
|
||||||
|
if err := selector.Err(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := selector.Query()
|
||||||
|
if err := mgb.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mgb *MailboxGroupBy) sqlQuery() *sql.Selector {
|
||||||
|
selector := mgb.sql.Select()
|
||||||
|
aggregation := make([]string, 0, len(mgb.fns))
|
||||||
|
for _, fn := range mgb.fns {
|
||||||
|
aggregation = append(aggregation, fn(selector))
|
||||||
|
}
|
||||||
|
// If no columns were selected in a custom aggregation function, the default
|
||||||
|
// selection is the fields used for "group-by", and the aggregation functions.
|
||||||
|
if len(selector.SelectedColumns()) == 0 {
|
||||||
|
columns := make([]string, 0, len(mgb.fields)+len(mgb.fns))
|
||||||
|
for _, f := range mgb.fields {
|
||||||
|
columns = append(columns, selector.C(f))
|
||||||
|
}
|
||||||
|
columns = append(columns, aggregation...)
|
||||||
|
selector.Select(columns...)
|
||||||
|
}
|
||||||
|
return selector.GroupBy(selector.Columns(mgb.fields...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MailboxSelect is the builder for selecting fields of Mailbox entities.
|
||||||
|
type MailboxSelect struct {
|
||||||
|
*MailboxQuery
|
||||||
|
// intermediate query (i.e. traversal path).
|
||||||
|
sql *sql.Selector
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan applies the selector query and scans the result into the given value.
|
||||||
|
func (ms *MailboxSelect) Scan(ctx context.Context, v interface{}) error {
|
||||||
|
if err := ms.prepareQuery(ctx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ms.sql = ms.MailboxQuery.sqlQuery(ctx)
|
||||||
|
return ms.sqlScan(ctx, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScanX is like Scan, but panics if an error occurs.
|
||||||
|
func (ms *MailboxSelect) ScanX(ctx context.Context, v interface{}) {
|
||||||
|
if err := ms.Scan(ctx, v); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||||
|
func (ms *MailboxSelect) Strings(ctx context.Context) ([]string, error) {
|
||||||
|
if len(ms.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: MailboxSelect.Strings is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []string
|
||||||
|
if err := ms.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringsX is like Strings, but panics if an error occurs.
|
||||||
|
func (ms *MailboxSelect) StringsX(ctx context.Context) []string {
|
||||||
|
v, err := ms.Strings(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// String returns a single string from a selector. It is only allowed when selecting one field.
|
||||||
|
func (ms *MailboxSelect) String(ctx context.Context) (_ string, err error) {
|
||||||
|
var v []string
|
||||||
|
if v, err = ms.Strings(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: MailboxSelect.Strings returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// StringX is like String, but panics if an error occurs.
|
||||||
|
func (ms *MailboxSelect) StringX(ctx context.Context) string {
|
||||||
|
v, err := ms.String(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
|
||||||
|
func (ms *MailboxSelect) Ints(ctx context.Context) ([]int, error) {
|
||||||
|
if len(ms.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: MailboxSelect.Ints is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []int
|
||||||
|
if err := ms.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntsX is like Ints, but panics if an error occurs.
|
||||||
|
func (ms *MailboxSelect) IntsX(ctx context.Context) []int {
|
||||||
|
v, err := ms.Ints(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Int returns a single int from a selector. It is only allowed when selecting one field.
|
||||||
|
func (ms *MailboxSelect) Int(ctx context.Context) (_ int, err error) {
|
||||||
|
var v []int
|
||||||
|
if v, err = ms.Ints(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: MailboxSelect.Ints returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// IntX is like Int, but panics if an error occurs.
|
||||||
|
func (ms *MailboxSelect) IntX(ctx context.Context) int {
|
||||||
|
v, err := ms.Int(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
|
||||||
|
func (ms *MailboxSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||||
|
if len(ms.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: MailboxSelect.Float64s is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []float64
|
||||||
|
if err := ms.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64sX is like Float64s, but panics if an error occurs.
|
||||||
|
func (ms *MailboxSelect) Float64sX(ctx context.Context) []float64 {
|
||||||
|
v, err := ms.Float64s(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
|
||||||
|
func (ms *MailboxSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||||
|
var v []float64
|
||||||
|
if v, err = ms.Float64s(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: MailboxSelect.Float64s returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Float64X is like Float64, but panics if an error occurs.
|
||||||
|
func (ms *MailboxSelect) Float64X(ctx context.Context) float64 {
|
||||||
|
v, err := ms.Float64(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
|
||||||
|
func (ms *MailboxSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||||
|
if len(ms.fields) > 1 {
|
||||||
|
return nil, errors.New("ent: MailboxSelect.Bools is not achievable when selecting more than 1 field")
|
||||||
|
}
|
||||||
|
var v []bool
|
||||||
|
if err := ms.Scan(ctx, &v); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolsX is like Bools, but panics if an error occurs.
|
||||||
|
func (ms *MailboxSelect) BoolsX(ctx context.Context) []bool {
|
||||||
|
v, err := ms.Bools(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
|
||||||
|
func (ms *MailboxSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||||
|
var v []bool
|
||||||
|
if v, err = ms.Bools(ctx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
switch len(v) {
|
||||||
|
case 1:
|
||||||
|
return v[0], nil
|
||||||
|
case 0:
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
default:
|
||||||
|
err = fmt.Errorf("ent: MailboxSelect.Bools returned %d results when one was expected", len(v))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// BoolX is like Bool, but panics if an error occurs.
|
||||||
|
func (ms *MailboxSelect) BoolX(ctx context.Context) bool {
|
||||||
|
v, err := ms.Bool(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ms *MailboxSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||||
|
rows := &sql.Rows{}
|
||||||
|
query, args := ms.sql.Query()
|
||||||
|
if err := ms.driver.Query(ctx, query, args, rows); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
return sql.ScanSlice(rows, v)
|
||||||
|
}
|
985
ent/mailbox_update.go
Normal file
985
ent/mailbox_update.go
Normal file
@ -0,0 +1,985 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/mailbox"
|
||||||
|
"code.icod.de/postfix/manager/ent/predicate"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MailboxUpdate is the builder for updating Mailbox entities.
|
||||||
|
type MailboxUpdate struct {
|
||||||
|
config
|
||||||
|
hooks []Hook
|
||||||
|
mutation *MailboxMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// Where appends a list predicates to the MailboxUpdate builder.
|
||||||
|
func (mu *MailboxUpdate) Where(ps ...predicate.Mailbox) *MailboxUpdate {
|
||||||
|
mu.mutation.Where(ps...)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActive sets the "active" field.
|
||||||
|
func (mu *MailboxUpdate) SetActive(b bool) *MailboxUpdate {
|
||||||
|
mu.mutation.SetActive(b)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModified sets the "modified" field.
|
||||||
|
func (mu *MailboxUpdate) SetModified(t time.Time) *MailboxUpdate {
|
||||||
|
mu.mutation.SetModified(t)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearModified clears the value of the "modified" field.
|
||||||
|
func (mu *MailboxUpdate) ClearModified() *MailboxUpdate {
|
||||||
|
mu.mutation.ClearModified()
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomainID sets the "domain_id" field.
|
||||||
|
func (mu *MailboxUpdate) SetDomainID(i int64) *MailboxUpdate {
|
||||||
|
mu.mutation.SetDomainID(i)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
||||||
|
func (mu *MailboxUpdate) SetNillableDomainID(i *int64) *MailboxUpdate {
|
||||||
|
if i != nil {
|
||||||
|
mu.SetDomainID(*i)
|
||||||
|
}
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomainID clears the value of the "domain_id" field.
|
||||||
|
func (mu *MailboxUpdate) ClearDomainID() *MailboxUpdate {
|
||||||
|
mu.mutation.ClearDomainID()
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUsername sets the "username" field.
|
||||||
|
func (mu *MailboxUpdate) SetUsername(s string) *MailboxUpdate {
|
||||||
|
mu.mutation.SetUsername(s)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPassword sets the "password" field.
|
||||||
|
func (mu *MailboxUpdate) SetPassword(b []byte) *MailboxUpdate {
|
||||||
|
mu.mutation.SetPassword(b)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (mu *MailboxUpdate) SetName(s string) *MailboxUpdate {
|
||||||
|
mu.mutation.SetName(s)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (mu *MailboxUpdate) SetNillableName(s *string) *MailboxUpdate {
|
||||||
|
if s != nil {
|
||||||
|
mu.SetName(*s)
|
||||||
|
}
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearName clears the value of the "name" field.
|
||||||
|
func (mu *MailboxUpdate) ClearName() *MailboxUpdate {
|
||||||
|
mu.mutation.ClearName()
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetQuota sets the "quota" field.
|
||||||
|
func (mu *MailboxUpdate) SetQuota(i int64) *MailboxUpdate {
|
||||||
|
mu.mutation.ResetQuota()
|
||||||
|
mu.mutation.SetQuota(i)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddQuota adds i to the "quota" field.
|
||||||
|
func (mu *MailboxUpdate) AddQuota(i int64) *MailboxUpdate {
|
||||||
|
mu.mutation.AddQuota(i)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLocalPart sets the "local_part" field.
|
||||||
|
func (mu *MailboxUpdate) SetLocalPart(s string) *MailboxUpdate {
|
||||||
|
mu.mutation.SetLocalPart(s)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHomedir sets the "homedir" field.
|
||||||
|
func (mu *MailboxUpdate) SetHomedir(s string) *MailboxUpdate {
|
||||||
|
mu.mutation.SetHomedir(s)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableHomedir sets the "homedir" field if the given value is not nil.
|
||||||
|
func (mu *MailboxUpdate) SetNillableHomedir(s *string) *MailboxUpdate {
|
||||||
|
if s != nil {
|
||||||
|
mu.SetHomedir(*s)
|
||||||
|
}
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearHomedir clears the value of the "homedir" field.
|
||||||
|
func (mu *MailboxUpdate) ClearHomedir() *MailboxUpdate {
|
||||||
|
mu.mutation.ClearHomedir()
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaildir sets the "maildir" field.
|
||||||
|
func (mu *MailboxUpdate) SetMaildir(s string) *MailboxUpdate {
|
||||||
|
mu.mutation.SetMaildir(s)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableMaildir sets the "maildir" field if the given value is not nil.
|
||||||
|
func (mu *MailboxUpdate) SetNillableMaildir(s *string) *MailboxUpdate {
|
||||||
|
if s != nil {
|
||||||
|
mu.SetMaildir(*s)
|
||||||
|
}
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearMaildir clears the value of the "maildir" field.
|
||||||
|
func (mu *MailboxUpdate) ClearMaildir() *MailboxUpdate {
|
||||||
|
mu.mutation.ClearMaildir()
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUID sets the "uid" field.
|
||||||
|
func (mu *MailboxUpdate) SetUID(i int32) *MailboxUpdate {
|
||||||
|
mu.mutation.ResetUID()
|
||||||
|
mu.mutation.SetUID(i)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUID sets the "uid" field if the given value is not nil.
|
||||||
|
func (mu *MailboxUpdate) SetNillableUID(i *int32) *MailboxUpdate {
|
||||||
|
if i != nil {
|
||||||
|
mu.SetUID(*i)
|
||||||
|
}
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddUID adds i to the "uid" field.
|
||||||
|
func (mu *MailboxUpdate) AddUID(i int32) *MailboxUpdate {
|
||||||
|
mu.mutation.AddUID(i)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUID clears the value of the "uid" field.
|
||||||
|
func (mu *MailboxUpdate) ClearUID() *MailboxUpdate {
|
||||||
|
mu.mutation.ClearUID()
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGid sets the "gid" field.
|
||||||
|
func (mu *MailboxUpdate) SetGid(i int32) *MailboxUpdate {
|
||||||
|
mu.mutation.ResetGid()
|
||||||
|
mu.mutation.SetGid(i)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableGid sets the "gid" field if the given value is not nil.
|
||||||
|
func (mu *MailboxUpdate) SetNillableGid(i *int32) *MailboxUpdate {
|
||||||
|
if i != nil {
|
||||||
|
mu.SetGid(*i)
|
||||||
|
}
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddGid adds i to the "gid" field.
|
||||||
|
func (mu *MailboxUpdate) AddGid(i int32) *MailboxUpdate {
|
||||||
|
mu.mutation.AddGid(i)
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearGid clears the value of the "gid" field.
|
||||||
|
func (mu *MailboxUpdate) ClearGid() *MailboxUpdate {
|
||||||
|
mu.mutation.ClearGid()
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomain sets the "domain" edge to the Domain entity.
|
||||||
|
func (mu *MailboxUpdate) SetDomain(d *Domain) *MailboxUpdate {
|
||||||
|
return mu.SetDomainID(d.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the MailboxMutation object of the builder.
|
||||||
|
func (mu *MailboxUpdate) Mutation() *MailboxMutation {
|
||||||
|
return mu.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomain clears the "domain" edge to the Domain entity.
|
||||||
|
func (mu *MailboxUpdate) ClearDomain() *MailboxUpdate {
|
||||||
|
mu.mutation.ClearDomain()
|
||||||
|
return mu
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||||
|
func (mu *MailboxUpdate) Save(ctx context.Context) (int, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
affected int
|
||||||
|
)
|
||||||
|
mu.defaults()
|
||||||
|
if len(mu.hooks) == 0 {
|
||||||
|
affected, err = mu.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*MailboxMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
mu.mutation = mutation
|
||||||
|
affected, err = mu.sqlSave(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return affected, err
|
||||||
|
})
|
||||||
|
for i := len(mu.hooks) - 1; i >= 0; i-- {
|
||||||
|
if mu.hooks[i] == nil {
|
||||||
|
return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = mu.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, mu.mutation); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return affected, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (mu *MailboxUpdate) SaveX(ctx context.Context) int {
|
||||||
|
affected, err := mu.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return affected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query.
|
||||||
|
func (mu *MailboxUpdate) Exec(ctx context.Context) error {
|
||||||
|
_, err := mu.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (mu *MailboxUpdate) ExecX(ctx context.Context) {
|
||||||
|
if err := mu.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (mu *MailboxUpdate) defaults() {
|
||||||
|
if _, ok := mu.mutation.Modified(); !ok && !mu.mutation.ModifiedCleared() {
|
||||||
|
v := mailbox.UpdateDefaultModified()
|
||||||
|
mu.mutation.SetModified(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (mu *MailboxUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||||
|
_spec := &sqlgraph.UpdateSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: mailbox.Table,
|
||||||
|
Columns: mailbox.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: mailbox.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if ps := mu.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.Active(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldActive,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.Modified(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if mu.mutation.ModifiedCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Column: mailbox.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.Username(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldUsername,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.Password(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBytes,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldPassword,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.Name(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if mu.mutation.NameCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Column: mailbox.FieldName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.Quota(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldQuota,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.AddedQuota(); ok {
|
||||||
|
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldQuota,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.LocalPart(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldLocalPart,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.Homedir(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldHomedir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if mu.mutation.HomedirCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Column: mailbox.FieldHomedir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.Maildir(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldMaildir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if mu.mutation.MaildirCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Column: mailbox.FieldMaildir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.UID(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldUID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.AddedUID(); ok {
|
||||||
|
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldUID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if mu.mutation.UIDCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Column: mailbox.FieldUID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.Gid(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldGid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := mu.mutation.AddedGid(); ok {
|
||||||
|
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldGid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if mu.mutation.GidCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Column: mailbox.FieldGid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if mu.mutation.DomainCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: mailbox.DomainTable,
|
||||||
|
Columns: []string{mailbox.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := mu.mutation.DomainIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: mailbox.DomainTable,
|
||||||
|
Columns: []string{mailbox.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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, mu.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
return n, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MailboxUpdateOne is the builder for updating a single Mailbox entity.
|
||||||
|
type MailboxUpdateOne struct {
|
||||||
|
config
|
||||||
|
fields []string
|
||||||
|
hooks []Hook
|
||||||
|
mutation *MailboxMutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetActive sets the "active" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetActive(b bool) *MailboxUpdateOne {
|
||||||
|
muo.mutation.SetActive(b)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetModified sets the "modified" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetModified(t time.Time) *MailboxUpdateOne {
|
||||||
|
muo.mutation.SetModified(t)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearModified clears the value of the "modified" field.
|
||||||
|
func (muo *MailboxUpdateOne) ClearModified() *MailboxUpdateOne {
|
||||||
|
muo.mutation.ClearModified()
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomainID sets the "domain_id" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetDomainID(i int64) *MailboxUpdateOne {
|
||||||
|
muo.mutation.SetDomainID(i)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableDomainID sets the "domain_id" field if the given value is not nil.
|
||||||
|
func (muo *MailboxUpdateOne) SetNillableDomainID(i *int64) *MailboxUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
muo.SetDomainID(*i)
|
||||||
|
}
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomainID clears the value of the "domain_id" field.
|
||||||
|
func (muo *MailboxUpdateOne) ClearDomainID() *MailboxUpdateOne {
|
||||||
|
muo.mutation.ClearDomainID()
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUsername sets the "username" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetUsername(s string) *MailboxUpdateOne {
|
||||||
|
muo.mutation.SetUsername(s)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetPassword sets the "password" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetPassword(b []byte) *MailboxUpdateOne {
|
||||||
|
muo.mutation.SetPassword(b)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetName sets the "name" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetName(s string) *MailboxUpdateOne {
|
||||||
|
muo.mutation.SetName(s)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableName sets the "name" field if the given value is not nil.
|
||||||
|
func (muo *MailboxUpdateOne) SetNillableName(s *string) *MailboxUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
muo.SetName(*s)
|
||||||
|
}
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearName clears the value of the "name" field.
|
||||||
|
func (muo *MailboxUpdateOne) ClearName() *MailboxUpdateOne {
|
||||||
|
muo.mutation.ClearName()
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetQuota sets the "quota" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetQuota(i int64) *MailboxUpdateOne {
|
||||||
|
muo.mutation.ResetQuota()
|
||||||
|
muo.mutation.SetQuota(i)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddQuota adds i to the "quota" field.
|
||||||
|
func (muo *MailboxUpdateOne) AddQuota(i int64) *MailboxUpdateOne {
|
||||||
|
muo.mutation.AddQuota(i)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLocalPart sets the "local_part" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetLocalPart(s string) *MailboxUpdateOne {
|
||||||
|
muo.mutation.SetLocalPart(s)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHomedir sets the "homedir" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetHomedir(s string) *MailboxUpdateOne {
|
||||||
|
muo.mutation.SetHomedir(s)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableHomedir sets the "homedir" field if the given value is not nil.
|
||||||
|
func (muo *MailboxUpdateOne) SetNillableHomedir(s *string) *MailboxUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
muo.SetHomedir(*s)
|
||||||
|
}
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearHomedir clears the value of the "homedir" field.
|
||||||
|
func (muo *MailboxUpdateOne) ClearHomedir() *MailboxUpdateOne {
|
||||||
|
muo.mutation.ClearHomedir()
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetMaildir sets the "maildir" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetMaildir(s string) *MailboxUpdateOne {
|
||||||
|
muo.mutation.SetMaildir(s)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableMaildir sets the "maildir" field if the given value is not nil.
|
||||||
|
func (muo *MailboxUpdateOne) SetNillableMaildir(s *string) *MailboxUpdateOne {
|
||||||
|
if s != nil {
|
||||||
|
muo.SetMaildir(*s)
|
||||||
|
}
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearMaildir clears the value of the "maildir" field.
|
||||||
|
func (muo *MailboxUpdateOne) ClearMaildir() *MailboxUpdateOne {
|
||||||
|
muo.mutation.ClearMaildir()
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUID sets the "uid" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetUID(i int32) *MailboxUpdateOne {
|
||||||
|
muo.mutation.ResetUID()
|
||||||
|
muo.mutation.SetUID(i)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableUID sets the "uid" field if the given value is not nil.
|
||||||
|
func (muo *MailboxUpdateOne) SetNillableUID(i *int32) *MailboxUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
muo.SetUID(*i)
|
||||||
|
}
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddUID adds i to the "uid" field.
|
||||||
|
func (muo *MailboxUpdateOne) AddUID(i int32) *MailboxUpdateOne {
|
||||||
|
muo.mutation.AddUID(i)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearUID clears the value of the "uid" field.
|
||||||
|
func (muo *MailboxUpdateOne) ClearUID() *MailboxUpdateOne {
|
||||||
|
muo.mutation.ClearUID()
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetGid sets the "gid" field.
|
||||||
|
func (muo *MailboxUpdateOne) SetGid(i int32) *MailboxUpdateOne {
|
||||||
|
muo.mutation.ResetGid()
|
||||||
|
muo.mutation.SetGid(i)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetNillableGid sets the "gid" field if the given value is not nil.
|
||||||
|
func (muo *MailboxUpdateOne) SetNillableGid(i *int32) *MailboxUpdateOne {
|
||||||
|
if i != nil {
|
||||||
|
muo.SetGid(*i)
|
||||||
|
}
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddGid adds i to the "gid" field.
|
||||||
|
func (muo *MailboxUpdateOne) AddGid(i int32) *MailboxUpdateOne {
|
||||||
|
muo.mutation.AddGid(i)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearGid clears the value of the "gid" field.
|
||||||
|
func (muo *MailboxUpdateOne) ClearGid() *MailboxUpdateOne {
|
||||||
|
muo.mutation.ClearGid()
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDomain sets the "domain" edge to the Domain entity.
|
||||||
|
func (muo *MailboxUpdateOne) SetDomain(d *Domain) *MailboxUpdateOne {
|
||||||
|
return muo.SetDomainID(d.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mutation returns the MailboxMutation object of the builder.
|
||||||
|
func (muo *MailboxUpdateOne) Mutation() *MailboxMutation {
|
||||||
|
return muo.mutation
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearDomain clears the "domain" edge to the Domain entity.
|
||||||
|
func (muo *MailboxUpdateOne) ClearDomain() *MailboxUpdateOne {
|
||||||
|
muo.mutation.ClearDomain()
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||||
|
// The default is selecting all fields defined in the entity schema.
|
||||||
|
func (muo *MailboxUpdateOne) Select(field string, fields ...string) *MailboxUpdateOne {
|
||||||
|
muo.fields = append([]string{field}, fields...)
|
||||||
|
return muo
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save executes the query and returns the updated Mailbox entity.
|
||||||
|
func (muo *MailboxUpdateOne) Save(ctx context.Context) (*Mailbox, error) {
|
||||||
|
var (
|
||||||
|
err error
|
||||||
|
node *Mailbox
|
||||||
|
)
|
||||||
|
muo.defaults()
|
||||||
|
if len(muo.hooks) == 0 {
|
||||||
|
node, err = muo.sqlSave(ctx)
|
||||||
|
} else {
|
||||||
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
|
mutation, ok := m.(*MailboxMutation)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||||
|
}
|
||||||
|
muo.mutation = mutation
|
||||||
|
node, err = muo.sqlSave(ctx)
|
||||||
|
mutation.done = true
|
||||||
|
return node, err
|
||||||
|
})
|
||||||
|
for i := len(muo.hooks) - 1; i >= 0; i-- {
|
||||||
|
if muo.hooks[i] == nil {
|
||||||
|
return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
|
||||||
|
}
|
||||||
|
mut = muo.hooks[i](mut)
|
||||||
|
}
|
||||||
|
if _, err := mut.Mutate(ctx, muo.mutation); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return node, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// SaveX is like Save, but panics if an error occurs.
|
||||||
|
func (muo *MailboxUpdateOne) SaveX(ctx context.Context) *Mailbox {
|
||||||
|
node, err := muo.Save(ctx)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return node
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the query on the entity.
|
||||||
|
func (muo *MailboxUpdateOne) Exec(ctx context.Context) error {
|
||||||
|
_, err := muo.Save(ctx)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExecX is like Exec, but panics if an error occurs.
|
||||||
|
func (muo *MailboxUpdateOne) ExecX(ctx context.Context) {
|
||||||
|
if err := muo.Exec(ctx); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (muo *MailboxUpdateOne) defaults() {
|
||||||
|
if _, ok := muo.mutation.Modified(); !ok && !muo.mutation.ModifiedCleared() {
|
||||||
|
v := mailbox.UpdateDefaultModified()
|
||||||
|
muo.mutation.SetModified(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (muo *MailboxUpdateOne) sqlSave(ctx context.Context) (_node *Mailbox, err error) {
|
||||||
|
_spec := &sqlgraph.UpdateSpec{
|
||||||
|
Node: &sqlgraph.NodeSpec{
|
||||||
|
Table: mailbox.Table,
|
||||||
|
Columns: mailbox.Columns,
|
||||||
|
ID: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: mailbox.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
id, ok := muo.mutation.ID()
|
||||||
|
if !ok {
|
||||||
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Mailbox.id" for update`)}
|
||||||
|
}
|
||||||
|
_spec.Node.ID.Value = id
|
||||||
|
if fields := muo.fields; len(fields) > 0 {
|
||||||
|
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, mailbox.FieldID)
|
||||||
|
for _, f := range fields {
|
||||||
|
if !mailbox.ValidColumn(f) {
|
||||||
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||||
|
}
|
||||||
|
if f != mailbox.FieldID {
|
||||||
|
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ps := muo.mutation.predicates; len(ps) > 0 {
|
||||||
|
_spec.Predicate = func(selector *sql.Selector) {
|
||||||
|
for i := range ps {
|
||||||
|
ps[i](selector)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.Active(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBool,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldActive,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.Modified(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if muo.mutation.ModifiedCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeTime,
|
||||||
|
Column: mailbox.FieldModified,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.Username(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldUsername,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.Password(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeBytes,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldPassword,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.Name(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if muo.mutation.NameCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Column: mailbox.FieldName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.Quota(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldQuota,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.AddedQuota(); ok {
|
||||||
|
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldQuota,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.LocalPart(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldLocalPart,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.Homedir(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldHomedir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if muo.mutation.HomedirCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Column: mailbox.FieldHomedir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.Maildir(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldMaildir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if muo.mutation.MaildirCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeString,
|
||||||
|
Column: mailbox.FieldMaildir,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.UID(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldUID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.AddedUID(); ok {
|
||||||
|
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldUID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if muo.mutation.UIDCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Column: mailbox.FieldUID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.Gid(); ok {
|
||||||
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldGid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if value, ok := muo.mutation.AddedGid(); ok {
|
||||||
|
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Value: value,
|
||||||
|
Column: mailbox.FieldGid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if muo.mutation.GidCleared() {
|
||||||
|
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt32,
|
||||||
|
Column: mailbox.FieldGid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if muo.mutation.DomainCleared() {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: mailbox.DomainTable,
|
||||||
|
Columns: []string{mailbox.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||||
|
}
|
||||||
|
if nodes := muo.mutation.DomainIDs(); len(nodes) > 0 {
|
||||||
|
edge := &sqlgraph.EdgeSpec{
|
||||||
|
Rel: sqlgraph.M2O,
|
||||||
|
Inverse: true,
|
||||||
|
Table: mailbox.DomainTable,
|
||||||
|
Columns: []string{mailbox.DomainColumn},
|
||||||
|
Bidi: false,
|
||||||
|
Target: &sqlgraph.EdgeTarget{
|
||||||
|
IDSpec: &sqlgraph.FieldSpec{
|
||||||
|
Type: field.TypeInt64,
|
||||||
|
Column: domain.FieldID,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, k := range nodes {
|
||||||
|
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||||
|
}
|
||||||
|
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||||
|
}
|
||||||
|
_node = &Mailbox{config: muo.config}
|
||||||
|
_spec.Assign = _node.assignValues
|
||||||
|
_spec.ScanValues = _node.scanValues
|
||||||
|
if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil {
|
||||||
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||||
|
err = &NotFoundError{mailbox.Label}
|
||||||
|
} else if sqlgraph.IsConstraintError(err) {
|
||||||
|
err = &ConstraintError{err.Error(), err}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return _node, nil
|
||||||
|
}
|
71
ent/migrate/migrate.go
Normal file
71
ent/migrate/migrate.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// WithGlobalUniqueID sets the universal ids options to the migration.
|
||||||
|
// If this option is enabled, ent migration will allocate a 1<<32 range
|
||||||
|
// for the ids of each entity (table).
|
||||||
|
// Note that this option cannot be applied on tables that already exist.
|
||||||
|
WithGlobalUniqueID = schema.WithGlobalUniqueID
|
||||||
|
// WithDropColumn sets the drop column option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old columns
|
||||||
|
// that were used for both fields and edges. This defaults to false.
|
||||||
|
WithDropColumn = schema.WithDropColumn
|
||||||
|
// WithDropIndex sets the drop index option to the migration.
|
||||||
|
// If this option is enabled, ent migration will drop old indexes
|
||||||
|
// that were defined in the schema. This defaults to false.
|
||||||
|
// Note that unique constraints are defined using `UNIQUE INDEX`,
|
||||||
|
// and therefore, it's recommended to enable this option to get more
|
||||||
|
// flexibility in the schema changes.
|
||||||
|
WithDropIndex = schema.WithDropIndex
|
||||||
|
// WithFixture sets the foreign-key renaming option to the migration when upgrading
|
||||||
|
// ent from v0.1.0 (issue-#285). Defaults to false.
|
||||||
|
WithFixture = schema.WithFixture
|
||||||
|
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
|
||||||
|
WithForeignKeys = schema.WithForeignKeys
|
||||||
|
)
|
||||||
|
|
||||||
|
// Schema is the API for creating, migrating and dropping a schema.
|
||||||
|
type Schema struct {
|
||||||
|
drv dialect.Driver
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewSchema creates a new schema client.
|
||||||
|
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
|
||||||
|
|
||||||
|
// Create creates all schema resources.
|
||||||
|
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
|
||||||
|
migrate, err := schema.NewMigrate(s.drv, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ent/migrate: %w", err)
|
||||||
|
}
|
||||||
|
return migrate.Create(ctx, Tables...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteTo writes the schema changes to w instead of running them against the database.
|
||||||
|
//
|
||||||
|
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
|
||||||
|
// log.Fatal(err)
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
|
||||||
|
drv := &schema.WriteDriver{
|
||||||
|
Writer: w,
|
||||||
|
Driver: s.drv,
|
||||||
|
}
|
||||||
|
migrate, err := schema.NewMigrate(drv, opts...)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("ent/migrate: %w", err)
|
||||||
|
}
|
||||||
|
return migrate.Create(ctx, Tables...)
|
||||||
|
}
|
174
ent/migrate/schema.go
Normal file
174
ent/migrate/schema.go
Normal file
@ -0,0 +1,174 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package migrate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql/schema"
|
||||||
|
"entgo.io/ent/schema/field"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// AccountsColumns holds the columns for the "accounts" table.
|
||||||
|
AccountsColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "created", Type: field.TypeTime},
|
||||||
|
{Name: "modified", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "username", Type: field.TypeString},
|
||||||
|
{Name: "password", Type: field.TypeBytes},
|
||||||
|
{Name: "super", Type: field.TypeBool},
|
||||||
|
{Name: "active", Type: field.TypeBool},
|
||||||
|
}
|
||||||
|
// AccountsTable holds the schema information for the "accounts" table.
|
||||||
|
AccountsTable = &schema.Table{
|
||||||
|
Name: "accounts",
|
||||||
|
Columns: AccountsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{AccountsColumns[0]},
|
||||||
|
}
|
||||||
|
// AliasColumns holds the columns for the "alias" table.
|
||||||
|
AliasColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "created", Type: field.TypeTime},
|
||||||
|
{Name: "modified", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "goto", Type: field.TypeString, Size: 2147483647},
|
||||||
|
{Name: "active", Type: field.TypeBool},
|
||||||
|
{Name: "domain_id", Type: field.TypeInt64, Nullable: true},
|
||||||
|
}
|
||||||
|
// AliasTable holds the schema information for the "alias" table.
|
||||||
|
AliasTable = &schema.Table{
|
||||||
|
Name: "alias",
|
||||||
|
Columns: AliasColumns,
|
||||||
|
PrimaryKey: []*schema.Column{AliasColumns[0]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "alias_domains_aliases",
|
||||||
|
Columns: []*schema.Column{AliasColumns[5]},
|
||||||
|
RefColumns: []*schema.Column{DomainsColumns[0]},
|
||||||
|
OnDelete: schema.SetNull,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// DomainsColumns holds the columns for the "domains" table.
|
||||||
|
DomainsColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "created", Type: field.TypeTime},
|
||||||
|
{Name: "modified", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "domain", Type: field.TypeString},
|
||||||
|
{Name: "description", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "max_aliases", Type: field.TypeInt64},
|
||||||
|
{Name: "max_mailboxes", Type: field.TypeInt64},
|
||||||
|
{Name: "max_quota", Type: field.TypeInt64},
|
||||||
|
{Name: "quota", Type: field.TypeInt64},
|
||||||
|
{Name: "transport", Type: field.TypeString},
|
||||||
|
{Name: "backup_mx", Type: field.TypeBool},
|
||||||
|
{Name: "active", Type: field.TypeBool},
|
||||||
|
}
|
||||||
|
// DomainsTable holds the schema information for the "domains" table.
|
||||||
|
DomainsTable = &schema.Table{
|
||||||
|
Name: "domains",
|
||||||
|
Columns: DomainsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{DomainsColumns[0]},
|
||||||
|
}
|
||||||
|
// LogentriesColumns holds the columns for the "logentries" table.
|
||||||
|
LogentriesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "timestamp", Type: field.TypeTime},
|
||||||
|
{Name: "action", Type: field.TypeString},
|
||||||
|
{Name: "data", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||||
|
{Name: "account_id", Type: field.TypeInt64, Nullable: true},
|
||||||
|
{Name: "domain_id", Type: field.TypeInt64, Nullable: true},
|
||||||
|
}
|
||||||
|
// LogentriesTable holds the schema information for the "logentries" table.
|
||||||
|
LogentriesTable = &schema.Table{
|
||||||
|
Name: "logentries",
|
||||||
|
Columns: LogentriesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{LogentriesColumns[0]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "logentries_accounts_logs",
|
||||||
|
Columns: []*schema.Column{LogentriesColumns[4]},
|
||||||
|
RefColumns: []*schema.Column{AccountsColumns[0]},
|
||||||
|
OnDelete: schema.SetNull,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Symbol: "logentries_domains_logs",
|
||||||
|
Columns: []*schema.Column{LogentriesColumns[5]},
|
||||||
|
RefColumns: []*schema.Column{DomainsColumns[0]},
|
||||||
|
OnDelete: schema.SetNull,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// MailboxesColumns holds the columns for the "mailboxes" table.
|
||||||
|
MailboxesColumns = []*schema.Column{
|
||||||
|
{Name: "id", Type: field.TypeInt64, Increment: true},
|
||||||
|
{Name: "active", Type: field.TypeBool},
|
||||||
|
{Name: "created", Type: field.TypeTime},
|
||||||
|
{Name: "modified", Type: field.TypeTime, Nullable: true},
|
||||||
|
{Name: "username", Type: field.TypeString},
|
||||||
|
{Name: "password", Type: field.TypeBytes},
|
||||||
|
{Name: "name", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "quota", Type: field.TypeInt64},
|
||||||
|
{Name: "local_part", Type: field.TypeString},
|
||||||
|
{Name: "homedir", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "maildir", Type: field.TypeString, Nullable: true},
|
||||||
|
{Name: "uid", Type: field.TypeInt32, Nullable: true},
|
||||||
|
{Name: "gid", Type: field.TypeInt32, Nullable: true},
|
||||||
|
{Name: "domain_id", Type: field.TypeInt64, Nullable: true},
|
||||||
|
}
|
||||||
|
// MailboxesTable holds the schema information for the "mailboxes" table.
|
||||||
|
MailboxesTable = &schema.Table{
|
||||||
|
Name: "mailboxes",
|
||||||
|
Columns: MailboxesColumns,
|
||||||
|
PrimaryKey: []*schema.Column{MailboxesColumns[0]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "mailboxes_domains_mailboxes",
|
||||||
|
Columns: []*schema.Column{MailboxesColumns[13]},
|
||||||
|
RefColumns: []*schema.Column{DomainsColumns[0]},
|
||||||
|
OnDelete: schema.SetNull,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// AccountDomainsColumns holds the columns for the "account_domains" table.
|
||||||
|
AccountDomainsColumns = []*schema.Column{
|
||||||
|
{Name: "account_id", Type: field.TypeInt64},
|
||||||
|
{Name: "domain_id", Type: field.TypeInt64},
|
||||||
|
}
|
||||||
|
// AccountDomainsTable holds the schema information for the "account_domains" table.
|
||||||
|
AccountDomainsTable = &schema.Table{
|
||||||
|
Name: "account_domains",
|
||||||
|
Columns: AccountDomainsColumns,
|
||||||
|
PrimaryKey: []*schema.Column{AccountDomainsColumns[0], AccountDomainsColumns[1]},
|
||||||
|
ForeignKeys: []*schema.ForeignKey{
|
||||||
|
{
|
||||||
|
Symbol: "account_domains_account_id",
|
||||||
|
Columns: []*schema.Column{AccountDomainsColumns[0]},
|
||||||
|
RefColumns: []*schema.Column{AccountsColumns[0]},
|
||||||
|
OnDelete: schema.Cascade,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Symbol: "account_domains_domain_id",
|
||||||
|
Columns: []*schema.Column{AccountDomainsColumns[1]},
|
||||||
|
RefColumns: []*schema.Column{DomainsColumns[0]},
|
||||||
|
OnDelete: schema.Cascade,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
// Tables holds all the tables in the schema.
|
||||||
|
Tables = []*schema.Table{
|
||||||
|
AccountsTable,
|
||||||
|
AliasTable,
|
||||||
|
DomainsTable,
|
||||||
|
LogentriesTable,
|
||||||
|
MailboxesTable,
|
||||||
|
AccountDomainsTable,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
AliasTable.ForeignKeys[0].RefTable = DomainsTable
|
||||||
|
LogentriesTable.ForeignKeys[0].RefTable = AccountsTable
|
||||||
|
LogentriesTable.ForeignKeys[1].RefTable = DomainsTable
|
||||||
|
MailboxesTable.ForeignKeys[0].RefTable = DomainsTable
|
||||||
|
AccountDomainsTable.ForeignKeys[0].RefTable = AccountsTable
|
||||||
|
AccountDomainsTable.ForeignKeys[1].RefTable = DomainsTable
|
||||||
|
}
|
4784
ent/mutation.go
Normal file
4784
ent/mutation.go
Normal file
File diff suppressed because it is too large
Load Diff
22
ent/predicate/predicate.go
Normal file
22
ent/predicate/predicate.go
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package predicate
|
||||||
|
|
||||||
|
import (
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Account is the predicate function for account builders.
|
||||||
|
type Account func(*sql.Selector)
|
||||||
|
|
||||||
|
// Alias is the predicate function for alias builders.
|
||||||
|
type Alias func(*sql.Selector)
|
||||||
|
|
||||||
|
// Domain is the predicate function for domain builders.
|
||||||
|
type Domain func(*sql.Selector)
|
||||||
|
|
||||||
|
// Logentry is the predicate function for logentry builders.
|
||||||
|
type Logentry func(*sql.Selector)
|
||||||
|
|
||||||
|
// Mailbox is the predicate function for mailbox builders.
|
||||||
|
type Mailbox func(*sql.Selector)
|
74
ent/runtime.go
Normal file
74
ent/runtime.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"code.icod.de/postfix/manager/ent/account"
|
||||||
|
"code.icod.de/postfix/manager/ent/alias"
|
||||||
|
"code.icod.de/postfix/manager/ent/domain"
|
||||||
|
"code.icod.de/postfix/manager/ent/logentry"
|
||||||
|
"code.icod.de/postfix/manager/ent/mailbox"
|
||||||
|
"code.icod.de/postfix/manager/ent/schema"
|
||||||
|
)
|
||||||
|
|
||||||
|
// The init function reads all schema descriptors with runtime code
|
||||||
|
// (default values, validators, hooks and policies) and stitches it
|
||||||
|
// to their package variables.
|
||||||
|
func init() {
|
||||||
|
accountFields := schema.Account{}.Fields()
|
||||||
|
_ = accountFields
|
||||||
|
// accountDescCreated is the schema descriptor for created field.
|
||||||
|
accountDescCreated := accountFields[1].Descriptor()
|
||||||
|
// account.DefaultCreated holds the default value on creation for the created field.
|
||||||
|
account.DefaultCreated = accountDescCreated.Default.(func() time.Time)
|
||||||
|
// accountDescModified is the schema descriptor for modified field.
|
||||||
|
accountDescModified := accountFields[2].Descriptor()
|
||||||
|
// account.DefaultModified holds the default value on creation for the modified field.
|
||||||
|
account.DefaultModified = accountDescModified.Default.(func() time.Time)
|
||||||
|
// account.UpdateDefaultModified holds the default value on update for the modified field.
|
||||||
|
account.UpdateDefaultModified = accountDescModified.UpdateDefault.(func() time.Time)
|
||||||
|
aliasFields := schema.Alias{}.Fields()
|
||||||
|
_ = aliasFields
|
||||||
|
// aliasDescCreated is the schema descriptor for created field.
|
||||||
|
aliasDescCreated := aliasFields[1].Descriptor()
|
||||||
|
// alias.DefaultCreated holds the default value on creation for the created field.
|
||||||
|
alias.DefaultCreated = aliasDescCreated.Default.(func() time.Time)
|
||||||
|
// aliasDescModified is the schema descriptor for modified field.
|
||||||
|
aliasDescModified := aliasFields[2].Descriptor()
|
||||||
|
// alias.DefaultModified holds the default value on creation for the modified field.
|
||||||
|
alias.DefaultModified = aliasDescModified.Default.(func() time.Time)
|
||||||
|
// alias.UpdateDefaultModified holds the default value on update for the modified field.
|
||||||
|
alias.UpdateDefaultModified = aliasDescModified.UpdateDefault.(func() time.Time)
|
||||||
|
domainFields := schema.Domain{}.Fields()
|
||||||
|
_ = domainFields
|
||||||
|
// domainDescCreated is the schema descriptor for created field.
|
||||||
|
domainDescCreated := domainFields[1].Descriptor()
|
||||||
|
// domain.DefaultCreated holds the default value on creation for the created field.
|
||||||
|
domain.DefaultCreated = domainDescCreated.Default.(func() time.Time)
|
||||||
|
// domainDescModified is the schema descriptor for modified field.
|
||||||
|
domainDescModified := domainFields[2].Descriptor()
|
||||||
|
// domain.DefaultModified holds the default value on creation for the modified field.
|
||||||
|
domain.DefaultModified = domainDescModified.Default.(func() time.Time)
|
||||||
|
// domain.UpdateDefaultModified holds the default value on update for the modified field.
|
||||||
|
domain.UpdateDefaultModified = domainDescModified.UpdateDefault.(func() time.Time)
|
||||||
|
logentryFields := schema.Logentry{}.Fields()
|
||||||
|
_ = logentryFields
|
||||||
|
// logentryDescTimestamp is the schema descriptor for timestamp field.
|
||||||
|
logentryDescTimestamp := logentryFields[1].Descriptor()
|
||||||
|
// logentry.DefaultTimestamp holds the default value on creation for the timestamp field.
|
||||||
|
logentry.DefaultTimestamp = logentryDescTimestamp.Default.(func() time.Time)
|
||||||
|
mailboxFields := schema.Mailbox{}.Fields()
|
||||||
|
_ = mailboxFields
|
||||||
|
// mailboxDescCreated is the schema descriptor for created field.
|
||||||
|
mailboxDescCreated := mailboxFields[2].Descriptor()
|
||||||
|
// mailbox.DefaultCreated holds the default value on creation for the created field.
|
||||||
|
mailbox.DefaultCreated = mailboxDescCreated.Default.(func() time.Time)
|
||||||
|
// mailboxDescModified is the schema descriptor for modified field.
|
||||||
|
mailboxDescModified := mailboxFields[3].Descriptor()
|
||||||
|
// mailbox.DefaultModified holds the default value on creation for the modified field.
|
||||||
|
mailbox.DefaultModified = mailboxDescModified.Default.(func() time.Time)
|
||||||
|
// mailbox.UpdateDefaultModified holds the default value on update for the modified field.
|
||||||
|
mailbox.UpdateDefaultModified = mailboxDescModified.UpdateDefault.(func() time.Time)
|
||||||
|
}
|
10
ent/runtime/runtime.go
Normal file
10
ent/runtime/runtime.go
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package runtime
|
||||||
|
|
||||||
|
// The schema-stitching logic is generated in code.icod.de/postfix/manager/ent/runtime.go
|
||||||
|
|
||||||
|
const (
|
||||||
|
Version = "v0.10.1" // Version of ent codegen.
|
||||||
|
Sum = "h1:dM5h4Zk6yHGIgw4dCqVzGw3nWgpGYJiV4/kyHEF6PFo=" // Sum of ent codegen.
|
||||||
|
)
|
222
ent/tx.go
Normal file
222
ent/tx.go
Normal file
@ -0,0 +1,222 @@
|
|||||||
|
// Code generated by entc, DO NOT EDIT.
|
||||||
|
|
||||||
|
package ent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"entgo.io/ent/dialect"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Tx is a transactional client that is created by calling Client.Tx().
|
||||||
|
type Tx struct {
|
||||||
|
config
|
||||||
|
// Account is the client for interacting with the Account builders.
|
||||||
|
Account *AccountClient
|
||||||
|
// Alias is the client for interacting with the Alias builders.
|
||||||
|
Alias *AliasClient
|
||||||
|
// Domain is the client for interacting with the Domain builders.
|
||||||
|
Domain *DomainClient
|
||||||
|
// Logentry is the client for interacting with the Logentry builders.
|
||||||
|
Logentry *LogentryClient
|
||||||
|
// Mailbox is the client for interacting with the Mailbox builders.
|
||||||
|
Mailbox *MailboxClient
|
||||||
|
|
||||||
|
// lazily loaded.
|
||||||
|
client *Client
|
||||||
|
clientOnce sync.Once
|
||||||
|
|
||||||
|
// completion callbacks.
|
||||||
|
mu sync.Mutex
|
||||||
|
onCommit []CommitHook
|
||||||
|
onRollback []RollbackHook
|
||||||
|
|
||||||
|
// ctx lives for the life of the transaction. It is
|
||||||
|
// the same context used by the underlying connection.
|
||||||
|
ctx context.Context
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Committer is the interface that wraps the Commit method.
|
||||||
|
Committer interface {
|
||||||
|
Commit(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The CommitFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Committer. If f is a function with the appropriate
|
||||||
|
// signature, CommitFunc(f) is a Committer that calls f.
|
||||||
|
CommitFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// CommitHook defines the "commit middleware". A function that gets a Committer
|
||||||
|
// and returns a Committer. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Committer) ent.Committer {
|
||||||
|
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Commit(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
CommitHook func(Committer) Committer
|
||||||
|
)
|
||||||
|
|
||||||
|
// Commit calls f(ctx, m).
|
||||||
|
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit commits the transaction.
|
||||||
|
func (tx *Tx) Commit() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Commit()
|
||||||
|
})
|
||||||
|
tx.mu.Lock()
|
||||||
|
hooks := append([]CommitHook(nil), tx.onCommit...)
|
||||||
|
tx.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Commit(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnCommit adds a hook to call on commit.
|
||||||
|
func (tx *Tx) OnCommit(f CommitHook) {
|
||||||
|
tx.mu.Lock()
|
||||||
|
defer tx.mu.Unlock()
|
||||||
|
tx.onCommit = append(tx.onCommit, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
type (
|
||||||
|
// Rollbacker is the interface that wraps the Rollback method.
|
||||||
|
Rollbacker interface {
|
||||||
|
Rollback(context.Context, *Tx) error
|
||||||
|
}
|
||||||
|
|
||||||
|
// The RollbackFunc type is an adapter to allow the use of ordinary
|
||||||
|
// function as a Rollbacker. If f is a function with the appropriate
|
||||||
|
// signature, RollbackFunc(f) is a Rollbacker that calls f.
|
||||||
|
RollbackFunc func(context.Context, *Tx) error
|
||||||
|
|
||||||
|
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
|
||||||
|
// and returns a Rollbacker. For example:
|
||||||
|
//
|
||||||
|
// hook := func(next ent.Rollbacker) ent.Rollbacker {
|
||||||
|
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
|
||||||
|
// // Do some stuff before.
|
||||||
|
// if err := next.Rollback(ctx, tx); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
// // Do some stuff after.
|
||||||
|
// return nil
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
RollbackHook func(Rollbacker) Rollbacker
|
||||||
|
)
|
||||||
|
|
||||||
|
// Rollback calls f(ctx, m).
|
||||||
|
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
|
||||||
|
return f(ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rollback rollbacks the transaction.
|
||||||
|
func (tx *Tx) Rollback() error {
|
||||||
|
txDriver := tx.config.driver.(*txDriver)
|
||||||
|
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
|
||||||
|
return txDriver.tx.Rollback()
|
||||||
|
})
|
||||||
|
tx.mu.Lock()
|
||||||
|
hooks := append([]RollbackHook(nil), tx.onRollback...)
|
||||||
|
tx.mu.Unlock()
|
||||||
|
for i := len(hooks) - 1; i >= 0; i-- {
|
||||||
|
fn = hooks[i](fn)
|
||||||
|
}
|
||||||
|
return fn.Rollback(tx.ctx, tx)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnRollback adds a hook to call on rollback.
|
||||||
|
func (tx *Tx) OnRollback(f RollbackHook) {
|
||||||
|
tx.mu.Lock()
|
||||||
|
defer tx.mu.Unlock()
|
||||||
|
tx.onRollback = append(tx.onRollback, f)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client returns a Client that binds to current transaction.
|
||||||
|
func (tx *Tx) Client() *Client {
|
||||||
|
tx.clientOnce.Do(func() {
|
||||||
|
tx.client = &Client{config: tx.config}
|
||||||
|
tx.client.init()
|
||||||
|
})
|
||||||
|
return tx.client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tx *Tx) init() {
|
||||||
|
tx.Account = NewAccountClient(tx.config)
|
||||||
|
tx.Alias = NewAliasClient(tx.config)
|
||||||
|
tx.Domain = NewDomainClient(tx.config)
|
||||||
|
tx.Logentry = NewLogentryClient(tx.config)
|
||||||
|
tx.Mailbox = NewMailboxClient(tx.config)
|
||||||
|
}
|
||||||
|
|
||||||
|
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
|
||||||
|
// The idea is to support transactions without adding any extra code to the builders.
|
||||||
|
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
|
||||||
|
// Commit and Rollback are nop for the internal builders and the user must call one
|
||||||
|
// 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: Account.QueryXXX(), the query will be executed
|
||||||
|
// through the driver which created this transaction.
|
||||||
|
//
|
||||||
|
// Note that txDriver is not goroutine safe.
|
||||||
|
type txDriver struct {
|
||||||
|
// the driver we started the transaction from.
|
||||||
|
drv dialect.Driver
|
||||||
|
// tx is the underlying transaction.
|
||||||
|
tx dialect.Tx
|
||||||
|
}
|
||||||
|
|
||||||
|
// newTx creates a new transactional driver.
|
||||||
|
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
|
||||||
|
tx, err := drv.Tx(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &txDriver{tx: tx, drv: drv}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
|
||||||
|
// from the internal builders. Should be called only by the internal builders.
|
||||||
|
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
|
||||||
|
|
||||||
|
// Dialect returns the dialect of the driver we started the transaction from.
|
||||||
|
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
|
||||||
|
|
||||||
|
// Close is a nop close.
|
||||||
|
func (*txDriver) Close() error { return nil }
|
||||||
|
|
||||||
|
// Commit is a nop commit for the internal builders.
|
||||||
|
// User must call `Tx.Commit` in order to commit the transaction.
|
||||||
|
func (*txDriver) Commit() error { return nil }
|
||||||
|
|
||||||
|
// Rollback is a nop rollback for the internal builders.
|
||||||
|
// User must call `Tx.Rollback` in order to rollback the transaction.
|
||||||
|
func (*txDriver) Rollback() error { return nil }
|
||||||
|
|
||||||
|
// Exec calls tx.Exec.
|
||||||
|
func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error {
|
||||||
|
return tx.tx.Exec(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Query calls tx.Query.
|
||||||
|
func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error {
|
||||||
|
return tx.tx.Query(ctx, query, args, v)
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ dialect.Driver = (*txDriver)(nil)
|
Loading…
Reference in New Issue
Block a user