manager/ent/mutation.go

4785 lines
134 KiB
Go
Raw Normal View History

2022-04-08 21:26:25 +02:00
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"sync"
"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/predicate"
"entgo.io/ent"
)
const (
// Operation types.
OpCreate = ent.OpCreate
OpDelete = ent.OpDelete
OpDeleteOne = ent.OpDeleteOne
OpUpdate = ent.OpUpdate
OpUpdateOne = ent.OpUpdateOne
// Node types.
TypeAccount = "Account"
TypeAlias = "Alias"
TypeDomain = "Domain"
TypeLogentry = "Logentry"
TypeMailbox = "Mailbox"
)
// AccountMutation represents an operation that mutates the Account nodes in the graph.
type AccountMutation struct {
config
op Op
typ string
id *int64
created *time.Time
modified *time.Time
username *string
password *[]byte
super *bool
active *bool
clearedFields map[string]struct{}
domains map[int64]struct{}
removeddomains map[int64]struct{}
cleareddomains bool
logs map[int64]struct{}
removedlogs map[int64]struct{}
clearedlogs bool
done bool
oldValue func(context.Context) (*Account, error)
predicates []predicate.Account
}
var _ ent.Mutation = (*AccountMutation)(nil)
// accountOption allows management of the mutation configuration using functional options.
type accountOption func(*AccountMutation)
// newAccountMutation creates new mutation for the Account entity.
func newAccountMutation(c config, op Op, opts ...accountOption) *AccountMutation {
m := &AccountMutation{
config: c,
op: op,
typ: TypeAccount,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withAccountID sets the ID field of the mutation.
func withAccountID(id int64) accountOption {
return func(m *AccountMutation) {
var (
err error
once sync.Once
value *Account
)
m.oldValue = func(ctx context.Context) (*Account, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Account.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withAccount sets the old Account of the mutation.
func withAccount(node *Account) accountOption {
return func(m *AccountMutation) {
m.oldValue = func(context.Context) (*Account, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m AccountMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m AccountMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Account entities.
func (m *AccountMutation) SetID(id int64) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *AccountMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *AccountMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Account.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreated sets the "created" field.
func (m *AccountMutation) SetCreated(t time.Time) {
m.created = &t
}
// Created returns the value of the "created" field in the mutation.
func (m *AccountMutation) Created() (r time.Time, exists bool) {
v := m.created
if v == nil {
return
}
return *v, true
}
// OldCreated returns the old "created" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldCreated(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreated is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreated requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreated: %w", err)
}
return oldValue.Created, nil
}
// ResetCreated resets all changes to the "created" field.
func (m *AccountMutation) ResetCreated() {
m.created = nil
}
// SetModified sets the "modified" field.
func (m *AccountMutation) SetModified(t time.Time) {
m.modified = &t
}
// Modified returns the value of the "modified" field in the mutation.
func (m *AccountMutation) Modified() (r time.Time, exists bool) {
v := m.modified
if v == nil {
return
}
return *v, true
}
// OldModified returns the old "modified" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldModified(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldModified is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldModified requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldModified: %w", err)
}
return oldValue.Modified, nil
}
// ClearModified clears the value of the "modified" field.
func (m *AccountMutation) ClearModified() {
m.modified = nil
m.clearedFields[account.FieldModified] = struct{}{}
}
// ModifiedCleared returns if the "modified" field was cleared in this mutation.
func (m *AccountMutation) ModifiedCleared() bool {
_, ok := m.clearedFields[account.FieldModified]
return ok
}
// ResetModified resets all changes to the "modified" field.
func (m *AccountMutation) ResetModified() {
m.modified = nil
delete(m.clearedFields, account.FieldModified)
}
// SetUsername sets the "username" field.
func (m *AccountMutation) SetUsername(s string) {
m.username = &s
}
// Username returns the value of the "username" field in the mutation.
func (m *AccountMutation) Username() (r string, exists bool) {
v := m.username
if v == nil {
return
}
return *v, true
}
// OldUsername returns the old "username" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldUsername(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUsername is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUsername requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUsername: %w", err)
}
return oldValue.Username, nil
}
// ResetUsername resets all changes to the "username" field.
func (m *AccountMutation) ResetUsername() {
m.username = nil
}
// SetPassword sets the "password" field.
func (m *AccountMutation) SetPassword(b []byte) {
m.password = &b
}
// Password returns the value of the "password" field in the mutation.
func (m *AccountMutation) Password() (r []byte, exists bool) {
v := m.password
if v == nil {
return
}
return *v, true
}
// OldPassword returns the old "password" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldPassword(ctx context.Context) (v []byte, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPassword is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPassword requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPassword: %w", err)
}
return oldValue.Password, nil
}
// ResetPassword resets all changes to the "password" field.
func (m *AccountMutation) ResetPassword() {
m.password = nil
}
// SetSuper sets the "super" field.
func (m *AccountMutation) SetSuper(b bool) {
m.super = &b
}
// Super returns the value of the "super" field in the mutation.
func (m *AccountMutation) Super() (r bool, exists bool) {
v := m.super
if v == nil {
return
}
return *v, true
}
// OldSuper returns the old "super" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldSuper(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldSuper is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldSuper requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldSuper: %w", err)
}
return oldValue.Super, nil
}
// ResetSuper resets all changes to the "super" field.
func (m *AccountMutation) ResetSuper() {
m.super = nil
}
// SetActive sets the "active" field.
func (m *AccountMutation) SetActive(b bool) {
m.active = &b
}
// Active returns the value of the "active" field in the mutation.
func (m *AccountMutation) Active() (r bool, exists bool) {
v := m.active
if v == nil {
return
}
return *v, true
}
// OldActive returns the old "active" field's value of the Account entity.
// If the Account object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AccountMutation) OldActive(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldActive is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldActive requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldActive: %w", err)
}
return oldValue.Active, nil
}
// ResetActive resets all changes to the "active" field.
func (m *AccountMutation) ResetActive() {
m.active = nil
}
// AddDomainIDs adds the "domains" edge to the Domain entity by ids.
func (m *AccountMutation) AddDomainIDs(ids ...int64) {
if m.domains == nil {
m.domains = make(map[int64]struct{})
}
for i := range ids {
m.domains[ids[i]] = struct{}{}
}
}
// ClearDomains clears the "domains" edge to the Domain entity.
func (m *AccountMutation) ClearDomains() {
m.cleareddomains = true
}
// DomainsCleared reports if the "domains" edge to the Domain entity was cleared.
func (m *AccountMutation) DomainsCleared() bool {
return m.cleareddomains
}
// RemoveDomainIDs removes the "domains" edge to the Domain entity by IDs.
func (m *AccountMutation) RemoveDomainIDs(ids ...int64) {
if m.removeddomains == nil {
m.removeddomains = make(map[int64]struct{})
}
for i := range ids {
delete(m.domains, ids[i])
m.removeddomains[ids[i]] = struct{}{}
}
}
// RemovedDomains returns the removed IDs of the "domains" edge to the Domain entity.
func (m *AccountMutation) RemovedDomainsIDs() (ids []int64) {
for id := range m.removeddomains {
ids = append(ids, id)
}
return
}
// DomainsIDs returns the "domains" edge IDs in the mutation.
func (m *AccountMutation) DomainsIDs() (ids []int64) {
for id := range m.domains {
ids = append(ids, id)
}
return
}
// ResetDomains resets all changes to the "domains" edge.
func (m *AccountMutation) ResetDomains() {
m.domains = nil
m.cleareddomains = false
m.removeddomains = nil
}
// AddLogIDs adds the "logs" edge to the Logentry entity by ids.
func (m *AccountMutation) AddLogIDs(ids ...int64) {
if m.logs == nil {
m.logs = make(map[int64]struct{})
}
for i := range ids {
m.logs[ids[i]] = struct{}{}
}
}
// ClearLogs clears the "logs" edge to the Logentry entity.
func (m *AccountMutation) ClearLogs() {
m.clearedlogs = true
}
// LogsCleared reports if the "logs" edge to the Logentry entity was cleared.
func (m *AccountMutation) LogsCleared() bool {
return m.clearedlogs
}
// RemoveLogIDs removes the "logs" edge to the Logentry entity by IDs.
func (m *AccountMutation) RemoveLogIDs(ids ...int64) {
if m.removedlogs == nil {
m.removedlogs = make(map[int64]struct{})
}
for i := range ids {
delete(m.logs, ids[i])
m.removedlogs[ids[i]] = struct{}{}
}
}
// RemovedLogs returns the removed IDs of the "logs" edge to the Logentry entity.
func (m *AccountMutation) RemovedLogsIDs() (ids []int64) {
for id := range m.removedlogs {
ids = append(ids, id)
}
return
}
// LogsIDs returns the "logs" edge IDs in the mutation.
func (m *AccountMutation) LogsIDs() (ids []int64) {
for id := range m.logs {
ids = append(ids, id)
}
return
}
// ResetLogs resets all changes to the "logs" edge.
func (m *AccountMutation) ResetLogs() {
m.logs = nil
m.clearedlogs = false
m.removedlogs = nil
}
// Where appends a list predicates to the AccountMutation builder.
func (m *AccountMutation) Where(ps ...predicate.Account) {
m.predicates = append(m.predicates, ps...)
}
// Op returns the operation name.
func (m *AccountMutation) Op() Op {
return m.op
}
// Type returns the node type of this mutation (Account).
func (m *AccountMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *AccountMutation) Fields() []string {
fields := make([]string, 0, 6)
if m.created != nil {
fields = append(fields, account.FieldCreated)
}
if m.modified != nil {
fields = append(fields, account.FieldModified)
}
if m.username != nil {
fields = append(fields, account.FieldUsername)
}
if m.password != nil {
fields = append(fields, account.FieldPassword)
}
if m.super != nil {
fields = append(fields, account.FieldSuper)
}
if m.active != nil {
fields = append(fields, account.FieldActive)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *AccountMutation) Field(name string) (ent.Value, bool) {
switch name {
case account.FieldCreated:
return m.Created()
case account.FieldModified:
return m.Modified()
case account.FieldUsername:
return m.Username()
case account.FieldPassword:
return m.Password()
case account.FieldSuper:
return m.Super()
case account.FieldActive:
return m.Active()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *AccountMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case account.FieldCreated:
return m.OldCreated(ctx)
case account.FieldModified:
return m.OldModified(ctx)
case account.FieldUsername:
return m.OldUsername(ctx)
case account.FieldPassword:
return m.OldPassword(ctx)
case account.FieldSuper:
return m.OldSuper(ctx)
case account.FieldActive:
return m.OldActive(ctx)
}
return nil, fmt.Errorf("unknown Account field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *AccountMutation) SetField(name string, value ent.Value) error {
switch name {
case account.FieldCreated:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreated(v)
return nil
case account.FieldModified:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetModified(v)
return nil
case account.FieldUsername:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsername(v)
return nil
case account.FieldPassword:
v, ok := value.([]byte)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPassword(v)
return nil
case account.FieldSuper:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetSuper(v)
return nil
case account.FieldActive:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetActive(v)
return nil
}
return fmt.Errorf("unknown Account field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *AccountMutation) AddedFields() []string {
return nil
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *AccountMutation) AddedField(name string) (ent.Value, bool) {
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *AccountMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Account numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *AccountMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(account.FieldModified) {
fields = append(fields, account.FieldModified)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AccountMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *AccountMutation) ClearField(name string) error {
switch name {
case account.FieldModified:
m.ClearModified()
return nil
}
return fmt.Errorf("unknown Account nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *AccountMutation) ResetField(name string) error {
switch name {
case account.FieldCreated:
m.ResetCreated()
return nil
case account.FieldModified:
m.ResetModified()
return nil
case account.FieldUsername:
m.ResetUsername()
return nil
case account.FieldPassword:
m.ResetPassword()
return nil
case account.FieldSuper:
m.ResetSuper()
return nil
case account.FieldActive:
m.ResetActive()
return nil
}
return fmt.Errorf("unknown Account field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AccountMutation) AddedEdges() []string {
edges := make([]string, 0, 2)
if m.domains != nil {
edges = append(edges, account.EdgeDomains)
}
if m.logs != nil {
edges = append(edges, account.EdgeLogs)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *AccountMutation) AddedIDs(name string) []ent.Value {
switch name {
case account.EdgeDomains:
ids := make([]ent.Value, 0, len(m.domains))
for id := range m.domains {
ids = append(ids, id)
}
return ids
case account.EdgeLogs:
ids := make([]ent.Value, 0, len(m.logs))
for id := range m.logs {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *AccountMutation) RemovedEdges() []string {
edges := make([]string, 0, 2)
if m.removeddomains != nil {
edges = append(edges, account.EdgeDomains)
}
if m.removedlogs != nil {
edges = append(edges, account.EdgeLogs)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *AccountMutation) RemovedIDs(name string) []ent.Value {
switch name {
case account.EdgeDomains:
ids := make([]ent.Value, 0, len(m.removeddomains))
for id := range m.removeddomains {
ids = append(ids, id)
}
return ids
case account.EdgeLogs:
ids := make([]ent.Value, 0, len(m.removedlogs))
for id := range m.removedlogs {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *AccountMutation) ClearedEdges() []string {
edges := make([]string, 0, 2)
if m.cleareddomains {
edges = append(edges, account.EdgeDomains)
}
if m.clearedlogs {
edges = append(edges, account.EdgeLogs)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AccountMutation) EdgeCleared(name string) bool {
switch name {
case account.EdgeDomains:
return m.cleareddomains
case account.EdgeLogs:
return m.clearedlogs
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *AccountMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown Account unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *AccountMutation) ResetEdge(name string) error {
switch name {
case account.EdgeDomains:
m.ResetDomains()
return nil
case account.EdgeLogs:
m.ResetLogs()
return nil
}
return fmt.Errorf("unknown Account edge %s", name)
}
// AliasMutation represents an operation that mutates the Alias nodes in the graph.
type AliasMutation struct {
config
op Op
typ string
id *int64
created *time.Time
modified *time.Time
_goto *string
active *bool
clearedFields map[string]struct{}
domain *int64
cleareddomain bool
done bool
oldValue func(context.Context) (*Alias, error)
predicates []predicate.Alias
}
var _ ent.Mutation = (*AliasMutation)(nil)
// aliasOption allows management of the mutation configuration using functional options.
type aliasOption func(*AliasMutation)
// newAliasMutation creates new mutation for the Alias entity.
func newAliasMutation(c config, op Op, opts ...aliasOption) *AliasMutation {
m := &AliasMutation{
config: c,
op: op,
typ: TypeAlias,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withAliasID sets the ID field of the mutation.
func withAliasID(id int64) aliasOption {
return func(m *AliasMutation) {
var (
err error
once sync.Once
value *Alias
)
m.oldValue = func(ctx context.Context) (*Alias, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Alias.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withAlias sets the old Alias of the mutation.
func withAlias(node *Alias) aliasOption {
return func(m *AliasMutation) {
m.oldValue = func(context.Context) (*Alias, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m AliasMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m AliasMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Alias entities.
func (m *AliasMutation) SetID(id int64) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *AliasMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *AliasMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Alias.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreated sets the "created" field.
func (m *AliasMutation) SetCreated(t time.Time) {
m.created = &t
}
// Created returns the value of the "created" field in the mutation.
func (m *AliasMutation) Created() (r time.Time, exists bool) {
v := m.created
if v == nil {
return
}
return *v, true
}
// OldCreated returns the old "created" field's value of the Alias entity.
// If the Alias object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AliasMutation) OldCreated(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreated is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreated requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreated: %w", err)
}
return oldValue.Created, nil
}
// ResetCreated resets all changes to the "created" field.
func (m *AliasMutation) ResetCreated() {
m.created = nil
}
// SetModified sets the "modified" field.
func (m *AliasMutation) SetModified(t time.Time) {
m.modified = &t
}
// Modified returns the value of the "modified" field in the mutation.
func (m *AliasMutation) Modified() (r time.Time, exists bool) {
v := m.modified
if v == nil {
return
}
return *v, true
}
// OldModified returns the old "modified" field's value of the Alias entity.
// If the Alias object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AliasMutation) OldModified(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldModified is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldModified requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldModified: %w", err)
}
return oldValue.Modified, nil
}
// ClearModified clears the value of the "modified" field.
func (m *AliasMutation) ClearModified() {
m.modified = nil
m.clearedFields[alias.FieldModified] = struct{}{}
}
// ModifiedCleared returns if the "modified" field was cleared in this mutation.
func (m *AliasMutation) ModifiedCleared() bool {
_, ok := m.clearedFields[alias.FieldModified]
return ok
}
// ResetModified resets all changes to the "modified" field.
func (m *AliasMutation) ResetModified() {
m.modified = nil
delete(m.clearedFields, alias.FieldModified)
}
// SetDomainID sets the "domain_id" field.
func (m *AliasMutation) SetDomainID(i int64) {
m.domain = &i
}
// DomainID returns the value of the "domain_id" field in the mutation.
func (m *AliasMutation) DomainID() (r int64, exists bool) {
v := m.domain
if v == nil {
return
}
return *v, true
}
// OldDomainID returns the old "domain_id" field's value of the Alias entity.
// If the Alias object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AliasMutation) OldDomainID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDomainID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDomainID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDomainID: %w", err)
}
return oldValue.DomainID, nil
}
// ClearDomainID clears the value of the "domain_id" field.
func (m *AliasMutation) ClearDomainID() {
m.domain = nil
m.clearedFields[alias.FieldDomainID] = struct{}{}
}
// DomainIDCleared returns if the "domain_id" field was cleared in this mutation.
func (m *AliasMutation) DomainIDCleared() bool {
_, ok := m.clearedFields[alias.FieldDomainID]
return ok
}
// ResetDomainID resets all changes to the "domain_id" field.
func (m *AliasMutation) ResetDomainID() {
m.domain = nil
delete(m.clearedFields, alias.FieldDomainID)
}
// SetGoto sets the "goto" field.
func (m *AliasMutation) SetGoto(s string) {
m._goto = &s
}
// Goto returns the value of the "goto" field in the mutation.
func (m *AliasMutation) Goto() (r string, exists bool) {
v := m._goto
if v == nil {
return
}
return *v, true
}
// OldGoto returns the old "goto" field's value of the Alias entity.
// If the Alias object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AliasMutation) OldGoto(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldGoto is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldGoto requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldGoto: %w", err)
}
return oldValue.Goto, nil
}
// ResetGoto resets all changes to the "goto" field.
func (m *AliasMutation) ResetGoto() {
m._goto = nil
}
// SetActive sets the "active" field.
func (m *AliasMutation) SetActive(b bool) {
m.active = &b
}
// Active returns the value of the "active" field in the mutation.
func (m *AliasMutation) Active() (r bool, exists bool) {
v := m.active
if v == nil {
return
}
return *v, true
}
// OldActive returns the old "active" field's value of the Alias entity.
// If the Alias object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *AliasMutation) OldActive(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldActive is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldActive requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldActive: %w", err)
}
return oldValue.Active, nil
}
// ResetActive resets all changes to the "active" field.
func (m *AliasMutation) ResetActive() {
m.active = nil
}
// ClearDomain clears the "domain" edge to the Domain entity.
func (m *AliasMutation) ClearDomain() {
m.cleareddomain = true
}
// DomainCleared reports if the "domain" edge to the Domain entity was cleared.
func (m *AliasMutation) DomainCleared() bool {
return m.DomainIDCleared() || m.cleareddomain
}
// DomainIDs returns the "domain" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// DomainID instead. It exists only for internal usage by the builders.
func (m *AliasMutation) DomainIDs() (ids []int64) {
if id := m.domain; id != nil {
ids = append(ids, *id)
}
return
}
// ResetDomain resets all changes to the "domain" edge.
func (m *AliasMutation) ResetDomain() {
m.domain = nil
m.cleareddomain = false
}
// Where appends a list predicates to the AliasMutation builder.
func (m *AliasMutation) Where(ps ...predicate.Alias) {
m.predicates = append(m.predicates, ps...)
}
// Op returns the operation name.
func (m *AliasMutation) Op() Op {
return m.op
}
// Type returns the node type of this mutation (Alias).
func (m *AliasMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *AliasMutation) Fields() []string {
fields := make([]string, 0, 5)
if m.created != nil {
fields = append(fields, alias.FieldCreated)
}
if m.modified != nil {
fields = append(fields, alias.FieldModified)
}
if m.domain != nil {
fields = append(fields, alias.FieldDomainID)
}
if m._goto != nil {
fields = append(fields, alias.FieldGoto)
}
if m.active != nil {
fields = append(fields, alias.FieldActive)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *AliasMutation) Field(name string) (ent.Value, bool) {
switch name {
case alias.FieldCreated:
return m.Created()
case alias.FieldModified:
return m.Modified()
case alias.FieldDomainID:
return m.DomainID()
case alias.FieldGoto:
return m.Goto()
case alias.FieldActive:
return m.Active()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *AliasMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case alias.FieldCreated:
return m.OldCreated(ctx)
case alias.FieldModified:
return m.OldModified(ctx)
case alias.FieldDomainID:
return m.OldDomainID(ctx)
case alias.FieldGoto:
return m.OldGoto(ctx)
case alias.FieldActive:
return m.OldActive(ctx)
}
return nil, fmt.Errorf("unknown Alias field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *AliasMutation) SetField(name string, value ent.Value) error {
switch name {
case alias.FieldCreated:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreated(v)
return nil
case alias.FieldModified:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetModified(v)
return nil
case alias.FieldDomainID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDomainID(v)
return nil
case alias.FieldGoto:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetGoto(v)
return nil
case alias.FieldActive:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetActive(v)
return nil
}
return fmt.Errorf("unknown Alias field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *AliasMutation) AddedFields() []string {
var fields []string
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *AliasMutation) AddedField(name string) (ent.Value, bool) {
switch name {
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *AliasMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Alias numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *AliasMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(alias.FieldModified) {
fields = append(fields, alias.FieldModified)
}
if m.FieldCleared(alias.FieldDomainID) {
fields = append(fields, alias.FieldDomainID)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *AliasMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *AliasMutation) ClearField(name string) error {
switch name {
case alias.FieldModified:
m.ClearModified()
return nil
case alias.FieldDomainID:
m.ClearDomainID()
return nil
}
return fmt.Errorf("unknown Alias nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *AliasMutation) ResetField(name string) error {
switch name {
case alias.FieldCreated:
m.ResetCreated()
return nil
case alias.FieldModified:
m.ResetModified()
return nil
case alias.FieldDomainID:
m.ResetDomainID()
return nil
case alias.FieldGoto:
m.ResetGoto()
return nil
case alias.FieldActive:
m.ResetActive()
return nil
}
return fmt.Errorf("unknown Alias field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *AliasMutation) AddedEdges() []string {
edges := make([]string, 0, 1)
if m.domain != nil {
edges = append(edges, alias.EdgeDomain)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *AliasMutation) AddedIDs(name string) []ent.Value {
switch name {
case alias.EdgeDomain:
if id := m.domain; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *AliasMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *AliasMutation) RemovedIDs(name string) []ent.Value {
switch name {
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *AliasMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
if m.cleareddomain {
edges = append(edges, alias.EdgeDomain)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *AliasMutation) EdgeCleared(name string) bool {
switch name {
case alias.EdgeDomain:
return m.cleareddomain
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *AliasMutation) ClearEdge(name string) error {
switch name {
case alias.EdgeDomain:
m.ClearDomain()
return nil
}
return fmt.Errorf("unknown Alias unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *AliasMutation) ResetEdge(name string) error {
switch name {
case alias.EdgeDomain:
m.ResetDomain()
return nil
}
return fmt.Errorf("unknown Alias edge %s", name)
}
// DomainMutation represents an operation that mutates the Domain nodes in the graph.
type DomainMutation struct {
config
op Op
typ string
id *int64
created *time.Time
modified *time.Time
domain *string
description *string
max_aliases *int64
addmax_aliases *int64
max_mailboxes *int64
addmax_mailboxes *int64
max_quota *int64
addmax_quota *int64
quota *int64
addquota *int64
transport *string
backup_mx *bool
active *bool
clearedFields map[string]struct{}
mailboxes map[int64]struct{}
removedmailboxes map[int64]struct{}
clearedmailboxes bool
aliases map[int64]struct{}
removedaliases map[int64]struct{}
clearedaliases bool
logs map[int64]struct{}
removedlogs map[int64]struct{}
clearedlogs bool
accounts map[int64]struct{}
removedaccounts map[int64]struct{}
clearedaccounts bool
done bool
oldValue func(context.Context) (*Domain, error)
predicates []predicate.Domain
}
var _ ent.Mutation = (*DomainMutation)(nil)
// domainOption allows management of the mutation configuration using functional options.
type domainOption func(*DomainMutation)
// newDomainMutation creates new mutation for the Domain entity.
func newDomainMutation(c config, op Op, opts ...domainOption) *DomainMutation {
m := &DomainMutation{
config: c,
op: op,
typ: TypeDomain,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withDomainID sets the ID field of the mutation.
func withDomainID(id int64) domainOption {
return func(m *DomainMutation) {
var (
err error
once sync.Once
value *Domain
)
m.oldValue = func(ctx context.Context) (*Domain, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Domain.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withDomain sets the old Domain of the mutation.
func withDomain(node *Domain) domainOption {
return func(m *DomainMutation) {
m.oldValue = func(context.Context) (*Domain, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m DomainMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m DomainMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Domain entities.
func (m *DomainMutation) SetID(id int64) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *DomainMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *DomainMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Domain.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetCreated sets the "created" field.
func (m *DomainMutation) SetCreated(t time.Time) {
m.created = &t
}
// Created returns the value of the "created" field in the mutation.
func (m *DomainMutation) Created() (r time.Time, exists bool) {
v := m.created
if v == nil {
return
}
return *v, true
}
// OldCreated returns the old "created" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldCreated(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreated is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreated requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreated: %w", err)
}
return oldValue.Created, nil
}
// ResetCreated resets all changes to the "created" field.
func (m *DomainMutation) ResetCreated() {
m.created = nil
}
// SetModified sets the "modified" field.
func (m *DomainMutation) SetModified(t time.Time) {
m.modified = &t
}
// Modified returns the value of the "modified" field in the mutation.
func (m *DomainMutation) Modified() (r time.Time, exists bool) {
v := m.modified
if v == nil {
return
}
return *v, true
}
// OldModified returns the old "modified" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldModified(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldModified is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldModified requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldModified: %w", err)
}
return oldValue.Modified, nil
}
// ClearModified clears the value of the "modified" field.
func (m *DomainMutation) ClearModified() {
m.modified = nil
m.clearedFields[domain.FieldModified] = struct{}{}
}
// ModifiedCleared returns if the "modified" field was cleared in this mutation.
func (m *DomainMutation) ModifiedCleared() bool {
_, ok := m.clearedFields[domain.FieldModified]
return ok
}
// ResetModified resets all changes to the "modified" field.
func (m *DomainMutation) ResetModified() {
m.modified = nil
delete(m.clearedFields, domain.FieldModified)
}
// SetDomain sets the "domain" field.
func (m *DomainMutation) SetDomain(s string) {
m.domain = &s
}
// Domain returns the value of the "domain" field in the mutation.
func (m *DomainMutation) Domain() (r string, exists bool) {
v := m.domain
if v == nil {
return
}
return *v, true
}
// OldDomain returns the old "domain" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldDomain(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDomain is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDomain requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDomain: %w", err)
}
return oldValue.Domain, nil
}
// ResetDomain resets all changes to the "domain" field.
func (m *DomainMutation) ResetDomain() {
m.domain = nil
}
// SetDescription sets the "description" field.
func (m *DomainMutation) SetDescription(s string) {
m.description = &s
}
// Description returns the value of the "description" field in the mutation.
func (m *DomainMutation) Description() (r string, exists bool) {
v := m.description
if v == nil {
return
}
return *v, true
}
// OldDescription returns the old "description" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldDescription(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDescription is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDescription requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDescription: %w", err)
}
return oldValue.Description, nil
}
// ClearDescription clears the value of the "description" field.
func (m *DomainMutation) ClearDescription() {
m.description = nil
m.clearedFields[domain.FieldDescription] = struct{}{}
}
// DescriptionCleared returns if the "description" field was cleared in this mutation.
func (m *DomainMutation) DescriptionCleared() bool {
_, ok := m.clearedFields[domain.FieldDescription]
return ok
}
// ResetDescription resets all changes to the "description" field.
func (m *DomainMutation) ResetDescription() {
m.description = nil
delete(m.clearedFields, domain.FieldDescription)
}
// SetMaxAliases sets the "max_aliases" field.
func (m *DomainMutation) SetMaxAliases(i int64) {
m.max_aliases = &i
m.addmax_aliases = nil
}
// MaxAliases returns the value of the "max_aliases" field in the mutation.
func (m *DomainMutation) MaxAliases() (r int64, exists bool) {
v := m.max_aliases
if v == nil {
return
}
return *v, true
}
// OldMaxAliases returns the old "max_aliases" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldMaxAliases(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMaxAliases is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMaxAliases requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMaxAliases: %w", err)
}
return oldValue.MaxAliases, nil
}
// AddMaxAliases adds i to the "max_aliases" field.
func (m *DomainMutation) AddMaxAliases(i int64) {
if m.addmax_aliases != nil {
*m.addmax_aliases += i
} else {
m.addmax_aliases = &i
}
}
// AddedMaxAliases returns the value that was added to the "max_aliases" field in this mutation.
func (m *DomainMutation) AddedMaxAliases() (r int64, exists bool) {
v := m.addmax_aliases
if v == nil {
return
}
return *v, true
}
// ResetMaxAliases resets all changes to the "max_aliases" field.
func (m *DomainMutation) ResetMaxAliases() {
m.max_aliases = nil
m.addmax_aliases = nil
}
// SetMaxMailboxes sets the "max_mailboxes" field.
func (m *DomainMutation) SetMaxMailboxes(i int64) {
m.max_mailboxes = &i
m.addmax_mailboxes = nil
}
// MaxMailboxes returns the value of the "max_mailboxes" field in the mutation.
func (m *DomainMutation) MaxMailboxes() (r int64, exists bool) {
v := m.max_mailboxes
if v == nil {
return
}
return *v, true
}
// OldMaxMailboxes returns the old "max_mailboxes" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldMaxMailboxes(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMaxMailboxes is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMaxMailboxes requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMaxMailboxes: %w", err)
}
return oldValue.MaxMailboxes, nil
}
// AddMaxMailboxes adds i to the "max_mailboxes" field.
func (m *DomainMutation) AddMaxMailboxes(i int64) {
if m.addmax_mailboxes != nil {
*m.addmax_mailboxes += i
} else {
m.addmax_mailboxes = &i
}
}
// AddedMaxMailboxes returns the value that was added to the "max_mailboxes" field in this mutation.
func (m *DomainMutation) AddedMaxMailboxes() (r int64, exists bool) {
v := m.addmax_mailboxes
if v == nil {
return
}
return *v, true
}
// ResetMaxMailboxes resets all changes to the "max_mailboxes" field.
func (m *DomainMutation) ResetMaxMailboxes() {
m.max_mailboxes = nil
m.addmax_mailboxes = nil
}
// SetMaxQuota sets the "max_quota" field.
func (m *DomainMutation) SetMaxQuota(i int64) {
m.max_quota = &i
m.addmax_quota = nil
}
// MaxQuota returns the value of the "max_quota" field in the mutation.
func (m *DomainMutation) MaxQuota() (r int64, exists bool) {
v := m.max_quota
if v == nil {
return
}
return *v, true
}
// OldMaxQuota returns the old "max_quota" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldMaxQuota(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMaxQuota is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMaxQuota requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMaxQuota: %w", err)
}
return oldValue.MaxQuota, nil
}
// AddMaxQuota adds i to the "max_quota" field.
func (m *DomainMutation) AddMaxQuota(i int64) {
if m.addmax_quota != nil {
*m.addmax_quota += i
} else {
m.addmax_quota = &i
}
}
// AddedMaxQuota returns the value that was added to the "max_quota" field in this mutation.
func (m *DomainMutation) AddedMaxQuota() (r int64, exists bool) {
v := m.addmax_quota
if v == nil {
return
}
return *v, true
}
// ResetMaxQuota resets all changes to the "max_quota" field.
func (m *DomainMutation) ResetMaxQuota() {
m.max_quota = nil
m.addmax_quota = nil
}
// SetQuota sets the "quota" field.
func (m *DomainMutation) SetQuota(i int64) {
m.quota = &i
m.addquota = nil
}
// Quota returns the value of the "quota" field in the mutation.
func (m *DomainMutation) Quota() (r int64, exists bool) {
v := m.quota
if v == nil {
return
}
return *v, true
}
// OldQuota returns the old "quota" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldQuota(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldQuota is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldQuota requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldQuota: %w", err)
}
return oldValue.Quota, nil
}
// AddQuota adds i to the "quota" field.
func (m *DomainMutation) AddQuota(i int64) {
if m.addquota != nil {
*m.addquota += i
} else {
m.addquota = &i
}
}
// AddedQuota returns the value that was added to the "quota" field in this mutation.
func (m *DomainMutation) AddedQuota() (r int64, exists bool) {
v := m.addquota
if v == nil {
return
}
return *v, true
}
// ResetQuota resets all changes to the "quota" field.
func (m *DomainMutation) ResetQuota() {
m.quota = nil
m.addquota = nil
}
// SetTransport sets the "transport" field.
func (m *DomainMutation) SetTransport(s string) {
m.transport = &s
}
// Transport returns the value of the "transport" field in the mutation.
func (m *DomainMutation) Transport() (r string, exists bool) {
v := m.transport
if v == nil {
return
}
return *v, true
}
// OldTransport returns the old "transport" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldTransport(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTransport is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTransport requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTransport: %w", err)
}
return oldValue.Transport, nil
}
// ResetTransport resets all changes to the "transport" field.
func (m *DomainMutation) ResetTransport() {
m.transport = nil
}
// SetBackupMx sets the "backup_mx" field.
func (m *DomainMutation) SetBackupMx(b bool) {
m.backup_mx = &b
}
// BackupMx returns the value of the "backup_mx" field in the mutation.
func (m *DomainMutation) BackupMx() (r bool, exists bool) {
v := m.backup_mx
if v == nil {
return
}
return *v, true
}
// OldBackupMx returns the old "backup_mx" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldBackupMx(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldBackupMx is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldBackupMx requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldBackupMx: %w", err)
}
return oldValue.BackupMx, nil
}
// ResetBackupMx resets all changes to the "backup_mx" field.
func (m *DomainMutation) ResetBackupMx() {
m.backup_mx = nil
}
// SetActive sets the "active" field.
func (m *DomainMutation) SetActive(b bool) {
m.active = &b
}
// Active returns the value of the "active" field in the mutation.
func (m *DomainMutation) Active() (r bool, exists bool) {
v := m.active
if v == nil {
return
}
return *v, true
}
// OldActive returns the old "active" field's value of the Domain entity.
// If the Domain object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *DomainMutation) OldActive(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldActive is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldActive requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldActive: %w", err)
}
return oldValue.Active, nil
}
// ResetActive resets all changes to the "active" field.
func (m *DomainMutation) ResetActive() {
m.active = nil
}
// AddMailboxIDs adds the "mailboxes" edge to the Mailbox entity by ids.
func (m *DomainMutation) AddMailboxIDs(ids ...int64) {
if m.mailboxes == nil {
m.mailboxes = make(map[int64]struct{})
}
for i := range ids {
m.mailboxes[ids[i]] = struct{}{}
}
}
// ClearMailboxes clears the "mailboxes" edge to the Mailbox entity.
func (m *DomainMutation) ClearMailboxes() {
m.clearedmailboxes = true
}
// MailboxesCleared reports if the "mailboxes" edge to the Mailbox entity was cleared.
func (m *DomainMutation) MailboxesCleared() bool {
return m.clearedmailboxes
}
// RemoveMailboxIDs removes the "mailboxes" edge to the Mailbox entity by IDs.
func (m *DomainMutation) RemoveMailboxIDs(ids ...int64) {
if m.removedmailboxes == nil {
m.removedmailboxes = make(map[int64]struct{})
}
for i := range ids {
delete(m.mailboxes, ids[i])
m.removedmailboxes[ids[i]] = struct{}{}
}
}
// RemovedMailboxes returns the removed IDs of the "mailboxes" edge to the Mailbox entity.
func (m *DomainMutation) RemovedMailboxesIDs() (ids []int64) {
for id := range m.removedmailboxes {
ids = append(ids, id)
}
return
}
// MailboxesIDs returns the "mailboxes" edge IDs in the mutation.
func (m *DomainMutation) MailboxesIDs() (ids []int64) {
for id := range m.mailboxes {
ids = append(ids, id)
}
return
}
// ResetMailboxes resets all changes to the "mailboxes" edge.
func (m *DomainMutation) ResetMailboxes() {
m.mailboxes = nil
m.clearedmailboxes = false
m.removedmailboxes = nil
}
// AddAliasIDs adds the "aliases" edge to the Alias entity by ids.
func (m *DomainMutation) AddAliasIDs(ids ...int64) {
if m.aliases == nil {
m.aliases = make(map[int64]struct{})
}
for i := range ids {
m.aliases[ids[i]] = struct{}{}
}
}
// ClearAliases clears the "aliases" edge to the Alias entity.
func (m *DomainMutation) ClearAliases() {
m.clearedaliases = true
}
// AliasesCleared reports if the "aliases" edge to the Alias entity was cleared.
func (m *DomainMutation) AliasesCleared() bool {
return m.clearedaliases
}
// RemoveAliasIDs removes the "aliases" edge to the Alias entity by IDs.
func (m *DomainMutation) RemoveAliasIDs(ids ...int64) {
if m.removedaliases == nil {
m.removedaliases = make(map[int64]struct{})
}
for i := range ids {
delete(m.aliases, ids[i])
m.removedaliases[ids[i]] = struct{}{}
}
}
// RemovedAliases returns the removed IDs of the "aliases" edge to the Alias entity.
func (m *DomainMutation) RemovedAliasesIDs() (ids []int64) {
for id := range m.removedaliases {
ids = append(ids, id)
}
return
}
// AliasesIDs returns the "aliases" edge IDs in the mutation.
func (m *DomainMutation) AliasesIDs() (ids []int64) {
for id := range m.aliases {
ids = append(ids, id)
}
return
}
// ResetAliases resets all changes to the "aliases" edge.
func (m *DomainMutation) ResetAliases() {
m.aliases = nil
m.clearedaliases = false
m.removedaliases = nil
}
// AddLogIDs adds the "logs" edge to the Logentry entity by ids.
func (m *DomainMutation) AddLogIDs(ids ...int64) {
if m.logs == nil {
m.logs = make(map[int64]struct{})
}
for i := range ids {
m.logs[ids[i]] = struct{}{}
}
}
// ClearLogs clears the "logs" edge to the Logentry entity.
func (m *DomainMutation) ClearLogs() {
m.clearedlogs = true
}
// LogsCleared reports if the "logs" edge to the Logentry entity was cleared.
func (m *DomainMutation) LogsCleared() bool {
return m.clearedlogs
}
// RemoveLogIDs removes the "logs" edge to the Logentry entity by IDs.
func (m *DomainMutation) RemoveLogIDs(ids ...int64) {
if m.removedlogs == nil {
m.removedlogs = make(map[int64]struct{})
}
for i := range ids {
delete(m.logs, ids[i])
m.removedlogs[ids[i]] = struct{}{}
}
}
// RemovedLogs returns the removed IDs of the "logs" edge to the Logentry entity.
func (m *DomainMutation) RemovedLogsIDs() (ids []int64) {
for id := range m.removedlogs {
ids = append(ids, id)
}
return
}
// LogsIDs returns the "logs" edge IDs in the mutation.
func (m *DomainMutation) LogsIDs() (ids []int64) {
for id := range m.logs {
ids = append(ids, id)
}
return
}
// ResetLogs resets all changes to the "logs" edge.
func (m *DomainMutation) ResetLogs() {
m.logs = nil
m.clearedlogs = false
m.removedlogs = nil
}
// AddAccountIDs adds the "accounts" edge to the Account entity by ids.
func (m *DomainMutation) AddAccountIDs(ids ...int64) {
if m.accounts == nil {
m.accounts = make(map[int64]struct{})
}
for i := range ids {
m.accounts[ids[i]] = struct{}{}
}
}
// ClearAccounts clears the "accounts" edge to the Account entity.
func (m *DomainMutation) ClearAccounts() {
m.clearedaccounts = true
}
// AccountsCleared reports if the "accounts" edge to the Account entity was cleared.
func (m *DomainMutation) AccountsCleared() bool {
return m.clearedaccounts
}
// RemoveAccountIDs removes the "accounts" edge to the Account entity by IDs.
func (m *DomainMutation) RemoveAccountIDs(ids ...int64) {
if m.removedaccounts == nil {
m.removedaccounts = make(map[int64]struct{})
}
for i := range ids {
delete(m.accounts, ids[i])
m.removedaccounts[ids[i]] = struct{}{}
}
}
// RemovedAccounts returns the removed IDs of the "accounts" edge to the Account entity.
func (m *DomainMutation) RemovedAccountsIDs() (ids []int64) {
for id := range m.removedaccounts {
ids = append(ids, id)
}
return
}
// AccountsIDs returns the "accounts" edge IDs in the mutation.
func (m *DomainMutation) AccountsIDs() (ids []int64) {
for id := range m.accounts {
ids = append(ids, id)
}
return
}
// ResetAccounts resets all changes to the "accounts" edge.
func (m *DomainMutation) ResetAccounts() {
m.accounts = nil
m.clearedaccounts = false
m.removedaccounts = nil
}
// Where appends a list predicates to the DomainMutation builder.
func (m *DomainMutation) Where(ps ...predicate.Domain) {
m.predicates = append(m.predicates, ps...)
}
// Op returns the operation name.
func (m *DomainMutation) Op() Op {
return m.op
}
// Type returns the node type of this mutation (Domain).
func (m *DomainMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *DomainMutation) Fields() []string {
fields := make([]string, 0, 11)
if m.created != nil {
fields = append(fields, domain.FieldCreated)
}
if m.modified != nil {
fields = append(fields, domain.FieldModified)
}
if m.domain != nil {
fields = append(fields, domain.FieldDomain)
}
if m.description != nil {
fields = append(fields, domain.FieldDescription)
}
if m.max_aliases != nil {
fields = append(fields, domain.FieldMaxAliases)
}
if m.max_mailboxes != nil {
fields = append(fields, domain.FieldMaxMailboxes)
}
if m.max_quota != nil {
fields = append(fields, domain.FieldMaxQuota)
}
if m.quota != nil {
fields = append(fields, domain.FieldQuota)
}
if m.transport != nil {
fields = append(fields, domain.FieldTransport)
}
if m.backup_mx != nil {
fields = append(fields, domain.FieldBackupMx)
}
if m.active != nil {
fields = append(fields, domain.FieldActive)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *DomainMutation) Field(name string) (ent.Value, bool) {
switch name {
case domain.FieldCreated:
return m.Created()
case domain.FieldModified:
return m.Modified()
case domain.FieldDomain:
return m.Domain()
case domain.FieldDescription:
return m.Description()
case domain.FieldMaxAliases:
return m.MaxAliases()
case domain.FieldMaxMailboxes:
return m.MaxMailboxes()
case domain.FieldMaxQuota:
return m.MaxQuota()
case domain.FieldQuota:
return m.Quota()
case domain.FieldTransport:
return m.Transport()
case domain.FieldBackupMx:
return m.BackupMx()
case domain.FieldActive:
return m.Active()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *DomainMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case domain.FieldCreated:
return m.OldCreated(ctx)
case domain.FieldModified:
return m.OldModified(ctx)
case domain.FieldDomain:
return m.OldDomain(ctx)
case domain.FieldDescription:
return m.OldDescription(ctx)
case domain.FieldMaxAliases:
return m.OldMaxAliases(ctx)
case domain.FieldMaxMailboxes:
return m.OldMaxMailboxes(ctx)
case domain.FieldMaxQuota:
return m.OldMaxQuota(ctx)
case domain.FieldQuota:
return m.OldQuota(ctx)
case domain.FieldTransport:
return m.OldTransport(ctx)
case domain.FieldBackupMx:
return m.OldBackupMx(ctx)
case domain.FieldActive:
return m.OldActive(ctx)
}
return nil, fmt.Errorf("unknown Domain field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *DomainMutation) SetField(name string, value ent.Value) error {
switch name {
case domain.FieldCreated:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreated(v)
return nil
case domain.FieldModified:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetModified(v)
return nil
case domain.FieldDomain:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDomain(v)
return nil
case domain.FieldDescription:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDescription(v)
return nil
case domain.FieldMaxAliases:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMaxAliases(v)
return nil
case domain.FieldMaxMailboxes:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMaxMailboxes(v)
return nil
case domain.FieldMaxQuota:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMaxQuota(v)
return nil
case domain.FieldQuota:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetQuota(v)
return nil
case domain.FieldTransport:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTransport(v)
return nil
case domain.FieldBackupMx:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetBackupMx(v)
return nil
case domain.FieldActive:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetActive(v)
return nil
}
return fmt.Errorf("unknown Domain field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *DomainMutation) AddedFields() []string {
var fields []string
if m.addmax_aliases != nil {
fields = append(fields, domain.FieldMaxAliases)
}
if m.addmax_mailboxes != nil {
fields = append(fields, domain.FieldMaxMailboxes)
}
if m.addmax_quota != nil {
fields = append(fields, domain.FieldMaxQuota)
}
if m.addquota != nil {
fields = append(fields, domain.FieldQuota)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *DomainMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case domain.FieldMaxAliases:
return m.AddedMaxAliases()
case domain.FieldMaxMailboxes:
return m.AddedMaxMailboxes()
case domain.FieldMaxQuota:
return m.AddedMaxQuota()
case domain.FieldQuota:
return m.AddedQuota()
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *DomainMutation) AddField(name string, value ent.Value) error {
switch name {
case domain.FieldMaxAliases:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddMaxAliases(v)
return nil
case domain.FieldMaxMailboxes:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddMaxMailboxes(v)
return nil
case domain.FieldMaxQuota:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddMaxQuota(v)
return nil
case domain.FieldQuota:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddQuota(v)
return nil
}
return fmt.Errorf("unknown Domain numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *DomainMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(domain.FieldModified) {
fields = append(fields, domain.FieldModified)
}
if m.FieldCleared(domain.FieldDescription) {
fields = append(fields, domain.FieldDescription)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *DomainMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *DomainMutation) ClearField(name string) error {
switch name {
case domain.FieldModified:
m.ClearModified()
return nil
case domain.FieldDescription:
m.ClearDescription()
return nil
}
return fmt.Errorf("unknown Domain nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *DomainMutation) ResetField(name string) error {
switch name {
case domain.FieldCreated:
m.ResetCreated()
return nil
case domain.FieldModified:
m.ResetModified()
return nil
case domain.FieldDomain:
m.ResetDomain()
return nil
case domain.FieldDescription:
m.ResetDescription()
return nil
case domain.FieldMaxAliases:
m.ResetMaxAliases()
return nil
case domain.FieldMaxMailboxes:
m.ResetMaxMailboxes()
return nil
case domain.FieldMaxQuota:
m.ResetMaxQuota()
return nil
case domain.FieldQuota:
m.ResetQuota()
return nil
case domain.FieldTransport:
m.ResetTransport()
return nil
case domain.FieldBackupMx:
m.ResetBackupMx()
return nil
case domain.FieldActive:
m.ResetActive()
return nil
}
return fmt.Errorf("unknown Domain field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *DomainMutation) AddedEdges() []string {
edges := make([]string, 0, 4)
if m.mailboxes != nil {
edges = append(edges, domain.EdgeMailboxes)
}
if m.aliases != nil {
edges = append(edges, domain.EdgeAliases)
}
if m.logs != nil {
edges = append(edges, domain.EdgeLogs)
}
if m.accounts != nil {
edges = append(edges, domain.EdgeAccounts)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *DomainMutation) AddedIDs(name string) []ent.Value {
switch name {
case domain.EdgeMailboxes:
ids := make([]ent.Value, 0, len(m.mailboxes))
for id := range m.mailboxes {
ids = append(ids, id)
}
return ids
case domain.EdgeAliases:
ids := make([]ent.Value, 0, len(m.aliases))
for id := range m.aliases {
ids = append(ids, id)
}
return ids
case domain.EdgeLogs:
ids := make([]ent.Value, 0, len(m.logs))
for id := range m.logs {
ids = append(ids, id)
}
return ids
case domain.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.accounts))
for id := range m.accounts {
ids = append(ids, id)
}
return ids
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *DomainMutation) RemovedEdges() []string {
edges := make([]string, 0, 4)
if m.removedmailboxes != nil {
edges = append(edges, domain.EdgeMailboxes)
}
if m.removedaliases != nil {
edges = append(edges, domain.EdgeAliases)
}
if m.removedlogs != nil {
edges = append(edges, domain.EdgeLogs)
}
if m.removedaccounts != nil {
edges = append(edges, domain.EdgeAccounts)
}
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *DomainMutation) RemovedIDs(name string) []ent.Value {
switch name {
case domain.EdgeMailboxes:
ids := make([]ent.Value, 0, len(m.removedmailboxes))
for id := range m.removedmailboxes {
ids = append(ids, id)
}
return ids
case domain.EdgeAliases:
ids := make([]ent.Value, 0, len(m.removedaliases))
for id := range m.removedaliases {
ids = append(ids, id)
}
return ids
case domain.EdgeLogs:
ids := make([]ent.Value, 0, len(m.removedlogs))
for id := range m.removedlogs {
ids = append(ids, id)
}
return ids
case domain.EdgeAccounts:
ids := make([]ent.Value, 0, len(m.removedaccounts))
for id := range m.removedaccounts {
ids = append(ids, id)
}
return ids
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *DomainMutation) ClearedEdges() []string {
edges := make([]string, 0, 4)
if m.clearedmailboxes {
edges = append(edges, domain.EdgeMailboxes)
}
if m.clearedaliases {
edges = append(edges, domain.EdgeAliases)
}
if m.clearedlogs {
edges = append(edges, domain.EdgeLogs)
}
if m.clearedaccounts {
edges = append(edges, domain.EdgeAccounts)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *DomainMutation) EdgeCleared(name string) bool {
switch name {
case domain.EdgeMailboxes:
return m.clearedmailboxes
case domain.EdgeAliases:
return m.clearedaliases
case domain.EdgeLogs:
return m.clearedlogs
case domain.EdgeAccounts:
return m.clearedaccounts
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *DomainMutation) ClearEdge(name string) error {
switch name {
}
return fmt.Errorf("unknown Domain unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *DomainMutation) ResetEdge(name string) error {
switch name {
case domain.EdgeMailboxes:
m.ResetMailboxes()
return nil
case domain.EdgeAliases:
m.ResetAliases()
return nil
case domain.EdgeLogs:
m.ResetLogs()
return nil
case domain.EdgeAccounts:
m.ResetAccounts()
return nil
}
return fmt.Errorf("unknown Domain edge %s", name)
}
// LogentryMutation represents an operation that mutates the Logentry nodes in the graph.
type LogentryMutation struct {
config
op Op
typ string
id *int64
timestamp *time.Time
action *string
data *string
clearedFields map[string]struct{}
account *int64
clearedaccount bool
domain *int64
cleareddomain bool
done bool
oldValue func(context.Context) (*Logentry, error)
predicates []predicate.Logentry
}
var _ ent.Mutation = (*LogentryMutation)(nil)
// logentryOption allows management of the mutation configuration using functional options.
type logentryOption func(*LogentryMutation)
// newLogentryMutation creates new mutation for the Logentry entity.
func newLogentryMutation(c config, op Op, opts ...logentryOption) *LogentryMutation {
m := &LogentryMutation{
config: c,
op: op,
typ: TypeLogentry,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withLogentryID sets the ID field of the mutation.
func withLogentryID(id int64) logentryOption {
return func(m *LogentryMutation) {
var (
err error
once sync.Once
value *Logentry
)
m.oldValue = func(ctx context.Context) (*Logentry, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Logentry.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withLogentry sets the old Logentry of the mutation.
func withLogentry(node *Logentry) logentryOption {
return func(m *LogentryMutation) {
m.oldValue = func(context.Context) (*Logentry, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m LogentryMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m LogentryMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Logentry entities.
func (m *LogentryMutation) SetID(id int64) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *LogentryMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *LogentryMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Logentry.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetTimestamp sets the "timestamp" field.
func (m *LogentryMutation) SetTimestamp(t time.Time) {
m.timestamp = &t
}
// Timestamp returns the value of the "timestamp" field in the mutation.
func (m *LogentryMutation) Timestamp() (r time.Time, exists bool) {
v := m.timestamp
if v == nil {
return
}
return *v, true
}
// OldTimestamp returns the old "timestamp" field's value of the Logentry entity.
// If the Logentry object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *LogentryMutation) OldTimestamp(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldTimestamp is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldTimestamp requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldTimestamp: %w", err)
}
return oldValue.Timestamp, nil
}
// ResetTimestamp resets all changes to the "timestamp" field.
func (m *LogentryMutation) ResetTimestamp() {
m.timestamp = nil
}
// SetAction sets the "action" field.
func (m *LogentryMutation) SetAction(s string) {
m.action = &s
}
// Action returns the value of the "action" field in the mutation.
func (m *LogentryMutation) Action() (r string, exists bool) {
v := m.action
if v == nil {
return
}
return *v, true
}
// OldAction returns the old "action" field's value of the Logentry entity.
// If the Logentry object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *LogentryMutation) OldAction(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAction is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldAction requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAction: %w", err)
}
return oldValue.Action, nil
}
// ResetAction resets all changes to the "action" field.
func (m *LogentryMutation) ResetAction() {
m.action = nil
}
// SetData sets the "data" field.
func (m *LogentryMutation) SetData(s string) {
m.data = &s
}
// Data returns the value of the "data" field in the mutation.
func (m *LogentryMutation) Data() (r string, exists bool) {
v := m.data
if v == nil {
return
}
return *v, true
}
// OldData returns the old "data" field's value of the Logentry entity.
// If the Logentry object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *LogentryMutation) OldData(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldData is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldData requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldData: %w", err)
}
return oldValue.Data, nil
}
// ClearData clears the value of the "data" field.
func (m *LogentryMutation) ClearData() {
m.data = nil
m.clearedFields[logentry.FieldData] = struct{}{}
}
// DataCleared returns if the "data" field was cleared in this mutation.
func (m *LogentryMutation) DataCleared() bool {
_, ok := m.clearedFields[logentry.FieldData]
return ok
}
// ResetData resets all changes to the "data" field.
func (m *LogentryMutation) ResetData() {
m.data = nil
delete(m.clearedFields, logentry.FieldData)
}
// SetAccountID sets the "account_id" field.
func (m *LogentryMutation) SetAccountID(i int64) {
m.account = &i
}
// AccountID returns the value of the "account_id" field in the mutation.
func (m *LogentryMutation) AccountID() (r int64, exists bool) {
v := m.account
if v == nil {
return
}
return *v, true
}
// OldAccountID returns the old "account_id" field's value of the Logentry entity.
// If the Logentry object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *LogentryMutation) OldAccountID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldAccountID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldAccountID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldAccountID: %w", err)
}
return oldValue.AccountID, nil
}
// ClearAccountID clears the value of the "account_id" field.
func (m *LogentryMutation) ClearAccountID() {
m.account = nil
m.clearedFields[logentry.FieldAccountID] = struct{}{}
}
// AccountIDCleared returns if the "account_id" field was cleared in this mutation.
func (m *LogentryMutation) AccountIDCleared() bool {
_, ok := m.clearedFields[logentry.FieldAccountID]
return ok
}
// ResetAccountID resets all changes to the "account_id" field.
func (m *LogentryMutation) ResetAccountID() {
m.account = nil
delete(m.clearedFields, logentry.FieldAccountID)
}
// SetDomainID sets the "domain_id" field.
func (m *LogentryMutation) SetDomainID(i int64) {
m.domain = &i
}
// DomainID returns the value of the "domain_id" field in the mutation.
func (m *LogentryMutation) DomainID() (r int64, exists bool) {
v := m.domain
if v == nil {
return
}
return *v, true
}
// OldDomainID returns the old "domain_id" field's value of the Logentry entity.
// If the Logentry object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *LogentryMutation) OldDomainID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDomainID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDomainID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDomainID: %w", err)
}
return oldValue.DomainID, nil
}
// ClearDomainID clears the value of the "domain_id" field.
func (m *LogentryMutation) ClearDomainID() {
m.domain = nil
m.clearedFields[logentry.FieldDomainID] = struct{}{}
}
// DomainIDCleared returns if the "domain_id" field was cleared in this mutation.
func (m *LogentryMutation) DomainIDCleared() bool {
_, ok := m.clearedFields[logentry.FieldDomainID]
return ok
}
// ResetDomainID resets all changes to the "domain_id" field.
func (m *LogentryMutation) ResetDomainID() {
m.domain = nil
delete(m.clearedFields, logentry.FieldDomainID)
}
// ClearAccount clears the "account" edge to the Account entity.
func (m *LogentryMutation) ClearAccount() {
m.clearedaccount = true
}
// AccountCleared reports if the "account" edge to the Account entity was cleared.
func (m *LogentryMutation) AccountCleared() bool {
return m.AccountIDCleared() || m.clearedaccount
}
// AccountIDs returns the "account" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// AccountID instead. It exists only for internal usage by the builders.
func (m *LogentryMutation) AccountIDs() (ids []int64) {
if id := m.account; id != nil {
ids = append(ids, *id)
}
return
}
// ResetAccount resets all changes to the "account" edge.
func (m *LogentryMutation) ResetAccount() {
m.account = nil
m.clearedaccount = false
}
// ClearDomain clears the "domain" edge to the Domain entity.
func (m *LogentryMutation) ClearDomain() {
m.cleareddomain = true
}
// DomainCleared reports if the "domain" edge to the Domain entity was cleared.
func (m *LogentryMutation) DomainCleared() bool {
return m.DomainIDCleared() || m.cleareddomain
}
// DomainIDs returns the "domain" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// DomainID instead. It exists only for internal usage by the builders.
func (m *LogentryMutation) DomainIDs() (ids []int64) {
if id := m.domain; id != nil {
ids = append(ids, *id)
}
return
}
// ResetDomain resets all changes to the "domain" edge.
func (m *LogentryMutation) ResetDomain() {
m.domain = nil
m.cleareddomain = false
}
// Where appends a list predicates to the LogentryMutation builder.
func (m *LogentryMutation) Where(ps ...predicate.Logentry) {
m.predicates = append(m.predicates, ps...)
}
// Op returns the operation name.
func (m *LogentryMutation) Op() Op {
return m.op
}
// Type returns the node type of this mutation (Logentry).
func (m *LogentryMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *LogentryMutation) Fields() []string {
fields := make([]string, 0, 5)
if m.timestamp != nil {
fields = append(fields, logentry.FieldTimestamp)
}
if m.action != nil {
fields = append(fields, logentry.FieldAction)
}
if m.data != nil {
fields = append(fields, logentry.FieldData)
}
if m.account != nil {
fields = append(fields, logentry.FieldAccountID)
}
if m.domain != nil {
fields = append(fields, logentry.FieldDomainID)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *LogentryMutation) Field(name string) (ent.Value, bool) {
switch name {
case logentry.FieldTimestamp:
return m.Timestamp()
case logentry.FieldAction:
return m.Action()
case logentry.FieldData:
return m.Data()
case logentry.FieldAccountID:
return m.AccountID()
case logentry.FieldDomainID:
return m.DomainID()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *LogentryMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case logentry.FieldTimestamp:
return m.OldTimestamp(ctx)
case logentry.FieldAction:
return m.OldAction(ctx)
case logentry.FieldData:
return m.OldData(ctx)
case logentry.FieldAccountID:
return m.OldAccountID(ctx)
case logentry.FieldDomainID:
return m.OldDomainID(ctx)
}
return nil, fmt.Errorf("unknown Logentry field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *LogentryMutation) SetField(name string, value ent.Value) error {
switch name {
case logentry.FieldTimestamp:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetTimestamp(v)
return nil
case logentry.FieldAction:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetAction(v)
return nil
case logentry.FieldData:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetData(v)
return nil
case logentry.FieldAccountID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetAccountID(v)
return nil
case logentry.FieldDomainID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDomainID(v)
return nil
}
return fmt.Errorf("unknown Logentry field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *LogentryMutation) AddedFields() []string {
var fields []string
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *LogentryMutation) AddedField(name string) (ent.Value, bool) {
switch name {
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *LogentryMutation) AddField(name string, value ent.Value) error {
switch name {
}
return fmt.Errorf("unknown Logentry numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *LogentryMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(logentry.FieldData) {
fields = append(fields, logentry.FieldData)
}
if m.FieldCleared(logentry.FieldAccountID) {
fields = append(fields, logentry.FieldAccountID)
}
if m.FieldCleared(logentry.FieldDomainID) {
fields = append(fields, logentry.FieldDomainID)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *LogentryMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *LogentryMutation) ClearField(name string) error {
switch name {
case logentry.FieldData:
m.ClearData()
return nil
case logentry.FieldAccountID:
m.ClearAccountID()
return nil
case logentry.FieldDomainID:
m.ClearDomainID()
return nil
}
return fmt.Errorf("unknown Logentry nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *LogentryMutation) ResetField(name string) error {
switch name {
case logentry.FieldTimestamp:
m.ResetTimestamp()
return nil
case logentry.FieldAction:
m.ResetAction()
return nil
case logentry.FieldData:
m.ResetData()
return nil
case logentry.FieldAccountID:
m.ResetAccountID()
return nil
case logentry.FieldDomainID:
m.ResetDomainID()
return nil
}
return fmt.Errorf("unknown Logentry field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *LogentryMutation) AddedEdges() []string {
edges := make([]string, 0, 2)
if m.account != nil {
edges = append(edges, logentry.EdgeAccount)
}
if m.domain != nil {
edges = append(edges, logentry.EdgeDomain)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *LogentryMutation) AddedIDs(name string) []ent.Value {
switch name {
case logentry.EdgeAccount:
if id := m.account; id != nil {
return []ent.Value{*id}
}
case logentry.EdgeDomain:
if id := m.domain; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *LogentryMutation) RemovedEdges() []string {
edges := make([]string, 0, 2)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *LogentryMutation) RemovedIDs(name string) []ent.Value {
switch name {
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *LogentryMutation) ClearedEdges() []string {
edges := make([]string, 0, 2)
if m.clearedaccount {
edges = append(edges, logentry.EdgeAccount)
}
if m.cleareddomain {
edges = append(edges, logentry.EdgeDomain)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *LogentryMutation) EdgeCleared(name string) bool {
switch name {
case logentry.EdgeAccount:
return m.clearedaccount
case logentry.EdgeDomain:
return m.cleareddomain
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *LogentryMutation) ClearEdge(name string) error {
switch name {
case logentry.EdgeAccount:
m.ClearAccount()
return nil
case logentry.EdgeDomain:
m.ClearDomain()
return nil
}
return fmt.Errorf("unknown Logentry unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *LogentryMutation) ResetEdge(name string) error {
switch name {
case logentry.EdgeAccount:
m.ResetAccount()
return nil
case logentry.EdgeDomain:
m.ResetDomain()
return nil
}
return fmt.Errorf("unknown Logentry edge %s", name)
}
// MailboxMutation represents an operation that mutates the Mailbox nodes in the graph.
type MailboxMutation struct {
config
op Op
typ string
id *int64
active *bool
created *time.Time
modified *time.Time
username *string
password *[]byte
name *string
quota *int64
addquota *int64
local_part *string
homedir *string
maildir *string
uid *int32
adduid *int32
gid *int32
addgid *int32
clearedFields map[string]struct{}
domain *int64
cleareddomain bool
done bool
oldValue func(context.Context) (*Mailbox, error)
predicates []predicate.Mailbox
}
var _ ent.Mutation = (*MailboxMutation)(nil)
// mailboxOption allows management of the mutation configuration using functional options.
type mailboxOption func(*MailboxMutation)
// newMailboxMutation creates new mutation for the Mailbox entity.
func newMailboxMutation(c config, op Op, opts ...mailboxOption) *MailboxMutation {
m := &MailboxMutation{
config: c,
op: op,
typ: TypeMailbox,
clearedFields: make(map[string]struct{}),
}
for _, opt := range opts {
opt(m)
}
return m
}
// withMailboxID sets the ID field of the mutation.
func withMailboxID(id int64) mailboxOption {
return func(m *MailboxMutation) {
var (
err error
once sync.Once
value *Mailbox
)
m.oldValue = func(ctx context.Context) (*Mailbox, error) {
once.Do(func() {
if m.done {
err = errors.New("querying old values post mutation is not allowed")
} else {
value, err = m.Client().Mailbox.Get(ctx, id)
}
})
return value, err
}
m.id = &id
}
}
// withMailbox sets the old Mailbox of the mutation.
func withMailbox(node *Mailbox) mailboxOption {
return func(m *MailboxMutation) {
m.oldValue = func(context.Context) (*Mailbox, error) {
return node, nil
}
m.id = &node.ID
}
}
// Client returns a new `ent.Client` from the mutation. If the mutation was
// executed in a transaction (ent.Tx), a transactional client is returned.
func (m MailboxMutation) Client() *Client {
client := &Client{config: m.config}
client.init()
return client
}
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
// it returns an error otherwise.
func (m MailboxMutation) Tx() (*Tx, error) {
if _, ok := m.driver.(*txDriver); !ok {
return nil, errors.New("ent: mutation is not running in a transaction")
}
tx := &Tx{config: m.config}
tx.init()
return tx, nil
}
// SetID sets the value of the id field. Note that this
// operation is only accepted on creation of Mailbox entities.
func (m *MailboxMutation) SetID(id int64) {
m.id = &id
}
// ID returns the ID value in the mutation. Note that the ID is only available
// if it was provided to the builder or after it was returned from the database.
func (m *MailboxMutation) ID() (id int64, exists bool) {
if m.id == nil {
return
}
return *m.id, true
}
// IDs queries the database and returns the entity ids that match the mutation's predicate.
// That means, if the mutation is applied within a transaction with an isolation level such
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
// or updated by the mutation.
func (m *MailboxMutation) IDs(ctx context.Context) ([]int64, error) {
switch {
case m.op.Is(OpUpdateOne | OpDeleteOne):
id, exists := m.ID()
if exists {
return []int64{id}, nil
}
fallthrough
case m.op.Is(OpUpdate | OpDelete):
return m.Client().Mailbox.Query().Where(m.predicates...).IDs(ctx)
default:
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
}
}
// SetActive sets the "active" field.
func (m *MailboxMutation) SetActive(b bool) {
m.active = &b
}
// Active returns the value of the "active" field in the mutation.
func (m *MailboxMutation) Active() (r bool, exists bool) {
v := m.active
if v == nil {
return
}
return *v, true
}
// OldActive returns the old "active" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldActive(ctx context.Context) (v bool, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldActive is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldActive requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldActive: %w", err)
}
return oldValue.Active, nil
}
// ResetActive resets all changes to the "active" field.
func (m *MailboxMutation) ResetActive() {
m.active = nil
}
// SetCreated sets the "created" field.
func (m *MailboxMutation) SetCreated(t time.Time) {
m.created = &t
}
// Created returns the value of the "created" field in the mutation.
func (m *MailboxMutation) Created() (r time.Time, exists bool) {
v := m.created
if v == nil {
return
}
return *v, true
}
// OldCreated returns the old "created" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldCreated(ctx context.Context) (v time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldCreated is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldCreated requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldCreated: %w", err)
}
return oldValue.Created, nil
}
// ResetCreated resets all changes to the "created" field.
func (m *MailboxMutation) ResetCreated() {
m.created = nil
}
// SetModified sets the "modified" field.
func (m *MailboxMutation) SetModified(t time.Time) {
m.modified = &t
}
// Modified returns the value of the "modified" field in the mutation.
func (m *MailboxMutation) Modified() (r time.Time, exists bool) {
v := m.modified
if v == nil {
return
}
return *v, true
}
// OldModified returns the old "modified" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldModified(ctx context.Context) (v *time.Time, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldModified is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldModified requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldModified: %w", err)
}
return oldValue.Modified, nil
}
// ClearModified clears the value of the "modified" field.
func (m *MailboxMutation) ClearModified() {
m.modified = nil
m.clearedFields[mailbox.FieldModified] = struct{}{}
}
// ModifiedCleared returns if the "modified" field was cleared in this mutation.
func (m *MailboxMutation) ModifiedCleared() bool {
_, ok := m.clearedFields[mailbox.FieldModified]
return ok
}
// ResetModified resets all changes to the "modified" field.
func (m *MailboxMutation) ResetModified() {
m.modified = nil
delete(m.clearedFields, mailbox.FieldModified)
}
// SetDomainID sets the "domain_id" field.
func (m *MailboxMutation) SetDomainID(i int64) {
m.domain = &i
}
// DomainID returns the value of the "domain_id" field in the mutation.
func (m *MailboxMutation) DomainID() (r int64, exists bool) {
v := m.domain
if v == nil {
return
}
return *v, true
}
// OldDomainID returns the old "domain_id" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldDomainID(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldDomainID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldDomainID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldDomainID: %w", err)
}
return oldValue.DomainID, nil
}
// ClearDomainID clears the value of the "domain_id" field.
func (m *MailboxMutation) ClearDomainID() {
m.domain = nil
m.clearedFields[mailbox.FieldDomainID] = struct{}{}
}
// DomainIDCleared returns if the "domain_id" field was cleared in this mutation.
func (m *MailboxMutation) DomainIDCleared() bool {
_, ok := m.clearedFields[mailbox.FieldDomainID]
return ok
}
// ResetDomainID resets all changes to the "domain_id" field.
func (m *MailboxMutation) ResetDomainID() {
m.domain = nil
delete(m.clearedFields, mailbox.FieldDomainID)
}
// SetUsername sets the "username" field.
func (m *MailboxMutation) SetUsername(s string) {
m.username = &s
}
// Username returns the value of the "username" field in the mutation.
func (m *MailboxMutation) Username() (r string, exists bool) {
v := m.username
if v == nil {
return
}
return *v, true
}
// OldUsername returns the old "username" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldUsername(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUsername is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUsername requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUsername: %w", err)
}
return oldValue.Username, nil
}
// ResetUsername resets all changes to the "username" field.
func (m *MailboxMutation) ResetUsername() {
m.username = nil
}
// SetPassword sets the "password" field.
func (m *MailboxMutation) SetPassword(b []byte) {
m.password = &b
}
// Password returns the value of the "password" field in the mutation.
func (m *MailboxMutation) Password() (r []byte, exists bool) {
v := m.password
if v == nil {
return
}
return *v, true
}
// OldPassword returns the old "password" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldPassword(ctx context.Context) (v []byte, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldPassword is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldPassword requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldPassword: %w", err)
}
return oldValue.Password, nil
}
// ResetPassword resets all changes to the "password" field.
func (m *MailboxMutation) ResetPassword() {
m.password = nil
}
// SetName sets the "name" field.
func (m *MailboxMutation) SetName(s string) {
m.name = &s
}
// Name returns the value of the "name" field in the mutation.
func (m *MailboxMutation) Name() (r string, exists bool) {
v := m.name
if v == nil {
return
}
return *v, true
}
// OldName returns the old "name" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldName(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldName is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldName requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldName: %w", err)
}
return oldValue.Name, nil
}
// ClearName clears the value of the "name" field.
func (m *MailboxMutation) ClearName() {
m.name = nil
m.clearedFields[mailbox.FieldName] = struct{}{}
}
// NameCleared returns if the "name" field was cleared in this mutation.
func (m *MailboxMutation) NameCleared() bool {
_, ok := m.clearedFields[mailbox.FieldName]
return ok
}
// ResetName resets all changes to the "name" field.
func (m *MailboxMutation) ResetName() {
m.name = nil
delete(m.clearedFields, mailbox.FieldName)
}
// SetQuota sets the "quota" field.
func (m *MailboxMutation) SetQuota(i int64) {
m.quota = &i
m.addquota = nil
}
// Quota returns the value of the "quota" field in the mutation.
func (m *MailboxMutation) Quota() (r int64, exists bool) {
v := m.quota
if v == nil {
return
}
return *v, true
}
// OldQuota returns the old "quota" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldQuota(ctx context.Context) (v int64, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldQuota is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldQuota requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldQuota: %w", err)
}
return oldValue.Quota, nil
}
// AddQuota adds i to the "quota" field.
func (m *MailboxMutation) AddQuota(i int64) {
if m.addquota != nil {
*m.addquota += i
} else {
m.addquota = &i
}
}
// AddedQuota returns the value that was added to the "quota" field in this mutation.
func (m *MailboxMutation) AddedQuota() (r int64, exists bool) {
v := m.addquota
if v == nil {
return
}
return *v, true
}
// ResetQuota resets all changes to the "quota" field.
func (m *MailboxMutation) ResetQuota() {
m.quota = nil
m.addquota = nil
}
// SetLocalPart sets the "local_part" field.
func (m *MailboxMutation) SetLocalPart(s string) {
m.local_part = &s
}
// LocalPart returns the value of the "local_part" field in the mutation.
func (m *MailboxMutation) LocalPart() (r string, exists bool) {
v := m.local_part
if v == nil {
return
}
return *v, true
}
// OldLocalPart returns the old "local_part" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldLocalPart(ctx context.Context) (v string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldLocalPart is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldLocalPart requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldLocalPart: %w", err)
}
return oldValue.LocalPart, nil
}
// ResetLocalPart resets all changes to the "local_part" field.
func (m *MailboxMutation) ResetLocalPart() {
m.local_part = nil
}
// SetHomedir sets the "homedir" field.
func (m *MailboxMutation) SetHomedir(s string) {
m.homedir = &s
}
// Homedir returns the value of the "homedir" field in the mutation.
func (m *MailboxMutation) Homedir() (r string, exists bool) {
v := m.homedir
if v == nil {
return
}
return *v, true
}
// OldHomedir returns the old "homedir" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldHomedir(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldHomedir is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldHomedir requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldHomedir: %w", err)
}
return oldValue.Homedir, nil
}
// ClearHomedir clears the value of the "homedir" field.
func (m *MailboxMutation) ClearHomedir() {
m.homedir = nil
m.clearedFields[mailbox.FieldHomedir] = struct{}{}
}
// HomedirCleared returns if the "homedir" field was cleared in this mutation.
func (m *MailboxMutation) HomedirCleared() bool {
_, ok := m.clearedFields[mailbox.FieldHomedir]
return ok
}
// ResetHomedir resets all changes to the "homedir" field.
func (m *MailboxMutation) ResetHomedir() {
m.homedir = nil
delete(m.clearedFields, mailbox.FieldHomedir)
}
// SetMaildir sets the "maildir" field.
func (m *MailboxMutation) SetMaildir(s string) {
m.maildir = &s
}
// Maildir returns the value of the "maildir" field in the mutation.
func (m *MailboxMutation) Maildir() (r string, exists bool) {
v := m.maildir
if v == nil {
return
}
return *v, true
}
// OldMaildir returns the old "maildir" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldMaildir(ctx context.Context) (v *string, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldMaildir is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldMaildir requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldMaildir: %w", err)
}
return oldValue.Maildir, nil
}
// ClearMaildir clears the value of the "maildir" field.
func (m *MailboxMutation) ClearMaildir() {
m.maildir = nil
m.clearedFields[mailbox.FieldMaildir] = struct{}{}
}
// MaildirCleared returns if the "maildir" field was cleared in this mutation.
func (m *MailboxMutation) MaildirCleared() bool {
_, ok := m.clearedFields[mailbox.FieldMaildir]
return ok
}
// ResetMaildir resets all changes to the "maildir" field.
func (m *MailboxMutation) ResetMaildir() {
m.maildir = nil
delete(m.clearedFields, mailbox.FieldMaildir)
}
// SetUID sets the "uid" field.
func (m *MailboxMutation) SetUID(i int32) {
m.uid = &i
m.adduid = nil
}
// UID returns the value of the "uid" field in the mutation.
func (m *MailboxMutation) UID() (r int32, exists bool) {
v := m.uid
if v == nil {
return
}
return *v, true
}
// OldUID returns the old "uid" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldUID(ctx context.Context) (v *int32, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldUID is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldUID requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldUID: %w", err)
}
return oldValue.UID, nil
}
// AddUID adds i to the "uid" field.
func (m *MailboxMutation) AddUID(i int32) {
if m.adduid != nil {
*m.adduid += i
} else {
m.adduid = &i
}
}
// AddedUID returns the value that was added to the "uid" field in this mutation.
func (m *MailboxMutation) AddedUID() (r int32, exists bool) {
v := m.adduid
if v == nil {
return
}
return *v, true
}
// ClearUID clears the value of the "uid" field.
func (m *MailboxMutation) ClearUID() {
m.uid = nil
m.adduid = nil
m.clearedFields[mailbox.FieldUID] = struct{}{}
}
// UIDCleared returns if the "uid" field was cleared in this mutation.
func (m *MailboxMutation) UIDCleared() bool {
_, ok := m.clearedFields[mailbox.FieldUID]
return ok
}
// ResetUID resets all changes to the "uid" field.
func (m *MailboxMutation) ResetUID() {
m.uid = nil
m.adduid = nil
delete(m.clearedFields, mailbox.FieldUID)
}
// SetGid sets the "gid" field.
func (m *MailboxMutation) SetGid(i int32) {
m.gid = &i
m.addgid = nil
}
// Gid returns the value of the "gid" field in the mutation.
func (m *MailboxMutation) Gid() (r int32, exists bool) {
v := m.gid
if v == nil {
return
}
return *v, true
}
// OldGid returns the old "gid" field's value of the Mailbox entity.
// If the Mailbox object wasn't provided to the builder, the object is fetched from the database.
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
func (m *MailboxMutation) OldGid(ctx context.Context) (v *int32, err error) {
if !m.op.Is(OpUpdateOne) {
return v, errors.New("OldGid is only allowed on UpdateOne operations")
}
if m.id == nil || m.oldValue == nil {
return v, errors.New("OldGid requires an ID field in the mutation")
}
oldValue, err := m.oldValue(ctx)
if err != nil {
return v, fmt.Errorf("querying old value for OldGid: %w", err)
}
return oldValue.Gid, nil
}
// AddGid adds i to the "gid" field.
func (m *MailboxMutation) AddGid(i int32) {
if m.addgid != nil {
*m.addgid += i
} else {
m.addgid = &i
}
}
// AddedGid returns the value that was added to the "gid" field in this mutation.
func (m *MailboxMutation) AddedGid() (r int32, exists bool) {
v := m.addgid
if v == nil {
return
}
return *v, true
}
// ClearGid clears the value of the "gid" field.
func (m *MailboxMutation) ClearGid() {
m.gid = nil
m.addgid = nil
m.clearedFields[mailbox.FieldGid] = struct{}{}
}
// GidCleared returns if the "gid" field was cleared in this mutation.
func (m *MailboxMutation) GidCleared() bool {
_, ok := m.clearedFields[mailbox.FieldGid]
return ok
}
// ResetGid resets all changes to the "gid" field.
func (m *MailboxMutation) ResetGid() {
m.gid = nil
m.addgid = nil
delete(m.clearedFields, mailbox.FieldGid)
}
// ClearDomain clears the "domain" edge to the Domain entity.
func (m *MailboxMutation) ClearDomain() {
m.cleareddomain = true
}
// DomainCleared reports if the "domain" edge to the Domain entity was cleared.
func (m *MailboxMutation) DomainCleared() bool {
return m.DomainIDCleared() || m.cleareddomain
}
// DomainIDs returns the "domain" edge IDs in the mutation.
// Note that IDs always returns len(IDs) <= 1 for unique edges, and you should use
// DomainID instead. It exists only for internal usage by the builders.
func (m *MailboxMutation) DomainIDs() (ids []int64) {
if id := m.domain; id != nil {
ids = append(ids, *id)
}
return
}
// ResetDomain resets all changes to the "domain" edge.
func (m *MailboxMutation) ResetDomain() {
m.domain = nil
m.cleareddomain = false
}
// Where appends a list predicates to the MailboxMutation builder.
func (m *MailboxMutation) Where(ps ...predicate.Mailbox) {
m.predicates = append(m.predicates, ps...)
}
// Op returns the operation name.
func (m *MailboxMutation) Op() Op {
return m.op
}
// Type returns the node type of this mutation (Mailbox).
func (m *MailboxMutation) Type() string {
return m.typ
}
// Fields returns all fields that were changed during this mutation. Note that in
// order to get all numeric fields that were incremented/decremented, call
// AddedFields().
func (m *MailboxMutation) Fields() []string {
fields := make([]string, 0, 13)
if m.active != nil {
fields = append(fields, mailbox.FieldActive)
}
if m.created != nil {
fields = append(fields, mailbox.FieldCreated)
}
if m.modified != nil {
fields = append(fields, mailbox.FieldModified)
}
if m.domain != nil {
fields = append(fields, mailbox.FieldDomainID)
}
if m.username != nil {
fields = append(fields, mailbox.FieldUsername)
}
if m.password != nil {
fields = append(fields, mailbox.FieldPassword)
}
if m.name != nil {
fields = append(fields, mailbox.FieldName)
}
if m.quota != nil {
fields = append(fields, mailbox.FieldQuota)
}
if m.local_part != nil {
fields = append(fields, mailbox.FieldLocalPart)
}
if m.homedir != nil {
fields = append(fields, mailbox.FieldHomedir)
}
if m.maildir != nil {
fields = append(fields, mailbox.FieldMaildir)
}
if m.uid != nil {
fields = append(fields, mailbox.FieldUID)
}
if m.gid != nil {
fields = append(fields, mailbox.FieldGid)
}
return fields
}
// Field returns the value of a field with the given name. The second boolean
// return value indicates that this field was not set, or was not defined in the
// schema.
func (m *MailboxMutation) Field(name string) (ent.Value, bool) {
switch name {
case mailbox.FieldActive:
return m.Active()
case mailbox.FieldCreated:
return m.Created()
case mailbox.FieldModified:
return m.Modified()
case mailbox.FieldDomainID:
return m.DomainID()
case mailbox.FieldUsername:
return m.Username()
case mailbox.FieldPassword:
return m.Password()
case mailbox.FieldName:
return m.Name()
case mailbox.FieldQuota:
return m.Quota()
case mailbox.FieldLocalPart:
return m.LocalPart()
case mailbox.FieldHomedir:
return m.Homedir()
case mailbox.FieldMaildir:
return m.Maildir()
case mailbox.FieldUID:
return m.UID()
case mailbox.FieldGid:
return m.Gid()
}
return nil, false
}
// OldField returns the old value of the field from the database. An error is
// returned if the mutation operation is not UpdateOne, or the query to the
// database failed.
func (m *MailboxMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
switch name {
case mailbox.FieldActive:
return m.OldActive(ctx)
case mailbox.FieldCreated:
return m.OldCreated(ctx)
case mailbox.FieldModified:
return m.OldModified(ctx)
case mailbox.FieldDomainID:
return m.OldDomainID(ctx)
case mailbox.FieldUsername:
return m.OldUsername(ctx)
case mailbox.FieldPassword:
return m.OldPassword(ctx)
case mailbox.FieldName:
return m.OldName(ctx)
case mailbox.FieldQuota:
return m.OldQuota(ctx)
case mailbox.FieldLocalPart:
return m.OldLocalPart(ctx)
case mailbox.FieldHomedir:
return m.OldHomedir(ctx)
case mailbox.FieldMaildir:
return m.OldMaildir(ctx)
case mailbox.FieldUID:
return m.OldUID(ctx)
case mailbox.FieldGid:
return m.OldGid(ctx)
}
return nil, fmt.Errorf("unknown Mailbox field %s", name)
}
// SetField sets the value of a field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *MailboxMutation) SetField(name string, value ent.Value) error {
switch name {
case mailbox.FieldActive:
v, ok := value.(bool)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetActive(v)
return nil
case mailbox.FieldCreated:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetCreated(v)
return nil
case mailbox.FieldModified:
v, ok := value.(time.Time)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetModified(v)
return nil
case mailbox.FieldDomainID:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetDomainID(v)
return nil
case mailbox.FieldUsername:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUsername(v)
return nil
case mailbox.FieldPassword:
v, ok := value.([]byte)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetPassword(v)
return nil
case mailbox.FieldName:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetName(v)
return nil
case mailbox.FieldQuota:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetQuota(v)
return nil
case mailbox.FieldLocalPart:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetLocalPart(v)
return nil
case mailbox.FieldHomedir:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetHomedir(v)
return nil
case mailbox.FieldMaildir:
v, ok := value.(string)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetMaildir(v)
return nil
case mailbox.FieldUID:
v, ok := value.(int32)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetUID(v)
return nil
case mailbox.FieldGid:
v, ok := value.(int32)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.SetGid(v)
return nil
}
return fmt.Errorf("unknown Mailbox field %s", name)
}
// AddedFields returns all numeric fields that were incremented/decremented during
// this mutation.
func (m *MailboxMutation) AddedFields() []string {
var fields []string
if m.addquota != nil {
fields = append(fields, mailbox.FieldQuota)
}
if m.adduid != nil {
fields = append(fields, mailbox.FieldUID)
}
if m.addgid != nil {
fields = append(fields, mailbox.FieldGid)
}
return fields
}
// AddedField returns the numeric value that was incremented/decremented on a field
// with the given name. The second boolean return value indicates that this field
// was not set, or was not defined in the schema.
func (m *MailboxMutation) AddedField(name string) (ent.Value, bool) {
switch name {
case mailbox.FieldQuota:
return m.AddedQuota()
case mailbox.FieldUID:
return m.AddedUID()
case mailbox.FieldGid:
return m.AddedGid()
}
return nil, false
}
// AddField adds the value to the field with the given name. It returns an error if
// the field is not defined in the schema, or if the type mismatched the field
// type.
func (m *MailboxMutation) AddField(name string, value ent.Value) error {
switch name {
case mailbox.FieldQuota:
v, ok := value.(int64)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddQuota(v)
return nil
case mailbox.FieldUID:
v, ok := value.(int32)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddUID(v)
return nil
case mailbox.FieldGid:
v, ok := value.(int32)
if !ok {
return fmt.Errorf("unexpected type %T for field %s", value, name)
}
m.AddGid(v)
return nil
}
return fmt.Errorf("unknown Mailbox numeric field %s", name)
}
// ClearedFields returns all nullable fields that were cleared during this
// mutation.
func (m *MailboxMutation) ClearedFields() []string {
var fields []string
if m.FieldCleared(mailbox.FieldModified) {
fields = append(fields, mailbox.FieldModified)
}
if m.FieldCleared(mailbox.FieldDomainID) {
fields = append(fields, mailbox.FieldDomainID)
}
if m.FieldCleared(mailbox.FieldName) {
fields = append(fields, mailbox.FieldName)
}
if m.FieldCleared(mailbox.FieldHomedir) {
fields = append(fields, mailbox.FieldHomedir)
}
if m.FieldCleared(mailbox.FieldMaildir) {
fields = append(fields, mailbox.FieldMaildir)
}
if m.FieldCleared(mailbox.FieldUID) {
fields = append(fields, mailbox.FieldUID)
}
if m.FieldCleared(mailbox.FieldGid) {
fields = append(fields, mailbox.FieldGid)
}
return fields
}
// FieldCleared returns a boolean indicating if a field with the given name was
// cleared in this mutation.
func (m *MailboxMutation) FieldCleared(name string) bool {
_, ok := m.clearedFields[name]
return ok
}
// ClearField clears the value of the field with the given name. It returns an
// error if the field is not defined in the schema.
func (m *MailboxMutation) ClearField(name string) error {
switch name {
case mailbox.FieldModified:
m.ClearModified()
return nil
case mailbox.FieldDomainID:
m.ClearDomainID()
return nil
case mailbox.FieldName:
m.ClearName()
return nil
case mailbox.FieldHomedir:
m.ClearHomedir()
return nil
case mailbox.FieldMaildir:
m.ClearMaildir()
return nil
case mailbox.FieldUID:
m.ClearUID()
return nil
case mailbox.FieldGid:
m.ClearGid()
return nil
}
return fmt.Errorf("unknown Mailbox nullable field %s", name)
}
// ResetField resets all changes in the mutation for the field with the given name.
// It returns an error if the field is not defined in the schema.
func (m *MailboxMutation) ResetField(name string) error {
switch name {
case mailbox.FieldActive:
m.ResetActive()
return nil
case mailbox.FieldCreated:
m.ResetCreated()
return nil
case mailbox.FieldModified:
m.ResetModified()
return nil
case mailbox.FieldDomainID:
m.ResetDomainID()
return nil
case mailbox.FieldUsername:
m.ResetUsername()
return nil
case mailbox.FieldPassword:
m.ResetPassword()
return nil
case mailbox.FieldName:
m.ResetName()
return nil
case mailbox.FieldQuota:
m.ResetQuota()
return nil
case mailbox.FieldLocalPart:
m.ResetLocalPart()
return nil
case mailbox.FieldHomedir:
m.ResetHomedir()
return nil
case mailbox.FieldMaildir:
m.ResetMaildir()
return nil
case mailbox.FieldUID:
m.ResetUID()
return nil
case mailbox.FieldGid:
m.ResetGid()
return nil
}
return fmt.Errorf("unknown Mailbox field %s", name)
}
// AddedEdges returns all edge names that were set/added in this mutation.
func (m *MailboxMutation) AddedEdges() []string {
edges := make([]string, 0, 1)
if m.domain != nil {
edges = append(edges, mailbox.EdgeDomain)
}
return edges
}
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
// name in this mutation.
func (m *MailboxMutation) AddedIDs(name string) []ent.Value {
switch name {
case mailbox.EdgeDomain:
if id := m.domain; id != nil {
return []ent.Value{*id}
}
}
return nil
}
// RemovedEdges returns all edge names that were removed in this mutation.
func (m *MailboxMutation) RemovedEdges() []string {
edges := make([]string, 0, 1)
return edges
}
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
// the given name in this mutation.
func (m *MailboxMutation) RemovedIDs(name string) []ent.Value {
switch name {
}
return nil
}
// ClearedEdges returns all edge names that were cleared in this mutation.
func (m *MailboxMutation) ClearedEdges() []string {
edges := make([]string, 0, 1)
if m.cleareddomain {
edges = append(edges, mailbox.EdgeDomain)
}
return edges
}
// EdgeCleared returns a boolean which indicates if the edge with the given name
// was cleared in this mutation.
func (m *MailboxMutation) EdgeCleared(name string) bool {
switch name {
case mailbox.EdgeDomain:
return m.cleareddomain
}
return false
}
// ClearEdge clears the value of the edge with the given name. It returns an error
// if that edge is not defined in the schema.
func (m *MailboxMutation) ClearEdge(name string) error {
switch name {
case mailbox.EdgeDomain:
m.ClearDomain()
return nil
}
return fmt.Errorf("unknown Mailbox unique edge %s", name)
}
// ResetEdge resets all changes to the edge with the given name in this mutation.
// It returns an error if the edge is not defined in the schema.
func (m *MailboxMutation) ResetEdge(name string) error {
switch name {
case mailbox.EdgeDomain:
m.ResetDomain()
return nil
}
return fmt.Errorf("unknown Mailbox edge %s", name)
}