From e9955b3a28fe65493f1f13cc7918d70677178900 Mon Sep 17 00:00:00 2001 From: Darko Luketic Date: Fri, 8 Apr 2022 21:26:25 +0200 Subject: [PATCH] ent schema post generation --- ent/account.go | 198 ++ ent/account/account.go | 80 + ent/account/where.go | 605 +++++ ent/account_create.go | 415 ++++ ent/account_delete.go | 111 + ent/account_query.go | 1091 ++++++++ ent/account_update.go | 774 ++++++ ent/alias.go | 179 ++ ent/alias/alias.go | 64 + ent/alias/where.go | 542 ++++ ent/alias_create.go | 351 +++ ent/alias_delete.go | 111 + ent/alias_query.go | 989 ++++++++ ent/alias_update.go | 493 ++++ ent/client.go | 762 ++++++ ent/config.go | 63 + ent/context.go | 33 + ent/domain.go | 284 +++ ent/domain/domain.go | 113 + ent/domain/where.go | 1160 +++++++++ ent/domain_create.go | 575 +++++ ent/domain_delete.go | 111 + ent/domain_query.go | 1215 +++++++++ ent/domain_update.go | 1418 +++++++++++ ent/ent.go | 267 ++ ent/enttest/enttest.go | 78 + ent/hook/hook.go | 256 ++ ent/logentry.go | 199 ++ ent/logentry/logentry.go | 69 + ent/logentry/where.go | 653 +++++ ent/logentry_create.go | 370 +++ ent/logentry_delete.go | 111 + ent/logentry_query.go | 1052 ++++++++ ent/logentry_update.go | 597 +++++ ent/mailbox.go | 276 +++ ent/mailbox/mailbox.go | 88 + ent/mailbox/where.go | 1416 +++++++++++ ent/mailbox_create.go | 512 ++++ ent/mailbox_delete.go | 111 + ent/mailbox_query.go | 989 ++++++++ ent/mailbox_update.go | 985 ++++++++ ent/migrate/migrate.go | 71 + ent/migrate/schema.go | 174 ++ ent/mutation.go | 4784 ++++++++++++++++++++++++++++++++++++ ent/predicate/predicate.go | 22 + ent/runtime.go | 74 + ent/runtime/runtime.go | 10 + ent/tx.go | 222 ++ 48 files changed, 25123 insertions(+) create mode 100644 ent/account.go create mode 100644 ent/account/account.go create mode 100644 ent/account/where.go create mode 100644 ent/account_create.go create mode 100644 ent/account_delete.go create mode 100644 ent/account_query.go create mode 100644 ent/account_update.go create mode 100644 ent/alias.go create mode 100644 ent/alias/alias.go create mode 100644 ent/alias/where.go create mode 100644 ent/alias_create.go create mode 100644 ent/alias_delete.go create mode 100644 ent/alias_query.go create mode 100644 ent/alias_update.go create mode 100644 ent/client.go create mode 100644 ent/config.go create mode 100644 ent/context.go create mode 100644 ent/domain.go create mode 100644 ent/domain/domain.go create mode 100644 ent/domain/where.go create mode 100644 ent/domain_create.go create mode 100644 ent/domain_delete.go create mode 100644 ent/domain_query.go create mode 100644 ent/domain_update.go create mode 100644 ent/ent.go create mode 100644 ent/enttest/enttest.go create mode 100644 ent/hook/hook.go create mode 100644 ent/logentry.go create mode 100644 ent/logentry/logentry.go create mode 100644 ent/logentry/where.go create mode 100644 ent/logentry_create.go create mode 100644 ent/logentry_delete.go create mode 100644 ent/logentry_query.go create mode 100644 ent/logentry_update.go create mode 100644 ent/mailbox.go create mode 100644 ent/mailbox/mailbox.go create mode 100644 ent/mailbox/where.go create mode 100644 ent/mailbox_create.go create mode 100644 ent/mailbox_delete.go create mode 100644 ent/mailbox_query.go create mode 100644 ent/mailbox_update.go create mode 100644 ent/migrate/migrate.go create mode 100644 ent/migrate/schema.go create mode 100644 ent/mutation.go create mode 100644 ent/predicate/predicate.go create mode 100644 ent/runtime.go create mode 100644 ent/runtime/runtime.go create mode 100644 ent/tx.go diff --git a/ent/account.go b/ent/account.go new file mode 100644 index 0000000..3428959 --- /dev/null +++ b/ent/account.go @@ -0,0 +1,198 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "code.icod.de/postfix/manager/ent/account" + "entgo.io/ent/dialect/sql" +) + +// Account is the model entity for the Account schema. +type Account struct { + config `json:"-"` + // ID of the ent. + ID int64 `json:"id,omitempty"` + // Created holds the value of the "created" field. + Created time.Time `json:"created,omitempty"` + // Modified holds the value of the "modified" field. + Modified time.Time `json:"modified,omitempty"` + // Username holds the value of the "username" field. + Username string `json:"username,omitempty"` + // Password holds the value of the "password" field. + Password []byte `json:"password,omitempty"` + // Super holds the value of the "super" field. + Super bool `json:"super,omitempty"` + // Active holds the value of the "active" field. + Active bool `json:"active,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the AccountQuery when eager-loading is set. + Edges AccountEdges `json:"edges"` +} + +// AccountEdges holds the relations/edges for other nodes in the graph. +type AccountEdges struct { + // Domains holds the value of the domains edge. + Domains []*Domain `json:"domains,omitempty"` + // Logs holds the value of the logs edge. + Logs []*Logentry `json:"logs,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [2]bool +} + +// DomainsOrErr returns the Domains value or an error if the edge +// was not loaded in eager-loading. +func (e AccountEdges) DomainsOrErr() ([]*Domain, error) { + if e.loadedTypes[0] { + return e.Domains, nil + } + return nil, &NotLoadedError{edge: "domains"} +} + +// LogsOrErr returns the Logs value or an error if the edge +// was not loaded in eager-loading. +func (e AccountEdges) LogsOrErr() ([]*Logentry, error) { + if e.loadedTypes[1] { + return e.Logs, nil + } + return nil, &NotLoadedError{edge: "logs"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Account) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case account.FieldPassword: + values[i] = new([]byte) + case account.FieldSuper, account.FieldActive: + values[i] = new(sql.NullBool) + case account.FieldID: + values[i] = new(sql.NullInt64) + case account.FieldUsername: + values[i] = new(sql.NullString) + case account.FieldCreated, account.FieldModified: + values[i] = new(sql.NullTime) + default: + return nil, fmt.Errorf("unexpected column %q for type Account", columns[i]) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Account fields. +func (a *Account) assignValues(columns []string, values []interface{}) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case account.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + a.ID = int64(value.Int64) + case account.FieldCreated: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created", values[i]) + } else if value.Valid { + a.Created = value.Time + } + case account.FieldModified: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field modified", values[i]) + } else if value.Valid { + a.Modified = value.Time + } + case account.FieldUsername: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field username", values[i]) + } else if value.Valid { + a.Username = value.String + } + case account.FieldPassword: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field password", values[i]) + } else if value != nil { + a.Password = *value + } + case account.FieldSuper: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field super", values[i]) + } else if value.Valid { + a.Super = value.Bool + } + case account.FieldActive: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field active", values[i]) + } else if value.Valid { + a.Active = value.Bool + } + } + } + return nil +} + +// QueryDomains queries the "domains" edge of the Account entity. +func (a *Account) QueryDomains() *DomainQuery { + return (&AccountClient{config: a.config}).QueryDomains(a) +} + +// QueryLogs queries the "logs" edge of the Account entity. +func (a *Account) QueryLogs() *LogentryQuery { + return (&AccountClient{config: a.config}).QueryLogs(a) +} + +// Update returns a builder for updating this Account. +// Note that you need to call Account.Unwrap() before calling this method if this Account +// was returned from a transaction, and the transaction was committed or rolled back. +func (a *Account) Update() *AccountUpdateOne { + return (&AccountClient{config: a.config}).UpdateOne(a) +} + +// Unwrap unwraps the Account entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (a *Account) Unwrap() *Account { + tx, ok := a.config.driver.(*txDriver) + if !ok { + panic("ent: Account is not a transactional entity") + } + a.config.driver = tx.drv + return a +} + +// String implements the fmt.Stringer. +func (a *Account) String() string { + var builder strings.Builder + builder.WriteString("Account(") + builder.WriteString(fmt.Sprintf("id=%v", a.ID)) + builder.WriteString(", created=") + builder.WriteString(a.Created.Format(time.ANSIC)) + builder.WriteString(", modified=") + builder.WriteString(a.Modified.Format(time.ANSIC)) + builder.WriteString(", username=") + builder.WriteString(a.Username) + builder.WriteString(", password=") + builder.WriteString(fmt.Sprintf("%v", a.Password)) + builder.WriteString(", super=") + builder.WriteString(fmt.Sprintf("%v", a.Super)) + builder.WriteString(", active=") + builder.WriteString(fmt.Sprintf("%v", a.Active)) + builder.WriteByte(')') + return builder.String() +} + +// Accounts is a parsable slice of Account. +type Accounts []*Account + +func (a Accounts) config(cfg config) { + for _i := range a { + a[_i].config = cfg + } +} diff --git a/ent/account/account.go b/ent/account/account.go new file mode 100644 index 0000000..5c6f270 --- /dev/null +++ b/ent/account/account.go @@ -0,0 +1,80 @@ +// Code generated by entc, DO NOT EDIT. + +package account + +import ( + "time" +) + +const ( + // Label holds the string label denoting the account type in the database. + Label = "account" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCreated holds the string denoting the created field in the database. + FieldCreated = "created" + // FieldModified holds the string denoting the modified field in the database. + FieldModified = "modified" + // FieldUsername holds the string denoting the username field in the database. + FieldUsername = "username" + // FieldPassword holds the string denoting the password field in the database. + FieldPassword = "password" + // FieldSuper holds the string denoting the super field in the database. + FieldSuper = "super" + // FieldActive holds the string denoting the active field in the database. + FieldActive = "active" + // EdgeDomains holds the string denoting the domains edge name in mutations. + EdgeDomains = "domains" + // EdgeLogs holds the string denoting the logs edge name in mutations. + EdgeLogs = "logs" + // Table holds the table name of the account in the database. + Table = "accounts" + // DomainsTable is the table that holds the domains relation/edge. The primary key declared below. + DomainsTable = "account_domains" + // DomainsInverseTable is the table name for the Domain entity. + // It exists in this package in order to avoid circular dependency with the "domain" package. + DomainsInverseTable = "domains" + // LogsTable is the table that holds the logs relation/edge. + LogsTable = "logentries" + // LogsInverseTable is the table name for the Logentry entity. + // It exists in this package in order to avoid circular dependency with the "logentry" package. + LogsInverseTable = "logentries" + // LogsColumn is the table column denoting the logs relation/edge. + LogsColumn = "account_id" +) + +// Columns holds all SQL columns for account fields. +var Columns = []string{ + FieldID, + FieldCreated, + FieldModified, + FieldUsername, + FieldPassword, + FieldSuper, + FieldActive, +} + +var ( + // DomainsPrimaryKey and DomainsColumn2 are the table columns denoting the + // primary key for the domains relation (M2M). + DomainsPrimaryKey = []string{"account_id", "domain_id"} +) + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreated holds the default value on creation for the "created" field. + DefaultCreated func() time.Time + // DefaultModified holds the default value on creation for the "modified" field. + DefaultModified func() time.Time + // UpdateDefaultModified holds the default value on update for the "modified" field. + UpdateDefaultModified func() time.Time +) diff --git a/ent/account/where.go b/ent/account/where.go new file mode 100644 index 0000000..f0931cd --- /dev/null +++ b/ent/account/where.go @@ -0,0 +1,605 @@ +// Code generated by entc, DO NOT EDIT. + +package account + +import ( + "time" + + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// ID filters vertices based on their ID field. +func ID(id int64) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int64) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int64) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldID), id)) + }) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int64) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.In(s.C(FieldID), v...)) + }) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int64) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.NotIn(s.C(FieldID), v...)) + }) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int64) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldID), id)) + }) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int64) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldID), id)) + }) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int64) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldID), id)) + }) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int64) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldID), id)) + }) +} + +// Created applies equality check predicate on the "created" field. It's identical to CreatedEQ. +func Created(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldCreated), v)) + }) +} + +// Modified applies equality check predicate on the "modified" field. It's identical to ModifiedEQ. +func Modified(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldModified), v)) + }) +} + +// Username applies equality check predicate on the "username" field. It's identical to UsernameEQ. +func Username(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUsername), v)) + }) +} + +// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ. +func Password(v []byte) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPassword), v)) + }) +} + +// Super applies equality check predicate on the "super" field. It's identical to SuperEQ. +func Super(v bool) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldSuper), v)) + }) +} + +// Active applies equality check predicate on the "active" field. It's identical to ActiveEQ. +func Active(v bool) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldActive), v)) + }) +} + +// CreatedEQ applies the EQ predicate on the "created" field. +func CreatedEQ(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldCreated), v)) + }) +} + +// CreatedNEQ applies the NEQ predicate on the "created" field. +func CreatedNEQ(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldCreated), v)) + }) +} + +// CreatedIn applies the In predicate on the "created" field. +func CreatedIn(vs ...time.Time) predicate.Account { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Account(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldCreated), v...)) + }) +} + +// CreatedNotIn applies the NotIn predicate on the "created" field. +func CreatedNotIn(vs ...time.Time) predicate.Account { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Account(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldCreated), v...)) + }) +} + +// CreatedGT applies the GT predicate on the "created" field. +func CreatedGT(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldCreated), v)) + }) +} + +// CreatedGTE applies the GTE predicate on the "created" field. +func CreatedGTE(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldCreated), v)) + }) +} + +// CreatedLT applies the LT predicate on the "created" field. +func CreatedLT(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldCreated), v)) + }) +} + +// CreatedLTE applies the LTE predicate on the "created" field. +func CreatedLTE(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldCreated), v)) + }) +} + +// ModifiedEQ applies the EQ predicate on the "modified" field. +func ModifiedEQ(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldModified), v)) + }) +} + +// ModifiedNEQ applies the NEQ predicate on the "modified" field. +func ModifiedNEQ(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldModified), v)) + }) +} + +// ModifiedIn applies the In predicate on the "modified" field. +func ModifiedIn(vs ...time.Time) predicate.Account { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Account(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldModified), v...)) + }) +} + +// ModifiedNotIn applies the NotIn predicate on the "modified" field. +func ModifiedNotIn(vs ...time.Time) predicate.Account { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Account(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldModified), v...)) + }) +} + +// ModifiedGT applies the GT predicate on the "modified" field. +func ModifiedGT(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldModified), v)) + }) +} + +// ModifiedGTE applies the GTE predicate on the "modified" field. +func ModifiedGTE(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldModified), v)) + }) +} + +// ModifiedLT applies the LT predicate on the "modified" field. +func ModifiedLT(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldModified), v)) + }) +} + +// ModifiedLTE applies the LTE predicate on the "modified" field. +func ModifiedLTE(v time.Time) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldModified), v)) + }) +} + +// ModifiedIsNil applies the IsNil predicate on the "modified" field. +func ModifiedIsNil() predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldModified))) + }) +} + +// ModifiedNotNil applies the NotNil predicate on the "modified" field. +func ModifiedNotNil() predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldModified))) + }) +} + +// UsernameEQ applies the EQ predicate on the "username" field. +func UsernameEQ(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUsername), v)) + }) +} + +// UsernameNEQ applies the NEQ predicate on the "username" field. +func UsernameNEQ(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldUsername), v)) + }) +} + +// UsernameIn applies the In predicate on the "username" field. +func UsernameIn(vs ...string) predicate.Account { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Account(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldUsername), v...)) + }) +} + +// UsernameNotIn applies the NotIn predicate on the "username" field. +func UsernameNotIn(vs ...string) predicate.Account { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Account(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldUsername), v...)) + }) +} + +// UsernameGT applies the GT predicate on the "username" field. +func UsernameGT(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldUsername), v)) + }) +} + +// UsernameGTE applies the GTE predicate on the "username" field. +func UsernameGTE(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldUsername), v)) + }) +} + +// UsernameLT applies the LT predicate on the "username" field. +func UsernameLT(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldUsername), v)) + }) +} + +// UsernameLTE applies the LTE predicate on the "username" field. +func UsernameLTE(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldUsername), v)) + }) +} + +// UsernameContains applies the Contains predicate on the "username" field. +func UsernameContains(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldUsername), v)) + }) +} + +// UsernameHasPrefix applies the HasPrefix predicate on the "username" field. +func UsernameHasPrefix(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldUsername), v)) + }) +} + +// UsernameHasSuffix applies the HasSuffix predicate on the "username" field. +func UsernameHasSuffix(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldUsername), v)) + }) +} + +// UsernameEqualFold applies the EqualFold predicate on the "username" field. +func UsernameEqualFold(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldUsername), v)) + }) +} + +// UsernameContainsFold applies the ContainsFold predicate on the "username" field. +func UsernameContainsFold(v string) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldUsername), v)) + }) +} + +// PasswordEQ applies the EQ predicate on the "password" field. +func PasswordEQ(v []byte) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPassword), v)) + }) +} + +// PasswordNEQ applies the NEQ predicate on the "password" field. +func PasswordNEQ(v []byte) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldPassword), v)) + }) +} + +// PasswordIn applies the In predicate on the "password" field. +func PasswordIn(vs ...[]byte) predicate.Account { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Account(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldPassword), v...)) + }) +} + +// PasswordNotIn applies the NotIn predicate on the "password" field. +func PasswordNotIn(vs ...[]byte) predicate.Account { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Account(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldPassword), v...)) + }) +} + +// PasswordGT applies the GT predicate on the "password" field. +func PasswordGT(v []byte) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldPassword), v)) + }) +} + +// PasswordGTE applies the GTE predicate on the "password" field. +func PasswordGTE(v []byte) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldPassword), v)) + }) +} + +// PasswordLT applies the LT predicate on the "password" field. +func PasswordLT(v []byte) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldPassword), v)) + }) +} + +// PasswordLTE applies the LTE predicate on the "password" field. +func PasswordLTE(v []byte) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldPassword), v)) + }) +} + +// SuperEQ applies the EQ predicate on the "super" field. +func SuperEQ(v bool) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldSuper), v)) + }) +} + +// SuperNEQ applies the NEQ predicate on the "super" field. +func SuperNEQ(v bool) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldSuper), v)) + }) +} + +// ActiveEQ applies the EQ predicate on the "active" field. +func ActiveEQ(v bool) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldActive), v)) + }) +} + +// ActiveNEQ applies the NEQ predicate on the "active" field. +func ActiveNEQ(v bool) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldActive), v)) + }) +} + +// HasDomains applies the HasEdge predicate on the "domains" edge. +func HasDomains() predicate.Account { + return predicate.Account(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(DomainsTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, DomainsTable, DomainsPrimaryKey...), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasDomainsWith applies the HasEdge predicate on the "domains" edge with a given conditions (other predicates). +func HasDomainsWith(preds ...predicate.Domain) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(DomainsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, DomainsTable, DomainsPrimaryKey...), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasLogs applies the HasEdge predicate on the "logs" edge. +func HasLogs() predicate.Account { + return predicate.Account(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(LogsTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, LogsTable, LogsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasLogsWith applies the HasEdge predicate on the "logs" edge with a given conditions (other predicates). +func HasLogsWith(preds ...predicate.Logentry) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(LogsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, LogsTable, LogsColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Account) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for _, p := range predicates { + p(s1) + } + s.Where(s1.P()) + }) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Account) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for i, p := range predicates { + if i > 0 { + s1.Or() + } + p(s1) + } + s.Where(s1.P()) + }) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Account) predicate.Account { + return predicate.Account(func(s *sql.Selector) { + p(s.Not()) + }) +} diff --git a/ent/account_create.go b/ent/account_create.go new file mode 100644 index 0000000..d94cb08 --- /dev/null +++ b/ent/account_create.go @@ -0,0 +1,415 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AccountCreate is the builder for creating a Account entity. +type AccountCreate struct { + config + mutation *AccountMutation + hooks []Hook +} + +// SetCreated sets the "created" field. +func (ac *AccountCreate) SetCreated(t time.Time) *AccountCreate { + ac.mutation.SetCreated(t) + return ac +} + +// SetNillableCreated sets the "created" field if the given value is not nil. +func (ac *AccountCreate) SetNillableCreated(t *time.Time) *AccountCreate { + if t != nil { + ac.SetCreated(*t) + } + return ac +} + +// SetModified sets the "modified" field. +func (ac *AccountCreate) SetModified(t time.Time) *AccountCreate { + ac.mutation.SetModified(t) + return ac +} + +// SetNillableModified sets the "modified" field if the given value is not nil. +func (ac *AccountCreate) SetNillableModified(t *time.Time) *AccountCreate { + if t != nil { + ac.SetModified(*t) + } + return ac +} + +// SetUsername sets the "username" field. +func (ac *AccountCreate) SetUsername(s string) *AccountCreate { + ac.mutation.SetUsername(s) + return ac +} + +// SetPassword sets the "password" field. +func (ac *AccountCreate) SetPassword(b []byte) *AccountCreate { + ac.mutation.SetPassword(b) + return ac +} + +// SetSuper sets the "super" field. +func (ac *AccountCreate) SetSuper(b bool) *AccountCreate { + ac.mutation.SetSuper(b) + return ac +} + +// SetActive sets the "active" field. +func (ac *AccountCreate) SetActive(b bool) *AccountCreate { + ac.mutation.SetActive(b) + return ac +} + +// SetID sets the "id" field. +func (ac *AccountCreate) SetID(i int64) *AccountCreate { + ac.mutation.SetID(i) + return ac +} + +// AddDomainIDs adds the "domains" edge to the Domain entity by IDs. +func (ac *AccountCreate) AddDomainIDs(ids ...int64) *AccountCreate { + ac.mutation.AddDomainIDs(ids...) + return ac +} + +// AddDomains adds the "domains" edges to the Domain entity. +func (ac *AccountCreate) AddDomains(d ...*Domain) *AccountCreate { + ids := make([]int64, len(d)) + for i := range d { + ids[i] = d[i].ID + } + return ac.AddDomainIDs(ids...) +} + +// AddLogIDs adds the "logs" edge to the Logentry entity by IDs. +func (ac *AccountCreate) AddLogIDs(ids ...int64) *AccountCreate { + ac.mutation.AddLogIDs(ids...) + return ac +} + +// AddLogs adds the "logs" edges to the Logentry entity. +func (ac *AccountCreate) AddLogs(l ...*Logentry) *AccountCreate { + ids := make([]int64, len(l)) + for i := range l { + ids[i] = l[i].ID + } + return ac.AddLogIDs(ids...) +} + +// Mutation returns the AccountMutation object of the builder. +func (ac *AccountCreate) Mutation() *AccountMutation { + return ac.mutation +} + +// Save creates the Account in the database. +func (ac *AccountCreate) Save(ctx context.Context) (*Account, error) { + var ( + err error + node *Account + ) + ac.defaults() + if len(ac.hooks) == 0 { + if err = ac.check(); err != nil { + return nil, err + } + node, err = ac.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AccountMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err = ac.check(); err != nil { + return nil, err + } + ac.mutation = mutation + if node, err = ac.sqlSave(ctx); err != nil { + return nil, err + } + mutation.id = &node.ID + mutation.done = true + return node, err + }) + for i := len(ac.hooks) - 1; i >= 0; i-- { + if ac.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = ac.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, ac.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX calls Save and panics if Save returns an error. +func (ac *AccountCreate) SaveX(ctx context.Context) *Account { + v, err := ac.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (ac *AccountCreate) Exec(ctx context.Context) error { + _, err := ac.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ac *AccountCreate) ExecX(ctx context.Context) { + if err := ac.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (ac *AccountCreate) defaults() { + if _, ok := ac.mutation.Created(); !ok { + v := account.DefaultCreated() + ac.mutation.SetCreated(v) + } + if _, ok := ac.mutation.Modified(); !ok { + v := account.DefaultModified() + ac.mutation.SetModified(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (ac *AccountCreate) check() error { + if _, ok := ac.mutation.Created(); !ok { + return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "Account.created"`)} + } + if _, ok := ac.mutation.Username(); !ok { + return &ValidationError{Name: "username", err: errors.New(`ent: missing required field "Account.username"`)} + } + if _, ok := ac.mutation.Password(); !ok { + return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Account.password"`)} + } + if _, ok := ac.mutation.Super(); !ok { + return &ValidationError{Name: "super", err: errors.New(`ent: missing required field "Account.super"`)} + } + if _, ok := ac.mutation.Active(); !ok { + return &ValidationError{Name: "active", err: errors.New(`ent: missing required field "Account.active"`)} + } + return nil +} + +func (ac *AccountCreate) sqlSave(ctx context.Context) (*Account, error) { + _node, _spec := ac.createSpec() + if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = int64(id) + } + return _node, nil +} + +func (ac *AccountCreate) createSpec() (*Account, *sqlgraph.CreateSpec) { + var ( + _node = &Account{config: ac.config} + _spec = &sqlgraph.CreateSpec{ + Table: account.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + } + ) + if id, ok := ac.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := ac.mutation.Created(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: account.FieldCreated, + }) + _node.Created = value + } + if value, ok := ac.mutation.Modified(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: account.FieldModified, + }) + _node.Modified = value + } + if value, ok := ac.mutation.Username(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: account.FieldUsername, + }) + _node.Username = value + } + if value, ok := ac.mutation.Password(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Value: value, + Column: account.FieldPassword, + }) + _node.Password = value + } + if value, ok := ac.mutation.Super(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: account.FieldSuper, + }) + _node.Super = value + } + if value, ok := ac.mutation.Active(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: account.FieldActive, + }) + _node.Active = value + } + if nodes := ac.mutation.DomainsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: account.DomainsTable, + Columns: account.DomainsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := ac.mutation.LogsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: account.LogsTable, + Columns: []string{account.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// AccountCreateBulk is the builder for creating many Account entities in bulk. +type AccountCreateBulk struct { + config + builders []*AccountCreate +} + +// Save creates the Account entities in the database. +func (acb *AccountCreateBulk) Save(ctx context.Context) ([]*Account, error) { + specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) + nodes := make([]*Account, len(acb.builders)) + mutators := make([]Mutator, len(acb.builders)) + for i := range acb.builders { + func(i int, root context.Context) { + builder := acb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AccountMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + nodes[i], specs[i] = builder.createSpec() + var err error + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, acb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, acb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + if specs[i].ID.Value != nil && nodes[i].ID == 0 { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int64(id) + } + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, acb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (acb *AccountCreateBulk) SaveX(ctx context.Context) []*Account { + v, err := acb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (acb *AccountCreateBulk) Exec(ctx context.Context) error { + _, err := acb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (acb *AccountCreateBulk) ExecX(ctx context.Context) { + if err := acb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/account_delete.go b/ent/account_delete.go new file mode 100644 index 0000000..e55588c --- /dev/null +++ b/ent/account_delete.go @@ -0,0 +1,111 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AccountDelete is the builder for deleting a Account entity. +type AccountDelete struct { + config + hooks []Hook + mutation *AccountMutation +} + +// Where appends a list predicates to the AccountDelete builder. +func (ad *AccountDelete) Where(ps ...predicate.Account) *AccountDelete { + ad.mutation.Where(ps...) + return ad +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (ad *AccountDelete) Exec(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + if len(ad.hooks) == 0 { + affected, err = ad.sqlExec(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AccountMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + ad.mutation = mutation + affected, err = ad.sqlExec(ctx) + mutation.done = true + return affected, err + }) + for i := len(ad.hooks) - 1; i >= 0; i-- { + if ad.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = ad.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, ad.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ad *AccountDelete) ExecX(ctx context.Context) int { + n, err := ad.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (ad *AccountDelete) sqlExec(ctx context.Context) (int, error) { + _spec := &sqlgraph.DeleteSpec{ + Node: &sqlgraph.NodeSpec{ + Table: account.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + if ps := ad.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return sqlgraph.DeleteNodes(ctx, ad.driver, _spec) +} + +// AccountDeleteOne is the builder for deleting a single Account entity. +type AccountDeleteOne struct { + ad *AccountDelete +} + +// Exec executes the deletion query. +func (ado *AccountDeleteOne) Exec(ctx context.Context) error { + n, err := ado.ad.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{account.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (ado *AccountDeleteOne) ExecX(ctx context.Context) { + ado.ad.ExecX(ctx) +} diff --git a/ent/account_query.go b/ent/account_query.go new file mode 100644 index 0000000..49a8ec6 --- /dev/null +++ b/ent/account_query.go @@ -0,0 +1,1091 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "errors" + "fmt" + "math" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AccountQuery is the builder for querying Account entities. +type AccountQuery struct { + config + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Account + // eager-loading edges. + withDomains *DomainQuery + withLogs *LogentryQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the AccountQuery builder. +func (aq *AccountQuery) Where(ps ...predicate.Account) *AccountQuery { + aq.predicates = append(aq.predicates, ps...) + return aq +} + +// Limit adds a limit step to the query. +func (aq *AccountQuery) Limit(limit int) *AccountQuery { + aq.limit = &limit + return aq +} + +// Offset adds an offset step to the query. +func (aq *AccountQuery) Offset(offset int) *AccountQuery { + aq.offset = &offset + return aq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (aq *AccountQuery) Unique(unique bool) *AccountQuery { + aq.unique = &unique + return aq +} + +// Order adds an order step to the query. +func (aq *AccountQuery) Order(o ...OrderFunc) *AccountQuery { + aq.order = append(aq.order, o...) + return aq +} + +// QueryDomains chains the current query on the "domains" edge. +func (aq *AccountQuery) QueryDomains() *DomainQuery { + query := &DomainQuery{config: aq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := aq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(account.Table, account.FieldID, selector), + sqlgraph.To(domain.Table, domain.FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, account.DomainsTable, account.DomainsPrimaryKey...), + ) + fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryLogs chains the current query on the "logs" edge. +func (aq *AccountQuery) QueryLogs() *LogentryQuery { + query := &LogentryQuery{config: aq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := aq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(account.Table, account.FieldID, selector), + sqlgraph.To(logentry.Table, logentry.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, account.LogsTable, account.LogsColumn), + ) + fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Account entity from the query. +// Returns a *NotFoundError when no Account was found. +func (aq *AccountQuery) First(ctx context.Context) (*Account, error) { + nodes, err := aq.Limit(1).All(ctx) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{account.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (aq *AccountQuery) FirstX(ctx context.Context) *Account { + node, err := aq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Account ID from the query. +// Returns a *NotFoundError when no Account ID was found. +func (aq *AccountQuery) FirstID(ctx context.Context) (id int64, err error) { + var ids []int64 + if ids, err = aq.Limit(1).IDs(ctx); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{account.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (aq *AccountQuery) FirstIDX(ctx context.Context) int64 { + id, err := aq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Account entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Account entity is found. +// Returns a *NotFoundError when no Account entities are found. +func (aq *AccountQuery) Only(ctx context.Context) (*Account, error) { + nodes, err := aq.Limit(2).All(ctx) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{account.Label} + default: + return nil, &NotSingularError{account.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (aq *AccountQuery) OnlyX(ctx context.Context) *Account { + node, err := aq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Account ID in the query. +// Returns a *NotSingularError when more than one Account ID is found. +// Returns a *NotFoundError when no entities are found. +func (aq *AccountQuery) OnlyID(ctx context.Context) (id int64, err error) { + var ids []int64 + if ids, err = aq.Limit(2).IDs(ctx); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{account.Label} + default: + err = &NotSingularError{account.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (aq *AccountQuery) OnlyIDX(ctx context.Context) int64 { + id, err := aq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Accounts. +func (aq *AccountQuery) All(ctx context.Context) ([]*Account, error) { + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + return aq.sqlAll(ctx) +} + +// AllX is like All, but panics if an error occurs. +func (aq *AccountQuery) AllX(ctx context.Context) []*Account { + nodes, err := aq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Account IDs. +func (aq *AccountQuery) IDs(ctx context.Context) ([]int64, error) { + var ids []int64 + if err := aq.Select(account.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (aq *AccountQuery) IDsX(ctx context.Context) []int64 { + ids, err := aq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (aq *AccountQuery) Count(ctx context.Context) (int, error) { + if err := aq.prepareQuery(ctx); err != nil { + return 0, err + } + return aq.sqlCount(ctx) +} + +// CountX is like Count, but panics if an error occurs. +func (aq *AccountQuery) CountX(ctx context.Context) int { + count, err := aq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (aq *AccountQuery) Exist(ctx context.Context) (bool, error) { + if err := aq.prepareQuery(ctx); err != nil { + return false, err + } + return aq.sqlExist(ctx) +} + +// ExistX is like Exist, but panics if an error occurs. +func (aq *AccountQuery) ExistX(ctx context.Context) bool { + exist, err := aq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the AccountQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (aq *AccountQuery) Clone() *AccountQuery { + if aq == nil { + return nil + } + return &AccountQuery{ + config: aq.config, + limit: aq.limit, + offset: aq.offset, + order: append([]OrderFunc{}, aq.order...), + predicates: append([]predicate.Account{}, aq.predicates...), + withDomains: aq.withDomains.Clone(), + withLogs: aq.withLogs.Clone(), + // clone intermediate query. + sql: aq.sql.Clone(), + path: aq.path, + unique: aq.unique, + } +} + +// WithDomains tells the query-builder to eager-load the nodes that are connected to +// the "domains" edge. The optional arguments are used to configure the query builder of the edge. +func (aq *AccountQuery) WithDomains(opts ...func(*DomainQuery)) *AccountQuery { + query := &DomainQuery{config: aq.config} + for _, opt := range opts { + opt(query) + } + aq.withDomains = query + return aq +} + +// WithLogs tells the query-builder to eager-load the nodes that are connected to +// the "logs" edge. The optional arguments are used to configure the query builder of the edge. +func (aq *AccountQuery) WithLogs(opts ...func(*LogentryQuery)) *AccountQuery { + query := &LogentryQuery{config: aq.config} + for _, opt := range opts { + opt(query) + } + aq.withLogs = query + return aq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Created time.Time `json:"created,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Account.Query(). +// GroupBy(account.FieldCreated). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +// +func (aq *AccountQuery) GroupBy(field string, fields ...string) *AccountGroupBy { + group := &AccountGroupBy{config: aq.config} + group.fields = append([]string{field}, fields...) + group.path = func(ctx context.Context) (prev *sql.Selector, err error) { + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + return aq.sqlQuery(ctx), nil + } + return group +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Created time.Time `json:"created,omitempty"` +// } +// +// client.Account.Query(). +// Select(account.FieldCreated). +// Scan(ctx, &v) +// +func (aq *AccountQuery) Select(fields ...string) *AccountSelect { + aq.fields = append(aq.fields, fields...) + return &AccountSelect{AccountQuery: aq} +} + +func (aq *AccountQuery) prepareQuery(ctx context.Context) error { + for _, f := range aq.fields { + if !account.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if aq.path != nil { + prev, err := aq.path(ctx) + if err != nil { + return err + } + aq.sql = prev + } + return nil +} + +func (aq *AccountQuery) sqlAll(ctx context.Context) ([]*Account, error) { + var ( + nodes = []*Account{} + _spec = aq.querySpec() + loadedTypes = [2]bool{ + aq.withDomains != nil, + aq.withLogs != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]interface{}, error) { + node := &Account{config: aq.config} + nodes = append(nodes, node) + return node.scanValues(columns) + } + _spec.Assign = func(columns []string, values []interface{}) error { + if len(nodes) == 0 { + return fmt.Errorf("ent: Assign called without calling ScanValues") + } + node := nodes[len(nodes)-1] + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if err := sqlgraph.QueryNodes(ctx, aq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + + if query := aq.withDomains; query != nil { + fks := make([]driver.Value, 0, len(nodes)) + ids := make(map[int64]*Account, len(nodes)) + for _, node := range nodes { + ids[node.ID] = node + fks = append(fks, node.ID) + node.Edges.Domains = []*Domain{} + } + var ( + edgeids []int64 + edges = make(map[int64][]*Account) + ) + _spec := &sqlgraph.EdgeQuerySpec{ + Edge: &sqlgraph.EdgeSpec{ + Inverse: false, + Table: account.DomainsTable, + Columns: account.DomainsPrimaryKey, + }, + Predicate: func(s *sql.Selector) { + s.Where(sql.InValues(account.DomainsPrimaryKey[0], fks...)) + }, + ScanValues: func() [2]interface{} { + return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)} + }, + Assign: func(out, in interface{}) error { + eout, ok := out.(*sql.NullInt64) + if !ok || eout == nil { + return fmt.Errorf("unexpected id value for edge-out") + } + ein, ok := in.(*sql.NullInt64) + if !ok || ein == nil { + return fmt.Errorf("unexpected id value for edge-in") + } + outValue := eout.Int64 + inValue := ein.Int64 + node, ok := ids[outValue] + if !ok { + return fmt.Errorf("unexpected node id in edges: %v", outValue) + } + if _, ok := edges[inValue]; !ok { + edgeids = append(edgeids, inValue) + } + edges[inValue] = append(edges[inValue], node) + return nil + }, + } + if err := sqlgraph.QueryEdges(ctx, aq.driver, _spec); err != nil { + return nil, fmt.Errorf(`query edges "domains": %w`, err) + } + query.Where(domain.IDIn(edgeids...)) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + nodes, ok := edges[n.ID] + if !ok { + return nil, fmt.Errorf(`unexpected "domains" node returned %v`, n.ID) + } + for i := range nodes { + nodes[i].Edges.Domains = append(nodes[i].Edges.Domains, n) + } + } + } + + if query := aq.withLogs; query != nil { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int64]*Account) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + nodes[i].Edges.Logs = []*Logentry{} + } + query.Where(predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.InValues(account.LogsColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + fk := n.AccountID + node, ok := nodeids[fk] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "account_id" returned %v for node %v`, fk, n.ID) + } + node.Edges.Logs = append(node.Edges.Logs, n) + } + } + + return nodes, nil +} + +func (aq *AccountQuery) sqlCount(ctx context.Context) (int, error) { + _spec := aq.querySpec() + _spec.Node.Columns = aq.fields + if len(aq.fields) > 0 { + _spec.Unique = aq.unique != nil && *aq.unique + } + return sqlgraph.CountNodes(ctx, aq.driver, _spec) +} + +func (aq *AccountQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := aq.sqlCount(ctx) + if err != nil { + return false, fmt.Errorf("ent: check existence: %w", err) + } + return n > 0, nil +} + +func (aq *AccountQuery) querySpec() *sqlgraph.QuerySpec { + _spec := &sqlgraph.QuerySpec{ + Node: &sqlgraph.NodeSpec{ + Table: account.Table, + Columns: account.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + From: aq.sql, + Unique: true, + } + if unique := aq.unique; unique != nil { + _spec.Unique = *unique + } + if fields := aq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, account.FieldID) + for i := range fields { + if fields[i] != account.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := aq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := aq.limit; limit != nil { + _spec.Limit = *limit + } + if offset := aq.offset; offset != nil { + _spec.Offset = *offset + } + if ps := aq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (aq *AccountQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(aq.driver.Dialect()) + t1 := builder.Table(account.Table) + columns := aq.fields + if len(columns) == 0 { + columns = account.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if aq.sql != nil { + selector = aq.sql + selector.Select(selector.Columns(columns...)...) + } + if aq.unique != nil && *aq.unique { + selector.Distinct() + } + for _, p := range aq.predicates { + p(selector) + } + for _, p := range aq.order { + p(selector) + } + if offset := aq.offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := aq.limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// AccountGroupBy is the group-by builder for Account entities. +type AccountGroupBy struct { + config + fields []string + fns []AggregateFunc + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (agb *AccountGroupBy) Aggregate(fns ...AggregateFunc) *AccountGroupBy { + agb.fns = append(agb.fns, fns...) + return agb +} + +// Scan applies the group-by query and scans the result into the given value. +func (agb *AccountGroupBy) Scan(ctx context.Context, v interface{}) error { + query, err := agb.path(ctx) + if err != nil { + return err + } + agb.sql = query + return agb.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (agb *AccountGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := agb.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. +func (agb *AccountGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(agb.fields) > 1 { + return nil, errors.New("ent: AccountGroupBy.Strings is not achievable when grouping more than 1 field") + } + var v []string + if err := agb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (agb *AccountGroupBy) StringsX(ctx context.Context) []string { + v, err := agb.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (agb *AccountGroupBy) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = agb.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{account.Label} + default: + err = fmt.Errorf("ent: AccountGroupBy.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (agb *AccountGroupBy) StringX(ctx context.Context) string { + v, err := agb.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. +func (agb *AccountGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(agb.fields) > 1 { + return nil, errors.New("ent: AccountGroupBy.Ints is not achievable when grouping more than 1 field") + } + var v []int + if err := agb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (agb *AccountGroupBy) IntsX(ctx context.Context) []int { + v, err := agb.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (agb *AccountGroupBy) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = agb.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{account.Label} + default: + err = fmt.Errorf("ent: AccountGroupBy.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (agb *AccountGroupBy) IntX(ctx context.Context) int { + v, err := agb.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. +func (agb *AccountGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(agb.fields) > 1 { + return nil, errors.New("ent: AccountGroupBy.Float64s is not achievable when grouping more than 1 field") + } + var v []float64 + if err := agb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (agb *AccountGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := agb.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (agb *AccountGroupBy) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = agb.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{account.Label} + default: + err = fmt.Errorf("ent: AccountGroupBy.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (agb *AccountGroupBy) Float64X(ctx context.Context) float64 { + v, err := agb.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. +func (agb *AccountGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(agb.fields) > 1 { + return nil, errors.New("ent: AccountGroupBy.Bools is not achievable when grouping more than 1 field") + } + var v []bool + if err := agb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (agb *AccountGroupBy) BoolsX(ctx context.Context) []bool { + v, err := agb.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (agb *AccountGroupBy) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = agb.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{account.Label} + default: + err = fmt.Errorf("ent: AccountGroupBy.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (agb *AccountGroupBy) BoolX(ctx context.Context) bool { + v, err := agb.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (agb *AccountGroupBy) sqlScan(ctx context.Context, v interface{}) error { + for _, f := range agb.fields { + if !account.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} + } + } + selector := agb.sqlQuery() + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := agb.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (agb *AccountGroupBy) sqlQuery() *sql.Selector { + selector := agb.sql.Select() + aggregation := make([]string, 0, len(agb.fns)) + for _, fn := range agb.fns { + aggregation = append(aggregation, fn(selector)) + } + // If no columns were selected in a custom aggregation function, the default + // selection is the fields used for "group-by", and the aggregation functions. + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(agb.fields)+len(agb.fns)) + for _, f := range agb.fields { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + return selector.GroupBy(selector.Columns(agb.fields...)...) +} + +// AccountSelect is the builder for selecting fields of Account entities. +type AccountSelect struct { + *AccountQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector +} + +// Scan applies the selector query and scans the result into the given value. +func (as *AccountSelect) Scan(ctx context.Context, v interface{}) error { + if err := as.prepareQuery(ctx); err != nil { + return err + } + as.sql = as.AccountQuery.sqlQuery(ctx) + return as.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (as *AccountSelect) ScanX(ctx context.Context, v interface{}) { + if err := as.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from a selector. It is only allowed when selecting one field. +func (as *AccountSelect) Strings(ctx context.Context) ([]string, error) { + if len(as.fields) > 1 { + return nil, errors.New("ent: AccountSelect.Strings is not achievable when selecting more than 1 field") + } + var v []string + if err := as.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (as *AccountSelect) StringsX(ctx context.Context) []string { + v, err := as.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a selector. It is only allowed when selecting one field. +func (as *AccountSelect) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = as.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{account.Label} + default: + err = fmt.Errorf("ent: AccountSelect.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (as *AccountSelect) StringX(ctx context.Context) string { + v, err := as.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from a selector. It is only allowed when selecting one field. +func (as *AccountSelect) Ints(ctx context.Context) ([]int, error) { + if len(as.fields) > 1 { + return nil, errors.New("ent: AccountSelect.Ints is not achievable when selecting more than 1 field") + } + var v []int + if err := as.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (as *AccountSelect) IntsX(ctx context.Context) []int { + v, err := as.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a selector. It is only allowed when selecting one field. +func (as *AccountSelect) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = as.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{account.Label} + default: + err = fmt.Errorf("ent: AccountSelect.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (as *AccountSelect) IntX(ctx context.Context) int { + v, err := as.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. +func (as *AccountSelect) Float64s(ctx context.Context) ([]float64, error) { + if len(as.fields) > 1 { + return nil, errors.New("ent: AccountSelect.Float64s is not achievable when selecting more than 1 field") + } + var v []float64 + if err := as.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (as *AccountSelect) Float64sX(ctx context.Context) []float64 { + v, err := as.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. +func (as *AccountSelect) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = as.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{account.Label} + default: + err = fmt.Errorf("ent: AccountSelect.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (as *AccountSelect) Float64X(ctx context.Context) float64 { + v, err := as.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from a selector. It is only allowed when selecting one field. +func (as *AccountSelect) Bools(ctx context.Context) ([]bool, error) { + if len(as.fields) > 1 { + return nil, errors.New("ent: AccountSelect.Bools is not achievable when selecting more than 1 field") + } + var v []bool + if err := as.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (as *AccountSelect) BoolsX(ctx context.Context) []bool { + v, err := as.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a selector. It is only allowed when selecting one field. +func (as *AccountSelect) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = as.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{account.Label} + default: + err = fmt.Errorf("ent: AccountSelect.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (as *AccountSelect) BoolX(ctx context.Context) bool { + v, err := as.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (as *AccountSelect) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := as.sql.Query() + if err := as.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/account_update.go b/ent/account_update.go new file mode 100644 index 0000000..c8d527f --- /dev/null +++ b/ent/account_update.go @@ -0,0 +1,774 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AccountUpdate is the builder for updating Account entities. +type AccountUpdate struct { + config + hooks []Hook + mutation *AccountMutation +} + +// Where appends a list predicates to the AccountUpdate builder. +func (au *AccountUpdate) Where(ps ...predicate.Account) *AccountUpdate { + au.mutation.Where(ps...) + return au +} + +// SetModified sets the "modified" field. +func (au *AccountUpdate) SetModified(t time.Time) *AccountUpdate { + au.mutation.SetModified(t) + return au +} + +// ClearModified clears the value of the "modified" field. +func (au *AccountUpdate) ClearModified() *AccountUpdate { + au.mutation.ClearModified() + return au +} + +// SetUsername sets the "username" field. +func (au *AccountUpdate) SetUsername(s string) *AccountUpdate { + au.mutation.SetUsername(s) + return au +} + +// SetPassword sets the "password" field. +func (au *AccountUpdate) SetPassword(b []byte) *AccountUpdate { + au.mutation.SetPassword(b) + return au +} + +// SetSuper sets the "super" field. +func (au *AccountUpdate) SetSuper(b bool) *AccountUpdate { + au.mutation.SetSuper(b) + return au +} + +// SetActive sets the "active" field. +func (au *AccountUpdate) SetActive(b bool) *AccountUpdate { + au.mutation.SetActive(b) + return au +} + +// AddDomainIDs adds the "domains" edge to the Domain entity by IDs. +func (au *AccountUpdate) AddDomainIDs(ids ...int64) *AccountUpdate { + au.mutation.AddDomainIDs(ids...) + return au +} + +// AddDomains adds the "domains" edges to the Domain entity. +func (au *AccountUpdate) AddDomains(d ...*Domain) *AccountUpdate { + ids := make([]int64, len(d)) + for i := range d { + ids[i] = d[i].ID + } + return au.AddDomainIDs(ids...) +} + +// AddLogIDs adds the "logs" edge to the Logentry entity by IDs. +func (au *AccountUpdate) AddLogIDs(ids ...int64) *AccountUpdate { + au.mutation.AddLogIDs(ids...) + return au +} + +// AddLogs adds the "logs" edges to the Logentry entity. +func (au *AccountUpdate) AddLogs(l ...*Logentry) *AccountUpdate { + ids := make([]int64, len(l)) + for i := range l { + ids[i] = l[i].ID + } + return au.AddLogIDs(ids...) +} + +// Mutation returns the AccountMutation object of the builder. +func (au *AccountUpdate) Mutation() *AccountMutation { + return au.mutation +} + +// ClearDomains clears all "domains" edges to the Domain entity. +func (au *AccountUpdate) ClearDomains() *AccountUpdate { + au.mutation.ClearDomains() + return au +} + +// RemoveDomainIDs removes the "domains" edge to Domain entities by IDs. +func (au *AccountUpdate) RemoveDomainIDs(ids ...int64) *AccountUpdate { + au.mutation.RemoveDomainIDs(ids...) + return au +} + +// RemoveDomains removes "domains" edges to Domain entities. +func (au *AccountUpdate) RemoveDomains(d ...*Domain) *AccountUpdate { + ids := make([]int64, len(d)) + for i := range d { + ids[i] = d[i].ID + } + return au.RemoveDomainIDs(ids...) +} + +// ClearLogs clears all "logs" edges to the Logentry entity. +func (au *AccountUpdate) ClearLogs() *AccountUpdate { + au.mutation.ClearLogs() + return au +} + +// RemoveLogIDs removes the "logs" edge to Logentry entities by IDs. +func (au *AccountUpdate) RemoveLogIDs(ids ...int64) *AccountUpdate { + au.mutation.RemoveLogIDs(ids...) + return au +} + +// RemoveLogs removes "logs" edges to Logentry entities. +func (au *AccountUpdate) RemoveLogs(l ...*Logentry) *AccountUpdate { + ids := make([]int64, len(l)) + for i := range l { + ids[i] = l[i].ID + } + return au.RemoveLogIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (au *AccountUpdate) Save(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + au.defaults() + if len(au.hooks) == 0 { + affected, err = au.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AccountMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + au.mutation = mutation + affected, err = au.sqlSave(ctx) + mutation.done = true + return affected, err + }) + for i := len(au.hooks) - 1; i >= 0; i-- { + if au.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = au.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, au.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// SaveX is like Save, but panics if an error occurs. +func (au *AccountUpdate) SaveX(ctx context.Context) int { + affected, err := au.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (au *AccountUpdate) Exec(ctx context.Context) error { + _, err := au.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (au *AccountUpdate) ExecX(ctx context.Context) { + if err := au.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (au *AccountUpdate) defaults() { + if _, ok := au.mutation.Modified(); !ok && !au.mutation.ModifiedCleared() { + v := account.UpdateDefaultModified() + au.mutation.SetModified(v) + } +} + +func (au *AccountUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: account.Table, + Columns: account.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + if ps := au.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := au.mutation.Modified(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: account.FieldModified, + }) + } + if au.mutation.ModifiedCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: account.FieldModified, + }) + } + if value, ok := au.mutation.Username(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: account.FieldUsername, + }) + } + if value, ok := au.mutation.Password(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Value: value, + Column: account.FieldPassword, + }) + } + if value, ok := au.mutation.Super(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: account.FieldSuper, + }) + } + if value, ok := au.mutation.Active(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: account.FieldActive, + }) + } + if au.mutation.DomainsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: account.DomainsTable, + Columns: account.DomainsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := au.mutation.RemovedDomainsIDs(); len(nodes) > 0 && !au.mutation.DomainsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: account.DomainsTable, + Columns: account.DomainsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := au.mutation.DomainsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: account.DomainsTable, + Columns: account.DomainsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if au.mutation.LogsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: account.LogsTable, + Columns: []string{account.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := au.mutation.RemovedLogsIDs(); len(nodes) > 0 && !au.mutation.LogsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: account.LogsTable, + Columns: []string{account.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := au.mutation.LogsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: account.LogsTable, + Columns: []string{account.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{account.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return 0, err + } + return n, nil +} + +// AccountUpdateOne is the builder for updating a single Account entity. +type AccountUpdateOne struct { + config + fields []string + hooks []Hook + mutation *AccountMutation +} + +// SetModified sets the "modified" field. +func (auo *AccountUpdateOne) SetModified(t time.Time) *AccountUpdateOne { + auo.mutation.SetModified(t) + return auo +} + +// ClearModified clears the value of the "modified" field. +func (auo *AccountUpdateOne) ClearModified() *AccountUpdateOne { + auo.mutation.ClearModified() + return auo +} + +// SetUsername sets the "username" field. +func (auo *AccountUpdateOne) SetUsername(s string) *AccountUpdateOne { + auo.mutation.SetUsername(s) + return auo +} + +// SetPassword sets the "password" field. +func (auo *AccountUpdateOne) SetPassword(b []byte) *AccountUpdateOne { + auo.mutation.SetPassword(b) + return auo +} + +// SetSuper sets the "super" field. +func (auo *AccountUpdateOne) SetSuper(b bool) *AccountUpdateOne { + auo.mutation.SetSuper(b) + return auo +} + +// SetActive sets the "active" field. +func (auo *AccountUpdateOne) SetActive(b bool) *AccountUpdateOne { + auo.mutation.SetActive(b) + return auo +} + +// AddDomainIDs adds the "domains" edge to the Domain entity by IDs. +func (auo *AccountUpdateOne) AddDomainIDs(ids ...int64) *AccountUpdateOne { + auo.mutation.AddDomainIDs(ids...) + return auo +} + +// AddDomains adds the "domains" edges to the Domain entity. +func (auo *AccountUpdateOne) AddDomains(d ...*Domain) *AccountUpdateOne { + ids := make([]int64, len(d)) + for i := range d { + ids[i] = d[i].ID + } + return auo.AddDomainIDs(ids...) +} + +// AddLogIDs adds the "logs" edge to the Logentry entity by IDs. +func (auo *AccountUpdateOne) AddLogIDs(ids ...int64) *AccountUpdateOne { + auo.mutation.AddLogIDs(ids...) + return auo +} + +// AddLogs adds the "logs" edges to the Logentry entity. +func (auo *AccountUpdateOne) AddLogs(l ...*Logentry) *AccountUpdateOne { + ids := make([]int64, len(l)) + for i := range l { + ids[i] = l[i].ID + } + return auo.AddLogIDs(ids...) +} + +// Mutation returns the AccountMutation object of the builder. +func (auo *AccountUpdateOne) Mutation() *AccountMutation { + return auo.mutation +} + +// ClearDomains clears all "domains" edges to the Domain entity. +func (auo *AccountUpdateOne) ClearDomains() *AccountUpdateOne { + auo.mutation.ClearDomains() + return auo +} + +// RemoveDomainIDs removes the "domains" edge to Domain entities by IDs. +func (auo *AccountUpdateOne) RemoveDomainIDs(ids ...int64) *AccountUpdateOne { + auo.mutation.RemoveDomainIDs(ids...) + return auo +} + +// RemoveDomains removes "domains" edges to Domain entities. +func (auo *AccountUpdateOne) RemoveDomains(d ...*Domain) *AccountUpdateOne { + ids := make([]int64, len(d)) + for i := range d { + ids[i] = d[i].ID + } + return auo.RemoveDomainIDs(ids...) +} + +// ClearLogs clears all "logs" edges to the Logentry entity. +func (auo *AccountUpdateOne) ClearLogs() *AccountUpdateOne { + auo.mutation.ClearLogs() + return auo +} + +// RemoveLogIDs removes the "logs" edge to Logentry entities by IDs. +func (auo *AccountUpdateOne) RemoveLogIDs(ids ...int64) *AccountUpdateOne { + auo.mutation.RemoveLogIDs(ids...) + return auo +} + +// RemoveLogs removes "logs" edges to Logentry entities. +func (auo *AccountUpdateOne) RemoveLogs(l ...*Logentry) *AccountUpdateOne { + ids := make([]int64, len(l)) + for i := range l { + ids[i] = l[i].ID + } + return auo.RemoveLogIDs(ids...) +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (auo *AccountUpdateOne) Select(field string, fields ...string) *AccountUpdateOne { + auo.fields = append([]string{field}, fields...) + return auo +} + +// Save executes the query and returns the updated Account entity. +func (auo *AccountUpdateOne) Save(ctx context.Context) (*Account, error) { + var ( + err error + node *Account + ) + auo.defaults() + if len(auo.hooks) == 0 { + node, err = auo.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AccountMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + auo.mutation = mutation + node, err = auo.sqlSave(ctx) + mutation.done = true + return node, err + }) + for i := len(auo.hooks) - 1; i >= 0; i-- { + if auo.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = auo.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, auo.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX is like Save, but panics if an error occurs. +func (auo *AccountUpdateOne) SaveX(ctx context.Context) *Account { + node, err := auo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (auo *AccountUpdateOne) Exec(ctx context.Context) error { + _, err := auo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (auo *AccountUpdateOne) ExecX(ctx context.Context) { + if err := auo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (auo *AccountUpdateOne) defaults() { + if _, ok := auo.mutation.Modified(); !ok && !auo.mutation.ModifiedCleared() { + v := account.UpdateDefaultModified() + auo.mutation.SetModified(v) + } +} + +func (auo *AccountUpdateOne) sqlSave(ctx context.Context) (_node *Account, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: account.Table, + Columns: account.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + id, ok := auo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Account.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := auo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, account.FieldID) + for _, f := range fields { + if !account.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != account.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := auo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := auo.mutation.Modified(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: account.FieldModified, + }) + } + if auo.mutation.ModifiedCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: account.FieldModified, + }) + } + if value, ok := auo.mutation.Username(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: account.FieldUsername, + }) + } + if value, ok := auo.mutation.Password(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Value: value, + Column: account.FieldPassword, + }) + } + if value, ok := auo.mutation.Super(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: account.FieldSuper, + }) + } + if value, ok := auo.mutation.Active(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: account.FieldActive, + }) + } + if auo.mutation.DomainsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: account.DomainsTable, + Columns: account.DomainsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := auo.mutation.RemovedDomainsIDs(); len(nodes) > 0 && !auo.mutation.DomainsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: account.DomainsTable, + Columns: account.DomainsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := auo.mutation.DomainsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: false, + Table: account.DomainsTable, + Columns: account.DomainsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if auo.mutation.LogsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: account.LogsTable, + Columns: []string{account.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := auo.mutation.RemovedLogsIDs(); len(nodes) > 0 && !auo.mutation.LogsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: account.LogsTable, + Columns: []string{account.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := auo.mutation.LogsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: account.LogsTable, + Columns: []string{account.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Account{config: auo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{account.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + return _node, nil +} diff --git a/ent/alias.go b/ent/alias.go new file mode 100644 index 0000000..ead362c --- /dev/null +++ b/ent/alias.go @@ -0,0 +1,179 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "code.icod.de/postfix/manager/ent/alias" + "code.icod.de/postfix/manager/ent/domain" + "entgo.io/ent/dialect/sql" +) + +// Alias is the model entity for the Alias schema. +type Alias struct { + config `json:"-"` + // ID of the ent. + ID int64 `json:"id,omitempty"` + // Created holds the value of the "created" field. + Created time.Time `json:"created,omitempty"` + // Modified holds the value of the "modified" field. + Modified *time.Time `json:"modified,omitempty"` + // DomainID holds the value of the "domain_id" field. + DomainID int64 `json:"domain_id,omitempty"` + // Goto holds the value of the "goto" field. + Goto string `json:"goto,omitempty"` + // Active holds the value of the "active" field. + Active bool `json:"active,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the AliasQuery when eager-loading is set. + Edges AliasEdges `json:"edges"` +} + +// AliasEdges holds the relations/edges for other nodes in the graph. +type AliasEdges struct { + // Domain holds the value of the domain edge. + Domain *Domain `json:"domain,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// DomainOrErr returns the Domain value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e AliasEdges) DomainOrErr() (*Domain, error) { + if e.loadedTypes[0] { + if e.Domain == nil { + // The edge domain was loaded in eager-loading, + // but was not found. + return nil, &NotFoundError{label: domain.Label} + } + return e.Domain, nil + } + return nil, &NotLoadedError{edge: "domain"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Alias) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case alias.FieldActive: + values[i] = new(sql.NullBool) + case alias.FieldID, alias.FieldDomainID: + values[i] = new(sql.NullInt64) + case alias.FieldGoto: + values[i] = new(sql.NullString) + case alias.FieldCreated, alias.FieldModified: + values[i] = new(sql.NullTime) + default: + return nil, fmt.Errorf("unexpected column %q for type Alias", columns[i]) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Alias fields. +func (a *Alias) assignValues(columns []string, values []interface{}) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case alias.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + a.ID = int64(value.Int64) + case alias.FieldCreated: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created", values[i]) + } else if value.Valid { + a.Created = value.Time + } + case alias.FieldModified: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field modified", values[i]) + } else if value.Valid { + a.Modified = new(time.Time) + *a.Modified = value.Time + } + case alias.FieldDomainID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field domain_id", values[i]) + } else if value.Valid { + a.DomainID = value.Int64 + } + case alias.FieldGoto: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field goto", values[i]) + } else if value.Valid { + a.Goto = value.String + } + case alias.FieldActive: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field active", values[i]) + } else if value.Valid { + a.Active = value.Bool + } + } + } + return nil +} + +// QueryDomain queries the "domain" edge of the Alias entity. +func (a *Alias) QueryDomain() *DomainQuery { + return (&AliasClient{config: a.config}).QueryDomain(a) +} + +// Update returns a builder for updating this Alias. +// Note that you need to call Alias.Unwrap() before calling this method if this Alias +// was returned from a transaction, and the transaction was committed or rolled back. +func (a *Alias) Update() *AliasUpdateOne { + return (&AliasClient{config: a.config}).UpdateOne(a) +} + +// Unwrap unwraps the Alias entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (a *Alias) Unwrap() *Alias { + tx, ok := a.config.driver.(*txDriver) + if !ok { + panic("ent: Alias is not a transactional entity") + } + a.config.driver = tx.drv + return a +} + +// String implements the fmt.Stringer. +func (a *Alias) String() string { + var builder strings.Builder + builder.WriteString("Alias(") + builder.WriteString(fmt.Sprintf("id=%v", a.ID)) + builder.WriteString(", created=") + builder.WriteString(a.Created.Format(time.ANSIC)) + if v := a.Modified; v != nil { + builder.WriteString(", modified=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", domain_id=") + builder.WriteString(fmt.Sprintf("%v", a.DomainID)) + builder.WriteString(", goto=") + builder.WriteString(a.Goto) + builder.WriteString(", active=") + builder.WriteString(fmt.Sprintf("%v", a.Active)) + builder.WriteByte(')') + return builder.String() +} + +// AliasSlice is a parsable slice of Alias. +type AliasSlice []*Alias + +func (a AliasSlice) config(cfg config) { + for _i := range a { + a[_i].config = cfg + } +} diff --git a/ent/alias/alias.go b/ent/alias/alias.go new file mode 100644 index 0000000..fec8fa0 --- /dev/null +++ b/ent/alias/alias.go @@ -0,0 +1,64 @@ +// Code generated by entc, DO NOT EDIT. + +package alias + +import ( + "time" +) + +const ( + // Label holds the string label denoting the alias type in the database. + Label = "alias" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCreated holds the string denoting the created field in the database. + FieldCreated = "created" + // FieldModified holds the string denoting the modified field in the database. + FieldModified = "modified" + // FieldDomainID holds the string denoting the domain_id field in the database. + FieldDomainID = "domain_id" + // FieldGoto holds the string denoting the goto field in the database. + FieldGoto = "goto" + // FieldActive holds the string denoting the active field in the database. + FieldActive = "active" + // EdgeDomain holds the string denoting the domain edge name in mutations. + EdgeDomain = "domain" + // Table holds the table name of the alias in the database. + Table = "alias" + // DomainTable is the table that holds the domain relation/edge. + DomainTable = "alias" + // DomainInverseTable is the table name for the Domain entity. + // It exists in this package in order to avoid circular dependency with the "domain" package. + DomainInverseTable = "domains" + // DomainColumn is the table column denoting the domain relation/edge. + DomainColumn = "domain_id" +) + +// Columns holds all SQL columns for alias fields. +var Columns = []string{ + FieldID, + FieldCreated, + FieldModified, + FieldDomainID, + FieldGoto, + FieldActive, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreated holds the default value on creation for the "created" field. + DefaultCreated func() time.Time + // DefaultModified holds the default value on creation for the "modified" field. + DefaultModified func() time.Time + // UpdateDefaultModified holds the default value on update for the "modified" field. + UpdateDefaultModified func() time.Time +) diff --git a/ent/alias/where.go b/ent/alias/where.go new file mode 100644 index 0000000..d28f549 --- /dev/null +++ b/ent/alias/where.go @@ -0,0 +1,542 @@ +// Code generated by entc, DO NOT EDIT. + +package alias + +import ( + "time" + + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// ID filters vertices based on their ID field. +func ID(id int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldID), id)) + }) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.In(s.C(FieldID), v...)) + }) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.NotIn(s.C(FieldID), v...)) + }) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldID), id)) + }) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldID), id)) + }) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldID), id)) + }) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldID), id)) + }) +} + +// Created applies equality check predicate on the "created" field. It's identical to CreatedEQ. +func Created(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldCreated), v)) + }) +} + +// Modified applies equality check predicate on the "modified" field. It's identical to ModifiedEQ. +func Modified(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldModified), v)) + }) +} + +// DomainID applies equality check predicate on the "domain_id" field. It's identical to DomainIDEQ. +func DomainID(v int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDomainID), v)) + }) +} + +// Goto applies equality check predicate on the "goto" field. It's identical to GotoEQ. +func Goto(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldGoto), v)) + }) +} + +// Active applies equality check predicate on the "active" field. It's identical to ActiveEQ. +func Active(v bool) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldActive), v)) + }) +} + +// CreatedEQ applies the EQ predicate on the "created" field. +func CreatedEQ(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldCreated), v)) + }) +} + +// CreatedNEQ applies the NEQ predicate on the "created" field. +func CreatedNEQ(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldCreated), v)) + }) +} + +// CreatedIn applies the In predicate on the "created" field. +func CreatedIn(vs ...time.Time) predicate.Alias { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Alias(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldCreated), v...)) + }) +} + +// CreatedNotIn applies the NotIn predicate on the "created" field. +func CreatedNotIn(vs ...time.Time) predicate.Alias { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Alias(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldCreated), v...)) + }) +} + +// CreatedGT applies the GT predicate on the "created" field. +func CreatedGT(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldCreated), v)) + }) +} + +// CreatedGTE applies the GTE predicate on the "created" field. +func CreatedGTE(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldCreated), v)) + }) +} + +// CreatedLT applies the LT predicate on the "created" field. +func CreatedLT(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldCreated), v)) + }) +} + +// CreatedLTE applies the LTE predicate on the "created" field. +func CreatedLTE(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldCreated), v)) + }) +} + +// ModifiedEQ applies the EQ predicate on the "modified" field. +func ModifiedEQ(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldModified), v)) + }) +} + +// ModifiedNEQ applies the NEQ predicate on the "modified" field. +func ModifiedNEQ(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldModified), v)) + }) +} + +// ModifiedIn applies the In predicate on the "modified" field. +func ModifiedIn(vs ...time.Time) predicate.Alias { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Alias(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldModified), v...)) + }) +} + +// ModifiedNotIn applies the NotIn predicate on the "modified" field. +func ModifiedNotIn(vs ...time.Time) predicate.Alias { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Alias(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldModified), v...)) + }) +} + +// ModifiedGT applies the GT predicate on the "modified" field. +func ModifiedGT(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldModified), v)) + }) +} + +// ModifiedGTE applies the GTE predicate on the "modified" field. +func ModifiedGTE(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldModified), v)) + }) +} + +// ModifiedLT applies the LT predicate on the "modified" field. +func ModifiedLT(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldModified), v)) + }) +} + +// ModifiedLTE applies the LTE predicate on the "modified" field. +func ModifiedLTE(v time.Time) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldModified), v)) + }) +} + +// ModifiedIsNil applies the IsNil predicate on the "modified" field. +func ModifiedIsNil() predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldModified))) + }) +} + +// ModifiedNotNil applies the NotNil predicate on the "modified" field. +func ModifiedNotNil() predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldModified))) + }) +} + +// DomainIDEQ applies the EQ predicate on the "domain_id" field. +func DomainIDEQ(v int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDomainID), v)) + }) +} + +// DomainIDNEQ applies the NEQ predicate on the "domain_id" field. +func DomainIDNEQ(v int64) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldDomainID), v)) + }) +} + +// DomainIDIn applies the In predicate on the "domain_id" field. +func DomainIDIn(vs ...int64) predicate.Alias { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Alias(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldDomainID), v...)) + }) +} + +// DomainIDNotIn applies the NotIn predicate on the "domain_id" field. +func DomainIDNotIn(vs ...int64) predicate.Alias { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Alias(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldDomainID), v...)) + }) +} + +// DomainIDIsNil applies the IsNil predicate on the "domain_id" field. +func DomainIDIsNil() predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldDomainID))) + }) +} + +// DomainIDNotNil applies the NotNil predicate on the "domain_id" field. +func DomainIDNotNil() predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldDomainID))) + }) +} + +// GotoEQ applies the EQ predicate on the "goto" field. +func GotoEQ(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldGoto), v)) + }) +} + +// GotoNEQ applies the NEQ predicate on the "goto" field. +func GotoNEQ(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldGoto), v)) + }) +} + +// GotoIn applies the In predicate on the "goto" field. +func GotoIn(vs ...string) predicate.Alias { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Alias(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldGoto), v...)) + }) +} + +// GotoNotIn applies the NotIn predicate on the "goto" field. +func GotoNotIn(vs ...string) predicate.Alias { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Alias(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldGoto), v...)) + }) +} + +// GotoGT applies the GT predicate on the "goto" field. +func GotoGT(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldGoto), v)) + }) +} + +// GotoGTE applies the GTE predicate on the "goto" field. +func GotoGTE(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldGoto), v)) + }) +} + +// GotoLT applies the LT predicate on the "goto" field. +func GotoLT(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldGoto), v)) + }) +} + +// GotoLTE applies the LTE predicate on the "goto" field. +func GotoLTE(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldGoto), v)) + }) +} + +// GotoContains applies the Contains predicate on the "goto" field. +func GotoContains(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldGoto), v)) + }) +} + +// GotoHasPrefix applies the HasPrefix predicate on the "goto" field. +func GotoHasPrefix(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldGoto), v)) + }) +} + +// GotoHasSuffix applies the HasSuffix predicate on the "goto" field. +func GotoHasSuffix(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldGoto), v)) + }) +} + +// GotoEqualFold applies the EqualFold predicate on the "goto" field. +func GotoEqualFold(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldGoto), v)) + }) +} + +// GotoContainsFold applies the ContainsFold predicate on the "goto" field. +func GotoContainsFold(v string) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldGoto), v)) + }) +} + +// ActiveEQ applies the EQ predicate on the "active" field. +func ActiveEQ(v bool) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldActive), v)) + }) +} + +// ActiveNEQ applies the NEQ predicate on the "active" field. +func ActiveNEQ(v bool) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldActive), v)) + }) +} + +// HasDomain applies the HasEdge predicate on the "domain" edge. +func HasDomain() predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(DomainTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, DomainTable, DomainColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasDomainWith applies the HasEdge predicate on the "domain" edge with a given conditions (other predicates). +func HasDomainWith(preds ...predicate.Domain) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(DomainInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, DomainTable, DomainColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Alias) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for _, p := range predicates { + p(s1) + } + s.Where(s1.P()) + }) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Alias) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for i, p := range predicates { + if i > 0 { + s1.Or() + } + p(s1) + } + s.Where(s1.P()) + }) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Alias) predicate.Alias { + return predicate.Alias(func(s *sql.Selector) { + p(s.Not()) + }) +} diff --git a/ent/alias_create.go b/ent/alias_create.go new file mode 100644 index 0000000..5d0f79d --- /dev/null +++ b/ent/alias_create.go @@ -0,0 +1,351 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/postfix/manager/ent/alias" + "code.icod.de/postfix/manager/ent/domain" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AliasCreate is the builder for creating a Alias entity. +type AliasCreate struct { + config + mutation *AliasMutation + hooks []Hook +} + +// SetCreated sets the "created" field. +func (ac *AliasCreate) SetCreated(t time.Time) *AliasCreate { + ac.mutation.SetCreated(t) + return ac +} + +// SetNillableCreated sets the "created" field if the given value is not nil. +func (ac *AliasCreate) SetNillableCreated(t *time.Time) *AliasCreate { + if t != nil { + ac.SetCreated(*t) + } + return ac +} + +// SetModified sets the "modified" field. +func (ac *AliasCreate) SetModified(t time.Time) *AliasCreate { + ac.mutation.SetModified(t) + return ac +} + +// SetNillableModified sets the "modified" field if the given value is not nil. +func (ac *AliasCreate) SetNillableModified(t *time.Time) *AliasCreate { + if t != nil { + ac.SetModified(*t) + } + return ac +} + +// SetDomainID sets the "domain_id" field. +func (ac *AliasCreate) SetDomainID(i int64) *AliasCreate { + ac.mutation.SetDomainID(i) + return ac +} + +// SetNillableDomainID sets the "domain_id" field if the given value is not nil. +func (ac *AliasCreate) SetNillableDomainID(i *int64) *AliasCreate { + if i != nil { + ac.SetDomainID(*i) + } + return ac +} + +// SetGoto sets the "goto" field. +func (ac *AliasCreate) SetGoto(s string) *AliasCreate { + ac.mutation.SetGoto(s) + return ac +} + +// SetActive sets the "active" field. +func (ac *AliasCreate) SetActive(b bool) *AliasCreate { + ac.mutation.SetActive(b) + return ac +} + +// SetID sets the "id" field. +func (ac *AliasCreate) SetID(i int64) *AliasCreate { + ac.mutation.SetID(i) + return ac +} + +// SetDomain sets the "domain" edge to the Domain entity. +func (ac *AliasCreate) SetDomain(d *Domain) *AliasCreate { + return ac.SetDomainID(d.ID) +} + +// Mutation returns the AliasMutation object of the builder. +func (ac *AliasCreate) Mutation() *AliasMutation { + return ac.mutation +} + +// Save creates the Alias in the database. +func (ac *AliasCreate) Save(ctx context.Context) (*Alias, error) { + var ( + err error + node *Alias + ) + ac.defaults() + if len(ac.hooks) == 0 { + if err = ac.check(); err != nil { + return nil, err + } + node, err = ac.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AliasMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err = ac.check(); err != nil { + return nil, err + } + ac.mutation = mutation + if node, err = ac.sqlSave(ctx); err != nil { + return nil, err + } + mutation.id = &node.ID + mutation.done = true + return node, err + }) + for i := len(ac.hooks) - 1; i >= 0; i-- { + if ac.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = ac.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, ac.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX calls Save and panics if Save returns an error. +func (ac *AliasCreate) SaveX(ctx context.Context) *Alias { + v, err := ac.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (ac *AliasCreate) Exec(ctx context.Context) error { + _, err := ac.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ac *AliasCreate) ExecX(ctx context.Context) { + if err := ac.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (ac *AliasCreate) defaults() { + if _, ok := ac.mutation.Created(); !ok { + v := alias.DefaultCreated() + ac.mutation.SetCreated(v) + } + if _, ok := ac.mutation.Modified(); !ok { + v := alias.DefaultModified() + ac.mutation.SetModified(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (ac *AliasCreate) check() error { + if _, ok := ac.mutation.Created(); !ok { + return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "Alias.created"`)} + } + if _, ok := ac.mutation.Goto(); !ok { + return &ValidationError{Name: "goto", err: errors.New(`ent: missing required field "Alias.goto"`)} + } + if _, ok := ac.mutation.Active(); !ok { + return &ValidationError{Name: "active", err: errors.New(`ent: missing required field "Alias.active"`)} + } + return nil +} + +func (ac *AliasCreate) sqlSave(ctx context.Context) (*Alias, error) { + _node, _spec := ac.createSpec() + if err := sqlgraph.CreateNode(ctx, ac.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = int64(id) + } + return _node, nil +} + +func (ac *AliasCreate) createSpec() (*Alias, *sqlgraph.CreateSpec) { + var ( + _node = &Alias{config: ac.config} + _spec = &sqlgraph.CreateSpec{ + Table: alias.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + } + ) + if id, ok := ac.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := ac.mutation.Created(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: alias.FieldCreated, + }) + _node.Created = value + } + if value, ok := ac.mutation.Modified(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: alias.FieldModified, + }) + _node.Modified = &value + } + if value, ok := ac.mutation.Goto(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: alias.FieldGoto, + }) + _node.Goto = value + } + if value, ok := ac.mutation.Active(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: alias.FieldActive, + }) + _node.Active = value + } + if nodes := ac.mutation.DomainIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: alias.DomainTable, + Columns: []string{alias.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.DomainID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// AliasCreateBulk is the builder for creating many Alias entities in bulk. +type AliasCreateBulk struct { + config + builders []*AliasCreate +} + +// Save creates the Alias entities in the database. +func (acb *AliasCreateBulk) Save(ctx context.Context) ([]*Alias, error) { + specs := make([]*sqlgraph.CreateSpec, len(acb.builders)) + nodes := make([]*Alias, len(acb.builders)) + mutators := make([]Mutator, len(acb.builders)) + for i := range acb.builders { + func(i int, root context.Context) { + builder := acb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AliasMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + nodes[i], specs[i] = builder.createSpec() + var err error + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, acb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, acb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + if specs[i].ID.Value != nil && nodes[i].ID == 0 { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int64(id) + } + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, acb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (acb *AliasCreateBulk) SaveX(ctx context.Context) []*Alias { + v, err := acb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (acb *AliasCreateBulk) Exec(ctx context.Context) error { + _, err := acb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (acb *AliasCreateBulk) ExecX(ctx context.Context) { + if err := acb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/alias_delete.go b/ent/alias_delete.go new file mode 100644 index 0000000..e7ef675 --- /dev/null +++ b/ent/alias_delete.go @@ -0,0 +1,111 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + + "code.icod.de/postfix/manager/ent/alias" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AliasDelete is the builder for deleting a Alias entity. +type AliasDelete struct { + config + hooks []Hook + mutation *AliasMutation +} + +// Where appends a list predicates to the AliasDelete builder. +func (ad *AliasDelete) Where(ps ...predicate.Alias) *AliasDelete { + ad.mutation.Where(ps...) + return ad +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (ad *AliasDelete) Exec(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + if len(ad.hooks) == 0 { + affected, err = ad.sqlExec(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AliasMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + ad.mutation = mutation + affected, err = ad.sqlExec(ctx) + mutation.done = true + return affected, err + }) + for i := len(ad.hooks) - 1; i >= 0; i-- { + if ad.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = ad.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, ad.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ad *AliasDelete) ExecX(ctx context.Context) int { + n, err := ad.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (ad *AliasDelete) sqlExec(ctx context.Context) (int, error) { + _spec := &sqlgraph.DeleteSpec{ + Node: &sqlgraph.NodeSpec{ + Table: alias.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + } + if ps := ad.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return sqlgraph.DeleteNodes(ctx, ad.driver, _spec) +} + +// AliasDeleteOne is the builder for deleting a single Alias entity. +type AliasDeleteOne struct { + ad *AliasDelete +} + +// Exec executes the deletion query. +func (ado *AliasDeleteOne) Exec(ctx context.Context) error { + n, err := ado.ad.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{alias.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (ado *AliasDeleteOne) ExecX(ctx context.Context) { + ado.ad.ExecX(ctx) +} diff --git a/ent/alias_query.go b/ent/alias_query.go new file mode 100644 index 0000000..8ccd3d5 --- /dev/null +++ b/ent/alias_query.go @@ -0,0 +1,989 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "math" + + "code.icod.de/postfix/manager/ent/alias" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AliasQuery is the builder for querying Alias entities. +type AliasQuery struct { + config + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Alias + // eager-loading edges. + withDomain *DomainQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the AliasQuery builder. +func (aq *AliasQuery) Where(ps ...predicate.Alias) *AliasQuery { + aq.predicates = append(aq.predicates, ps...) + return aq +} + +// Limit adds a limit step to the query. +func (aq *AliasQuery) Limit(limit int) *AliasQuery { + aq.limit = &limit + return aq +} + +// Offset adds an offset step to the query. +func (aq *AliasQuery) Offset(offset int) *AliasQuery { + aq.offset = &offset + return aq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (aq *AliasQuery) Unique(unique bool) *AliasQuery { + aq.unique = &unique + return aq +} + +// Order adds an order step to the query. +func (aq *AliasQuery) Order(o ...OrderFunc) *AliasQuery { + aq.order = append(aq.order, o...) + return aq +} + +// QueryDomain chains the current query on the "domain" edge. +func (aq *AliasQuery) QueryDomain() *DomainQuery { + query := &DomainQuery{config: aq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := aq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(alias.Table, alias.FieldID, selector), + sqlgraph.To(domain.Table, domain.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, alias.DomainTable, alias.DomainColumn), + ) + fromU = sqlgraph.SetNeighbors(aq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Alias entity from the query. +// Returns a *NotFoundError when no Alias was found. +func (aq *AliasQuery) First(ctx context.Context) (*Alias, error) { + nodes, err := aq.Limit(1).All(ctx) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{alias.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (aq *AliasQuery) FirstX(ctx context.Context) *Alias { + node, err := aq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Alias ID from the query. +// Returns a *NotFoundError when no Alias ID was found. +func (aq *AliasQuery) FirstID(ctx context.Context) (id int64, err error) { + var ids []int64 + if ids, err = aq.Limit(1).IDs(ctx); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{alias.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (aq *AliasQuery) FirstIDX(ctx context.Context) int64 { + id, err := aq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Alias entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Alias entity is found. +// Returns a *NotFoundError when no Alias entities are found. +func (aq *AliasQuery) Only(ctx context.Context) (*Alias, error) { + nodes, err := aq.Limit(2).All(ctx) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{alias.Label} + default: + return nil, &NotSingularError{alias.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (aq *AliasQuery) OnlyX(ctx context.Context) *Alias { + node, err := aq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Alias ID in the query. +// Returns a *NotSingularError when more than one Alias ID is found. +// Returns a *NotFoundError when no entities are found. +func (aq *AliasQuery) OnlyID(ctx context.Context) (id int64, err error) { + var ids []int64 + if ids, err = aq.Limit(2).IDs(ctx); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{alias.Label} + default: + err = &NotSingularError{alias.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (aq *AliasQuery) OnlyIDX(ctx context.Context) int64 { + id, err := aq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of AliasSlice. +func (aq *AliasQuery) All(ctx context.Context) ([]*Alias, error) { + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + return aq.sqlAll(ctx) +} + +// AllX is like All, but panics if an error occurs. +func (aq *AliasQuery) AllX(ctx context.Context) []*Alias { + nodes, err := aq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Alias IDs. +func (aq *AliasQuery) IDs(ctx context.Context) ([]int64, error) { + var ids []int64 + if err := aq.Select(alias.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (aq *AliasQuery) IDsX(ctx context.Context) []int64 { + ids, err := aq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (aq *AliasQuery) Count(ctx context.Context) (int, error) { + if err := aq.prepareQuery(ctx); err != nil { + return 0, err + } + return aq.sqlCount(ctx) +} + +// CountX is like Count, but panics if an error occurs. +func (aq *AliasQuery) CountX(ctx context.Context) int { + count, err := aq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (aq *AliasQuery) Exist(ctx context.Context) (bool, error) { + if err := aq.prepareQuery(ctx); err != nil { + return false, err + } + return aq.sqlExist(ctx) +} + +// ExistX is like Exist, but panics if an error occurs. +func (aq *AliasQuery) ExistX(ctx context.Context) bool { + exist, err := aq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the AliasQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (aq *AliasQuery) Clone() *AliasQuery { + if aq == nil { + return nil + } + return &AliasQuery{ + config: aq.config, + limit: aq.limit, + offset: aq.offset, + order: append([]OrderFunc{}, aq.order...), + predicates: append([]predicate.Alias{}, aq.predicates...), + withDomain: aq.withDomain.Clone(), + // clone intermediate query. + sql: aq.sql.Clone(), + path: aq.path, + unique: aq.unique, + } +} + +// WithDomain tells the query-builder to eager-load the nodes that are connected to +// the "domain" edge. The optional arguments are used to configure the query builder of the edge. +func (aq *AliasQuery) WithDomain(opts ...func(*DomainQuery)) *AliasQuery { + query := &DomainQuery{config: aq.config} + for _, opt := range opts { + opt(query) + } + aq.withDomain = query + return aq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Created time.Time `json:"created,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Alias.Query(). +// GroupBy(alias.FieldCreated). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +// +func (aq *AliasQuery) GroupBy(field string, fields ...string) *AliasGroupBy { + group := &AliasGroupBy{config: aq.config} + group.fields = append([]string{field}, fields...) + group.path = func(ctx context.Context) (prev *sql.Selector, err error) { + if err := aq.prepareQuery(ctx); err != nil { + return nil, err + } + return aq.sqlQuery(ctx), nil + } + return group +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Created time.Time `json:"created,omitempty"` +// } +// +// client.Alias.Query(). +// Select(alias.FieldCreated). +// Scan(ctx, &v) +// +func (aq *AliasQuery) Select(fields ...string) *AliasSelect { + aq.fields = append(aq.fields, fields...) + return &AliasSelect{AliasQuery: aq} +} + +func (aq *AliasQuery) prepareQuery(ctx context.Context) error { + for _, f := range aq.fields { + if !alias.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if aq.path != nil { + prev, err := aq.path(ctx) + if err != nil { + return err + } + aq.sql = prev + } + return nil +} + +func (aq *AliasQuery) sqlAll(ctx context.Context) ([]*Alias, error) { + var ( + nodes = []*Alias{} + _spec = aq.querySpec() + loadedTypes = [1]bool{ + aq.withDomain != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]interface{}, error) { + node := &Alias{config: aq.config} + nodes = append(nodes, node) + return node.scanValues(columns) + } + _spec.Assign = func(columns []string, values []interface{}) error { + if len(nodes) == 0 { + return fmt.Errorf("ent: Assign called without calling ScanValues") + } + node := nodes[len(nodes)-1] + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if err := sqlgraph.QueryNodes(ctx, aq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + + if query := aq.withDomain; query != nil { + ids := make([]int64, 0, len(nodes)) + nodeids := make(map[int64][]*Alias) + for i := range nodes { + fk := nodes[i].DomainID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(domain.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "domain_id" returned %v`, n.ID) + } + for i := range nodes { + nodes[i].Edges.Domain = n + } + } + } + + return nodes, nil +} + +func (aq *AliasQuery) sqlCount(ctx context.Context) (int, error) { + _spec := aq.querySpec() + _spec.Node.Columns = aq.fields + if len(aq.fields) > 0 { + _spec.Unique = aq.unique != nil && *aq.unique + } + return sqlgraph.CountNodes(ctx, aq.driver, _spec) +} + +func (aq *AliasQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := aq.sqlCount(ctx) + if err != nil { + return false, fmt.Errorf("ent: check existence: %w", err) + } + return n > 0, nil +} + +func (aq *AliasQuery) querySpec() *sqlgraph.QuerySpec { + _spec := &sqlgraph.QuerySpec{ + Node: &sqlgraph.NodeSpec{ + Table: alias.Table, + Columns: alias.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + From: aq.sql, + Unique: true, + } + if unique := aq.unique; unique != nil { + _spec.Unique = *unique + } + if fields := aq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, alias.FieldID) + for i := range fields { + if fields[i] != alias.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := aq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := aq.limit; limit != nil { + _spec.Limit = *limit + } + if offset := aq.offset; offset != nil { + _spec.Offset = *offset + } + if ps := aq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (aq *AliasQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(aq.driver.Dialect()) + t1 := builder.Table(alias.Table) + columns := aq.fields + if len(columns) == 0 { + columns = alias.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if aq.sql != nil { + selector = aq.sql + selector.Select(selector.Columns(columns...)...) + } + if aq.unique != nil && *aq.unique { + selector.Distinct() + } + for _, p := range aq.predicates { + p(selector) + } + for _, p := range aq.order { + p(selector) + } + if offset := aq.offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := aq.limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// AliasGroupBy is the group-by builder for Alias entities. +type AliasGroupBy struct { + config + fields []string + fns []AggregateFunc + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (agb *AliasGroupBy) Aggregate(fns ...AggregateFunc) *AliasGroupBy { + agb.fns = append(agb.fns, fns...) + return agb +} + +// Scan applies the group-by query and scans the result into the given value. +func (agb *AliasGroupBy) Scan(ctx context.Context, v interface{}) error { + query, err := agb.path(ctx) + if err != nil { + return err + } + agb.sql = query + return agb.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (agb *AliasGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := agb.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. +func (agb *AliasGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(agb.fields) > 1 { + return nil, errors.New("ent: AliasGroupBy.Strings is not achievable when grouping more than 1 field") + } + var v []string + if err := agb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (agb *AliasGroupBy) StringsX(ctx context.Context) []string { + v, err := agb.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (agb *AliasGroupBy) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = agb.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{alias.Label} + default: + err = fmt.Errorf("ent: AliasGroupBy.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (agb *AliasGroupBy) StringX(ctx context.Context) string { + v, err := agb.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. +func (agb *AliasGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(agb.fields) > 1 { + return nil, errors.New("ent: AliasGroupBy.Ints is not achievable when grouping more than 1 field") + } + var v []int + if err := agb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (agb *AliasGroupBy) IntsX(ctx context.Context) []int { + v, err := agb.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (agb *AliasGroupBy) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = agb.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{alias.Label} + default: + err = fmt.Errorf("ent: AliasGroupBy.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (agb *AliasGroupBy) IntX(ctx context.Context) int { + v, err := agb.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. +func (agb *AliasGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(agb.fields) > 1 { + return nil, errors.New("ent: AliasGroupBy.Float64s is not achievable when grouping more than 1 field") + } + var v []float64 + if err := agb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (agb *AliasGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := agb.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (agb *AliasGroupBy) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = agb.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{alias.Label} + default: + err = fmt.Errorf("ent: AliasGroupBy.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (agb *AliasGroupBy) Float64X(ctx context.Context) float64 { + v, err := agb.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. +func (agb *AliasGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(agb.fields) > 1 { + return nil, errors.New("ent: AliasGroupBy.Bools is not achievable when grouping more than 1 field") + } + var v []bool + if err := agb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (agb *AliasGroupBy) BoolsX(ctx context.Context) []bool { + v, err := agb.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (agb *AliasGroupBy) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = agb.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{alias.Label} + default: + err = fmt.Errorf("ent: AliasGroupBy.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (agb *AliasGroupBy) BoolX(ctx context.Context) bool { + v, err := agb.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (agb *AliasGroupBy) sqlScan(ctx context.Context, v interface{}) error { + for _, f := range agb.fields { + if !alias.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} + } + } + selector := agb.sqlQuery() + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := agb.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (agb *AliasGroupBy) sqlQuery() *sql.Selector { + selector := agb.sql.Select() + aggregation := make([]string, 0, len(agb.fns)) + for _, fn := range agb.fns { + aggregation = append(aggregation, fn(selector)) + } + // If no columns were selected in a custom aggregation function, the default + // selection is the fields used for "group-by", and the aggregation functions. + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(agb.fields)+len(agb.fns)) + for _, f := range agb.fields { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + return selector.GroupBy(selector.Columns(agb.fields...)...) +} + +// AliasSelect is the builder for selecting fields of Alias entities. +type AliasSelect struct { + *AliasQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector +} + +// Scan applies the selector query and scans the result into the given value. +func (as *AliasSelect) Scan(ctx context.Context, v interface{}) error { + if err := as.prepareQuery(ctx); err != nil { + return err + } + as.sql = as.AliasQuery.sqlQuery(ctx) + return as.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (as *AliasSelect) ScanX(ctx context.Context, v interface{}) { + if err := as.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from a selector. It is only allowed when selecting one field. +func (as *AliasSelect) Strings(ctx context.Context) ([]string, error) { + if len(as.fields) > 1 { + return nil, errors.New("ent: AliasSelect.Strings is not achievable when selecting more than 1 field") + } + var v []string + if err := as.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (as *AliasSelect) StringsX(ctx context.Context) []string { + v, err := as.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a selector. It is only allowed when selecting one field. +func (as *AliasSelect) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = as.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{alias.Label} + default: + err = fmt.Errorf("ent: AliasSelect.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (as *AliasSelect) StringX(ctx context.Context) string { + v, err := as.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from a selector. It is only allowed when selecting one field. +func (as *AliasSelect) Ints(ctx context.Context) ([]int, error) { + if len(as.fields) > 1 { + return nil, errors.New("ent: AliasSelect.Ints is not achievable when selecting more than 1 field") + } + var v []int + if err := as.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (as *AliasSelect) IntsX(ctx context.Context) []int { + v, err := as.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a selector. It is only allowed when selecting one field. +func (as *AliasSelect) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = as.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{alias.Label} + default: + err = fmt.Errorf("ent: AliasSelect.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (as *AliasSelect) IntX(ctx context.Context) int { + v, err := as.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. +func (as *AliasSelect) Float64s(ctx context.Context) ([]float64, error) { + if len(as.fields) > 1 { + return nil, errors.New("ent: AliasSelect.Float64s is not achievable when selecting more than 1 field") + } + var v []float64 + if err := as.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (as *AliasSelect) Float64sX(ctx context.Context) []float64 { + v, err := as.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. +func (as *AliasSelect) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = as.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{alias.Label} + default: + err = fmt.Errorf("ent: AliasSelect.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (as *AliasSelect) Float64X(ctx context.Context) float64 { + v, err := as.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from a selector. It is only allowed when selecting one field. +func (as *AliasSelect) Bools(ctx context.Context) ([]bool, error) { + if len(as.fields) > 1 { + return nil, errors.New("ent: AliasSelect.Bools is not achievable when selecting more than 1 field") + } + var v []bool + if err := as.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (as *AliasSelect) BoolsX(ctx context.Context) []bool { + v, err := as.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a selector. It is only allowed when selecting one field. +func (as *AliasSelect) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = as.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{alias.Label} + default: + err = fmt.Errorf("ent: AliasSelect.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (as *AliasSelect) BoolX(ctx context.Context) bool { + v, err := as.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (as *AliasSelect) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := as.sql.Query() + if err := as.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/alias_update.go b/ent/alias_update.go new file mode 100644 index 0000000..c74ce99 --- /dev/null +++ b/ent/alias_update.go @@ -0,0 +1,493 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/postfix/manager/ent/alias" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AliasUpdate is the builder for updating Alias entities. +type AliasUpdate struct { + config + hooks []Hook + mutation *AliasMutation +} + +// Where appends a list predicates to the AliasUpdate builder. +func (au *AliasUpdate) Where(ps ...predicate.Alias) *AliasUpdate { + au.mutation.Where(ps...) + return au +} + +// SetModified sets the "modified" field. +func (au *AliasUpdate) SetModified(t time.Time) *AliasUpdate { + au.mutation.SetModified(t) + return au +} + +// ClearModified clears the value of the "modified" field. +func (au *AliasUpdate) ClearModified() *AliasUpdate { + au.mutation.ClearModified() + return au +} + +// SetDomainID sets the "domain_id" field. +func (au *AliasUpdate) SetDomainID(i int64) *AliasUpdate { + au.mutation.SetDomainID(i) + return au +} + +// SetNillableDomainID sets the "domain_id" field if the given value is not nil. +func (au *AliasUpdate) SetNillableDomainID(i *int64) *AliasUpdate { + if i != nil { + au.SetDomainID(*i) + } + return au +} + +// ClearDomainID clears the value of the "domain_id" field. +func (au *AliasUpdate) ClearDomainID() *AliasUpdate { + au.mutation.ClearDomainID() + return au +} + +// SetGoto sets the "goto" field. +func (au *AliasUpdate) SetGoto(s string) *AliasUpdate { + au.mutation.SetGoto(s) + return au +} + +// SetActive sets the "active" field. +func (au *AliasUpdate) SetActive(b bool) *AliasUpdate { + au.mutation.SetActive(b) + return au +} + +// SetDomain sets the "domain" edge to the Domain entity. +func (au *AliasUpdate) SetDomain(d *Domain) *AliasUpdate { + return au.SetDomainID(d.ID) +} + +// Mutation returns the AliasMutation object of the builder. +func (au *AliasUpdate) Mutation() *AliasMutation { + return au.mutation +} + +// ClearDomain clears the "domain" edge to the Domain entity. +func (au *AliasUpdate) ClearDomain() *AliasUpdate { + au.mutation.ClearDomain() + return au +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (au *AliasUpdate) Save(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + au.defaults() + if len(au.hooks) == 0 { + affected, err = au.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AliasMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + au.mutation = mutation + affected, err = au.sqlSave(ctx) + mutation.done = true + return affected, err + }) + for i := len(au.hooks) - 1; i >= 0; i-- { + if au.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = au.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, au.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// SaveX is like Save, but panics if an error occurs. +func (au *AliasUpdate) SaveX(ctx context.Context) int { + affected, err := au.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (au *AliasUpdate) Exec(ctx context.Context) error { + _, err := au.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (au *AliasUpdate) ExecX(ctx context.Context) { + if err := au.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (au *AliasUpdate) defaults() { + if _, ok := au.mutation.Modified(); !ok && !au.mutation.ModifiedCleared() { + v := alias.UpdateDefaultModified() + au.mutation.SetModified(v) + } +} + +func (au *AliasUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: alias.Table, + Columns: alias.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + } + if ps := au.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := au.mutation.Modified(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: alias.FieldModified, + }) + } + if au.mutation.ModifiedCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: alias.FieldModified, + }) + } + if value, ok := au.mutation.Goto(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: alias.FieldGoto, + }) + } + if value, ok := au.mutation.Active(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: alias.FieldActive, + }) + } + if au.mutation.DomainCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: alias.DomainTable, + Columns: []string{alias.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := au.mutation.DomainIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: alias.DomainTable, + Columns: []string{alias.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, au.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{alias.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return 0, err + } + return n, nil +} + +// AliasUpdateOne is the builder for updating a single Alias entity. +type AliasUpdateOne struct { + config + fields []string + hooks []Hook + mutation *AliasMutation +} + +// SetModified sets the "modified" field. +func (auo *AliasUpdateOne) SetModified(t time.Time) *AliasUpdateOne { + auo.mutation.SetModified(t) + return auo +} + +// ClearModified clears the value of the "modified" field. +func (auo *AliasUpdateOne) ClearModified() *AliasUpdateOne { + auo.mutation.ClearModified() + return auo +} + +// SetDomainID sets the "domain_id" field. +func (auo *AliasUpdateOne) SetDomainID(i int64) *AliasUpdateOne { + auo.mutation.SetDomainID(i) + return auo +} + +// SetNillableDomainID sets the "domain_id" field if the given value is not nil. +func (auo *AliasUpdateOne) SetNillableDomainID(i *int64) *AliasUpdateOne { + if i != nil { + auo.SetDomainID(*i) + } + return auo +} + +// ClearDomainID clears the value of the "domain_id" field. +func (auo *AliasUpdateOne) ClearDomainID() *AliasUpdateOne { + auo.mutation.ClearDomainID() + return auo +} + +// SetGoto sets the "goto" field. +func (auo *AliasUpdateOne) SetGoto(s string) *AliasUpdateOne { + auo.mutation.SetGoto(s) + return auo +} + +// SetActive sets the "active" field. +func (auo *AliasUpdateOne) SetActive(b bool) *AliasUpdateOne { + auo.mutation.SetActive(b) + return auo +} + +// SetDomain sets the "domain" edge to the Domain entity. +func (auo *AliasUpdateOne) SetDomain(d *Domain) *AliasUpdateOne { + return auo.SetDomainID(d.ID) +} + +// Mutation returns the AliasMutation object of the builder. +func (auo *AliasUpdateOne) Mutation() *AliasMutation { + return auo.mutation +} + +// ClearDomain clears the "domain" edge to the Domain entity. +func (auo *AliasUpdateOne) ClearDomain() *AliasUpdateOne { + auo.mutation.ClearDomain() + return auo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (auo *AliasUpdateOne) Select(field string, fields ...string) *AliasUpdateOne { + auo.fields = append([]string{field}, fields...) + return auo +} + +// Save executes the query and returns the updated Alias entity. +func (auo *AliasUpdateOne) Save(ctx context.Context) (*Alias, error) { + var ( + err error + node *Alias + ) + auo.defaults() + if len(auo.hooks) == 0 { + node, err = auo.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*AliasMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + auo.mutation = mutation + node, err = auo.sqlSave(ctx) + mutation.done = true + return node, err + }) + for i := len(auo.hooks) - 1; i >= 0; i-- { + if auo.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = auo.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, auo.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX is like Save, but panics if an error occurs. +func (auo *AliasUpdateOne) SaveX(ctx context.Context) *Alias { + node, err := auo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (auo *AliasUpdateOne) Exec(ctx context.Context) error { + _, err := auo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (auo *AliasUpdateOne) ExecX(ctx context.Context) { + if err := auo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (auo *AliasUpdateOne) defaults() { + if _, ok := auo.mutation.Modified(); !ok && !auo.mutation.ModifiedCleared() { + v := alias.UpdateDefaultModified() + auo.mutation.SetModified(v) + } +} + +func (auo *AliasUpdateOne) sqlSave(ctx context.Context) (_node *Alias, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: alias.Table, + Columns: alias.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + } + id, ok := auo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Alias.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := auo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, alias.FieldID) + for _, f := range fields { + if !alias.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != alias.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := auo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := auo.mutation.Modified(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: alias.FieldModified, + }) + } + if auo.mutation.ModifiedCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: alias.FieldModified, + }) + } + if value, ok := auo.mutation.Goto(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: alias.FieldGoto, + }) + } + if value, ok := auo.mutation.Active(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: alias.FieldActive, + }) + } + if auo.mutation.DomainCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: alias.DomainTable, + Columns: []string{alias.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := auo.mutation.DomainIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: alias.DomainTable, + Columns: []string{alias.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Alias{config: auo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, auo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{alias.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + return _node, nil +} diff --git a/ent/client.go b/ent/client.go new file mode 100644 index 0000000..b61f4bd --- /dev/null +++ b/ent/client.go @@ -0,0 +1,762 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + "log" + + "code.icod.de/postfix/manager/ent/migrate" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/alias" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "code.icod.de/postfix/manager/ent/mailbox" + + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// Client is the client that holds all ent builders. +type Client struct { + config + // Schema is the client for creating, migrating and dropping schema. + Schema *migrate.Schema + // Account is the client for interacting with the Account builders. + Account *AccountClient + // Alias is the client for interacting with the Alias builders. + Alias *AliasClient + // Domain is the client for interacting with the Domain builders. + Domain *DomainClient + // Logentry is the client for interacting with the Logentry builders. + Logentry *LogentryClient + // Mailbox is the client for interacting with the Mailbox builders. + Mailbox *MailboxClient +} + +// NewClient creates a new client configured with the given options. +func NewClient(opts ...Option) *Client { + cfg := config{log: log.Println, hooks: &hooks{}} + cfg.options(opts...) + client := &Client{config: cfg} + client.init() + return client +} + +func (c *Client) init() { + c.Schema = migrate.NewSchema(c.driver) + c.Account = NewAccountClient(c.config) + c.Alias = NewAliasClient(c.config) + c.Domain = NewDomainClient(c.config) + c.Logentry = NewLogentryClient(c.config) + c.Mailbox = NewMailboxClient(c.config) +} + +// Open opens a database/sql.DB specified by the driver name and +// the data source name, and returns a new client attached to it. +// Optional parameters can be added for configuring the client. +func Open(driverName, dataSourceName string, options ...Option) (*Client, error) { + switch driverName { + case dialect.MySQL, dialect.Postgres, dialect.SQLite: + drv, err := sql.Open(driverName, dataSourceName) + if err != nil { + return nil, err + } + return NewClient(append(options, Driver(drv))...), nil + default: + return nil, fmt.Errorf("unsupported driver: %q", driverName) + } +} + +// Tx returns a new transactional client. The provided context +// is used until the transaction is committed or rolled back. +func (c *Client) Tx(ctx context.Context) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") + } + tx, err := newTx(ctx, c.driver) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %w", err) + } + cfg := c.config + cfg.driver = tx + return &Tx{ + ctx: ctx, + config: cfg, + Account: NewAccountClient(cfg), + Alias: NewAliasClient(cfg), + Domain: NewDomainClient(cfg), + Logentry: NewLogentryClient(cfg), + Mailbox: NewMailboxClient(cfg), + }, nil +} + +// BeginTx returns a transactional client with specified options. +func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) { + if _, ok := c.driver.(*txDriver); ok { + return nil, fmt.Errorf("ent: cannot start a transaction within a transaction") + } + tx, err := c.driver.(interface { + BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error) + }).BeginTx(ctx, opts) + if err != nil { + return nil, fmt.Errorf("ent: starting a transaction: %w", err) + } + cfg := c.config + cfg.driver = &txDriver{tx: tx, drv: c.driver} + return &Tx{ + ctx: ctx, + config: cfg, + Account: NewAccountClient(cfg), + Alias: NewAliasClient(cfg), + Domain: NewDomainClient(cfg), + Logentry: NewLogentryClient(cfg), + Mailbox: NewMailboxClient(cfg), + }, nil +} + +// Debug returns a new debug-client. It's used to get verbose logging on specific operations. +// +// client.Debug(). +// Account. +// Query(). +// Count(ctx) +// +func (c *Client) Debug() *Client { + if c.debug { + return c + } + cfg := c.config + cfg.driver = dialect.Debug(c.driver, c.log) + client := &Client{config: cfg} + client.init() + return client +} + +// Close closes the database connection and prevents new queries from starting. +func (c *Client) Close() error { + return c.driver.Close() +} + +// Use adds the mutation hooks to all the entity clients. +// In order to add hooks to a specific client, call: `client.Node.Use(...)`. +func (c *Client) Use(hooks ...Hook) { + c.Account.Use(hooks...) + c.Alias.Use(hooks...) + c.Domain.Use(hooks...) + c.Logentry.Use(hooks...) + c.Mailbox.Use(hooks...) +} + +// AccountClient is a client for the Account schema. +type AccountClient struct { + config +} + +// NewAccountClient returns a client for the Account from the given config. +func NewAccountClient(c config) *AccountClient { + return &AccountClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `account.Hooks(f(g(h())))`. +func (c *AccountClient) Use(hooks ...Hook) { + c.hooks.Account = append(c.hooks.Account, hooks...) +} + +// Create returns a create builder for Account. +func (c *AccountClient) Create() *AccountCreate { + mutation := newAccountMutation(c.config, OpCreate) + return &AccountCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Account entities. +func (c *AccountClient) CreateBulk(builders ...*AccountCreate) *AccountCreateBulk { + return &AccountCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Account. +func (c *AccountClient) Update() *AccountUpdate { + mutation := newAccountMutation(c.config, OpUpdate) + return &AccountUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *AccountClient) UpdateOne(a *Account) *AccountUpdateOne { + mutation := newAccountMutation(c.config, OpUpdateOne, withAccount(a)) + return &AccountUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *AccountClient) UpdateOneID(id int64) *AccountUpdateOne { + mutation := newAccountMutation(c.config, OpUpdateOne, withAccountID(id)) + return &AccountUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Account. +func (c *AccountClient) Delete() *AccountDelete { + mutation := newAccountMutation(c.config, OpDelete) + return &AccountDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *AccountClient) DeleteOne(a *Account) *AccountDeleteOne { + return c.DeleteOneID(a.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *AccountClient) DeleteOneID(id int64) *AccountDeleteOne { + builder := c.Delete().Where(account.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &AccountDeleteOne{builder} +} + +// Query returns a query builder for Account. +func (c *AccountClient) Query() *AccountQuery { + return &AccountQuery{ + config: c.config, + } +} + +// Get returns a Account entity by its id. +func (c *AccountClient) Get(ctx context.Context, id int64) (*Account, error) { + return c.Query().Where(account.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *AccountClient) GetX(ctx context.Context, id int64) *Account { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryDomains queries the domains edge of a Account. +func (c *AccountClient) QueryDomains(a *Account) *DomainQuery { + query := &DomainQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := a.ID + step := sqlgraph.NewStep( + sqlgraph.From(account.Table, account.FieldID, id), + sqlgraph.To(domain.Table, domain.FieldID), + sqlgraph.Edge(sqlgraph.M2M, false, account.DomainsTable, account.DomainsPrimaryKey...), + ) + fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryLogs queries the logs edge of a Account. +func (c *AccountClient) QueryLogs(a *Account) *LogentryQuery { + query := &LogentryQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := a.ID + step := sqlgraph.NewStep( + sqlgraph.From(account.Table, account.FieldID, id), + sqlgraph.To(logentry.Table, logentry.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, account.LogsTable, account.LogsColumn), + ) + fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *AccountClient) Hooks() []Hook { + return c.hooks.Account +} + +// AliasClient is a client for the Alias schema. +type AliasClient struct { + config +} + +// NewAliasClient returns a client for the Alias from the given config. +func NewAliasClient(c config) *AliasClient { + return &AliasClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `alias.Hooks(f(g(h())))`. +func (c *AliasClient) Use(hooks ...Hook) { + c.hooks.Alias = append(c.hooks.Alias, hooks...) +} + +// Create returns a create builder for Alias. +func (c *AliasClient) Create() *AliasCreate { + mutation := newAliasMutation(c.config, OpCreate) + return &AliasCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Alias entities. +func (c *AliasClient) CreateBulk(builders ...*AliasCreate) *AliasCreateBulk { + return &AliasCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Alias. +func (c *AliasClient) Update() *AliasUpdate { + mutation := newAliasMutation(c.config, OpUpdate) + return &AliasUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *AliasClient) UpdateOne(a *Alias) *AliasUpdateOne { + mutation := newAliasMutation(c.config, OpUpdateOne, withAlias(a)) + return &AliasUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *AliasClient) UpdateOneID(id int64) *AliasUpdateOne { + mutation := newAliasMutation(c.config, OpUpdateOne, withAliasID(id)) + return &AliasUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Alias. +func (c *AliasClient) Delete() *AliasDelete { + mutation := newAliasMutation(c.config, OpDelete) + return &AliasDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *AliasClient) DeleteOne(a *Alias) *AliasDeleteOne { + return c.DeleteOneID(a.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *AliasClient) DeleteOneID(id int64) *AliasDeleteOne { + builder := c.Delete().Where(alias.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &AliasDeleteOne{builder} +} + +// Query returns a query builder for Alias. +func (c *AliasClient) Query() *AliasQuery { + return &AliasQuery{ + config: c.config, + } +} + +// Get returns a Alias entity by its id. +func (c *AliasClient) Get(ctx context.Context, id int64) (*Alias, error) { + return c.Query().Where(alias.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *AliasClient) GetX(ctx context.Context, id int64) *Alias { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryDomain queries the domain edge of a Alias. +func (c *AliasClient) QueryDomain(a *Alias) *DomainQuery { + query := &DomainQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := a.ID + step := sqlgraph.NewStep( + sqlgraph.From(alias.Table, alias.FieldID, id), + sqlgraph.To(domain.Table, domain.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, alias.DomainTable, alias.DomainColumn), + ) + fromV = sqlgraph.Neighbors(a.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *AliasClient) Hooks() []Hook { + return c.hooks.Alias +} + +// DomainClient is a client for the Domain schema. +type DomainClient struct { + config +} + +// NewDomainClient returns a client for the Domain from the given config. +func NewDomainClient(c config) *DomainClient { + return &DomainClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `domain.Hooks(f(g(h())))`. +func (c *DomainClient) Use(hooks ...Hook) { + c.hooks.Domain = append(c.hooks.Domain, hooks...) +} + +// Create returns a create builder for Domain. +func (c *DomainClient) Create() *DomainCreate { + mutation := newDomainMutation(c.config, OpCreate) + return &DomainCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Domain entities. +func (c *DomainClient) CreateBulk(builders ...*DomainCreate) *DomainCreateBulk { + return &DomainCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Domain. +func (c *DomainClient) Update() *DomainUpdate { + mutation := newDomainMutation(c.config, OpUpdate) + return &DomainUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *DomainClient) UpdateOne(d *Domain) *DomainUpdateOne { + mutation := newDomainMutation(c.config, OpUpdateOne, withDomain(d)) + return &DomainUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *DomainClient) UpdateOneID(id int64) *DomainUpdateOne { + mutation := newDomainMutation(c.config, OpUpdateOne, withDomainID(id)) + return &DomainUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Domain. +func (c *DomainClient) Delete() *DomainDelete { + mutation := newDomainMutation(c.config, OpDelete) + return &DomainDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *DomainClient) DeleteOne(d *Domain) *DomainDeleteOne { + return c.DeleteOneID(d.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *DomainClient) DeleteOneID(id int64) *DomainDeleteOne { + builder := c.Delete().Where(domain.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &DomainDeleteOne{builder} +} + +// Query returns a query builder for Domain. +func (c *DomainClient) Query() *DomainQuery { + return &DomainQuery{ + config: c.config, + } +} + +// Get returns a Domain entity by its id. +func (c *DomainClient) Get(ctx context.Context, id int64) (*Domain, error) { + return c.Query().Where(domain.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *DomainClient) GetX(ctx context.Context, id int64) *Domain { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryMailboxes queries the mailboxes edge of a Domain. +func (c *DomainClient) QueryMailboxes(d *Domain) *MailboxQuery { + query := &MailboxQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := d.ID + step := sqlgraph.NewStep( + sqlgraph.From(domain.Table, domain.FieldID, id), + sqlgraph.To(mailbox.Table, mailbox.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, domain.MailboxesTable, domain.MailboxesColumn), + ) + fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryAliases queries the aliases edge of a Domain. +func (c *DomainClient) QueryAliases(d *Domain) *AliasQuery { + query := &AliasQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := d.ID + step := sqlgraph.NewStep( + sqlgraph.From(domain.Table, domain.FieldID, id), + sqlgraph.To(alias.Table, alias.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, domain.AliasesTable, domain.AliasesColumn), + ) + fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryLogs queries the logs edge of a Domain. +func (c *DomainClient) QueryLogs(d *Domain) *LogentryQuery { + query := &LogentryQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := d.ID + step := sqlgraph.NewStep( + sqlgraph.From(domain.Table, domain.FieldID, id), + sqlgraph.To(logentry.Table, logentry.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, domain.LogsTable, domain.LogsColumn), + ) + fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryAccounts queries the accounts edge of a Domain. +func (c *DomainClient) QueryAccounts(d *Domain) *AccountQuery { + query := &AccountQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := d.ID + step := sqlgraph.NewStep( + sqlgraph.From(domain.Table, domain.FieldID, id), + sqlgraph.To(account.Table, account.FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, domain.AccountsTable, domain.AccountsPrimaryKey...), + ) + fromV = sqlgraph.Neighbors(d.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *DomainClient) Hooks() []Hook { + return c.hooks.Domain +} + +// LogentryClient is a client for the Logentry schema. +type LogentryClient struct { + config +} + +// NewLogentryClient returns a client for the Logentry from the given config. +func NewLogentryClient(c config) *LogentryClient { + return &LogentryClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `logentry.Hooks(f(g(h())))`. +func (c *LogentryClient) Use(hooks ...Hook) { + c.hooks.Logentry = append(c.hooks.Logentry, hooks...) +} + +// Create returns a create builder for Logentry. +func (c *LogentryClient) Create() *LogentryCreate { + mutation := newLogentryMutation(c.config, OpCreate) + return &LogentryCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Logentry entities. +func (c *LogentryClient) CreateBulk(builders ...*LogentryCreate) *LogentryCreateBulk { + return &LogentryCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Logentry. +func (c *LogentryClient) Update() *LogentryUpdate { + mutation := newLogentryMutation(c.config, OpUpdate) + return &LogentryUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *LogentryClient) UpdateOne(l *Logentry) *LogentryUpdateOne { + mutation := newLogentryMutation(c.config, OpUpdateOne, withLogentry(l)) + return &LogentryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *LogentryClient) UpdateOneID(id int64) *LogentryUpdateOne { + mutation := newLogentryMutation(c.config, OpUpdateOne, withLogentryID(id)) + return &LogentryUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Logentry. +func (c *LogentryClient) Delete() *LogentryDelete { + mutation := newLogentryMutation(c.config, OpDelete) + return &LogentryDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *LogentryClient) DeleteOne(l *Logentry) *LogentryDeleteOne { + return c.DeleteOneID(l.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *LogentryClient) DeleteOneID(id int64) *LogentryDeleteOne { + builder := c.Delete().Where(logentry.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &LogentryDeleteOne{builder} +} + +// Query returns a query builder for Logentry. +func (c *LogentryClient) Query() *LogentryQuery { + return &LogentryQuery{ + config: c.config, + } +} + +// Get returns a Logentry entity by its id. +func (c *LogentryClient) Get(ctx context.Context, id int64) (*Logentry, error) { + return c.Query().Where(logentry.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *LogentryClient) GetX(ctx context.Context, id int64) *Logentry { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryAccount queries the account edge of a Logentry. +func (c *LogentryClient) QueryAccount(l *Logentry) *AccountQuery { + query := &AccountQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := l.ID + step := sqlgraph.NewStep( + sqlgraph.From(logentry.Table, logentry.FieldID, id), + sqlgraph.To(account.Table, account.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, logentry.AccountTable, logentry.AccountColumn), + ) + fromV = sqlgraph.Neighbors(l.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// QueryDomain queries the domain edge of a Logentry. +func (c *LogentryClient) QueryDomain(l *Logentry) *DomainQuery { + query := &DomainQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := l.ID + step := sqlgraph.NewStep( + sqlgraph.From(logentry.Table, logentry.FieldID, id), + sqlgraph.To(domain.Table, domain.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, logentry.DomainTable, logentry.DomainColumn), + ) + fromV = sqlgraph.Neighbors(l.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *LogentryClient) Hooks() []Hook { + return c.hooks.Logentry +} + +// MailboxClient is a client for the Mailbox schema. +type MailboxClient struct { + config +} + +// NewMailboxClient returns a client for the Mailbox from the given config. +func NewMailboxClient(c config) *MailboxClient { + return &MailboxClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `mailbox.Hooks(f(g(h())))`. +func (c *MailboxClient) Use(hooks ...Hook) { + c.hooks.Mailbox = append(c.hooks.Mailbox, hooks...) +} + +// Create returns a create builder for Mailbox. +func (c *MailboxClient) Create() *MailboxCreate { + mutation := newMailboxMutation(c.config, OpCreate) + return &MailboxCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of Mailbox entities. +func (c *MailboxClient) CreateBulk(builders ...*MailboxCreate) *MailboxCreateBulk { + return &MailboxCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for Mailbox. +func (c *MailboxClient) Update() *MailboxUpdate { + mutation := newMailboxMutation(c.config, OpUpdate) + return &MailboxUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *MailboxClient) UpdateOne(m *Mailbox) *MailboxUpdateOne { + mutation := newMailboxMutation(c.config, OpUpdateOne, withMailbox(m)) + return &MailboxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *MailboxClient) UpdateOneID(id int64) *MailboxUpdateOne { + mutation := newMailboxMutation(c.config, OpUpdateOne, withMailboxID(id)) + return &MailboxUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for Mailbox. +func (c *MailboxClient) Delete() *MailboxDelete { + mutation := newMailboxMutation(c.config, OpDelete) + return &MailboxDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a delete builder for the given entity. +func (c *MailboxClient) DeleteOne(m *Mailbox) *MailboxDeleteOne { + return c.DeleteOneID(m.ID) +} + +// DeleteOneID returns a delete builder for the given id. +func (c *MailboxClient) DeleteOneID(id int64) *MailboxDeleteOne { + builder := c.Delete().Where(mailbox.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &MailboxDeleteOne{builder} +} + +// Query returns a query builder for Mailbox. +func (c *MailboxClient) Query() *MailboxQuery { + return &MailboxQuery{ + config: c.config, + } +} + +// Get returns a Mailbox entity by its id. +func (c *MailboxClient) Get(ctx context.Context, id int64) (*Mailbox, error) { + return c.Query().Where(mailbox.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *MailboxClient) GetX(ctx context.Context, id int64) *Mailbox { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// QueryDomain queries the domain edge of a Mailbox. +func (c *MailboxClient) QueryDomain(m *Mailbox) *DomainQuery { + query := &DomainQuery{config: c.config} + query.path = func(ctx context.Context) (fromV *sql.Selector, _ error) { + id := m.ID + step := sqlgraph.NewStep( + sqlgraph.From(mailbox.Table, mailbox.FieldID, id), + sqlgraph.To(domain.Table, domain.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, mailbox.DomainTable, mailbox.DomainColumn), + ) + fromV = sqlgraph.Neighbors(m.driver.Dialect(), step) + return fromV, nil + } + return query +} + +// Hooks returns the client hooks. +func (c *MailboxClient) Hooks() []Hook { + return c.hooks.Mailbox +} diff --git a/ent/config.go b/ent/config.go new file mode 100644 index 0000000..5e70a0b --- /dev/null +++ b/ent/config.go @@ -0,0 +1,63 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "entgo.io/ent" + "entgo.io/ent/dialect" +) + +// Option function to configure the client. +type Option func(*config) + +// Config is the configuration for the client and its builder. +type config struct { + // driver used for executing database requests. + driver dialect.Driver + // debug enable a debug logging. + debug bool + // log used for logging on debug mode. + log func(...interface{}) + // hooks to execute on mutations. + hooks *hooks +} + +// hooks per client, for fast access. +type hooks struct { + Account []ent.Hook + Alias []ent.Hook + Domain []ent.Hook + Logentry []ent.Hook + Mailbox []ent.Hook +} + +// Options applies the options on the config object. +func (c *config) options(opts ...Option) { + for _, opt := range opts { + opt(c) + } + if c.debug { + c.driver = dialect.Debug(c.driver, c.log) + } +} + +// Debug enables debug logging on the ent.Driver. +func Debug() Option { + return func(c *config) { + c.debug = true + } +} + +// Log sets the logging function for debug mode. +func Log(fn func(...interface{})) Option { + return func(c *config) { + c.log = fn + } +} + +// Driver configures the client driver. +func Driver(driver dialect.Driver) Option { + return func(c *config) { + c.driver = driver + } +} diff --git a/ent/context.go b/ent/context.go new file mode 100644 index 0000000..0840726 --- /dev/null +++ b/ent/context.go @@ -0,0 +1,33 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" +) + +type clientCtxKey struct{} + +// FromContext returns a Client stored inside a context, or nil if there isn't one. +func FromContext(ctx context.Context) *Client { + c, _ := ctx.Value(clientCtxKey{}).(*Client) + return c +} + +// NewContext returns a new context with the given Client attached. +func NewContext(parent context.Context, c *Client) context.Context { + return context.WithValue(parent, clientCtxKey{}, c) +} + +type txCtxKey struct{} + +// TxFromContext returns a Tx stored inside a context, or nil if there isn't one. +func TxFromContext(ctx context.Context) *Tx { + tx, _ := ctx.Value(txCtxKey{}).(*Tx) + return tx +} + +// NewTxContext returns a new context with the given Tx attached. +func NewTxContext(parent context.Context, tx *Tx) context.Context { + return context.WithValue(parent, txCtxKey{}, tx) +} diff --git a/ent/domain.go b/ent/domain.go new file mode 100644 index 0000000..f92ff42 --- /dev/null +++ b/ent/domain.go @@ -0,0 +1,284 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "code.icod.de/postfix/manager/ent/domain" + "entgo.io/ent/dialect/sql" +) + +// Domain is the model entity for the Domain schema. +type Domain struct { + config `json:"-"` + // ID of the ent. + ID int64 `json:"id,omitempty"` + // Created holds the value of the "created" field. + Created time.Time `json:"created,omitempty"` + // Modified holds the value of the "modified" field. + Modified *time.Time `json:"modified,omitempty"` + // Domain holds the value of the "domain" field. + Domain string `json:"domain,omitempty"` + // Description holds the value of the "description" field. + Description *string `json:"description,omitempty"` + // MaxAliases holds the value of the "max_aliases" field. + MaxAliases int64 `json:"max_aliases,omitempty"` + // MaxMailboxes holds the value of the "max_mailboxes" field. + MaxMailboxes int64 `json:"max_mailboxes,omitempty"` + // MaxQuota holds the value of the "max_quota" field. + MaxQuota int64 `json:"max_quota,omitempty"` + // Quota holds the value of the "quota" field. + Quota int64 `json:"quota,omitempty"` + // Transport holds the value of the "transport" field. + Transport string `json:"transport,omitempty"` + // BackupMx holds the value of the "backup_mx" field. + BackupMx bool `json:"backup_mx,omitempty"` + // Active holds the value of the "active" field. + Active bool `json:"active,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the DomainQuery when eager-loading is set. + Edges DomainEdges `json:"edges"` +} + +// DomainEdges holds the relations/edges for other nodes in the graph. +type DomainEdges struct { + // Mailboxes holds the value of the mailboxes edge. + Mailboxes []*Mailbox `json:"mailboxes,omitempty"` + // Aliases holds the value of the aliases edge. + Aliases []*Alias `json:"aliases,omitempty"` + // Logs holds the value of the logs edge. + Logs []*Logentry `json:"logs,omitempty"` + // Accounts holds the value of the accounts edge. + Accounts []*Account `json:"accounts,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [4]bool +} + +// MailboxesOrErr returns the Mailboxes value or an error if the edge +// was not loaded in eager-loading. +func (e DomainEdges) MailboxesOrErr() ([]*Mailbox, error) { + if e.loadedTypes[0] { + return e.Mailboxes, nil + } + return nil, &NotLoadedError{edge: "mailboxes"} +} + +// AliasesOrErr returns the Aliases value or an error if the edge +// was not loaded in eager-loading. +func (e DomainEdges) AliasesOrErr() ([]*Alias, error) { + if e.loadedTypes[1] { + return e.Aliases, nil + } + return nil, &NotLoadedError{edge: "aliases"} +} + +// LogsOrErr returns the Logs value or an error if the edge +// was not loaded in eager-loading. +func (e DomainEdges) LogsOrErr() ([]*Logentry, error) { + if e.loadedTypes[2] { + return e.Logs, nil + } + return nil, &NotLoadedError{edge: "logs"} +} + +// AccountsOrErr returns the Accounts value or an error if the edge +// was not loaded in eager-loading. +func (e DomainEdges) AccountsOrErr() ([]*Account, error) { + if e.loadedTypes[3] { + return e.Accounts, nil + } + return nil, &NotLoadedError{edge: "accounts"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Domain) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case domain.FieldBackupMx, domain.FieldActive: + values[i] = new(sql.NullBool) + case domain.FieldID, domain.FieldMaxAliases, domain.FieldMaxMailboxes, domain.FieldMaxQuota, domain.FieldQuota: + values[i] = new(sql.NullInt64) + case domain.FieldDomain, domain.FieldDescription, domain.FieldTransport: + values[i] = new(sql.NullString) + case domain.FieldCreated, domain.FieldModified: + values[i] = new(sql.NullTime) + default: + return nil, fmt.Errorf("unexpected column %q for type Domain", columns[i]) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Domain fields. +func (d *Domain) assignValues(columns []string, values []interface{}) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case domain.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + d.ID = int64(value.Int64) + case domain.FieldCreated: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created", values[i]) + } else if value.Valid { + d.Created = value.Time + } + case domain.FieldModified: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field modified", values[i]) + } else if value.Valid { + d.Modified = new(time.Time) + *d.Modified = value.Time + } + case domain.FieldDomain: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field domain", values[i]) + } else if value.Valid { + d.Domain = value.String + } + case domain.FieldDescription: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field description", values[i]) + } else if value.Valid { + d.Description = new(string) + *d.Description = value.String + } + case domain.FieldMaxAliases: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field max_aliases", values[i]) + } else if value.Valid { + d.MaxAliases = value.Int64 + } + case domain.FieldMaxMailboxes: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field max_mailboxes", values[i]) + } else if value.Valid { + d.MaxMailboxes = value.Int64 + } + case domain.FieldMaxQuota: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field max_quota", values[i]) + } else if value.Valid { + d.MaxQuota = value.Int64 + } + case domain.FieldQuota: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field quota", values[i]) + } else if value.Valid { + d.Quota = value.Int64 + } + case domain.FieldTransport: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field transport", values[i]) + } else if value.Valid { + d.Transport = value.String + } + case domain.FieldBackupMx: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field backup_mx", values[i]) + } else if value.Valid { + d.BackupMx = value.Bool + } + case domain.FieldActive: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field active", values[i]) + } else if value.Valid { + d.Active = value.Bool + } + } + } + return nil +} + +// QueryMailboxes queries the "mailboxes" edge of the Domain entity. +func (d *Domain) QueryMailboxes() *MailboxQuery { + return (&DomainClient{config: d.config}).QueryMailboxes(d) +} + +// QueryAliases queries the "aliases" edge of the Domain entity. +func (d *Domain) QueryAliases() *AliasQuery { + return (&DomainClient{config: d.config}).QueryAliases(d) +} + +// QueryLogs queries the "logs" edge of the Domain entity. +func (d *Domain) QueryLogs() *LogentryQuery { + return (&DomainClient{config: d.config}).QueryLogs(d) +} + +// QueryAccounts queries the "accounts" edge of the Domain entity. +func (d *Domain) QueryAccounts() *AccountQuery { + return (&DomainClient{config: d.config}).QueryAccounts(d) +} + +// Update returns a builder for updating this Domain. +// Note that you need to call Domain.Unwrap() before calling this method if this Domain +// was returned from a transaction, and the transaction was committed or rolled back. +func (d *Domain) Update() *DomainUpdateOne { + return (&DomainClient{config: d.config}).UpdateOne(d) +} + +// Unwrap unwraps the Domain entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (d *Domain) Unwrap() *Domain { + tx, ok := d.config.driver.(*txDriver) + if !ok { + panic("ent: Domain is not a transactional entity") + } + d.config.driver = tx.drv + return d +} + +// String implements the fmt.Stringer. +func (d *Domain) String() string { + var builder strings.Builder + builder.WriteString("Domain(") + builder.WriteString(fmt.Sprintf("id=%v", d.ID)) + builder.WriteString(", created=") + builder.WriteString(d.Created.Format(time.ANSIC)) + if v := d.Modified; v != nil { + builder.WriteString(", modified=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", domain=") + builder.WriteString(d.Domain) + if v := d.Description; v != nil { + builder.WriteString(", description=") + builder.WriteString(*v) + } + builder.WriteString(", max_aliases=") + builder.WriteString(fmt.Sprintf("%v", d.MaxAliases)) + builder.WriteString(", max_mailboxes=") + builder.WriteString(fmt.Sprintf("%v", d.MaxMailboxes)) + builder.WriteString(", max_quota=") + builder.WriteString(fmt.Sprintf("%v", d.MaxQuota)) + builder.WriteString(", quota=") + builder.WriteString(fmt.Sprintf("%v", d.Quota)) + builder.WriteString(", transport=") + builder.WriteString(d.Transport) + builder.WriteString(", backup_mx=") + builder.WriteString(fmt.Sprintf("%v", d.BackupMx)) + builder.WriteString(", active=") + builder.WriteString(fmt.Sprintf("%v", d.Active)) + builder.WriteByte(')') + return builder.String() +} + +// Domains is a parsable slice of Domain. +type Domains []*Domain + +func (d Domains) config(cfg config) { + for _i := range d { + d[_i].config = cfg + } +} diff --git a/ent/domain/domain.go b/ent/domain/domain.go new file mode 100644 index 0000000..c222e5c --- /dev/null +++ b/ent/domain/domain.go @@ -0,0 +1,113 @@ +// Code generated by entc, DO NOT EDIT. + +package domain + +import ( + "time" +) + +const ( + // Label holds the string label denoting the domain type in the database. + Label = "domain" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldCreated holds the string denoting the created field in the database. + FieldCreated = "created" + // FieldModified holds the string denoting the modified field in the database. + FieldModified = "modified" + // FieldDomain holds the string denoting the domain field in the database. + FieldDomain = "domain" + // FieldDescription holds the string denoting the description field in the database. + FieldDescription = "description" + // FieldMaxAliases holds the string denoting the max_aliases field in the database. + FieldMaxAliases = "max_aliases" + // FieldMaxMailboxes holds the string denoting the max_mailboxes field in the database. + FieldMaxMailboxes = "max_mailboxes" + // FieldMaxQuota holds the string denoting the max_quota field in the database. + FieldMaxQuota = "max_quota" + // FieldQuota holds the string denoting the quota field in the database. + FieldQuota = "quota" + // FieldTransport holds the string denoting the transport field in the database. + FieldTransport = "transport" + // FieldBackupMx holds the string denoting the backup_mx field in the database. + FieldBackupMx = "backup_mx" + // FieldActive holds the string denoting the active field in the database. + FieldActive = "active" + // EdgeMailboxes holds the string denoting the mailboxes edge name in mutations. + EdgeMailboxes = "mailboxes" + // EdgeAliases holds the string denoting the aliases edge name in mutations. + EdgeAliases = "aliases" + // EdgeLogs holds the string denoting the logs edge name in mutations. + EdgeLogs = "logs" + // EdgeAccounts holds the string denoting the accounts edge name in mutations. + EdgeAccounts = "accounts" + // Table holds the table name of the domain in the database. + Table = "domains" + // MailboxesTable is the table that holds the mailboxes relation/edge. + MailboxesTable = "mailboxes" + // MailboxesInverseTable is the table name for the Mailbox entity. + // It exists in this package in order to avoid circular dependency with the "mailbox" package. + MailboxesInverseTable = "mailboxes" + // MailboxesColumn is the table column denoting the mailboxes relation/edge. + MailboxesColumn = "domain_id" + // AliasesTable is the table that holds the aliases relation/edge. + AliasesTable = "alias" + // AliasesInverseTable is the table name for the Alias entity. + // It exists in this package in order to avoid circular dependency with the "alias" package. + AliasesInverseTable = "alias" + // AliasesColumn is the table column denoting the aliases relation/edge. + AliasesColumn = "domain_id" + // LogsTable is the table that holds the logs relation/edge. + LogsTable = "logentries" + // LogsInverseTable is the table name for the Logentry entity. + // It exists in this package in order to avoid circular dependency with the "logentry" package. + LogsInverseTable = "logentries" + // LogsColumn is the table column denoting the logs relation/edge. + LogsColumn = "domain_id" + // AccountsTable is the table that holds the accounts relation/edge. The primary key declared below. + AccountsTable = "account_domains" + // AccountsInverseTable is the table name for the Account entity. + // It exists in this package in order to avoid circular dependency with the "account" package. + AccountsInverseTable = "accounts" +) + +// Columns holds all SQL columns for domain fields. +var Columns = []string{ + FieldID, + FieldCreated, + FieldModified, + FieldDomain, + FieldDescription, + FieldMaxAliases, + FieldMaxMailboxes, + FieldMaxQuota, + FieldQuota, + FieldTransport, + FieldBackupMx, + FieldActive, +} + +var ( + // AccountsPrimaryKey and AccountsColumn2 are the table columns denoting the + // primary key for the accounts relation (M2M). + AccountsPrimaryKey = []string{"account_id", "domain_id"} +) + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreated holds the default value on creation for the "created" field. + DefaultCreated func() time.Time + // DefaultModified holds the default value on creation for the "modified" field. + DefaultModified func() time.Time + // UpdateDefaultModified holds the default value on update for the "modified" field. + UpdateDefaultModified func() time.Time +) diff --git a/ent/domain/where.go b/ent/domain/where.go new file mode 100644 index 0000000..28dc615 --- /dev/null +++ b/ent/domain/where.go @@ -0,0 +1,1160 @@ +// Code generated by entc, DO NOT EDIT. + +package domain + +import ( + "time" + + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// ID filters vertices based on their ID field. +func ID(id int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldID), id)) + }) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.In(s.C(FieldID), v...)) + }) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.NotIn(s.C(FieldID), v...)) + }) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldID), id)) + }) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldID), id)) + }) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldID), id)) + }) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldID), id)) + }) +} + +// Created applies equality check predicate on the "created" field. It's identical to CreatedEQ. +func Created(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldCreated), v)) + }) +} + +// Modified applies equality check predicate on the "modified" field. It's identical to ModifiedEQ. +func Modified(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldModified), v)) + }) +} + +// Domain applies equality check predicate on the "domain" field. It's identical to DomainEQ. +func Domain(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDomain), v)) + }) +} + +// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ. +func Description(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDescription), v)) + }) +} + +// MaxAliases applies equality check predicate on the "max_aliases" field. It's identical to MaxAliasesEQ. +func MaxAliases(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldMaxAliases), v)) + }) +} + +// MaxMailboxes applies equality check predicate on the "max_mailboxes" field. It's identical to MaxMailboxesEQ. +func MaxMailboxes(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldMaxMailboxes), v)) + }) +} + +// MaxQuota applies equality check predicate on the "max_quota" field. It's identical to MaxQuotaEQ. +func MaxQuota(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldMaxQuota), v)) + }) +} + +// Quota applies equality check predicate on the "quota" field. It's identical to QuotaEQ. +func Quota(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldQuota), v)) + }) +} + +// Transport applies equality check predicate on the "transport" field. It's identical to TransportEQ. +func Transport(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldTransport), v)) + }) +} + +// BackupMx applies equality check predicate on the "backup_mx" field. It's identical to BackupMxEQ. +func BackupMx(v bool) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldBackupMx), v)) + }) +} + +// Active applies equality check predicate on the "active" field. It's identical to ActiveEQ. +func Active(v bool) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldActive), v)) + }) +} + +// CreatedEQ applies the EQ predicate on the "created" field. +func CreatedEQ(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldCreated), v)) + }) +} + +// CreatedNEQ applies the NEQ predicate on the "created" field. +func CreatedNEQ(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldCreated), v)) + }) +} + +// CreatedIn applies the In predicate on the "created" field. +func CreatedIn(vs ...time.Time) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldCreated), v...)) + }) +} + +// CreatedNotIn applies the NotIn predicate on the "created" field. +func CreatedNotIn(vs ...time.Time) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldCreated), v...)) + }) +} + +// CreatedGT applies the GT predicate on the "created" field. +func CreatedGT(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldCreated), v)) + }) +} + +// CreatedGTE applies the GTE predicate on the "created" field. +func CreatedGTE(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldCreated), v)) + }) +} + +// CreatedLT applies the LT predicate on the "created" field. +func CreatedLT(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldCreated), v)) + }) +} + +// CreatedLTE applies the LTE predicate on the "created" field. +func CreatedLTE(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldCreated), v)) + }) +} + +// ModifiedEQ applies the EQ predicate on the "modified" field. +func ModifiedEQ(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldModified), v)) + }) +} + +// ModifiedNEQ applies the NEQ predicate on the "modified" field. +func ModifiedNEQ(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldModified), v)) + }) +} + +// ModifiedIn applies the In predicate on the "modified" field. +func ModifiedIn(vs ...time.Time) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldModified), v...)) + }) +} + +// ModifiedNotIn applies the NotIn predicate on the "modified" field. +func ModifiedNotIn(vs ...time.Time) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldModified), v...)) + }) +} + +// ModifiedGT applies the GT predicate on the "modified" field. +func ModifiedGT(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldModified), v)) + }) +} + +// ModifiedGTE applies the GTE predicate on the "modified" field. +func ModifiedGTE(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldModified), v)) + }) +} + +// ModifiedLT applies the LT predicate on the "modified" field. +func ModifiedLT(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldModified), v)) + }) +} + +// ModifiedLTE applies the LTE predicate on the "modified" field. +func ModifiedLTE(v time.Time) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldModified), v)) + }) +} + +// ModifiedIsNil applies the IsNil predicate on the "modified" field. +func ModifiedIsNil() predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldModified))) + }) +} + +// ModifiedNotNil applies the NotNil predicate on the "modified" field. +func ModifiedNotNil() predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldModified))) + }) +} + +// DomainEQ applies the EQ predicate on the "domain" field. +func DomainEQ(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDomain), v)) + }) +} + +// DomainNEQ applies the NEQ predicate on the "domain" field. +func DomainNEQ(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldDomain), v)) + }) +} + +// DomainIn applies the In predicate on the "domain" field. +func DomainIn(vs ...string) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldDomain), v...)) + }) +} + +// DomainNotIn applies the NotIn predicate on the "domain" field. +func DomainNotIn(vs ...string) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldDomain), v...)) + }) +} + +// DomainGT applies the GT predicate on the "domain" field. +func DomainGT(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldDomain), v)) + }) +} + +// DomainGTE applies the GTE predicate on the "domain" field. +func DomainGTE(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldDomain), v)) + }) +} + +// DomainLT applies the LT predicate on the "domain" field. +func DomainLT(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldDomain), v)) + }) +} + +// DomainLTE applies the LTE predicate on the "domain" field. +func DomainLTE(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldDomain), v)) + }) +} + +// DomainContains applies the Contains predicate on the "domain" field. +func DomainContains(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldDomain), v)) + }) +} + +// DomainHasPrefix applies the HasPrefix predicate on the "domain" field. +func DomainHasPrefix(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldDomain), v)) + }) +} + +// DomainHasSuffix applies the HasSuffix predicate on the "domain" field. +func DomainHasSuffix(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldDomain), v)) + }) +} + +// DomainEqualFold applies the EqualFold predicate on the "domain" field. +func DomainEqualFold(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldDomain), v)) + }) +} + +// DomainContainsFold applies the ContainsFold predicate on the "domain" field. +func DomainContainsFold(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldDomain), v)) + }) +} + +// DescriptionEQ applies the EQ predicate on the "description" field. +func DescriptionEQ(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDescription), v)) + }) +} + +// DescriptionNEQ applies the NEQ predicate on the "description" field. +func DescriptionNEQ(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldDescription), v)) + }) +} + +// DescriptionIn applies the In predicate on the "description" field. +func DescriptionIn(vs ...string) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldDescription), v...)) + }) +} + +// DescriptionNotIn applies the NotIn predicate on the "description" field. +func DescriptionNotIn(vs ...string) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldDescription), v...)) + }) +} + +// DescriptionGT applies the GT predicate on the "description" field. +func DescriptionGT(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldDescription), v)) + }) +} + +// DescriptionGTE applies the GTE predicate on the "description" field. +func DescriptionGTE(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldDescription), v)) + }) +} + +// DescriptionLT applies the LT predicate on the "description" field. +func DescriptionLT(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldDescription), v)) + }) +} + +// DescriptionLTE applies the LTE predicate on the "description" field. +func DescriptionLTE(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldDescription), v)) + }) +} + +// DescriptionContains applies the Contains predicate on the "description" field. +func DescriptionContains(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldDescription), v)) + }) +} + +// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field. +func DescriptionHasPrefix(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldDescription), v)) + }) +} + +// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field. +func DescriptionHasSuffix(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldDescription), v)) + }) +} + +// DescriptionIsNil applies the IsNil predicate on the "description" field. +func DescriptionIsNil() predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldDescription))) + }) +} + +// DescriptionNotNil applies the NotNil predicate on the "description" field. +func DescriptionNotNil() predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldDescription))) + }) +} + +// DescriptionEqualFold applies the EqualFold predicate on the "description" field. +func DescriptionEqualFold(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldDescription), v)) + }) +} + +// DescriptionContainsFold applies the ContainsFold predicate on the "description" field. +func DescriptionContainsFold(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldDescription), v)) + }) +} + +// MaxAliasesEQ applies the EQ predicate on the "max_aliases" field. +func MaxAliasesEQ(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldMaxAliases), v)) + }) +} + +// MaxAliasesNEQ applies the NEQ predicate on the "max_aliases" field. +func MaxAliasesNEQ(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldMaxAliases), v)) + }) +} + +// MaxAliasesIn applies the In predicate on the "max_aliases" field. +func MaxAliasesIn(vs ...int64) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldMaxAliases), v...)) + }) +} + +// MaxAliasesNotIn applies the NotIn predicate on the "max_aliases" field. +func MaxAliasesNotIn(vs ...int64) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldMaxAliases), v...)) + }) +} + +// MaxAliasesGT applies the GT predicate on the "max_aliases" field. +func MaxAliasesGT(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldMaxAliases), v)) + }) +} + +// MaxAliasesGTE applies the GTE predicate on the "max_aliases" field. +func MaxAliasesGTE(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldMaxAliases), v)) + }) +} + +// MaxAliasesLT applies the LT predicate on the "max_aliases" field. +func MaxAliasesLT(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldMaxAliases), v)) + }) +} + +// MaxAliasesLTE applies the LTE predicate on the "max_aliases" field. +func MaxAliasesLTE(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldMaxAliases), v)) + }) +} + +// MaxMailboxesEQ applies the EQ predicate on the "max_mailboxes" field. +func MaxMailboxesEQ(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldMaxMailboxes), v)) + }) +} + +// MaxMailboxesNEQ applies the NEQ predicate on the "max_mailboxes" field. +func MaxMailboxesNEQ(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldMaxMailboxes), v)) + }) +} + +// MaxMailboxesIn applies the In predicate on the "max_mailboxes" field. +func MaxMailboxesIn(vs ...int64) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldMaxMailboxes), v...)) + }) +} + +// MaxMailboxesNotIn applies the NotIn predicate on the "max_mailboxes" field. +func MaxMailboxesNotIn(vs ...int64) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldMaxMailboxes), v...)) + }) +} + +// MaxMailboxesGT applies the GT predicate on the "max_mailboxes" field. +func MaxMailboxesGT(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldMaxMailboxes), v)) + }) +} + +// MaxMailboxesGTE applies the GTE predicate on the "max_mailboxes" field. +func MaxMailboxesGTE(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldMaxMailboxes), v)) + }) +} + +// MaxMailboxesLT applies the LT predicate on the "max_mailboxes" field. +func MaxMailboxesLT(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldMaxMailboxes), v)) + }) +} + +// MaxMailboxesLTE applies the LTE predicate on the "max_mailboxes" field. +func MaxMailboxesLTE(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldMaxMailboxes), v)) + }) +} + +// MaxQuotaEQ applies the EQ predicate on the "max_quota" field. +func MaxQuotaEQ(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldMaxQuota), v)) + }) +} + +// MaxQuotaNEQ applies the NEQ predicate on the "max_quota" field. +func MaxQuotaNEQ(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldMaxQuota), v)) + }) +} + +// MaxQuotaIn applies the In predicate on the "max_quota" field. +func MaxQuotaIn(vs ...int64) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldMaxQuota), v...)) + }) +} + +// MaxQuotaNotIn applies the NotIn predicate on the "max_quota" field. +func MaxQuotaNotIn(vs ...int64) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldMaxQuota), v...)) + }) +} + +// MaxQuotaGT applies the GT predicate on the "max_quota" field. +func MaxQuotaGT(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldMaxQuota), v)) + }) +} + +// MaxQuotaGTE applies the GTE predicate on the "max_quota" field. +func MaxQuotaGTE(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldMaxQuota), v)) + }) +} + +// MaxQuotaLT applies the LT predicate on the "max_quota" field. +func MaxQuotaLT(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldMaxQuota), v)) + }) +} + +// MaxQuotaLTE applies the LTE predicate on the "max_quota" field. +func MaxQuotaLTE(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldMaxQuota), v)) + }) +} + +// QuotaEQ applies the EQ predicate on the "quota" field. +func QuotaEQ(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldQuota), v)) + }) +} + +// QuotaNEQ applies the NEQ predicate on the "quota" field. +func QuotaNEQ(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldQuota), v)) + }) +} + +// QuotaIn applies the In predicate on the "quota" field. +func QuotaIn(vs ...int64) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldQuota), v...)) + }) +} + +// QuotaNotIn applies the NotIn predicate on the "quota" field. +func QuotaNotIn(vs ...int64) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldQuota), v...)) + }) +} + +// QuotaGT applies the GT predicate on the "quota" field. +func QuotaGT(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldQuota), v)) + }) +} + +// QuotaGTE applies the GTE predicate on the "quota" field. +func QuotaGTE(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldQuota), v)) + }) +} + +// QuotaLT applies the LT predicate on the "quota" field. +func QuotaLT(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldQuota), v)) + }) +} + +// QuotaLTE applies the LTE predicate on the "quota" field. +func QuotaLTE(v int64) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldQuota), v)) + }) +} + +// TransportEQ applies the EQ predicate on the "transport" field. +func TransportEQ(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldTransport), v)) + }) +} + +// TransportNEQ applies the NEQ predicate on the "transport" field. +func TransportNEQ(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldTransport), v)) + }) +} + +// TransportIn applies the In predicate on the "transport" field. +func TransportIn(vs ...string) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldTransport), v...)) + }) +} + +// TransportNotIn applies the NotIn predicate on the "transport" field. +func TransportNotIn(vs ...string) predicate.Domain { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Domain(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldTransport), v...)) + }) +} + +// TransportGT applies the GT predicate on the "transport" field. +func TransportGT(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldTransport), v)) + }) +} + +// TransportGTE applies the GTE predicate on the "transport" field. +func TransportGTE(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldTransport), v)) + }) +} + +// TransportLT applies the LT predicate on the "transport" field. +func TransportLT(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldTransport), v)) + }) +} + +// TransportLTE applies the LTE predicate on the "transport" field. +func TransportLTE(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldTransport), v)) + }) +} + +// TransportContains applies the Contains predicate on the "transport" field. +func TransportContains(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldTransport), v)) + }) +} + +// TransportHasPrefix applies the HasPrefix predicate on the "transport" field. +func TransportHasPrefix(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldTransport), v)) + }) +} + +// TransportHasSuffix applies the HasSuffix predicate on the "transport" field. +func TransportHasSuffix(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldTransport), v)) + }) +} + +// TransportEqualFold applies the EqualFold predicate on the "transport" field. +func TransportEqualFold(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldTransport), v)) + }) +} + +// TransportContainsFold applies the ContainsFold predicate on the "transport" field. +func TransportContainsFold(v string) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldTransport), v)) + }) +} + +// BackupMxEQ applies the EQ predicate on the "backup_mx" field. +func BackupMxEQ(v bool) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldBackupMx), v)) + }) +} + +// BackupMxNEQ applies the NEQ predicate on the "backup_mx" field. +func BackupMxNEQ(v bool) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldBackupMx), v)) + }) +} + +// ActiveEQ applies the EQ predicate on the "active" field. +func ActiveEQ(v bool) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldActive), v)) + }) +} + +// ActiveNEQ applies the NEQ predicate on the "active" field. +func ActiveNEQ(v bool) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldActive), v)) + }) +} + +// HasMailboxes applies the HasEdge predicate on the "mailboxes" edge. +func HasMailboxes() predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(MailboxesTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, MailboxesTable, MailboxesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasMailboxesWith applies the HasEdge predicate on the "mailboxes" edge with a given conditions (other predicates). +func HasMailboxesWith(preds ...predicate.Mailbox) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(MailboxesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, MailboxesTable, MailboxesColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasAliases applies the HasEdge predicate on the "aliases" edge. +func HasAliases() predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AliasesTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, AliasesTable, AliasesColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasAliasesWith applies the HasEdge predicate on the "aliases" edge with a given conditions (other predicates). +func HasAliasesWith(preds ...predicate.Alias) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AliasesInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, AliasesTable, AliasesColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasLogs applies the HasEdge predicate on the "logs" edge. +func HasLogs() predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(LogsTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, LogsTable, LogsColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasLogsWith applies the HasEdge predicate on the "logs" edge with a given conditions (other predicates). +func HasLogsWith(preds ...predicate.Logentry) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(LogsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, LogsTable, LogsColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasAccounts applies the HasEdge predicate on the "accounts" edge. +func HasAccounts() predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AccountsTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, AccountsTable, AccountsPrimaryKey...), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasAccountsWith applies the HasEdge predicate on the "accounts" edge with a given conditions (other predicates). +func HasAccountsWith(preds ...predicate.Account) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AccountsInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, AccountsTable, AccountsPrimaryKey...), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Domain) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for _, p := range predicates { + p(s1) + } + s.Where(s1.P()) + }) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Domain) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for i, p := range predicates { + if i > 0 { + s1.Or() + } + p(s1) + } + s.Where(s1.P()) + }) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Domain) predicate.Domain { + return predicate.Domain(func(s *sql.Selector) { + p(s.Not()) + }) +} diff --git a/ent/domain_create.go b/ent/domain_create.go new file mode 100644 index 0000000..96f0aff --- /dev/null +++ b/ent/domain_create.go @@ -0,0 +1,575 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/alias" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "code.icod.de/postfix/manager/ent/mailbox" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// DomainCreate is the builder for creating a Domain entity. +type DomainCreate struct { + config + mutation *DomainMutation + hooks []Hook +} + +// SetCreated sets the "created" field. +func (dc *DomainCreate) SetCreated(t time.Time) *DomainCreate { + dc.mutation.SetCreated(t) + return dc +} + +// SetNillableCreated sets the "created" field if the given value is not nil. +func (dc *DomainCreate) SetNillableCreated(t *time.Time) *DomainCreate { + if t != nil { + dc.SetCreated(*t) + } + return dc +} + +// SetModified sets the "modified" field. +func (dc *DomainCreate) SetModified(t time.Time) *DomainCreate { + dc.mutation.SetModified(t) + return dc +} + +// SetNillableModified sets the "modified" field if the given value is not nil. +func (dc *DomainCreate) SetNillableModified(t *time.Time) *DomainCreate { + if t != nil { + dc.SetModified(*t) + } + return dc +} + +// SetDomain sets the "domain" field. +func (dc *DomainCreate) SetDomain(s string) *DomainCreate { + dc.mutation.SetDomain(s) + return dc +} + +// SetDescription sets the "description" field. +func (dc *DomainCreate) SetDescription(s string) *DomainCreate { + dc.mutation.SetDescription(s) + return dc +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (dc *DomainCreate) SetNillableDescription(s *string) *DomainCreate { + if s != nil { + dc.SetDescription(*s) + } + return dc +} + +// SetMaxAliases sets the "max_aliases" field. +func (dc *DomainCreate) SetMaxAliases(i int64) *DomainCreate { + dc.mutation.SetMaxAliases(i) + return dc +} + +// SetMaxMailboxes sets the "max_mailboxes" field. +func (dc *DomainCreate) SetMaxMailboxes(i int64) *DomainCreate { + dc.mutation.SetMaxMailboxes(i) + return dc +} + +// SetMaxQuota sets the "max_quota" field. +func (dc *DomainCreate) SetMaxQuota(i int64) *DomainCreate { + dc.mutation.SetMaxQuota(i) + return dc +} + +// SetQuota sets the "quota" field. +func (dc *DomainCreate) SetQuota(i int64) *DomainCreate { + dc.mutation.SetQuota(i) + return dc +} + +// SetTransport sets the "transport" field. +func (dc *DomainCreate) SetTransport(s string) *DomainCreate { + dc.mutation.SetTransport(s) + return dc +} + +// SetBackupMx sets the "backup_mx" field. +func (dc *DomainCreate) SetBackupMx(b bool) *DomainCreate { + dc.mutation.SetBackupMx(b) + return dc +} + +// SetActive sets the "active" field. +func (dc *DomainCreate) SetActive(b bool) *DomainCreate { + dc.mutation.SetActive(b) + return dc +} + +// SetID sets the "id" field. +func (dc *DomainCreate) SetID(i int64) *DomainCreate { + dc.mutation.SetID(i) + return dc +} + +// AddMailboxIDs adds the "mailboxes" edge to the Mailbox entity by IDs. +func (dc *DomainCreate) AddMailboxIDs(ids ...int64) *DomainCreate { + dc.mutation.AddMailboxIDs(ids...) + return dc +} + +// AddMailboxes adds the "mailboxes" edges to the Mailbox entity. +func (dc *DomainCreate) AddMailboxes(m ...*Mailbox) *DomainCreate { + ids := make([]int64, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return dc.AddMailboxIDs(ids...) +} + +// AddAliasIDs adds the "aliases" edge to the Alias entity by IDs. +func (dc *DomainCreate) AddAliasIDs(ids ...int64) *DomainCreate { + dc.mutation.AddAliasIDs(ids...) + return dc +} + +// AddAliases adds the "aliases" edges to the Alias entity. +func (dc *DomainCreate) AddAliases(a ...*Alias) *DomainCreate { + ids := make([]int64, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return dc.AddAliasIDs(ids...) +} + +// AddLogIDs adds the "logs" edge to the Logentry entity by IDs. +func (dc *DomainCreate) AddLogIDs(ids ...int64) *DomainCreate { + dc.mutation.AddLogIDs(ids...) + return dc +} + +// AddLogs adds the "logs" edges to the Logentry entity. +func (dc *DomainCreate) AddLogs(l ...*Logentry) *DomainCreate { + ids := make([]int64, len(l)) + for i := range l { + ids[i] = l[i].ID + } + return dc.AddLogIDs(ids...) +} + +// AddAccountIDs adds the "accounts" edge to the Account entity by IDs. +func (dc *DomainCreate) AddAccountIDs(ids ...int64) *DomainCreate { + dc.mutation.AddAccountIDs(ids...) + return dc +} + +// AddAccounts adds the "accounts" edges to the Account entity. +func (dc *DomainCreate) AddAccounts(a ...*Account) *DomainCreate { + ids := make([]int64, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return dc.AddAccountIDs(ids...) +} + +// Mutation returns the DomainMutation object of the builder. +func (dc *DomainCreate) Mutation() *DomainMutation { + return dc.mutation +} + +// Save creates the Domain in the database. +func (dc *DomainCreate) Save(ctx context.Context) (*Domain, error) { + var ( + err error + node *Domain + ) + dc.defaults() + if len(dc.hooks) == 0 { + if err = dc.check(); err != nil { + return nil, err + } + node, err = dc.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*DomainMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err = dc.check(); err != nil { + return nil, err + } + dc.mutation = mutation + if node, err = dc.sqlSave(ctx); err != nil { + return nil, err + } + mutation.id = &node.ID + mutation.done = true + return node, err + }) + for i := len(dc.hooks) - 1; i >= 0; i-- { + if dc.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = dc.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, dc.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX calls Save and panics if Save returns an error. +func (dc *DomainCreate) SaveX(ctx context.Context) *Domain { + v, err := dc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (dc *DomainCreate) Exec(ctx context.Context) error { + _, err := dc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (dc *DomainCreate) ExecX(ctx context.Context) { + if err := dc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (dc *DomainCreate) defaults() { + if _, ok := dc.mutation.Created(); !ok { + v := domain.DefaultCreated() + dc.mutation.SetCreated(v) + } + if _, ok := dc.mutation.Modified(); !ok { + v := domain.DefaultModified() + dc.mutation.SetModified(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (dc *DomainCreate) check() error { + if _, ok := dc.mutation.Created(); !ok { + return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "Domain.created"`)} + } + if _, ok := dc.mutation.Domain(); !ok { + return &ValidationError{Name: "domain", err: errors.New(`ent: missing required field "Domain.domain"`)} + } + if _, ok := dc.mutation.MaxAliases(); !ok { + return &ValidationError{Name: "max_aliases", err: errors.New(`ent: missing required field "Domain.max_aliases"`)} + } + if _, ok := dc.mutation.MaxMailboxes(); !ok { + return &ValidationError{Name: "max_mailboxes", err: errors.New(`ent: missing required field "Domain.max_mailboxes"`)} + } + if _, ok := dc.mutation.MaxQuota(); !ok { + return &ValidationError{Name: "max_quota", err: errors.New(`ent: missing required field "Domain.max_quota"`)} + } + if _, ok := dc.mutation.Quota(); !ok { + return &ValidationError{Name: "quota", err: errors.New(`ent: missing required field "Domain.quota"`)} + } + if _, ok := dc.mutation.Transport(); !ok { + return &ValidationError{Name: "transport", err: errors.New(`ent: missing required field "Domain.transport"`)} + } + if _, ok := dc.mutation.BackupMx(); !ok { + return &ValidationError{Name: "backup_mx", err: errors.New(`ent: missing required field "Domain.backup_mx"`)} + } + if _, ok := dc.mutation.Active(); !ok { + return &ValidationError{Name: "active", err: errors.New(`ent: missing required field "Domain.active"`)} + } + return nil +} + +func (dc *DomainCreate) sqlSave(ctx context.Context) (*Domain, error) { + _node, _spec := dc.createSpec() + if err := sqlgraph.CreateNode(ctx, dc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = int64(id) + } + return _node, nil +} + +func (dc *DomainCreate) createSpec() (*Domain, *sqlgraph.CreateSpec) { + var ( + _node = &Domain{config: dc.config} + _spec = &sqlgraph.CreateSpec{ + Table: domain.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + } + ) + if id, ok := dc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := dc.mutation.Created(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: domain.FieldCreated, + }) + _node.Created = value + } + if value, ok := dc.mutation.Modified(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: domain.FieldModified, + }) + _node.Modified = &value + } + if value, ok := dc.mutation.Domain(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: domain.FieldDomain, + }) + _node.Domain = value + } + if value, ok := dc.mutation.Description(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: domain.FieldDescription, + }) + _node.Description = &value + } + if value, ok := dc.mutation.MaxAliases(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxAliases, + }) + _node.MaxAliases = value + } + if value, ok := dc.mutation.MaxMailboxes(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxMailboxes, + }) + _node.MaxMailboxes = value + } + if value, ok := dc.mutation.MaxQuota(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxQuota, + }) + _node.MaxQuota = value + } + if value, ok := dc.mutation.Quota(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldQuota, + }) + _node.Quota = value + } + if value, ok := dc.mutation.Transport(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: domain.FieldTransport, + }) + _node.Transport = value + } + if value, ok := dc.mutation.BackupMx(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: domain.FieldBackupMx, + }) + _node.BackupMx = value + } + if value, ok := dc.mutation.Active(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: domain.FieldActive, + }) + _node.Active = value + } + if nodes := dc.mutation.MailboxesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.MailboxesTable, + Columns: []string{domain.MailboxesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := dc.mutation.AliasesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.AliasesTable, + Columns: []string{domain.AliasesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := dc.mutation.LogsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.LogsTable, + Columns: []string{domain.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := dc.mutation.AccountsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: domain.AccountsTable, + Columns: domain.AccountsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// DomainCreateBulk is the builder for creating many Domain entities in bulk. +type DomainCreateBulk struct { + config + builders []*DomainCreate +} + +// Save creates the Domain entities in the database. +func (dcb *DomainCreateBulk) Save(ctx context.Context) ([]*Domain, error) { + specs := make([]*sqlgraph.CreateSpec, len(dcb.builders)) + nodes := make([]*Domain, len(dcb.builders)) + mutators := make([]Mutator, len(dcb.builders)) + for i := range dcb.builders { + func(i int, root context.Context) { + builder := dcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*DomainMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + nodes[i], specs[i] = builder.createSpec() + var err error + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, dcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, dcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + if specs[i].ID.Value != nil && nodes[i].ID == 0 { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int64(id) + } + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, dcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (dcb *DomainCreateBulk) SaveX(ctx context.Context) []*Domain { + v, err := dcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (dcb *DomainCreateBulk) Exec(ctx context.Context) error { + _, err := dcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (dcb *DomainCreateBulk) ExecX(ctx context.Context) { + if err := dcb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/domain_delete.go b/ent/domain_delete.go new file mode 100644 index 0000000..3701634 --- /dev/null +++ b/ent/domain_delete.go @@ -0,0 +1,111 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// DomainDelete is the builder for deleting a Domain entity. +type DomainDelete struct { + config + hooks []Hook + mutation *DomainMutation +} + +// Where appends a list predicates to the DomainDelete builder. +func (dd *DomainDelete) Where(ps ...predicate.Domain) *DomainDelete { + dd.mutation.Where(ps...) + return dd +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (dd *DomainDelete) Exec(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + if len(dd.hooks) == 0 { + affected, err = dd.sqlExec(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*DomainMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + dd.mutation = mutation + affected, err = dd.sqlExec(ctx) + mutation.done = true + return affected, err + }) + for i := len(dd.hooks) - 1; i >= 0; i-- { + if dd.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = dd.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, dd.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// ExecX is like Exec, but panics if an error occurs. +func (dd *DomainDelete) ExecX(ctx context.Context) int { + n, err := dd.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (dd *DomainDelete) sqlExec(ctx context.Context) (int, error) { + _spec := &sqlgraph.DeleteSpec{ + Node: &sqlgraph.NodeSpec{ + Table: domain.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + if ps := dd.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return sqlgraph.DeleteNodes(ctx, dd.driver, _spec) +} + +// DomainDeleteOne is the builder for deleting a single Domain entity. +type DomainDeleteOne struct { + dd *DomainDelete +} + +// Exec executes the deletion query. +func (ddo *DomainDeleteOne) Exec(ctx context.Context) error { + n, err := ddo.dd.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{domain.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (ddo *DomainDeleteOne) ExecX(ctx context.Context) { + ddo.dd.ExecX(ctx) +} diff --git a/ent/domain_query.go b/ent/domain_query.go new file mode 100644 index 0000000..698386e --- /dev/null +++ b/ent/domain_query.go @@ -0,0 +1,1215 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "database/sql/driver" + "errors" + "fmt" + "math" + + "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/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// DomainQuery is the builder for querying Domain entities. +type DomainQuery struct { + config + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Domain + // eager-loading edges. + withMailboxes *MailboxQuery + withAliases *AliasQuery + withLogs *LogentryQuery + withAccounts *AccountQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the DomainQuery builder. +func (dq *DomainQuery) Where(ps ...predicate.Domain) *DomainQuery { + dq.predicates = append(dq.predicates, ps...) + return dq +} + +// Limit adds a limit step to the query. +func (dq *DomainQuery) Limit(limit int) *DomainQuery { + dq.limit = &limit + return dq +} + +// Offset adds an offset step to the query. +func (dq *DomainQuery) Offset(offset int) *DomainQuery { + dq.offset = &offset + return dq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (dq *DomainQuery) Unique(unique bool) *DomainQuery { + dq.unique = &unique + return dq +} + +// Order adds an order step to the query. +func (dq *DomainQuery) Order(o ...OrderFunc) *DomainQuery { + dq.order = append(dq.order, o...) + return dq +} + +// QueryMailboxes chains the current query on the "mailboxes" edge. +func (dq *DomainQuery) QueryMailboxes() *MailboxQuery { + query := &MailboxQuery{config: dq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := dq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := dq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(domain.Table, domain.FieldID, selector), + sqlgraph.To(mailbox.Table, mailbox.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, domain.MailboxesTable, domain.MailboxesColumn), + ) + fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryAliases chains the current query on the "aliases" edge. +func (dq *DomainQuery) QueryAliases() *AliasQuery { + query := &AliasQuery{config: dq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := dq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := dq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(domain.Table, domain.FieldID, selector), + sqlgraph.To(alias.Table, alias.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, domain.AliasesTable, domain.AliasesColumn), + ) + fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryLogs chains the current query on the "logs" edge. +func (dq *DomainQuery) QueryLogs() *LogentryQuery { + query := &LogentryQuery{config: dq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := dq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := dq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(domain.Table, domain.FieldID, selector), + sqlgraph.To(logentry.Table, logentry.FieldID), + sqlgraph.Edge(sqlgraph.O2M, false, domain.LogsTable, domain.LogsColumn), + ) + fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryAccounts chains the current query on the "accounts" edge. +func (dq *DomainQuery) QueryAccounts() *AccountQuery { + query := &AccountQuery{config: dq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := dq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := dq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(domain.Table, domain.FieldID, selector), + sqlgraph.To(account.Table, account.FieldID), + sqlgraph.Edge(sqlgraph.M2M, true, domain.AccountsTable, domain.AccountsPrimaryKey...), + ) + fromU = sqlgraph.SetNeighbors(dq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Domain entity from the query. +// Returns a *NotFoundError when no Domain was found. +func (dq *DomainQuery) First(ctx context.Context) (*Domain, error) { + nodes, err := dq.Limit(1).All(ctx) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{domain.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (dq *DomainQuery) FirstX(ctx context.Context) *Domain { + node, err := dq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Domain ID from the query. +// Returns a *NotFoundError when no Domain ID was found. +func (dq *DomainQuery) FirstID(ctx context.Context) (id int64, err error) { + var ids []int64 + if ids, err = dq.Limit(1).IDs(ctx); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{domain.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (dq *DomainQuery) FirstIDX(ctx context.Context) int64 { + id, err := dq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Domain entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Domain entity is found. +// Returns a *NotFoundError when no Domain entities are found. +func (dq *DomainQuery) Only(ctx context.Context) (*Domain, error) { + nodes, err := dq.Limit(2).All(ctx) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{domain.Label} + default: + return nil, &NotSingularError{domain.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (dq *DomainQuery) OnlyX(ctx context.Context) *Domain { + node, err := dq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Domain ID in the query. +// Returns a *NotSingularError when more than one Domain ID is found. +// Returns a *NotFoundError when no entities are found. +func (dq *DomainQuery) OnlyID(ctx context.Context) (id int64, err error) { + var ids []int64 + if ids, err = dq.Limit(2).IDs(ctx); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{domain.Label} + default: + err = &NotSingularError{domain.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (dq *DomainQuery) OnlyIDX(ctx context.Context) int64 { + id, err := dq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Domains. +func (dq *DomainQuery) All(ctx context.Context) ([]*Domain, error) { + if err := dq.prepareQuery(ctx); err != nil { + return nil, err + } + return dq.sqlAll(ctx) +} + +// AllX is like All, but panics if an error occurs. +func (dq *DomainQuery) AllX(ctx context.Context) []*Domain { + nodes, err := dq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Domain IDs. +func (dq *DomainQuery) IDs(ctx context.Context) ([]int64, error) { + var ids []int64 + if err := dq.Select(domain.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (dq *DomainQuery) IDsX(ctx context.Context) []int64 { + ids, err := dq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (dq *DomainQuery) Count(ctx context.Context) (int, error) { + if err := dq.prepareQuery(ctx); err != nil { + return 0, err + } + return dq.sqlCount(ctx) +} + +// CountX is like Count, but panics if an error occurs. +func (dq *DomainQuery) CountX(ctx context.Context) int { + count, err := dq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (dq *DomainQuery) Exist(ctx context.Context) (bool, error) { + if err := dq.prepareQuery(ctx); err != nil { + return false, err + } + return dq.sqlExist(ctx) +} + +// ExistX is like Exist, but panics if an error occurs. +func (dq *DomainQuery) ExistX(ctx context.Context) bool { + exist, err := dq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the DomainQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (dq *DomainQuery) Clone() *DomainQuery { + if dq == nil { + return nil + } + return &DomainQuery{ + config: dq.config, + limit: dq.limit, + offset: dq.offset, + order: append([]OrderFunc{}, dq.order...), + predicates: append([]predicate.Domain{}, dq.predicates...), + withMailboxes: dq.withMailboxes.Clone(), + withAliases: dq.withAliases.Clone(), + withLogs: dq.withLogs.Clone(), + withAccounts: dq.withAccounts.Clone(), + // clone intermediate query. + sql: dq.sql.Clone(), + path: dq.path, + unique: dq.unique, + } +} + +// WithMailboxes tells the query-builder to eager-load the nodes that are connected to +// the "mailboxes" edge. The optional arguments are used to configure the query builder of the edge. +func (dq *DomainQuery) WithMailboxes(opts ...func(*MailboxQuery)) *DomainQuery { + query := &MailboxQuery{config: dq.config} + for _, opt := range opts { + opt(query) + } + dq.withMailboxes = query + return dq +} + +// WithAliases tells the query-builder to eager-load the nodes that are connected to +// the "aliases" edge. The optional arguments are used to configure the query builder of the edge. +func (dq *DomainQuery) WithAliases(opts ...func(*AliasQuery)) *DomainQuery { + query := &AliasQuery{config: dq.config} + for _, opt := range opts { + opt(query) + } + dq.withAliases = query + return dq +} + +// WithLogs tells the query-builder to eager-load the nodes that are connected to +// the "logs" edge. The optional arguments are used to configure the query builder of the edge. +func (dq *DomainQuery) WithLogs(opts ...func(*LogentryQuery)) *DomainQuery { + query := &LogentryQuery{config: dq.config} + for _, opt := range opts { + opt(query) + } + dq.withLogs = query + return dq +} + +// WithAccounts tells the query-builder to eager-load the nodes that are connected to +// the "accounts" edge. The optional arguments are used to configure the query builder of the edge. +func (dq *DomainQuery) WithAccounts(opts ...func(*AccountQuery)) *DomainQuery { + query := &AccountQuery{config: dq.config} + for _, opt := range opts { + opt(query) + } + dq.withAccounts = query + return dq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Created time.Time `json:"created,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Domain.Query(). +// GroupBy(domain.FieldCreated). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +// +func (dq *DomainQuery) GroupBy(field string, fields ...string) *DomainGroupBy { + group := &DomainGroupBy{config: dq.config} + group.fields = append([]string{field}, fields...) + group.path = func(ctx context.Context) (prev *sql.Selector, err error) { + if err := dq.prepareQuery(ctx); err != nil { + return nil, err + } + return dq.sqlQuery(ctx), nil + } + return group +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Created time.Time `json:"created,omitempty"` +// } +// +// client.Domain.Query(). +// Select(domain.FieldCreated). +// Scan(ctx, &v) +// +func (dq *DomainQuery) Select(fields ...string) *DomainSelect { + dq.fields = append(dq.fields, fields...) + return &DomainSelect{DomainQuery: dq} +} + +func (dq *DomainQuery) prepareQuery(ctx context.Context) error { + for _, f := range dq.fields { + if !domain.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if dq.path != nil { + prev, err := dq.path(ctx) + if err != nil { + return err + } + dq.sql = prev + } + return nil +} + +func (dq *DomainQuery) sqlAll(ctx context.Context) ([]*Domain, error) { + var ( + nodes = []*Domain{} + _spec = dq.querySpec() + loadedTypes = [4]bool{ + dq.withMailboxes != nil, + dq.withAliases != nil, + dq.withLogs != nil, + dq.withAccounts != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]interface{}, error) { + node := &Domain{config: dq.config} + nodes = append(nodes, node) + return node.scanValues(columns) + } + _spec.Assign = func(columns []string, values []interface{}) error { + if len(nodes) == 0 { + return fmt.Errorf("ent: Assign called without calling ScanValues") + } + node := nodes[len(nodes)-1] + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if err := sqlgraph.QueryNodes(ctx, dq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + + if query := dq.withMailboxes; query != nil { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int64]*Domain) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + nodes[i].Edges.Mailboxes = []*Mailbox{} + } + query.Where(predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.InValues(domain.MailboxesColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + fk := n.DomainID + node, ok := nodeids[fk] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "domain_id" returned %v for node %v`, fk, n.ID) + } + node.Edges.Mailboxes = append(node.Edges.Mailboxes, n) + } + } + + if query := dq.withAliases; query != nil { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int64]*Domain) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + nodes[i].Edges.Aliases = []*Alias{} + } + query.Where(predicate.Alias(func(s *sql.Selector) { + s.Where(sql.InValues(domain.AliasesColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + fk := n.DomainID + node, ok := nodeids[fk] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "domain_id" returned %v for node %v`, fk, n.ID) + } + node.Edges.Aliases = append(node.Edges.Aliases, n) + } + } + + if query := dq.withLogs; query != nil { + fks := make([]driver.Value, 0, len(nodes)) + nodeids := make(map[int64]*Domain) + for i := range nodes { + fks = append(fks, nodes[i].ID) + nodeids[nodes[i].ID] = nodes[i] + nodes[i].Edges.Logs = []*Logentry{} + } + query.Where(predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.InValues(domain.LogsColumn, fks...)) + })) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + fk := n.DomainID + node, ok := nodeids[fk] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "domain_id" returned %v for node %v`, fk, n.ID) + } + node.Edges.Logs = append(node.Edges.Logs, n) + } + } + + if query := dq.withAccounts; query != nil { + fks := make([]driver.Value, 0, len(nodes)) + ids := make(map[int64]*Domain, len(nodes)) + for _, node := range nodes { + ids[node.ID] = node + fks = append(fks, node.ID) + node.Edges.Accounts = []*Account{} + } + var ( + edgeids []int64 + edges = make(map[int64][]*Domain) + ) + _spec := &sqlgraph.EdgeQuerySpec{ + Edge: &sqlgraph.EdgeSpec{ + Inverse: true, + Table: domain.AccountsTable, + Columns: domain.AccountsPrimaryKey, + }, + Predicate: func(s *sql.Selector) { + s.Where(sql.InValues(domain.AccountsPrimaryKey[1], fks...)) + }, + ScanValues: func() [2]interface{} { + return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)} + }, + Assign: func(out, in interface{}) error { + eout, ok := out.(*sql.NullInt64) + if !ok || eout == nil { + return fmt.Errorf("unexpected id value for edge-out") + } + ein, ok := in.(*sql.NullInt64) + if !ok || ein == nil { + return fmt.Errorf("unexpected id value for edge-in") + } + outValue := eout.Int64 + inValue := ein.Int64 + node, ok := ids[outValue] + if !ok { + return fmt.Errorf("unexpected node id in edges: %v", outValue) + } + if _, ok := edges[inValue]; !ok { + edgeids = append(edgeids, inValue) + } + edges[inValue] = append(edges[inValue], node) + return nil + }, + } + if err := sqlgraph.QueryEdges(ctx, dq.driver, _spec); err != nil { + return nil, fmt.Errorf(`query edges "accounts": %w`, err) + } + query.Where(account.IDIn(edgeids...)) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + nodes, ok := edges[n.ID] + if !ok { + return nil, fmt.Errorf(`unexpected "accounts" node returned %v`, n.ID) + } + for i := range nodes { + nodes[i].Edges.Accounts = append(nodes[i].Edges.Accounts, n) + } + } + } + + return nodes, nil +} + +func (dq *DomainQuery) sqlCount(ctx context.Context) (int, error) { + _spec := dq.querySpec() + _spec.Node.Columns = dq.fields + if len(dq.fields) > 0 { + _spec.Unique = dq.unique != nil && *dq.unique + } + return sqlgraph.CountNodes(ctx, dq.driver, _spec) +} + +func (dq *DomainQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := dq.sqlCount(ctx) + if err != nil { + return false, fmt.Errorf("ent: check existence: %w", err) + } + return n > 0, nil +} + +func (dq *DomainQuery) querySpec() *sqlgraph.QuerySpec { + _spec := &sqlgraph.QuerySpec{ + Node: &sqlgraph.NodeSpec{ + Table: domain.Table, + Columns: domain.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + From: dq.sql, + Unique: true, + } + if unique := dq.unique; unique != nil { + _spec.Unique = *unique + } + if fields := dq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, domain.FieldID) + for i := range fields { + if fields[i] != domain.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := dq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := dq.limit; limit != nil { + _spec.Limit = *limit + } + if offset := dq.offset; offset != nil { + _spec.Offset = *offset + } + if ps := dq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (dq *DomainQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(dq.driver.Dialect()) + t1 := builder.Table(domain.Table) + columns := dq.fields + if len(columns) == 0 { + columns = domain.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if dq.sql != nil { + selector = dq.sql + selector.Select(selector.Columns(columns...)...) + } + if dq.unique != nil && *dq.unique { + selector.Distinct() + } + for _, p := range dq.predicates { + p(selector) + } + for _, p := range dq.order { + p(selector) + } + if offset := dq.offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := dq.limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// DomainGroupBy is the group-by builder for Domain entities. +type DomainGroupBy struct { + config + fields []string + fns []AggregateFunc + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (dgb *DomainGroupBy) Aggregate(fns ...AggregateFunc) *DomainGroupBy { + dgb.fns = append(dgb.fns, fns...) + return dgb +} + +// Scan applies the group-by query and scans the result into the given value. +func (dgb *DomainGroupBy) Scan(ctx context.Context, v interface{}) error { + query, err := dgb.path(ctx) + if err != nil { + return err + } + dgb.sql = query + return dgb.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (dgb *DomainGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := dgb.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. +func (dgb *DomainGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(dgb.fields) > 1 { + return nil, errors.New("ent: DomainGroupBy.Strings is not achievable when grouping more than 1 field") + } + var v []string + if err := dgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (dgb *DomainGroupBy) StringsX(ctx context.Context) []string { + v, err := dgb.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (dgb *DomainGroupBy) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = dgb.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{domain.Label} + default: + err = fmt.Errorf("ent: DomainGroupBy.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (dgb *DomainGroupBy) StringX(ctx context.Context) string { + v, err := dgb.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. +func (dgb *DomainGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(dgb.fields) > 1 { + return nil, errors.New("ent: DomainGroupBy.Ints is not achievable when grouping more than 1 field") + } + var v []int + if err := dgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (dgb *DomainGroupBy) IntsX(ctx context.Context) []int { + v, err := dgb.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (dgb *DomainGroupBy) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = dgb.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{domain.Label} + default: + err = fmt.Errorf("ent: DomainGroupBy.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (dgb *DomainGroupBy) IntX(ctx context.Context) int { + v, err := dgb.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. +func (dgb *DomainGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(dgb.fields) > 1 { + return nil, errors.New("ent: DomainGroupBy.Float64s is not achievable when grouping more than 1 field") + } + var v []float64 + if err := dgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (dgb *DomainGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := dgb.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (dgb *DomainGroupBy) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = dgb.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{domain.Label} + default: + err = fmt.Errorf("ent: DomainGroupBy.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (dgb *DomainGroupBy) Float64X(ctx context.Context) float64 { + v, err := dgb.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. +func (dgb *DomainGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(dgb.fields) > 1 { + return nil, errors.New("ent: DomainGroupBy.Bools is not achievable when grouping more than 1 field") + } + var v []bool + if err := dgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (dgb *DomainGroupBy) BoolsX(ctx context.Context) []bool { + v, err := dgb.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (dgb *DomainGroupBy) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = dgb.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{domain.Label} + default: + err = fmt.Errorf("ent: DomainGroupBy.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (dgb *DomainGroupBy) BoolX(ctx context.Context) bool { + v, err := dgb.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (dgb *DomainGroupBy) sqlScan(ctx context.Context, v interface{}) error { + for _, f := range dgb.fields { + if !domain.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} + } + } + selector := dgb.sqlQuery() + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := dgb.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (dgb *DomainGroupBy) sqlQuery() *sql.Selector { + selector := dgb.sql.Select() + aggregation := make([]string, 0, len(dgb.fns)) + for _, fn := range dgb.fns { + aggregation = append(aggregation, fn(selector)) + } + // If no columns were selected in a custom aggregation function, the default + // selection is the fields used for "group-by", and the aggregation functions. + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(dgb.fields)+len(dgb.fns)) + for _, f := range dgb.fields { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + return selector.GroupBy(selector.Columns(dgb.fields...)...) +} + +// DomainSelect is the builder for selecting fields of Domain entities. +type DomainSelect struct { + *DomainQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector +} + +// Scan applies the selector query and scans the result into the given value. +func (ds *DomainSelect) Scan(ctx context.Context, v interface{}) error { + if err := ds.prepareQuery(ctx); err != nil { + return err + } + ds.sql = ds.DomainQuery.sqlQuery(ctx) + return ds.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (ds *DomainSelect) ScanX(ctx context.Context, v interface{}) { + if err := ds.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from a selector. It is only allowed when selecting one field. +func (ds *DomainSelect) Strings(ctx context.Context) ([]string, error) { + if len(ds.fields) > 1 { + return nil, errors.New("ent: DomainSelect.Strings is not achievable when selecting more than 1 field") + } + var v []string + if err := ds.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (ds *DomainSelect) StringsX(ctx context.Context) []string { + v, err := ds.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a selector. It is only allowed when selecting one field. +func (ds *DomainSelect) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = ds.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{domain.Label} + default: + err = fmt.Errorf("ent: DomainSelect.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (ds *DomainSelect) StringX(ctx context.Context) string { + v, err := ds.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from a selector. It is only allowed when selecting one field. +func (ds *DomainSelect) Ints(ctx context.Context) ([]int, error) { + if len(ds.fields) > 1 { + return nil, errors.New("ent: DomainSelect.Ints is not achievable when selecting more than 1 field") + } + var v []int + if err := ds.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (ds *DomainSelect) IntsX(ctx context.Context) []int { + v, err := ds.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a selector. It is only allowed when selecting one field. +func (ds *DomainSelect) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = ds.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{domain.Label} + default: + err = fmt.Errorf("ent: DomainSelect.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (ds *DomainSelect) IntX(ctx context.Context) int { + v, err := ds.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. +func (ds *DomainSelect) Float64s(ctx context.Context) ([]float64, error) { + if len(ds.fields) > 1 { + return nil, errors.New("ent: DomainSelect.Float64s is not achievable when selecting more than 1 field") + } + var v []float64 + if err := ds.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (ds *DomainSelect) Float64sX(ctx context.Context) []float64 { + v, err := ds.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. +func (ds *DomainSelect) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = ds.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{domain.Label} + default: + err = fmt.Errorf("ent: DomainSelect.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (ds *DomainSelect) Float64X(ctx context.Context) float64 { + v, err := ds.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from a selector. It is only allowed when selecting one field. +func (ds *DomainSelect) Bools(ctx context.Context) ([]bool, error) { + if len(ds.fields) > 1 { + return nil, errors.New("ent: DomainSelect.Bools is not achievable when selecting more than 1 field") + } + var v []bool + if err := ds.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (ds *DomainSelect) BoolsX(ctx context.Context) []bool { + v, err := ds.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a selector. It is only allowed when selecting one field. +func (ds *DomainSelect) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = ds.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{domain.Label} + default: + err = fmt.Errorf("ent: DomainSelect.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (ds *DomainSelect) BoolX(ctx context.Context) bool { + v, err := ds.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (ds *DomainSelect) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := ds.sql.Query() + if err := ds.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/domain_update.go b/ent/domain_update.go new file mode 100644 index 0000000..5b5558d --- /dev/null +++ b/ent/domain_update.go @@ -0,0 +1,1418 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/alias" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "code.icod.de/postfix/manager/ent/mailbox" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// DomainUpdate is the builder for updating Domain entities. +type DomainUpdate struct { + config + hooks []Hook + mutation *DomainMutation +} + +// Where appends a list predicates to the DomainUpdate builder. +func (du *DomainUpdate) Where(ps ...predicate.Domain) *DomainUpdate { + du.mutation.Where(ps...) + return du +} + +// SetModified sets the "modified" field. +func (du *DomainUpdate) SetModified(t time.Time) *DomainUpdate { + du.mutation.SetModified(t) + return du +} + +// ClearModified clears the value of the "modified" field. +func (du *DomainUpdate) ClearModified() *DomainUpdate { + du.mutation.ClearModified() + return du +} + +// SetDomain sets the "domain" field. +func (du *DomainUpdate) SetDomain(s string) *DomainUpdate { + du.mutation.SetDomain(s) + return du +} + +// SetDescription sets the "description" field. +func (du *DomainUpdate) SetDescription(s string) *DomainUpdate { + du.mutation.SetDescription(s) + return du +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (du *DomainUpdate) SetNillableDescription(s *string) *DomainUpdate { + if s != nil { + du.SetDescription(*s) + } + return du +} + +// ClearDescription clears the value of the "description" field. +func (du *DomainUpdate) ClearDescription() *DomainUpdate { + du.mutation.ClearDescription() + return du +} + +// SetMaxAliases sets the "max_aliases" field. +func (du *DomainUpdate) SetMaxAliases(i int64) *DomainUpdate { + du.mutation.ResetMaxAliases() + du.mutation.SetMaxAliases(i) + return du +} + +// AddMaxAliases adds i to the "max_aliases" field. +func (du *DomainUpdate) AddMaxAliases(i int64) *DomainUpdate { + du.mutation.AddMaxAliases(i) + return du +} + +// SetMaxMailboxes sets the "max_mailboxes" field. +func (du *DomainUpdate) SetMaxMailboxes(i int64) *DomainUpdate { + du.mutation.ResetMaxMailboxes() + du.mutation.SetMaxMailboxes(i) + return du +} + +// AddMaxMailboxes adds i to the "max_mailboxes" field. +func (du *DomainUpdate) AddMaxMailboxes(i int64) *DomainUpdate { + du.mutation.AddMaxMailboxes(i) + return du +} + +// SetMaxQuota sets the "max_quota" field. +func (du *DomainUpdate) SetMaxQuota(i int64) *DomainUpdate { + du.mutation.ResetMaxQuota() + du.mutation.SetMaxQuota(i) + return du +} + +// AddMaxQuota adds i to the "max_quota" field. +func (du *DomainUpdate) AddMaxQuota(i int64) *DomainUpdate { + du.mutation.AddMaxQuota(i) + return du +} + +// SetQuota sets the "quota" field. +func (du *DomainUpdate) SetQuota(i int64) *DomainUpdate { + du.mutation.ResetQuota() + du.mutation.SetQuota(i) + return du +} + +// AddQuota adds i to the "quota" field. +func (du *DomainUpdate) AddQuota(i int64) *DomainUpdate { + du.mutation.AddQuota(i) + return du +} + +// SetTransport sets the "transport" field. +func (du *DomainUpdate) SetTransport(s string) *DomainUpdate { + du.mutation.SetTransport(s) + return du +} + +// SetBackupMx sets the "backup_mx" field. +func (du *DomainUpdate) SetBackupMx(b bool) *DomainUpdate { + du.mutation.SetBackupMx(b) + return du +} + +// SetActive sets the "active" field. +func (du *DomainUpdate) SetActive(b bool) *DomainUpdate { + du.mutation.SetActive(b) + return du +} + +// AddMailboxIDs adds the "mailboxes" edge to the Mailbox entity by IDs. +func (du *DomainUpdate) AddMailboxIDs(ids ...int64) *DomainUpdate { + du.mutation.AddMailboxIDs(ids...) + return du +} + +// AddMailboxes adds the "mailboxes" edges to the Mailbox entity. +func (du *DomainUpdate) AddMailboxes(m ...*Mailbox) *DomainUpdate { + ids := make([]int64, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return du.AddMailboxIDs(ids...) +} + +// AddAliasIDs adds the "aliases" edge to the Alias entity by IDs. +func (du *DomainUpdate) AddAliasIDs(ids ...int64) *DomainUpdate { + du.mutation.AddAliasIDs(ids...) + return du +} + +// AddAliases adds the "aliases" edges to the Alias entity. +func (du *DomainUpdate) AddAliases(a ...*Alias) *DomainUpdate { + ids := make([]int64, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return du.AddAliasIDs(ids...) +} + +// AddLogIDs adds the "logs" edge to the Logentry entity by IDs. +func (du *DomainUpdate) AddLogIDs(ids ...int64) *DomainUpdate { + du.mutation.AddLogIDs(ids...) + return du +} + +// AddLogs adds the "logs" edges to the Logentry entity. +func (du *DomainUpdate) AddLogs(l ...*Logentry) *DomainUpdate { + ids := make([]int64, len(l)) + for i := range l { + ids[i] = l[i].ID + } + return du.AddLogIDs(ids...) +} + +// AddAccountIDs adds the "accounts" edge to the Account entity by IDs. +func (du *DomainUpdate) AddAccountIDs(ids ...int64) *DomainUpdate { + du.mutation.AddAccountIDs(ids...) + return du +} + +// AddAccounts adds the "accounts" edges to the Account entity. +func (du *DomainUpdate) AddAccounts(a ...*Account) *DomainUpdate { + ids := make([]int64, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return du.AddAccountIDs(ids...) +} + +// Mutation returns the DomainMutation object of the builder. +func (du *DomainUpdate) Mutation() *DomainMutation { + return du.mutation +} + +// ClearMailboxes clears all "mailboxes" edges to the Mailbox entity. +func (du *DomainUpdate) ClearMailboxes() *DomainUpdate { + du.mutation.ClearMailboxes() + return du +} + +// RemoveMailboxIDs removes the "mailboxes" edge to Mailbox entities by IDs. +func (du *DomainUpdate) RemoveMailboxIDs(ids ...int64) *DomainUpdate { + du.mutation.RemoveMailboxIDs(ids...) + return du +} + +// RemoveMailboxes removes "mailboxes" edges to Mailbox entities. +func (du *DomainUpdate) RemoveMailboxes(m ...*Mailbox) *DomainUpdate { + ids := make([]int64, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return du.RemoveMailboxIDs(ids...) +} + +// ClearAliases clears all "aliases" edges to the Alias entity. +func (du *DomainUpdate) ClearAliases() *DomainUpdate { + du.mutation.ClearAliases() + return du +} + +// RemoveAliasIDs removes the "aliases" edge to Alias entities by IDs. +func (du *DomainUpdate) RemoveAliasIDs(ids ...int64) *DomainUpdate { + du.mutation.RemoveAliasIDs(ids...) + return du +} + +// RemoveAliases removes "aliases" edges to Alias entities. +func (du *DomainUpdate) RemoveAliases(a ...*Alias) *DomainUpdate { + ids := make([]int64, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return du.RemoveAliasIDs(ids...) +} + +// ClearLogs clears all "logs" edges to the Logentry entity. +func (du *DomainUpdate) ClearLogs() *DomainUpdate { + du.mutation.ClearLogs() + return du +} + +// RemoveLogIDs removes the "logs" edge to Logentry entities by IDs. +func (du *DomainUpdate) RemoveLogIDs(ids ...int64) *DomainUpdate { + du.mutation.RemoveLogIDs(ids...) + return du +} + +// RemoveLogs removes "logs" edges to Logentry entities. +func (du *DomainUpdate) RemoveLogs(l ...*Logentry) *DomainUpdate { + ids := make([]int64, len(l)) + for i := range l { + ids[i] = l[i].ID + } + return du.RemoveLogIDs(ids...) +} + +// ClearAccounts clears all "accounts" edges to the Account entity. +func (du *DomainUpdate) ClearAccounts() *DomainUpdate { + du.mutation.ClearAccounts() + return du +} + +// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs. +func (du *DomainUpdate) RemoveAccountIDs(ids ...int64) *DomainUpdate { + du.mutation.RemoveAccountIDs(ids...) + return du +} + +// RemoveAccounts removes "accounts" edges to Account entities. +func (du *DomainUpdate) RemoveAccounts(a ...*Account) *DomainUpdate { + ids := make([]int64, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return du.RemoveAccountIDs(ids...) +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (du *DomainUpdate) Save(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + du.defaults() + if len(du.hooks) == 0 { + affected, err = du.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*DomainMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + du.mutation = mutation + affected, err = du.sqlSave(ctx) + mutation.done = true + return affected, err + }) + for i := len(du.hooks) - 1; i >= 0; i-- { + if du.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = du.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, du.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// SaveX is like Save, but panics if an error occurs. +func (du *DomainUpdate) SaveX(ctx context.Context) int { + affected, err := du.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (du *DomainUpdate) Exec(ctx context.Context) error { + _, err := du.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (du *DomainUpdate) ExecX(ctx context.Context) { + if err := du.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (du *DomainUpdate) defaults() { + if _, ok := du.mutation.Modified(); !ok && !du.mutation.ModifiedCleared() { + v := domain.UpdateDefaultModified() + du.mutation.SetModified(v) + } +} + +func (du *DomainUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: domain.Table, + Columns: domain.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + if ps := du.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := du.mutation.Modified(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: domain.FieldModified, + }) + } + if du.mutation.ModifiedCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: domain.FieldModified, + }) + } + if value, ok := du.mutation.Domain(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: domain.FieldDomain, + }) + } + if value, ok := du.mutation.Description(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: domain.FieldDescription, + }) + } + if du.mutation.DescriptionCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: domain.FieldDescription, + }) + } + if value, ok := du.mutation.MaxAliases(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxAliases, + }) + } + if value, ok := du.mutation.AddedMaxAliases(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxAliases, + }) + } + if value, ok := du.mutation.MaxMailboxes(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxMailboxes, + }) + } + if value, ok := du.mutation.AddedMaxMailboxes(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxMailboxes, + }) + } + if value, ok := du.mutation.MaxQuota(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxQuota, + }) + } + if value, ok := du.mutation.AddedMaxQuota(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxQuota, + }) + } + if value, ok := du.mutation.Quota(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldQuota, + }) + } + if value, ok := du.mutation.AddedQuota(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldQuota, + }) + } + if value, ok := du.mutation.Transport(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: domain.FieldTransport, + }) + } + if value, ok := du.mutation.BackupMx(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: domain.FieldBackupMx, + }) + } + if value, ok := du.mutation.Active(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: domain.FieldActive, + }) + } + if du.mutation.MailboxesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.MailboxesTable, + Columns: []string{domain.MailboxesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := du.mutation.RemovedMailboxesIDs(); len(nodes) > 0 && !du.mutation.MailboxesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.MailboxesTable, + Columns: []string{domain.MailboxesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := du.mutation.MailboxesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.MailboxesTable, + Columns: []string{domain.MailboxesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if du.mutation.AliasesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.AliasesTable, + Columns: []string{domain.AliasesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := du.mutation.RemovedAliasesIDs(); len(nodes) > 0 && !du.mutation.AliasesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.AliasesTable, + Columns: []string{domain.AliasesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := du.mutation.AliasesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.AliasesTable, + Columns: []string{domain.AliasesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if du.mutation.LogsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.LogsTable, + Columns: []string{domain.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := du.mutation.RemovedLogsIDs(); len(nodes) > 0 && !du.mutation.LogsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.LogsTable, + Columns: []string{domain.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := du.mutation.LogsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.LogsTable, + Columns: []string{domain.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if du.mutation.AccountsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: domain.AccountsTable, + Columns: domain.AccountsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := du.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !du.mutation.AccountsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: domain.AccountsTable, + Columns: domain.AccountsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := du.mutation.AccountsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: domain.AccountsTable, + Columns: domain.AccountsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, du.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{domain.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return 0, err + } + return n, nil +} + +// DomainUpdateOne is the builder for updating a single Domain entity. +type DomainUpdateOne struct { + config + fields []string + hooks []Hook + mutation *DomainMutation +} + +// SetModified sets the "modified" field. +func (duo *DomainUpdateOne) SetModified(t time.Time) *DomainUpdateOne { + duo.mutation.SetModified(t) + return duo +} + +// ClearModified clears the value of the "modified" field. +func (duo *DomainUpdateOne) ClearModified() *DomainUpdateOne { + duo.mutation.ClearModified() + return duo +} + +// SetDomain sets the "domain" field. +func (duo *DomainUpdateOne) SetDomain(s string) *DomainUpdateOne { + duo.mutation.SetDomain(s) + return duo +} + +// SetDescription sets the "description" field. +func (duo *DomainUpdateOne) SetDescription(s string) *DomainUpdateOne { + duo.mutation.SetDescription(s) + return duo +} + +// SetNillableDescription sets the "description" field if the given value is not nil. +func (duo *DomainUpdateOne) SetNillableDescription(s *string) *DomainUpdateOne { + if s != nil { + duo.SetDescription(*s) + } + return duo +} + +// ClearDescription clears the value of the "description" field. +func (duo *DomainUpdateOne) ClearDescription() *DomainUpdateOne { + duo.mutation.ClearDescription() + return duo +} + +// SetMaxAliases sets the "max_aliases" field. +func (duo *DomainUpdateOne) SetMaxAliases(i int64) *DomainUpdateOne { + duo.mutation.ResetMaxAliases() + duo.mutation.SetMaxAliases(i) + return duo +} + +// AddMaxAliases adds i to the "max_aliases" field. +func (duo *DomainUpdateOne) AddMaxAliases(i int64) *DomainUpdateOne { + duo.mutation.AddMaxAliases(i) + return duo +} + +// SetMaxMailboxes sets the "max_mailboxes" field. +func (duo *DomainUpdateOne) SetMaxMailboxes(i int64) *DomainUpdateOne { + duo.mutation.ResetMaxMailboxes() + duo.mutation.SetMaxMailboxes(i) + return duo +} + +// AddMaxMailboxes adds i to the "max_mailboxes" field. +func (duo *DomainUpdateOne) AddMaxMailboxes(i int64) *DomainUpdateOne { + duo.mutation.AddMaxMailboxes(i) + return duo +} + +// SetMaxQuota sets the "max_quota" field. +func (duo *DomainUpdateOne) SetMaxQuota(i int64) *DomainUpdateOne { + duo.mutation.ResetMaxQuota() + duo.mutation.SetMaxQuota(i) + return duo +} + +// AddMaxQuota adds i to the "max_quota" field. +func (duo *DomainUpdateOne) AddMaxQuota(i int64) *DomainUpdateOne { + duo.mutation.AddMaxQuota(i) + return duo +} + +// SetQuota sets the "quota" field. +func (duo *DomainUpdateOne) SetQuota(i int64) *DomainUpdateOne { + duo.mutation.ResetQuota() + duo.mutation.SetQuota(i) + return duo +} + +// AddQuota adds i to the "quota" field. +func (duo *DomainUpdateOne) AddQuota(i int64) *DomainUpdateOne { + duo.mutation.AddQuota(i) + return duo +} + +// SetTransport sets the "transport" field. +func (duo *DomainUpdateOne) SetTransport(s string) *DomainUpdateOne { + duo.mutation.SetTransport(s) + return duo +} + +// SetBackupMx sets the "backup_mx" field. +func (duo *DomainUpdateOne) SetBackupMx(b bool) *DomainUpdateOne { + duo.mutation.SetBackupMx(b) + return duo +} + +// SetActive sets the "active" field. +func (duo *DomainUpdateOne) SetActive(b bool) *DomainUpdateOne { + duo.mutation.SetActive(b) + return duo +} + +// AddMailboxIDs adds the "mailboxes" edge to the Mailbox entity by IDs. +func (duo *DomainUpdateOne) AddMailboxIDs(ids ...int64) *DomainUpdateOne { + duo.mutation.AddMailboxIDs(ids...) + return duo +} + +// AddMailboxes adds the "mailboxes" edges to the Mailbox entity. +func (duo *DomainUpdateOne) AddMailboxes(m ...*Mailbox) *DomainUpdateOne { + ids := make([]int64, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return duo.AddMailboxIDs(ids...) +} + +// AddAliasIDs adds the "aliases" edge to the Alias entity by IDs. +func (duo *DomainUpdateOne) AddAliasIDs(ids ...int64) *DomainUpdateOne { + duo.mutation.AddAliasIDs(ids...) + return duo +} + +// AddAliases adds the "aliases" edges to the Alias entity. +func (duo *DomainUpdateOne) AddAliases(a ...*Alias) *DomainUpdateOne { + ids := make([]int64, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return duo.AddAliasIDs(ids...) +} + +// AddLogIDs adds the "logs" edge to the Logentry entity by IDs. +func (duo *DomainUpdateOne) AddLogIDs(ids ...int64) *DomainUpdateOne { + duo.mutation.AddLogIDs(ids...) + return duo +} + +// AddLogs adds the "logs" edges to the Logentry entity. +func (duo *DomainUpdateOne) AddLogs(l ...*Logentry) *DomainUpdateOne { + ids := make([]int64, len(l)) + for i := range l { + ids[i] = l[i].ID + } + return duo.AddLogIDs(ids...) +} + +// AddAccountIDs adds the "accounts" edge to the Account entity by IDs. +func (duo *DomainUpdateOne) AddAccountIDs(ids ...int64) *DomainUpdateOne { + duo.mutation.AddAccountIDs(ids...) + return duo +} + +// AddAccounts adds the "accounts" edges to the Account entity. +func (duo *DomainUpdateOne) AddAccounts(a ...*Account) *DomainUpdateOne { + ids := make([]int64, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return duo.AddAccountIDs(ids...) +} + +// Mutation returns the DomainMutation object of the builder. +func (duo *DomainUpdateOne) Mutation() *DomainMutation { + return duo.mutation +} + +// ClearMailboxes clears all "mailboxes" edges to the Mailbox entity. +func (duo *DomainUpdateOne) ClearMailboxes() *DomainUpdateOne { + duo.mutation.ClearMailboxes() + return duo +} + +// RemoveMailboxIDs removes the "mailboxes" edge to Mailbox entities by IDs. +func (duo *DomainUpdateOne) RemoveMailboxIDs(ids ...int64) *DomainUpdateOne { + duo.mutation.RemoveMailboxIDs(ids...) + return duo +} + +// RemoveMailboxes removes "mailboxes" edges to Mailbox entities. +func (duo *DomainUpdateOne) RemoveMailboxes(m ...*Mailbox) *DomainUpdateOne { + ids := make([]int64, len(m)) + for i := range m { + ids[i] = m[i].ID + } + return duo.RemoveMailboxIDs(ids...) +} + +// ClearAliases clears all "aliases" edges to the Alias entity. +func (duo *DomainUpdateOne) ClearAliases() *DomainUpdateOne { + duo.mutation.ClearAliases() + return duo +} + +// RemoveAliasIDs removes the "aliases" edge to Alias entities by IDs. +func (duo *DomainUpdateOne) RemoveAliasIDs(ids ...int64) *DomainUpdateOne { + duo.mutation.RemoveAliasIDs(ids...) + return duo +} + +// RemoveAliases removes "aliases" edges to Alias entities. +func (duo *DomainUpdateOne) RemoveAliases(a ...*Alias) *DomainUpdateOne { + ids := make([]int64, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return duo.RemoveAliasIDs(ids...) +} + +// ClearLogs clears all "logs" edges to the Logentry entity. +func (duo *DomainUpdateOne) ClearLogs() *DomainUpdateOne { + duo.mutation.ClearLogs() + return duo +} + +// RemoveLogIDs removes the "logs" edge to Logentry entities by IDs. +func (duo *DomainUpdateOne) RemoveLogIDs(ids ...int64) *DomainUpdateOne { + duo.mutation.RemoveLogIDs(ids...) + return duo +} + +// RemoveLogs removes "logs" edges to Logentry entities. +func (duo *DomainUpdateOne) RemoveLogs(l ...*Logentry) *DomainUpdateOne { + ids := make([]int64, len(l)) + for i := range l { + ids[i] = l[i].ID + } + return duo.RemoveLogIDs(ids...) +} + +// ClearAccounts clears all "accounts" edges to the Account entity. +func (duo *DomainUpdateOne) ClearAccounts() *DomainUpdateOne { + duo.mutation.ClearAccounts() + return duo +} + +// RemoveAccountIDs removes the "accounts" edge to Account entities by IDs. +func (duo *DomainUpdateOne) RemoveAccountIDs(ids ...int64) *DomainUpdateOne { + duo.mutation.RemoveAccountIDs(ids...) + return duo +} + +// RemoveAccounts removes "accounts" edges to Account entities. +func (duo *DomainUpdateOne) RemoveAccounts(a ...*Account) *DomainUpdateOne { + ids := make([]int64, len(a)) + for i := range a { + ids[i] = a[i].ID + } + return duo.RemoveAccountIDs(ids...) +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (duo *DomainUpdateOne) Select(field string, fields ...string) *DomainUpdateOne { + duo.fields = append([]string{field}, fields...) + return duo +} + +// Save executes the query and returns the updated Domain entity. +func (duo *DomainUpdateOne) Save(ctx context.Context) (*Domain, error) { + var ( + err error + node *Domain + ) + duo.defaults() + if len(duo.hooks) == 0 { + node, err = duo.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*DomainMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + duo.mutation = mutation + node, err = duo.sqlSave(ctx) + mutation.done = true + return node, err + }) + for i := len(duo.hooks) - 1; i >= 0; i-- { + if duo.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = duo.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, duo.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX is like Save, but panics if an error occurs. +func (duo *DomainUpdateOne) SaveX(ctx context.Context) *Domain { + node, err := duo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (duo *DomainUpdateOne) Exec(ctx context.Context) error { + _, err := duo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (duo *DomainUpdateOne) ExecX(ctx context.Context) { + if err := duo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (duo *DomainUpdateOne) defaults() { + if _, ok := duo.mutation.Modified(); !ok && !duo.mutation.ModifiedCleared() { + v := domain.UpdateDefaultModified() + duo.mutation.SetModified(v) + } +} + +func (duo *DomainUpdateOne) sqlSave(ctx context.Context) (_node *Domain, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: domain.Table, + Columns: domain.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + id, ok := duo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Domain.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := duo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, domain.FieldID) + for _, f := range fields { + if !domain.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != domain.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := duo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := duo.mutation.Modified(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: domain.FieldModified, + }) + } + if duo.mutation.ModifiedCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: domain.FieldModified, + }) + } + if value, ok := duo.mutation.Domain(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: domain.FieldDomain, + }) + } + if value, ok := duo.mutation.Description(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: domain.FieldDescription, + }) + } + if duo.mutation.DescriptionCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: domain.FieldDescription, + }) + } + if value, ok := duo.mutation.MaxAliases(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxAliases, + }) + } + if value, ok := duo.mutation.AddedMaxAliases(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxAliases, + }) + } + if value, ok := duo.mutation.MaxMailboxes(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxMailboxes, + }) + } + if value, ok := duo.mutation.AddedMaxMailboxes(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxMailboxes, + }) + } + if value, ok := duo.mutation.MaxQuota(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxQuota, + }) + } + if value, ok := duo.mutation.AddedMaxQuota(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldMaxQuota, + }) + } + if value, ok := duo.mutation.Quota(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldQuota, + }) + } + if value, ok := duo.mutation.AddedQuota(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: domain.FieldQuota, + }) + } + if value, ok := duo.mutation.Transport(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: domain.FieldTransport, + }) + } + if value, ok := duo.mutation.BackupMx(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: domain.FieldBackupMx, + }) + } + if value, ok := duo.mutation.Active(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: domain.FieldActive, + }) + } + if duo.mutation.MailboxesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.MailboxesTable, + Columns: []string{domain.MailboxesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := duo.mutation.RemovedMailboxesIDs(); len(nodes) > 0 && !duo.mutation.MailboxesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.MailboxesTable, + Columns: []string{domain.MailboxesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := duo.mutation.MailboxesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.MailboxesTable, + Columns: []string{domain.MailboxesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if duo.mutation.AliasesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.AliasesTable, + Columns: []string{domain.AliasesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := duo.mutation.RemovedAliasesIDs(); len(nodes) > 0 && !duo.mutation.AliasesCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.AliasesTable, + Columns: []string{domain.AliasesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := duo.mutation.AliasesIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.AliasesTable, + Columns: []string{domain.AliasesColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: alias.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if duo.mutation.LogsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.LogsTable, + Columns: []string{domain.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := duo.mutation.RemovedLogsIDs(); len(nodes) > 0 && !duo.mutation.LogsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.LogsTable, + Columns: []string{domain.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := duo.mutation.LogsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.O2M, + Inverse: false, + Table: domain.LogsTable, + Columns: []string{domain.LogsColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if duo.mutation.AccountsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: domain.AccountsTable, + Columns: domain.AccountsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := duo.mutation.RemovedAccountsIDs(); len(nodes) > 0 && !duo.mutation.AccountsCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: domain.AccountsTable, + Columns: domain.AccountsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := duo.mutation.AccountsIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2M, + Inverse: true, + Table: domain.AccountsTable, + Columns: domain.AccountsPrimaryKey, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Domain{config: duo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, duo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{domain.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + return _node, nil +} diff --git a/ent/ent.go b/ent/ent.go new file mode 100644 index 0000000..453b3b2 --- /dev/null +++ b/ent/ent.go @@ -0,0 +1,267 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "errors" + "fmt" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/alias" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "code.icod.de/postfix/manager/ent/mailbox" + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// ent aliases to avoid import conflicts in user's code. +type ( + Op = ent.Op + Hook = ent.Hook + Value = ent.Value + Query = ent.Query + Policy = ent.Policy + Mutator = ent.Mutator + Mutation = ent.Mutation + MutateFunc = ent.MutateFunc +) + +// OrderFunc applies an ordering on the sql selector. +type OrderFunc func(*sql.Selector) + +// columnChecker returns a function indicates if the column exists in the given column. +func columnChecker(table string) func(string) error { + checks := map[string]func(string) bool{ + account.Table: account.ValidColumn, + alias.Table: alias.ValidColumn, + domain.Table: domain.ValidColumn, + logentry.Table: logentry.ValidColumn, + mailbox.Table: mailbox.ValidColumn, + } + check, ok := checks[table] + if !ok { + return func(string) error { + return fmt.Errorf("unknown table %q", table) + } + } + return func(column string) error { + if !check(column) { + return fmt.Errorf("unknown column %q for table %q", column, table) + } + return nil + } +} + +// Asc applies the given fields in ASC order. +func Asc(fields ...string) OrderFunc { + return func(s *sql.Selector) { + check := columnChecker(s.TableName()) + for _, f := range fields { + if err := check(f); err != nil { + s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) + } + s.OrderBy(sql.Asc(s.C(f))) + } + } +} + +// Desc applies the given fields in DESC order. +func Desc(fields ...string) OrderFunc { + return func(s *sql.Selector) { + check := columnChecker(s.TableName()) + for _, f := range fields { + if err := check(f); err != nil { + s.AddError(&ValidationError{Name: f, err: fmt.Errorf("ent: %w", err)}) + } + s.OrderBy(sql.Desc(s.C(f))) + } + } +} + +// AggregateFunc applies an aggregation step on the group-by traversal/selector. +type AggregateFunc func(*sql.Selector) string + +// As is a pseudo aggregation function for renaming another other functions with custom names. For example: +// +// GroupBy(field1, field2). +// Aggregate(ent.As(ent.Sum(field1), "sum_field1"), (ent.As(ent.Sum(field2), "sum_field2")). +// Scan(ctx, &v) +// +func As(fn AggregateFunc, end string) AggregateFunc { + return func(s *sql.Selector) string { + return sql.As(fn(s), end) + } +} + +// Count applies the "count" aggregation function on each group. +func Count() AggregateFunc { + return func(s *sql.Selector) string { + return sql.Count("*") + } +} + +// Max applies the "max" aggregation function on the given field of each group. +func Max(field string) AggregateFunc { + return func(s *sql.Selector) string { + check := columnChecker(s.TableName()) + if err := check(field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Max(s.C(field)) + } +} + +// Mean applies the "mean" aggregation function on the given field of each group. +func Mean(field string) AggregateFunc { + return func(s *sql.Selector) string { + check := columnChecker(s.TableName()) + if err := check(field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Avg(s.C(field)) + } +} + +// Min applies the "min" aggregation function on the given field of each group. +func Min(field string) AggregateFunc { + return func(s *sql.Selector) string { + check := columnChecker(s.TableName()) + if err := check(field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Min(s.C(field)) + } +} + +// Sum applies the "sum" aggregation function on the given field of each group. +func Sum(field string) AggregateFunc { + return func(s *sql.Selector) string { + check := columnChecker(s.TableName()) + if err := check(field); err != nil { + s.AddError(&ValidationError{Name: field, err: fmt.Errorf("ent: %w", err)}) + return "" + } + return sql.Sum(s.C(field)) + } +} + +// ValidationError returns when validating a field or edge fails. +type ValidationError struct { + Name string // Field or edge name. + err error +} + +// Error implements the error interface. +func (e *ValidationError) Error() string { + return e.err.Error() +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ValidationError) Unwrap() error { + return e.err +} + +// IsValidationError returns a boolean indicating whether the error is a validation error. +func IsValidationError(err error) bool { + if err == nil { + return false + } + var e *ValidationError + return errors.As(err, &e) +} + +// NotFoundError returns when trying to fetch a specific entity and it was not found in the database. +type NotFoundError struct { + label string +} + +// Error implements the error interface. +func (e *NotFoundError) Error() string { + return "ent: " + e.label + " not found" +} + +// IsNotFound returns a boolean indicating whether the error is a not found error. +func IsNotFound(err error) bool { + if err == nil { + return false + } + var e *NotFoundError + return errors.As(err, &e) +} + +// MaskNotFound masks not found error. +func MaskNotFound(err error) error { + if IsNotFound(err) { + return nil + } + return err +} + +// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database. +type NotSingularError struct { + label string +} + +// Error implements the error interface. +func (e *NotSingularError) Error() string { + return "ent: " + e.label + " not singular" +} + +// IsNotSingular returns a boolean indicating whether the error is a not singular error. +func IsNotSingular(err error) bool { + if err == nil { + return false + } + var e *NotSingularError + return errors.As(err, &e) +} + +// NotLoadedError returns when trying to get a node that was not loaded by the query. +type NotLoadedError struct { + edge string +} + +// Error implements the error interface. +func (e *NotLoadedError) Error() string { + return "ent: " + e.edge + " edge was not loaded" +} + +// IsNotLoaded returns a boolean indicating whether the error is a not loaded error. +func IsNotLoaded(err error) bool { + if err == nil { + return false + } + var e *NotLoadedError + return errors.As(err, &e) +} + +// ConstraintError returns when trying to create/update one or more entities and +// one or more of their constraints failed. For example, violation of edge or +// field uniqueness. +type ConstraintError struct { + msg string + wrap error +} + +// Error implements the error interface. +func (e ConstraintError) Error() string { + return "ent: constraint failed: " + e.msg +} + +// Unwrap implements the errors.Wrapper interface. +func (e *ConstraintError) Unwrap() error { + return e.wrap +} + +// IsConstraintError returns a boolean indicating whether the error is a constraint failure. +func IsConstraintError(err error) bool { + if err == nil { + return false + } + var e *ConstraintError + return errors.As(err, &e) +} diff --git a/ent/enttest/enttest.go b/ent/enttest/enttest.go new file mode 100644 index 0000000..15e5511 --- /dev/null +++ b/ent/enttest/enttest.go @@ -0,0 +1,78 @@ +// Code generated by entc, DO NOT EDIT. + +package enttest + +import ( + "context" + + "code.icod.de/postfix/manager/ent" + // required by schema hooks. + _ "code.icod.de/postfix/manager/ent/runtime" + + "entgo.io/ent/dialect/sql/schema" +) + +type ( + // TestingT is the interface that is shared between + // testing.T and testing.B and used by enttest. + TestingT interface { + FailNow() + Error(...interface{}) + } + + // Option configures client creation. + Option func(*options) + + options struct { + opts []ent.Option + migrateOpts []schema.MigrateOption + } +) + +// WithOptions forwards options to client creation. +func WithOptions(opts ...ent.Option) Option { + return func(o *options) { + o.opts = append(o.opts, opts...) + } +} + +// WithMigrateOptions forwards options to auto migration. +func WithMigrateOptions(opts ...schema.MigrateOption) Option { + return func(o *options) { + o.migrateOpts = append(o.migrateOpts, opts...) + } +} + +func newOptions(opts []Option) *options { + o := &options{} + for _, opt := range opts { + opt(o) + } + return o +} + +// Open calls ent.Open and auto-run migration. +func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *ent.Client { + o := newOptions(opts) + c, err := ent.Open(driverName, dataSourceName, o.opts...) + if err != nil { + t.Error(err) + t.FailNow() + } + if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { + t.Error(err) + t.FailNow() + } + return c +} + +// NewClient calls ent.NewClient and auto-run migration. +func NewClient(t TestingT, opts ...Option) *ent.Client { + o := newOptions(opts) + c := ent.NewClient(o.opts...) + if err := c.Schema.Create(context.Background(), o.migrateOpts...); err != nil { + t.Error(err) + t.FailNow() + } + return c +} diff --git a/ent/hook/hook.go b/ent/hook/hook.go new file mode 100644 index 0000000..085a05b --- /dev/null +++ b/ent/hook/hook.go @@ -0,0 +1,256 @@ +// Code generated by entc, DO NOT EDIT. + +package hook + +import ( + "context" + "fmt" + + "code.icod.de/postfix/manager/ent" +) + +// The AccountFunc type is an adapter to allow the use of ordinary +// function as Account mutator. +type AccountFunc func(context.Context, *ent.AccountMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f AccountFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + mv, ok := m.(*ent.AccountMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AccountMutation", m) + } + return f(ctx, mv) +} + +// The AliasFunc type is an adapter to allow the use of ordinary +// function as Alias mutator. +type AliasFunc func(context.Context, *ent.AliasMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f AliasFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + mv, ok := m.(*ent.AliasMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AliasMutation", m) + } + return f(ctx, mv) +} + +// The DomainFunc type is an adapter to allow the use of ordinary +// function as Domain mutator. +type DomainFunc func(context.Context, *ent.DomainMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f DomainFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + mv, ok := m.(*ent.DomainMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.DomainMutation", m) + } + return f(ctx, mv) +} + +// The LogentryFunc type is an adapter to allow the use of ordinary +// function as Logentry mutator. +type LogentryFunc func(context.Context, *ent.LogentryMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f LogentryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + mv, ok := m.(*ent.LogentryMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.LogentryMutation", m) + } + return f(ctx, mv) +} + +// The MailboxFunc type is an adapter to allow the use of ordinary +// function as Mailbox mutator. +type MailboxFunc func(context.Context, *ent.MailboxMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f MailboxFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + mv, ok := m.(*ent.MailboxMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MailboxMutation", m) + } + return f(ctx, mv) +} + +// Condition is a hook condition function. +type Condition func(context.Context, ent.Mutation) bool + +// And groups conditions with the AND operator. +func And(first, second Condition, rest ...Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + if !first(ctx, m) || !second(ctx, m) { + return false + } + for _, cond := range rest { + if !cond(ctx, m) { + return false + } + } + return true + } +} + +// Or groups conditions with the OR operator. +func Or(first, second Condition, rest ...Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + if first(ctx, m) || second(ctx, m) { + return true + } + for _, cond := range rest { + if cond(ctx, m) { + return true + } + } + return false + } +} + +// Not negates a given condition. +func Not(cond Condition) Condition { + return func(ctx context.Context, m ent.Mutation) bool { + return !cond(ctx, m) + } +} + +// HasOp is a condition testing mutation operation. +func HasOp(op ent.Op) Condition { + return func(_ context.Context, m ent.Mutation) bool { + return m.Op().Is(op) + } +} + +// HasAddedFields is a condition validating `.AddedField` on fields. +func HasAddedFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if _, exists := m.AddedField(field); !exists { + return false + } + for _, field := range fields { + if _, exists := m.AddedField(field); !exists { + return false + } + } + return true + } +} + +// HasClearedFields is a condition validating `.FieldCleared` on fields. +func HasClearedFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if exists := m.FieldCleared(field); !exists { + return false + } + for _, field := range fields { + if exists := m.FieldCleared(field); !exists { + return false + } + } + return true + } +} + +// HasFields is a condition validating `.Field` on fields. +func HasFields(field string, fields ...string) Condition { + return func(_ context.Context, m ent.Mutation) bool { + if _, exists := m.Field(field); !exists { + return false + } + for _, field := range fields { + if _, exists := m.Field(field); !exists { + return false + } + } + return true + } +} + +// If executes the given hook under condition. +// +// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...))) +// +func If(hk ent.Hook, cond Condition) ent.Hook { + return func(next ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if cond(ctx, m) { + return hk(next).Mutate(ctx, m) + } + return next.Mutate(ctx, m) + }) + } +} + +// On executes the given hook only for the given operation. +// +// hook.On(Log, ent.Delete|ent.Create) +// +func On(hk ent.Hook, op ent.Op) ent.Hook { + return If(hk, HasOp(op)) +} + +// Unless skips the given hook only for the given operation. +// +// hook.Unless(Log, ent.Update|ent.UpdateOne) +// +func Unless(hk ent.Hook, op ent.Op) ent.Hook { + return If(hk, Not(HasOp(op))) +} + +// FixedError is a hook returning a fixed error. +func FixedError(err error) ent.Hook { + return func(ent.Mutator) ent.Mutator { + return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) { + return nil, err + }) + } +} + +// Reject returns a hook that rejects all operations that match op. +// +// func (T) Hooks() []ent.Hook { +// return []ent.Hook{ +// Reject(ent.Delete|ent.Update), +// } +// } +// +func Reject(op ent.Op) ent.Hook { + hk := FixedError(fmt.Errorf("%s operation is not allowed", op)) + return On(hk, op) +} + +// Chain acts as a list of hooks and is effectively immutable. +// Once created, it will always hold the same set of hooks in the same order. +type Chain struct { + hooks []ent.Hook +} + +// NewChain creates a new chain of hooks. +func NewChain(hooks ...ent.Hook) Chain { + return Chain{append([]ent.Hook(nil), hooks...)} +} + +// Hook chains the list of hooks and returns the final hook. +func (c Chain) Hook() ent.Hook { + return func(mutator ent.Mutator) ent.Mutator { + for i := len(c.hooks) - 1; i >= 0; i-- { + mutator = c.hooks[i](mutator) + } + return mutator + } +} + +// Append extends a chain, adding the specified hook +// as the last ones in the mutation flow. +func (c Chain) Append(hooks ...ent.Hook) Chain { + newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks)) + newHooks = append(newHooks, c.hooks...) + newHooks = append(newHooks, hooks...) + return Chain{newHooks} +} + +// Extend extends a chain, adding the specified chain +// as the last ones in the mutation flow. +func (c Chain) Extend(chain Chain) Chain { + return c.Append(chain.hooks...) +} diff --git a/ent/logentry.go b/ent/logentry.go new file mode 100644 index 0000000..00fb84d --- /dev/null +++ b/ent/logentry.go @@ -0,0 +1,199 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "entgo.io/ent/dialect/sql" +) + +// Logentry is the model entity for the Logentry schema. +type Logentry struct { + config `json:"-"` + // ID of the ent. + ID int64 `json:"id,omitempty"` + // Timestamp holds the value of the "timestamp" field. + Timestamp time.Time `json:"timestamp,omitempty"` + // Action holds the value of the "action" field. + Action string `json:"action,omitempty"` + // Data holds the value of the "data" field. + Data *string `json:"data,omitempty"` + // AccountID holds the value of the "account_id" field. + AccountID int64 `json:"account_id,omitempty"` + // DomainID holds the value of the "domain_id" field. + DomainID int64 `json:"domain_id,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the LogentryQuery when eager-loading is set. + Edges LogentryEdges `json:"edges"` +} + +// LogentryEdges holds the relations/edges for other nodes in the graph. +type LogentryEdges struct { + // Account holds the value of the account edge. + Account *Account `json:"account,omitempty"` + // Domain holds the value of the domain edge. + Domain *Domain `json:"domain,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [2]bool +} + +// AccountOrErr returns the Account value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e LogentryEdges) AccountOrErr() (*Account, error) { + if e.loadedTypes[0] { + if e.Account == nil { + // The edge account was loaded in eager-loading, + // but was not found. + return nil, &NotFoundError{label: account.Label} + } + return e.Account, nil + } + return nil, &NotLoadedError{edge: "account"} +} + +// DomainOrErr returns the Domain value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e LogentryEdges) DomainOrErr() (*Domain, error) { + if e.loadedTypes[1] { + if e.Domain == nil { + // The edge domain was loaded in eager-loading, + // but was not found. + return nil, &NotFoundError{label: domain.Label} + } + return e.Domain, nil + } + return nil, &NotLoadedError{edge: "domain"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Logentry) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case logentry.FieldID, logentry.FieldAccountID, logentry.FieldDomainID: + values[i] = new(sql.NullInt64) + case logentry.FieldAction, logentry.FieldData: + values[i] = new(sql.NullString) + case logentry.FieldTimestamp: + values[i] = new(sql.NullTime) + default: + return nil, fmt.Errorf("unexpected column %q for type Logentry", columns[i]) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Logentry fields. +func (l *Logentry) assignValues(columns []string, values []interface{}) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case logentry.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + l.ID = int64(value.Int64) + case logentry.FieldTimestamp: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field timestamp", values[i]) + } else if value.Valid { + l.Timestamp = value.Time + } + case logentry.FieldAction: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field action", values[i]) + } else if value.Valid { + l.Action = value.String + } + case logentry.FieldData: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field data", values[i]) + } else if value.Valid { + l.Data = new(string) + *l.Data = value.String + } + case logentry.FieldAccountID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field account_id", values[i]) + } else if value.Valid { + l.AccountID = value.Int64 + } + case logentry.FieldDomainID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field domain_id", values[i]) + } else if value.Valid { + l.DomainID = value.Int64 + } + } + } + return nil +} + +// QueryAccount queries the "account" edge of the Logentry entity. +func (l *Logentry) QueryAccount() *AccountQuery { + return (&LogentryClient{config: l.config}).QueryAccount(l) +} + +// QueryDomain queries the "domain" edge of the Logentry entity. +func (l *Logentry) QueryDomain() *DomainQuery { + return (&LogentryClient{config: l.config}).QueryDomain(l) +} + +// Update returns a builder for updating this Logentry. +// Note that you need to call Logentry.Unwrap() before calling this method if this Logentry +// was returned from a transaction, and the transaction was committed or rolled back. +func (l *Logentry) Update() *LogentryUpdateOne { + return (&LogentryClient{config: l.config}).UpdateOne(l) +} + +// Unwrap unwraps the Logentry entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (l *Logentry) Unwrap() *Logentry { + tx, ok := l.config.driver.(*txDriver) + if !ok { + panic("ent: Logentry is not a transactional entity") + } + l.config.driver = tx.drv + return l +} + +// String implements the fmt.Stringer. +func (l *Logentry) String() string { + var builder strings.Builder + builder.WriteString("Logentry(") + builder.WriteString(fmt.Sprintf("id=%v", l.ID)) + builder.WriteString(", timestamp=") + builder.WriteString(l.Timestamp.Format(time.ANSIC)) + builder.WriteString(", action=") + builder.WriteString(l.Action) + if v := l.Data; v != nil { + builder.WriteString(", data=") + builder.WriteString(*v) + } + builder.WriteString(", account_id=") + builder.WriteString(fmt.Sprintf("%v", l.AccountID)) + builder.WriteString(", domain_id=") + builder.WriteString(fmt.Sprintf("%v", l.DomainID)) + builder.WriteByte(')') + return builder.String() +} + +// Logentries is a parsable slice of Logentry. +type Logentries []*Logentry + +func (l Logentries) config(cfg config) { + for _i := range l { + l[_i].config = cfg + } +} diff --git a/ent/logentry/logentry.go b/ent/logentry/logentry.go new file mode 100644 index 0000000..906904c --- /dev/null +++ b/ent/logentry/logentry.go @@ -0,0 +1,69 @@ +// Code generated by entc, DO NOT EDIT. + +package logentry + +import ( + "time" +) + +const ( + // Label holds the string label denoting the logentry type in the database. + Label = "logentry" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldTimestamp holds the string denoting the timestamp field in the database. + FieldTimestamp = "timestamp" + // FieldAction holds the string denoting the action field in the database. + FieldAction = "action" + // FieldData holds the string denoting the data field in the database. + FieldData = "data" + // FieldAccountID holds the string denoting the account_id field in the database. + FieldAccountID = "account_id" + // FieldDomainID holds the string denoting the domain_id field in the database. + FieldDomainID = "domain_id" + // EdgeAccount holds the string denoting the account edge name in mutations. + EdgeAccount = "account" + // EdgeDomain holds the string denoting the domain edge name in mutations. + EdgeDomain = "domain" + // Table holds the table name of the logentry in the database. + Table = "logentries" + // AccountTable is the table that holds the account relation/edge. + AccountTable = "logentries" + // AccountInverseTable is the table name for the Account entity. + // It exists in this package in order to avoid circular dependency with the "account" package. + AccountInverseTable = "accounts" + // AccountColumn is the table column denoting the account relation/edge. + AccountColumn = "account_id" + // DomainTable is the table that holds the domain relation/edge. + DomainTable = "logentries" + // DomainInverseTable is the table name for the Domain entity. + // It exists in this package in order to avoid circular dependency with the "domain" package. + DomainInverseTable = "domains" + // DomainColumn is the table column denoting the domain relation/edge. + DomainColumn = "domain_id" +) + +// Columns holds all SQL columns for logentry fields. +var Columns = []string{ + FieldID, + FieldTimestamp, + FieldAction, + FieldData, + FieldAccountID, + FieldDomainID, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultTimestamp holds the default value on creation for the "timestamp" field. + DefaultTimestamp func() time.Time +) diff --git a/ent/logentry/where.go b/ent/logentry/where.go new file mode 100644 index 0000000..7075267 --- /dev/null +++ b/ent/logentry/where.go @@ -0,0 +1,653 @@ +// Code generated by entc, DO NOT EDIT. + +package logentry + +import ( + "time" + + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// ID filters vertices based on their ID field. +func ID(id int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldID), id)) + }) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.In(s.C(FieldID), v...)) + }) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.NotIn(s.C(FieldID), v...)) + }) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldID), id)) + }) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldID), id)) + }) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldID), id)) + }) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldID), id)) + }) +} + +// Timestamp applies equality check predicate on the "timestamp" field. It's identical to TimestampEQ. +func Timestamp(v time.Time) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldTimestamp), v)) + }) +} + +// Action applies equality check predicate on the "action" field. It's identical to ActionEQ. +func Action(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldAction), v)) + }) +} + +// Data applies equality check predicate on the "data" field. It's identical to DataEQ. +func Data(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldData), v)) + }) +} + +// AccountID applies equality check predicate on the "account_id" field. It's identical to AccountIDEQ. +func AccountID(v int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldAccountID), v)) + }) +} + +// DomainID applies equality check predicate on the "domain_id" field. It's identical to DomainIDEQ. +func DomainID(v int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDomainID), v)) + }) +} + +// TimestampEQ applies the EQ predicate on the "timestamp" field. +func TimestampEQ(v time.Time) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldTimestamp), v)) + }) +} + +// TimestampNEQ applies the NEQ predicate on the "timestamp" field. +func TimestampNEQ(v time.Time) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldTimestamp), v)) + }) +} + +// TimestampIn applies the In predicate on the "timestamp" field. +func TimestampIn(vs ...time.Time) predicate.Logentry { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldTimestamp), v...)) + }) +} + +// TimestampNotIn applies the NotIn predicate on the "timestamp" field. +func TimestampNotIn(vs ...time.Time) predicate.Logentry { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldTimestamp), v...)) + }) +} + +// TimestampGT applies the GT predicate on the "timestamp" field. +func TimestampGT(v time.Time) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldTimestamp), v)) + }) +} + +// TimestampGTE applies the GTE predicate on the "timestamp" field. +func TimestampGTE(v time.Time) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldTimestamp), v)) + }) +} + +// TimestampLT applies the LT predicate on the "timestamp" field. +func TimestampLT(v time.Time) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldTimestamp), v)) + }) +} + +// TimestampLTE applies the LTE predicate on the "timestamp" field. +func TimestampLTE(v time.Time) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldTimestamp), v)) + }) +} + +// ActionEQ applies the EQ predicate on the "action" field. +func ActionEQ(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldAction), v)) + }) +} + +// ActionNEQ applies the NEQ predicate on the "action" field. +func ActionNEQ(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldAction), v)) + }) +} + +// ActionIn applies the In predicate on the "action" field. +func ActionIn(vs ...string) predicate.Logentry { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldAction), v...)) + }) +} + +// ActionNotIn applies the NotIn predicate on the "action" field. +func ActionNotIn(vs ...string) predicate.Logentry { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldAction), v...)) + }) +} + +// ActionGT applies the GT predicate on the "action" field. +func ActionGT(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldAction), v)) + }) +} + +// ActionGTE applies the GTE predicate on the "action" field. +func ActionGTE(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldAction), v)) + }) +} + +// ActionLT applies the LT predicate on the "action" field. +func ActionLT(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldAction), v)) + }) +} + +// ActionLTE applies the LTE predicate on the "action" field. +func ActionLTE(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldAction), v)) + }) +} + +// ActionContains applies the Contains predicate on the "action" field. +func ActionContains(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldAction), v)) + }) +} + +// ActionHasPrefix applies the HasPrefix predicate on the "action" field. +func ActionHasPrefix(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldAction), v)) + }) +} + +// ActionHasSuffix applies the HasSuffix predicate on the "action" field. +func ActionHasSuffix(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldAction), v)) + }) +} + +// ActionEqualFold applies the EqualFold predicate on the "action" field. +func ActionEqualFold(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldAction), v)) + }) +} + +// ActionContainsFold applies the ContainsFold predicate on the "action" field. +func ActionContainsFold(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldAction), v)) + }) +} + +// DataEQ applies the EQ predicate on the "data" field. +func DataEQ(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldData), v)) + }) +} + +// DataNEQ applies the NEQ predicate on the "data" field. +func DataNEQ(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldData), v)) + }) +} + +// DataIn applies the In predicate on the "data" field. +func DataIn(vs ...string) predicate.Logentry { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldData), v...)) + }) +} + +// DataNotIn applies the NotIn predicate on the "data" field. +func DataNotIn(vs ...string) predicate.Logentry { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldData), v...)) + }) +} + +// DataGT applies the GT predicate on the "data" field. +func DataGT(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldData), v)) + }) +} + +// DataGTE applies the GTE predicate on the "data" field. +func DataGTE(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldData), v)) + }) +} + +// DataLT applies the LT predicate on the "data" field. +func DataLT(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldData), v)) + }) +} + +// DataLTE applies the LTE predicate on the "data" field. +func DataLTE(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldData), v)) + }) +} + +// DataContains applies the Contains predicate on the "data" field. +func DataContains(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldData), v)) + }) +} + +// DataHasPrefix applies the HasPrefix predicate on the "data" field. +func DataHasPrefix(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldData), v)) + }) +} + +// DataHasSuffix applies the HasSuffix predicate on the "data" field. +func DataHasSuffix(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldData), v)) + }) +} + +// DataIsNil applies the IsNil predicate on the "data" field. +func DataIsNil() predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldData))) + }) +} + +// DataNotNil applies the NotNil predicate on the "data" field. +func DataNotNil() predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldData))) + }) +} + +// DataEqualFold applies the EqualFold predicate on the "data" field. +func DataEqualFold(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldData), v)) + }) +} + +// DataContainsFold applies the ContainsFold predicate on the "data" field. +func DataContainsFold(v string) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldData), v)) + }) +} + +// AccountIDEQ applies the EQ predicate on the "account_id" field. +func AccountIDEQ(v int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldAccountID), v)) + }) +} + +// AccountIDNEQ applies the NEQ predicate on the "account_id" field. +func AccountIDNEQ(v int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldAccountID), v)) + }) +} + +// AccountIDIn applies the In predicate on the "account_id" field. +func AccountIDIn(vs ...int64) predicate.Logentry { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldAccountID), v...)) + }) +} + +// AccountIDNotIn applies the NotIn predicate on the "account_id" field. +func AccountIDNotIn(vs ...int64) predicate.Logentry { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldAccountID), v...)) + }) +} + +// AccountIDIsNil applies the IsNil predicate on the "account_id" field. +func AccountIDIsNil() predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldAccountID))) + }) +} + +// AccountIDNotNil applies the NotNil predicate on the "account_id" field. +func AccountIDNotNil() predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldAccountID))) + }) +} + +// DomainIDEQ applies the EQ predicate on the "domain_id" field. +func DomainIDEQ(v int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDomainID), v)) + }) +} + +// DomainIDNEQ applies the NEQ predicate on the "domain_id" field. +func DomainIDNEQ(v int64) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldDomainID), v)) + }) +} + +// DomainIDIn applies the In predicate on the "domain_id" field. +func DomainIDIn(vs ...int64) predicate.Logentry { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldDomainID), v...)) + }) +} + +// DomainIDNotIn applies the NotIn predicate on the "domain_id" field. +func DomainIDNotIn(vs ...int64) predicate.Logentry { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Logentry(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldDomainID), v...)) + }) +} + +// DomainIDIsNil applies the IsNil predicate on the "domain_id" field. +func DomainIDIsNil() predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldDomainID))) + }) +} + +// DomainIDNotNil applies the NotNil predicate on the "domain_id" field. +func DomainIDNotNil() predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldDomainID))) + }) +} + +// HasAccount applies the HasEdge predicate on the "account" edge. +func HasAccount() predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AccountTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, AccountTable, AccountColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasAccountWith applies the HasEdge predicate on the "account" edge with a given conditions (other predicates). +func HasAccountWith(preds ...predicate.Account) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(AccountInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, AccountTable, AccountColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// HasDomain applies the HasEdge predicate on the "domain" edge. +func HasDomain() predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(DomainTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, DomainTable, DomainColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasDomainWith applies the HasEdge predicate on the "domain" edge with a given conditions (other predicates). +func HasDomainWith(preds ...predicate.Domain) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(DomainInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, DomainTable, DomainColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Logentry) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for _, p := range predicates { + p(s1) + } + s.Where(s1.P()) + }) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Logentry) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for i, p := range predicates { + if i > 0 { + s1.Or() + } + p(s1) + } + s.Where(s1.P()) + }) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Logentry) predicate.Logentry { + return predicate.Logentry(func(s *sql.Selector) { + p(s.Not()) + }) +} diff --git a/ent/logentry_create.go b/ent/logentry_create.go new file mode 100644 index 0000000..5844ad7 --- /dev/null +++ b/ent/logentry_create.go @@ -0,0 +1,370 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// LogentryCreate is the builder for creating a Logentry entity. +type LogentryCreate struct { + config + mutation *LogentryMutation + hooks []Hook +} + +// SetTimestamp sets the "timestamp" field. +func (lc *LogentryCreate) SetTimestamp(t time.Time) *LogentryCreate { + lc.mutation.SetTimestamp(t) + return lc +} + +// SetNillableTimestamp sets the "timestamp" field if the given value is not nil. +func (lc *LogentryCreate) SetNillableTimestamp(t *time.Time) *LogentryCreate { + if t != nil { + lc.SetTimestamp(*t) + } + return lc +} + +// SetAction sets the "action" field. +func (lc *LogentryCreate) SetAction(s string) *LogentryCreate { + lc.mutation.SetAction(s) + return lc +} + +// SetData sets the "data" field. +func (lc *LogentryCreate) SetData(s string) *LogentryCreate { + lc.mutation.SetData(s) + return lc +} + +// SetNillableData sets the "data" field if the given value is not nil. +func (lc *LogentryCreate) SetNillableData(s *string) *LogentryCreate { + if s != nil { + lc.SetData(*s) + } + return lc +} + +// SetAccountID sets the "account_id" field. +func (lc *LogentryCreate) SetAccountID(i int64) *LogentryCreate { + lc.mutation.SetAccountID(i) + return lc +} + +// SetNillableAccountID sets the "account_id" field if the given value is not nil. +func (lc *LogentryCreate) SetNillableAccountID(i *int64) *LogentryCreate { + if i != nil { + lc.SetAccountID(*i) + } + return lc +} + +// SetDomainID sets the "domain_id" field. +func (lc *LogentryCreate) SetDomainID(i int64) *LogentryCreate { + lc.mutation.SetDomainID(i) + return lc +} + +// SetNillableDomainID sets the "domain_id" field if the given value is not nil. +func (lc *LogentryCreate) SetNillableDomainID(i *int64) *LogentryCreate { + if i != nil { + lc.SetDomainID(*i) + } + return lc +} + +// SetID sets the "id" field. +func (lc *LogentryCreate) SetID(i int64) *LogentryCreate { + lc.mutation.SetID(i) + return lc +} + +// SetAccount sets the "account" edge to the Account entity. +func (lc *LogentryCreate) SetAccount(a *Account) *LogentryCreate { + return lc.SetAccountID(a.ID) +} + +// SetDomain sets the "domain" edge to the Domain entity. +func (lc *LogentryCreate) SetDomain(d *Domain) *LogentryCreate { + return lc.SetDomainID(d.ID) +} + +// Mutation returns the LogentryMutation object of the builder. +func (lc *LogentryCreate) Mutation() *LogentryMutation { + return lc.mutation +} + +// Save creates the Logentry in the database. +func (lc *LogentryCreate) Save(ctx context.Context) (*Logentry, error) { + var ( + err error + node *Logentry + ) + lc.defaults() + if len(lc.hooks) == 0 { + if err = lc.check(); err != nil { + return nil, err + } + node, err = lc.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*LogentryMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err = lc.check(); err != nil { + return nil, err + } + lc.mutation = mutation + if node, err = lc.sqlSave(ctx); err != nil { + return nil, err + } + mutation.id = &node.ID + mutation.done = true + return node, err + }) + for i := len(lc.hooks) - 1; i >= 0; i-- { + if lc.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = lc.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, lc.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX calls Save and panics if Save returns an error. +func (lc *LogentryCreate) SaveX(ctx context.Context) *Logentry { + v, err := lc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (lc *LogentryCreate) Exec(ctx context.Context) error { + _, err := lc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (lc *LogentryCreate) ExecX(ctx context.Context) { + if err := lc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (lc *LogentryCreate) defaults() { + if _, ok := lc.mutation.Timestamp(); !ok { + v := logentry.DefaultTimestamp() + lc.mutation.SetTimestamp(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (lc *LogentryCreate) check() error { + if _, ok := lc.mutation.Timestamp(); !ok { + return &ValidationError{Name: "timestamp", err: errors.New(`ent: missing required field "Logentry.timestamp"`)} + } + if _, ok := lc.mutation.Action(); !ok { + return &ValidationError{Name: "action", err: errors.New(`ent: missing required field "Logentry.action"`)} + } + return nil +} + +func (lc *LogentryCreate) sqlSave(ctx context.Context) (*Logentry, error) { + _node, _spec := lc.createSpec() + if err := sqlgraph.CreateNode(ctx, lc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = int64(id) + } + return _node, nil +} + +func (lc *LogentryCreate) createSpec() (*Logentry, *sqlgraph.CreateSpec) { + var ( + _node = &Logentry{config: lc.config} + _spec = &sqlgraph.CreateSpec{ + Table: logentry.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + } + ) + if id, ok := lc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := lc.mutation.Timestamp(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: logentry.FieldTimestamp, + }) + _node.Timestamp = value + } + if value, ok := lc.mutation.Action(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: logentry.FieldAction, + }) + _node.Action = value + } + if value, ok := lc.mutation.Data(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: logentry.FieldData, + }) + _node.Data = &value + } + if nodes := lc.mutation.AccountIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: logentry.AccountTable, + Columns: []string{logentry.AccountColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.AccountID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + if nodes := lc.mutation.DomainIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: logentry.DomainTable, + Columns: []string{logentry.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.DomainID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// LogentryCreateBulk is the builder for creating many Logentry entities in bulk. +type LogentryCreateBulk struct { + config + builders []*LogentryCreate +} + +// Save creates the Logentry entities in the database. +func (lcb *LogentryCreateBulk) Save(ctx context.Context) ([]*Logentry, error) { + specs := make([]*sqlgraph.CreateSpec, len(lcb.builders)) + nodes := make([]*Logentry, len(lcb.builders)) + mutators := make([]Mutator, len(lcb.builders)) + for i := range lcb.builders { + func(i int, root context.Context) { + builder := lcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*LogentryMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + nodes[i], specs[i] = builder.createSpec() + var err error + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, lcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, lcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + if specs[i].ID.Value != nil && nodes[i].ID == 0 { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int64(id) + } + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, lcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (lcb *LogentryCreateBulk) SaveX(ctx context.Context) []*Logentry { + v, err := lcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (lcb *LogentryCreateBulk) Exec(ctx context.Context) error { + _, err := lcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (lcb *LogentryCreateBulk) ExecX(ctx context.Context) { + if err := lcb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/logentry_delete.go b/ent/logentry_delete.go new file mode 100644 index 0000000..86a2b44 --- /dev/null +++ b/ent/logentry_delete.go @@ -0,0 +1,111 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + + "code.icod.de/postfix/manager/ent/logentry" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// LogentryDelete is the builder for deleting a Logentry entity. +type LogentryDelete struct { + config + hooks []Hook + mutation *LogentryMutation +} + +// Where appends a list predicates to the LogentryDelete builder. +func (ld *LogentryDelete) Where(ps ...predicate.Logentry) *LogentryDelete { + ld.mutation.Where(ps...) + return ld +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (ld *LogentryDelete) Exec(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + if len(ld.hooks) == 0 { + affected, err = ld.sqlExec(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*LogentryMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + ld.mutation = mutation + affected, err = ld.sqlExec(ctx) + mutation.done = true + return affected, err + }) + for i := len(ld.hooks) - 1; i >= 0; i-- { + if ld.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = ld.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, ld.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// ExecX is like Exec, but panics if an error occurs. +func (ld *LogentryDelete) ExecX(ctx context.Context) int { + n, err := ld.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (ld *LogentryDelete) sqlExec(ctx context.Context) (int, error) { + _spec := &sqlgraph.DeleteSpec{ + Node: &sqlgraph.NodeSpec{ + Table: logentry.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + if ps := ld.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return sqlgraph.DeleteNodes(ctx, ld.driver, _spec) +} + +// LogentryDeleteOne is the builder for deleting a single Logentry entity. +type LogentryDeleteOne struct { + ld *LogentryDelete +} + +// Exec executes the deletion query. +func (ldo *LogentryDeleteOne) Exec(ctx context.Context) error { + n, err := ldo.ld.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{logentry.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (ldo *LogentryDeleteOne) ExecX(ctx context.Context) { + ldo.ld.ExecX(ctx) +} diff --git a/ent/logentry_query.go b/ent/logentry_query.go new file mode 100644 index 0000000..9ee904d --- /dev/null +++ b/ent/logentry_query.go @@ -0,0 +1,1052 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "math" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// LogentryQuery is the builder for querying Logentry entities. +type LogentryQuery struct { + config + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Logentry + // eager-loading edges. + withAccount *AccountQuery + withDomain *DomainQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the LogentryQuery builder. +func (lq *LogentryQuery) Where(ps ...predicate.Logentry) *LogentryQuery { + lq.predicates = append(lq.predicates, ps...) + return lq +} + +// Limit adds a limit step to the query. +func (lq *LogentryQuery) Limit(limit int) *LogentryQuery { + lq.limit = &limit + return lq +} + +// Offset adds an offset step to the query. +func (lq *LogentryQuery) Offset(offset int) *LogentryQuery { + lq.offset = &offset + return lq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (lq *LogentryQuery) Unique(unique bool) *LogentryQuery { + lq.unique = &unique + return lq +} + +// Order adds an order step to the query. +func (lq *LogentryQuery) Order(o ...OrderFunc) *LogentryQuery { + lq.order = append(lq.order, o...) + return lq +} + +// QueryAccount chains the current query on the "account" edge. +func (lq *LogentryQuery) QueryAccount() *AccountQuery { + query := &AccountQuery{config: lq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := lq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := lq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(logentry.Table, logentry.FieldID, selector), + sqlgraph.To(account.Table, account.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, logentry.AccountTable, logentry.AccountColumn), + ) + fromU = sqlgraph.SetNeighbors(lq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// QueryDomain chains the current query on the "domain" edge. +func (lq *LogentryQuery) QueryDomain() *DomainQuery { + query := &DomainQuery{config: lq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := lq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := lq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(logentry.Table, logentry.FieldID, selector), + sqlgraph.To(domain.Table, domain.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, logentry.DomainTable, logentry.DomainColumn), + ) + fromU = sqlgraph.SetNeighbors(lq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Logentry entity from the query. +// Returns a *NotFoundError when no Logentry was found. +func (lq *LogentryQuery) First(ctx context.Context) (*Logentry, error) { + nodes, err := lq.Limit(1).All(ctx) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{logentry.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (lq *LogentryQuery) FirstX(ctx context.Context) *Logentry { + node, err := lq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Logentry ID from the query. +// Returns a *NotFoundError when no Logentry ID was found. +func (lq *LogentryQuery) FirstID(ctx context.Context) (id int64, err error) { + var ids []int64 + if ids, err = lq.Limit(1).IDs(ctx); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{logentry.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (lq *LogentryQuery) FirstIDX(ctx context.Context) int64 { + id, err := lq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Logentry entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Logentry entity is found. +// Returns a *NotFoundError when no Logentry entities are found. +func (lq *LogentryQuery) Only(ctx context.Context) (*Logentry, error) { + nodes, err := lq.Limit(2).All(ctx) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{logentry.Label} + default: + return nil, &NotSingularError{logentry.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (lq *LogentryQuery) OnlyX(ctx context.Context) *Logentry { + node, err := lq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Logentry ID in the query. +// Returns a *NotSingularError when more than one Logentry ID is found. +// Returns a *NotFoundError when no entities are found. +func (lq *LogentryQuery) OnlyID(ctx context.Context) (id int64, err error) { + var ids []int64 + if ids, err = lq.Limit(2).IDs(ctx); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{logentry.Label} + default: + err = &NotSingularError{logentry.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (lq *LogentryQuery) OnlyIDX(ctx context.Context) int64 { + id, err := lq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Logentries. +func (lq *LogentryQuery) All(ctx context.Context) ([]*Logentry, error) { + if err := lq.prepareQuery(ctx); err != nil { + return nil, err + } + return lq.sqlAll(ctx) +} + +// AllX is like All, but panics if an error occurs. +func (lq *LogentryQuery) AllX(ctx context.Context) []*Logentry { + nodes, err := lq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Logentry IDs. +func (lq *LogentryQuery) IDs(ctx context.Context) ([]int64, error) { + var ids []int64 + if err := lq.Select(logentry.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (lq *LogentryQuery) IDsX(ctx context.Context) []int64 { + ids, err := lq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (lq *LogentryQuery) Count(ctx context.Context) (int, error) { + if err := lq.prepareQuery(ctx); err != nil { + return 0, err + } + return lq.sqlCount(ctx) +} + +// CountX is like Count, but panics if an error occurs. +func (lq *LogentryQuery) CountX(ctx context.Context) int { + count, err := lq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (lq *LogentryQuery) Exist(ctx context.Context) (bool, error) { + if err := lq.prepareQuery(ctx); err != nil { + return false, err + } + return lq.sqlExist(ctx) +} + +// ExistX is like Exist, but panics if an error occurs. +func (lq *LogentryQuery) ExistX(ctx context.Context) bool { + exist, err := lq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the LogentryQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (lq *LogentryQuery) Clone() *LogentryQuery { + if lq == nil { + return nil + } + return &LogentryQuery{ + config: lq.config, + limit: lq.limit, + offset: lq.offset, + order: append([]OrderFunc{}, lq.order...), + predicates: append([]predicate.Logentry{}, lq.predicates...), + withAccount: lq.withAccount.Clone(), + withDomain: lq.withDomain.Clone(), + // clone intermediate query. + sql: lq.sql.Clone(), + path: lq.path, + unique: lq.unique, + } +} + +// WithAccount tells the query-builder to eager-load the nodes that are connected to +// the "account" edge. The optional arguments are used to configure the query builder of the edge. +func (lq *LogentryQuery) WithAccount(opts ...func(*AccountQuery)) *LogentryQuery { + query := &AccountQuery{config: lq.config} + for _, opt := range opts { + opt(query) + } + lq.withAccount = query + return lq +} + +// WithDomain tells the query-builder to eager-load the nodes that are connected to +// the "domain" edge. The optional arguments are used to configure the query builder of the edge. +func (lq *LogentryQuery) WithDomain(opts ...func(*DomainQuery)) *LogentryQuery { + query := &DomainQuery{config: lq.config} + for _, opt := range opts { + opt(query) + } + lq.withDomain = query + return lq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Timestamp time.Time `json:"timestamp,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Logentry.Query(). +// GroupBy(logentry.FieldTimestamp). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +// +func (lq *LogentryQuery) GroupBy(field string, fields ...string) *LogentryGroupBy { + group := &LogentryGroupBy{config: lq.config} + group.fields = append([]string{field}, fields...) + group.path = func(ctx context.Context) (prev *sql.Selector, err error) { + if err := lq.prepareQuery(ctx); err != nil { + return nil, err + } + return lq.sqlQuery(ctx), nil + } + return group +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Timestamp time.Time `json:"timestamp,omitempty"` +// } +// +// client.Logentry.Query(). +// Select(logentry.FieldTimestamp). +// Scan(ctx, &v) +// +func (lq *LogentryQuery) Select(fields ...string) *LogentrySelect { + lq.fields = append(lq.fields, fields...) + return &LogentrySelect{LogentryQuery: lq} +} + +func (lq *LogentryQuery) prepareQuery(ctx context.Context) error { + for _, f := range lq.fields { + if !logentry.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if lq.path != nil { + prev, err := lq.path(ctx) + if err != nil { + return err + } + lq.sql = prev + } + return nil +} + +func (lq *LogentryQuery) sqlAll(ctx context.Context) ([]*Logentry, error) { + var ( + nodes = []*Logentry{} + _spec = lq.querySpec() + loadedTypes = [2]bool{ + lq.withAccount != nil, + lq.withDomain != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]interface{}, error) { + node := &Logentry{config: lq.config} + nodes = append(nodes, node) + return node.scanValues(columns) + } + _spec.Assign = func(columns []string, values []interface{}) error { + if len(nodes) == 0 { + return fmt.Errorf("ent: Assign called without calling ScanValues") + } + node := nodes[len(nodes)-1] + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if err := sqlgraph.QueryNodes(ctx, lq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + + if query := lq.withAccount; query != nil { + ids := make([]int64, 0, len(nodes)) + nodeids := make(map[int64][]*Logentry) + for i := range nodes { + fk := nodes[i].AccountID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(account.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "account_id" returned %v`, n.ID) + } + for i := range nodes { + nodes[i].Edges.Account = n + } + } + } + + if query := lq.withDomain; query != nil { + ids := make([]int64, 0, len(nodes)) + nodeids := make(map[int64][]*Logentry) + for i := range nodes { + fk := nodes[i].DomainID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(domain.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "domain_id" returned %v`, n.ID) + } + for i := range nodes { + nodes[i].Edges.Domain = n + } + } + } + + return nodes, nil +} + +func (lq *LogentryQuery) sqlCount(ctx context.Context) (int, error) { + _spec := lq.querySpec() + _spec.Node.Columns = lq.fields + if len(lq.fields) > 0 { + _spec.Unique = lq.unique != nil && *lq.unique + } + return sqlgraph.CountNodes(ctx, lq.driver, _spec) +} + +func (lq *LogentryQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := lq.sqlCount(ctx) + if err != nil { + return false, fmt.Errorf("ent: check existence: %w", err) + } + return n > 0, nil +} + +func (lq *LogentryQuery) querySpec() *sqlgraph.QuerySpec { + _spec := &sqlgraph.QuerySpec{ + Node: &sqlgraph.NodeSpec{ + Table: logentry.Table, + Columns: logentry.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + From: lq.sql, + Unique: true, + } + if unique := lq.unique; unique != nil { + _spec.Unique = *unique + } + if fields := lq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, logentry.FieldID) + for i := range fields { + if fields[i] != logentry.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := lq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := lq.limit; limit != nil { + _spec.Limit = *limit + } + if offset := lq.offset; offset != nil { + _spec.Offset = *offset + } + if ps := lq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (lq *LogentryQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(lq.driver.Dialect()) + t1 := builder.Table(logentry.Table) + columns := lq.fields + if len(columns) == 0 { + columns = logentry.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if lq.sql != nil { + selector = lq.sql + selector.Select(selector.Columns(columns...)...) + } + if lq.unique != nil && *lq.unique { + selector.Distinct() + } + for _, p := range lq.predicates { + p(selector) + } + for _, p := range lq.order { + p(selector) + } + if offset := lq.offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := lq.limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// LogentryGroupBy is the group-by builder for Logentry entities. +type LogentryGroupBy struct { + config + fields []string + fns []AggregateFunc + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (lgb *LogentryGroupBy) Aggregate(fns ...AggregateFunc) *LogentryGroupBy { + lgb.fns = append(lgb.fns, fns...) + return lgb +} + +// Scan applies the group-by query and scans the result into the given value. +func (lgb *LogentryGroupBy) Scan(ctx context.Context, v interface{}) error { + query, err := lgb.path(ctx) + if err != nil { + return err + } + lgb.sql = query + return lgb.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (lgb *LogentryGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := lgb.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. +func (lgb *LogentryGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(lgb.fields) > 1 { + return nil, errors.New("ent: LogentryGroupBy.Strings is not achievable when grouping more than 1 field") + } + var v []string + if err := lgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (lgb *LogentryGroupBy) StringsX(ctx context.Context) []string { + v, err := lgb.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (lgb *LogentryGroupBy) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = lgb.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{logentry.Label} + default: + err = fmt.Errorf("ent: LogentryGroupBy.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (lgb *LogentryGroupBy) StringX(ctx context.Context) string { + v, err := lgb.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. +func (lgb *LogentryGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(lgb.fields) > 1 { + return nil, errors.New("ent: LogentryGroupBy.Ints is not achievable when grouping more than 1 field") + } + var v []int + if err := lgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (lgb *LogentryGroupBy) IntsX(ctx context.Context) []int { + v, err := lgb.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (lgb *LogentryGroupBy) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = lgb.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{logentry.Label} + default: + err = fmt.Errorf("ent: LogentryGroupBy.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (lgb *LogentryGroupBy) IntX(ctx context.Context) int { + v, err := lgb.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. +func (lgb *LogentryGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(lgb.fields) > 1 { + return nil, errors.New("ent: LogentryGroupBy.Float64s is not achievable when grouping more than 1 field") + } + var v []float64 + if err := lgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (lgb *LogentryGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := lgb.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (lgb *LogentryGroupBy) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = lgb.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{logentry.Label} + default: + err = fmt.Errorf("ent: LogentryGroupBy.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (lgb *LogentryGroupBy) Float64X(ctx context.Context) float64 { + v, err := lgb.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. +func (lgb *LogentryGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(lgb.fields) > 1 { + return nil, errors.New("ent: LogentryGroupBy.Bools is not achievable when grouping more than 1 field") + } + var v []bool + if err := lgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (lgb *LogentryGroupBy) BoolsX(ctx context.Context) []bool { + v, err := lgb.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (lgb *LogentryGroupBy) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = lgb.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{logentry.Label} + default: + err = fmt.Errorf("ent: LogentryGroupBy.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (lgb *LogentryGroupBy) BoolX(ctx context.Context) bool { + v, err := lgb.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (lgb *LogentryGroupBy) sqlScan(ctx context.Context, v interface{}) error { + for _, f := range lgb.fields { + if !logentry.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} + } + } + selector := lgb.sqlQuery() + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := lgb.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (lgb *LogentryGroupBy) sqlQuery() *sql.Selector { + selector := lgb.sql.Select() + aggregation := make([]string, 0, len(lgb.fns)) + for _, fn := range lgb.fns { + aggregation = append(aggregation, fn(selector)) + } + // If no columns were selected in a custom aggregation function, the default + // selection is the fields used for "group-by", and the aggregation functions. + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(lgb.fields)+len(lgb.fns)) + for _, f := range lgb.fields { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + return selector.GroupBy(selector.Columns(lgb.fields...)...) +} + +// LogentrySelect is the builder for selecting fields of Logentry entities. +type LogentrySelect struct { + *LogentryQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector +} + +// Scan applies the selector query and scans the result into the given value. +func (ls *LogentrySelect) Scan(ctx context.Context, v interface{}) error { + if err := ls.prepareQuery(ctx); err != nil { + return err + } + ls.sql = ls.LogentryQuery.sqlQuery(ctx) + return ls.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (ls *LogentrySelect) ScanX(ctx context.Context, v interface{}) { + if err := ls.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from a selector. It is only allowed when selecting one field. +func (ls *LogentrySelect) Strings(ctx context.Context) ([]string, error) { + if len(ls.fields) > 1 { + return nil, errors.New("ent: LogentrySelect.Strings is not achievable when selecting more than 1 field") + } + var v []string + if err := ls.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (ls *LogentrySelect) StringsX(ctx context.Context) []string { + v, err := ls.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a selector. It is only allowed when selecting one field. +func (ls *LogentrySelect) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = ls.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{logentry.Label} + default: + err = fmt.Errorf("ent: LogentrySelect.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (ls *LogentrySelect) StringX(ctx context.Context) string { + v, err := ls.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from a selector. It is only allowed when selecting one field. +func (ls *LogentrySelect) Ints(ctx context.Context) ([]int, error) { + if len(ls.fields) > 1 { + return nil, errors.New("ent: LogentrySelect.Ints is not achievable when selecting more than 1 field") + } + var v []int + if err := ls.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (ls *LogentrySelect) IntsX(ctx context.Context) []int { + v, err := ls.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a selector. It is only allowed when selecting one field. +func (ls *LogentrySelect) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = ls.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{logentry.Label} + default: + err = fmt.Errorf("ent: LogentrySelect.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (ls *LogentrySelect) IntX(ctx context.Context) int { + v, err := ls.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. +func (ls *LogentrySelect) Float64s(ctx context.Context) ([]float64, error) { + if len(ls.fields) > 1 { + return nil, errors.New("ent: LogentrySelect.Float64s is not achievable when selecting more than 1 field") + } + var v []float64 + if err := ls.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (ls *LogentrySelect) Float64sX(ctx context.Context) []float64 { + v, err := ls.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. +func (ls *LogentrySelect) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = ls.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{logentry.Label} + default: + err = fmt.Errorf("ent: LogentrySelect.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (ls *LogentrySelect) Float64X(ctx context.Context) float64 { + v, err := ls.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from a selector. It is only allowed when selecting one field. +func (ls *LogentrySelect) Bools(ctx context.Context) ([]bool, error) { + if len(ls.fields) > 1 { + return nil, errors.New("ent: LogentrySelect.Bools is not achievable when selecting more than 1 field") + } + var v []bool + if err := ls.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (ls *LogentrySelect) BoolsX(ctx context.Context) []bool { + v, err := ls.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a selector. It is only allowed when selecting one field. +func (ls *LogentrySelect) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = ls.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{logentry.Label} + default: + err = fmt.Errorf("ent: LogentrySelect.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (ls *LogentrySelect) BoolX(ctx context.Context) bool { + v, err := ls.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (ls *LogentrySelect) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := ls.sql.Query() + if err := ls.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/logentry_update.go b/ent/logentry_update.go new file mode 100644 index 0000000..1bbe08a --- /dev/null +++ b/ent/logentry_update.go @@ -0,0 +1,597 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// LogentryUpdate is the builder for updating Logentry entities. +type LogentryUpdate struct { + config + hooks []Hook + mutation *LogentryMutation +} + +// Where appends a list predicates to the LogentryUpdate builder. +func (lu *LogentryUpdate) Where(ps ...predicate.Logentry) *LogentryUpdate { + lu.mutation.Where(ps...) + return lu +} + +// SetAction sets the "action" field. +func (lu *LogentryUpdate) SetAction(s string) *LogentryUpdate { + lu.mutation.SetAction(s) + return lu +} + +// SetData sets the "data" field. +func (lu *LogentryUpdate) SetData(s string) *LogentryUpdate { + lu.mutation.SetData(s) + return lu +} + +// SetNillableData sets the "data" field if the given value is not nil. +func (lu *LogentryUpdate) SetNillableData(s *string) *LogentryUpdate { + if s != nil { + lu.SetData(*s) + } + return lu +} + +// ClearData clears the value of the "data" field. +func (lu *LogentryUpdate) ClearData() *LogentryUpdate { + lu.mutation.ClearData() + return lu +} + +// SetAccountID sets the "account_id" field. +func (lu *LogentryUpdate) SetAccountID(i int64) *LogentryUpdate { + lu.mutation.SetAccountID(i) + return lu +} + +// SetNillableAccountID sets the "account_id" field if the given value is not nil. +func (lu *LogentryUpdate) SetNillableAccountID(i *int64) *LogentryUpdate { + if i != nil { + lu.SetAccountID(*i) + } + return lu +} + +// ClearAccountID clears the value of the "account_id" field. +func (lu *LogentryUpdate) ClearAccountID() *LogentryUpdate { + lu.mutation.ClearAccountID() + return lu +} + +// SetDomainID sets the "domain_id" field. +func (lu *LogentryUpdate) SetDomainID(i int64) *LogentryUpdate { + lu.mutation.SetDomainID(i) + return lu +} + +// SetNillableDomainID sets the "domain_id" field if the given value is not nil. +func (lu *LogentryUpdate) SetNillableDomainID(i *int64) *LogentryUpdate { + if i != nil { + lu.SetDomainID(*i) + } + return lu +} + +// ClearDomainID clears the value of the "domain_id" field. +func (lu *LogentryUpdate) ClearDomainID() *LogentryUpdate { + lu.mutation.ClearDomainID() + return lu +} + +// SetAccount sets the "account" edge to the Account entity. +func (lu *LogentryUpdate) SetAccount(a *Account) *LogentryUpdate { + return lu.SetAccountID(a.ID) +} + +// SetDomain sets the "domain" edge to the Domain entity. +func (lu *LogentryUpdate) SetDomain(d *Domain) *LogentryUpdate { + return lu.SetDomainID(d.ID) +} + +// Mutation returns the LogentryMutation object of the builder. +func (lu *LogentryUpdate) Mutation() *LogentryMutation { + return lu.mutation +} + +// ClearAccount clears the "account" edge to the Account entity. +func (lu *LogentryUpdate) ClearAccount() *LogentryUpdate { + lu.mutation.ClearAccount() + return lu +} + +// ClearDomain clears the "domain" edge to the Domain entity. +func (lu *LogentryUpdate) ClearDomain() *LogentryUpdate { + lu.mutation.ClearDomain() + return lu +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (lu *LogentryUpdate) Save(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + if len(lu.hooks) == 0 { + affected, err = lu.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*LogentryMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + lu.mutation = mutation + affected, err = lu.sqlSave(ctx) + mutation.done = true + return affected, err + }) + for i := len(lu.hooks) - 1; i >= 0; i-- { + if lu.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = lu.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, lu.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// SaveX is like Save, but panics if an error occurs. +func (lu *LogentryUpdate) SaveX(ctx context.Context) int { + affected, err := lu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (lu *LogentryUpdate) Exec(ctx context.Context) error { + _, err := lu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (lu *LogentryUpdate) ExecX(ctx context.Context) { + if err := lu.Exec(ctx); err != nil { + panic(err) + } +} + +func (lu *LogentryUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: logentry.Table, + Columns: logentry.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + if ps := lu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := lu.mutation.Action(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: logentry.FieldAction, + }) + } + if value, ok := lu.mutation.Data(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: logentry.FieldData, + }) + } + if lu.mutation.DataCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: logentry.FieldData, + }) + } + if lu.mutation.AccountCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: logentry.AccountTable, + Columns: []string{logentry.AccountColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := lu.mutation.AccountIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: logentry.AccountTable, + Columns: []string{logentry.AccountColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if lu.mutation.DomainCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: logentry.DomainTable, + Columns: []string{logentry.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := lu.mutation.DomainIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: logentry.DomainTable, + Columns: []string{logentry.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, lu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{logentry.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return 0, err + } + return n, nil +} + +// LogentryUpdateOne is the builder for updating a single Logentry entity. +type LogentryUpdateOne struct { + config + fields []string + hooks []Hook + mutation *LogentryMutation +} + +// SetAction sets the "action" field. +func (luo *LogentryUpdateOne) SetAction(s string) *LogentryUpdateOne { + luo.mutation.SetAction(s) + return luo +} + +// SetData sets the "data" field. +func (luo *LogentryUpdateOne) SetData(s string) *LogentryUpdateOne { + luo.mutation.SetData(s) + return luo +} + +// SetNillableData sets the "data" field if the given value is not nil. +func (luo *LogentryUpdateOne) SetNillableData(s *string) *LogentryUpdateOne { + if s != nil { + luo.SetData(*s) + } + return luo +} + +// ClearData clears the value of the "data" field. +func (luo *LogentryUpdateOne) ClearData() *LogentryUpdateOne { + luo.mutation.ClearData() + return luo +} + +// SetAccountID sets the "account_id" field. +func (luo *LogentryUpdateOne) SetAccountID(i int64) *LogentryUpdateOne { + luo.mutation.SetAccountID(i) + return luo +} + +// SetNillableAccountID sets the "account_id" field if the given value is not nil. +func (luo *LogentryUpdateOne) SetNillableAccountID(i *int64) *LogentryUpdateOne { + if i != nil { + luo.SetAccountID(*i) + } + return luo +} + +// ClearAccountID clears the value of the "account_id" field. +func (luo *LogentryUpdateOne) ClearAccountID() *LogentryUpdateOne { + luo.mutation.ClearAccountID() + return luo +} + +// SetDomainID sets the "domain_id" field. +func (luo *LogentryUpdateOne) SetDomainID(i int64) *LogentryUpdateOne { + luo.mutation.SetDomainID(i) + return luo +} + +// SetNillableDomainID sets the "domain_id" field if the given value is not nil. +func (luo *LogentryUpdateOne) SetNillableDomainID(i *int64) *LogentryUpdateOne { + if i != nil { + luo.SetDomainID(*i) + } + return luo +} + +// ClearDomainID clears the value of the "domain_id" field. +func (luo *LogentryUpdateOne) ClearDomainID() *LogentryUpdateOne { + luo.mutation.ClearDomainID() + return luo +} + +// SetAccount sets the "account" edge to the Account entity. +func (luo *LogentryUpdateOne) SetAccount(a *Account) *LogentryUpdateOne { + return luo.SetAccountID(a.ID) +} + +// SetDomain sets the "domain" edge to the Domain entity. +func (luo *LogentryUpdateOne) SetDomain(d *Domain) *LogentryUpdateOne { + return luo.SetDomainID(d.ID) +} + +// Mutation returns the LogentryMutation object of the builder. +func (luo *LogentryUpdateOne) Mutation() *LogentryMutation { + return luo.mutation +} + +// ClearAccount clears the "account" edge to the Account entity. +func (luo *LogentryUpdateOne) ClearAccount() *LogentryUpdateOne { + luo.mutation.ClearAccount() + return luo +} + +// ClearDomain clears the "domain" edge to the Domain entity. +func (luo *LogentryUpdateOne) ClearDomain() *LogentryUpdateOne { + luo.mutation.ClearDomain() + return luo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (luo *LogentryUpdateOne) Select(field string, fields ...string) *LogentryUpdateOne { + luo.fields = append([]string{field}, fields...) + return luo +} + +// Save executes the query and returns the updated Logentry entity. +func (luo *LogentryUpdateOne) Save(ctx context.Context) (*Logentry, error) { + var ( + err error + node *Logentry + ) + if len(luo.hooks) == 0 { + node, err = luo.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*LogentryMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + luo.mutation = mutation + node, err = luo.sqlSave(ctx) + mutation.done = true + return node, err + }) + for i := len(luo.hooks) - 1; i >= 0; i-- { + if luo.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = luo.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, luo.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX is like Save, but panics if an error occurs. +func (luo *LogentryUpdateOne) SaveX(ctx context.Context) *Logentry { + node, err := luo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (luo *LogentryUpdateOne) Exec(ctx context.Context) error { + _, err := luo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (luo *LogentryUpdateOne) ExecX(ctx context.Context) { + if err := luo.Exec(ctx); err != nil { + panic(err) + } +} + +func (luo *LogentryUpdateOne) sqlSave(ctx context.Context) (_node *Logentry, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: logentry.Table, + Columns: logentry.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: logentry.FieldID, + }, + }, + } + id, ok := luo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Logentry.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := luo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, logentry.FieldID) + for _, f := range fields { + if !logentry.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != logentry.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := luo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := luo.mutation.Action(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: logentry.FieldAction, + }) + } + if value, ok := luo.mutation.Data(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: logentry.FieldData, + }) + } + if luo.mutation.DataCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: logentry.FieldData, + }) + } + if luo.mutation.AccountCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: logentry.AccountTable, + Columns: []string{logentry.AccountColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := luo.mutation.AccountIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: logentry.AccountTable, + Columns: []string{logentry.AccountColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: account.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if luo.mutation.DomainCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: logentry.DomainTable, + Columns: []string{logentry.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := luo.mutation.DomainIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: logentry.DomainTable, + Columns: []string{logentry.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Logentry{config: luo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, luo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{logentry.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + return _node, nil +} diff --git a/ent/mailbox.go b/ent/mailbox.go new file mode 100644 index 0000000..01d50b4 --- /dev/null +++ b/ent/mailbox.go @@ -0,0 +1,276 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "fmt" + "strings" + "time" + + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/mailbox" + "entgo.io/ent/dialect/sql" +) + +// Mailbox is the model entity for the Mailbox schema. +type Mailbox struct { + config `json:"-"` + // ID of the ent. + ID int64 `json:"id,omitempty"` + // Active holds the value of the "active" field. + Active bool `json:"active,omitempty"` + // Created holds the value of the "created" field. + Created time.Time `json:"created,omitempty"` + // Modified holds the value of the "modified" field. + Modified *time.Time `json:"modified,omitempty"` + // DomainID holds the value of the "domain_id" field. + DomainID int64 `json:"domain_id,omitempty"` + // Username holds the value of the "username" field. + Username string `json:"username,omitempty"` + // Password holds the value of the "password" field. + Password []byte `json:"password,omitempty"` + // Name holds the value of the "name" field. + Name *string `json:"name,omitempty"` + // Quota holds the value of the "quota" field. + Quota int64 `json:"quota,omitempty"` + // LocalPart holds the value of the "local_part" field. + LocalPart string `json:"local_part,omitempty"` + // Homedir holds the value of the "homedir" field. + Homedir *string `json:"homedir,omitempty"` + // Maildir holds the value of the "maildir" field. + Maildir *string `json:"maildir,omitempty"` + // UID holds the value of the "uid" field. + UID *int32 `json:"uid,omitempty"` + // Gid holds the value of the "gid" field. + Gid *int32 `json:"gid,omitempty"` + // Edges holds the relations/edges for other nodes in the graph. + // The values are being populated by the MailboxQuery when eager-loading is set. + Edges MailboxEdges `json:"edges"` +} + +// MailboxEdges holds the relations/edges for other nodes in the graph. +type MailboxEdges struct { + // Domain holds the value of the domain edge. + Domain *Domain `json:"domain,omitempty"` + // loadedTypes holds the information for reporting if a + // type was loaded (or requested) in eager-loading or not. + loadedTypes [1]bool +} + +// DomainOrErr returns the Domain value or an error if the edge +// was not loaded in eager-loading, or loaded but was not found. +func (e MailboxEdges) DomainOrErr() (*Domain, error) { + if e.loadedTypes[0] { + if e.Domain == nil { + // The edge domain was loaded in eager-loading, + // but was not found. + return nil, &NotFoundError{label: domain.Label} + } + return e.Domain, nil + } + return nil, &NotLoadedError{edge: "domain"} +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*Mailbox) scanValues(columns []string) ([]interface{}, error) { + values := make([]interface{}, len(columns)) + for i := range columns { + switch columns[i] { + case mailbox.FieldPassword: + values[i] = new([]byte) + case mailbox.FieldActive: + values[i] = new(sql.NullBool) + case mailbox.FieldID, mailbox.FieldDomainID, mailbox.FieldQuota, mailbox.FieldUID, mailbox.FieldGid: + values[i] = new(sql.NullInt64) + case mailbox.FieldUsername, mailbox.FieldName, mailbox.FieldLocalPart, mailbox.FieldHomedir, mailbox.FieldMaildir: + values[i] = new(sql.NullString) + case mailbox.FieldCreated, mailbox.FieldModified: + values[i] = new(sql.NullTime) + default: + return nil, fmt.Errorf("unexpected column %q for type Mailbox", columns[i]) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the Mailbox fields. +func (m *Mailbox) assignValues(columns []string, values []interface{}) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case mailbox.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + m.ID = int64(value.Int64) + case mailbox.FieldActive: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field active", values[i]) + } else if value.Valid { + m.Active = value.Bool + } + case mailbox.FieldCreated: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created", values[i]) + } else if value.Valid { + m.Created = value.Time + } + case mailbox.FieldModified: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field modified", values[i]) + } else if value.Valid { + m.Modified = new(time.Time) + *m.Modified = value.Time + } + case mailbox.FieldDomainID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field domain_id", values[i]) + } else if value.Valid { + m.DomainID = value.Int64 + } + case mailbox.FieldUsername: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field username", values[i]) + } else if value.Valid { + m.Username = value.String + } + case mailbox.FieldPassword: + if value, ok := values[i].(*[]byte); !ok { + return fmt.Errorf("unexpected type %T for field password", values[i]) + } else if value != nil { + m.Password = *value + } + case mailbox.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + m.Name = new(string) + *m.Name = value.String + } + case mailbox.FieldQuota: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field quota", values[i]) + } else if value.Valid { + m.Quota = value.Int64 + } + case mailbox.FieldLocalPart: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field local_part", values[i]) + } else if value.Valid { + m.LocalPart = value.String + } + case mailbox.FieldHomedir: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field homedir", values[i]) + } else if value.Valid { + m.Homedir = new(string) + *m.Homedir = value.String + } + case mailbox.FieldMaildir: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field maildir", values[i]) + } else if value.Valid { + m.Maildir = new(string) + *m.Maildir = value.String + } + case mailbox.FieldUID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field uid", values[i]) + } else if value.Valid { + m.UID = new(int32) + *m.UID = int32(value.Int64) + } + case mailbox.FieldGid: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field gid", values[i]) + } else if value.Valid { + m.Gid = new(int32) + *m.Gid = int32(value.Int64) + } + } + } + return nil +} + +// QueryDomain queries the "domain" edge of the Mailbox entity. +func (m *Mailbox) QueryDomain() *DomainQuery { + return (&MailboxClient{config: m.config}).QueryDomain(m) +} + +// Update returns a builder for updating this Mailbox. +// Note that you need to call Mailbox.Unwrap() before calling this method if this Mailbox +// was returned from a transaction, and the transaction was committed or rolled back. +func (m *Mailbox) Update() *MailboxUpdateOne { + return (&MailboxClient{config: m.config}).UpdateOne(m) +} + +// Unwrap unwraps the Mailbox entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (m *Mailbox) Unwrap() *Mailbox { + tx, ok := m.config.driver.(*txDriver) + if !ok { + panic("ent: Mailbox is not a transactional entity") + } + m.config.driver = tx.drv + return m +} + +// String implements the fmt.Stringer. +func (m *Mailbox) String() string { + var builder strings.Builder + builder.WriteString("Mailbox(") + builder.WriteString(fmt.Sprintf("id=%v", m.ID)) + builder.WriteString(", active=") + builder.WriteString(fmt.Sprintf("%v", m.Active)) + builder.WriteString(", created=") + builder.WriteString(m.Created.Format(time.ANSIC)) + if v := m.Modified; v != nil { + builder.WriteString(", modified=") + builder.WriteString(v.Format(time.ANSIC)) + } + builder.WriteString(", domain_id=") + builder.WriteString(fmt.Sprintf("%v", m.DomainID)) + builder.WriteString(", username=") + builder.WriteString(m.Username) + builder.WriteString(", password=") + builder.WriteString(fmt.Sprintf("%v", m.Password)) + if v := m.Name; v != nil { + builder.WriteString(", name=") + builder.WriteString(*v) + } + builder.WriteString(", quota=") + builder.WriteString(fmt.Sprintf("%v", m.Quota)) + builder.WriteString(", local_part=") + builder.WriteString(m.LocalPart) + if v := m.Homedir; v != nil { + builder.WriteString(", homedir=") + builder.WriteString(*v) + } + if v := m.Maildir; v != nil { + builder.WriteString(", maildir=") + builder.WriteString(*v) + } + if v := m.UID; v != nil { + builder.WriteString(", uid=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + if v := m.Gid; v != nil { + builder.WriteString(", gid=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteByte(')') + return builder.String() +} + +// Mailboxes is a parsable slice of Mailbox. +type Mailboxes []*Mailbox + +func (m Mailboxes) config(cfg config) { + for _i := range m { + m[_i].config = cfg + } +} diff --git a/ent/mailbox/mailbox.go b/ent/mailbox/mailbox.go new file mode 100644 index 0000000..3394987 --- /dev/null +++ b/ent/mailbox/mailbox.go @@ -0,0 +1,88 @@ +// Code generated by entc, DO NOT EDIT. + +package mailbox + +import ( + "time" +) + +const ( + // Label holds the string label denoting the mailbox type in the database. + Label = "mailbox" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldActive holds the string denoting the active field in the database. + FieldActive = "active" + // FieldCreated holds the string denoting the created field in the database. + FieldCreated = "created" + // FieldModified holds the string denoting the modified field in the database. + FieldModified = "modified" + // FieldDomainID holds the string denoting the domain_id field in the database. + FieldDomainID = "domain_id" + // FieldUsername holds the string denoting the username field in the database. + FieldUsername = "username" + // FieldPassword holds the string denoting the password field in the database. + FieldPassword = "password" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldQuota holds the string denoting the quota field in the database. + FieldQuota = "quota" + // FieldLocalPart holds the string denoting the local_part field in the database. + FieldLocalPart = "local_part" + // FieldHomedir holds the string denoting the homedir field in the database. + FieldHomedir = "homedir" + // FieldMaildir holds the string denoting the maildir field in the database. + FieldMaildir = "maildir" + // FieldUID holds the string denoting the uid field in the database. + FieldUID = "uid" + // FieldGid holds the string denoting the gid field in the database. + FieldGid = "gid" + // EdgeDomain holds the string denoting the domain edge name in mutations. + EdgeDomain = "domain" + // Table holds the table name of the mailbox in the database. + Table = "mailboxes" + // DomainTable is the table that holds the domain relation/edge. + DomainTable = "mailboxes" + // DomainInverseTable is the table name for the Domain entity. + // It exists in this package in order to avoid circular dependency with the "domain" package. + DomainInverseTable = "domains" + // DomainColumn is the table column denoting the domain relation/edge. + DomainColumn = "domain_id" +) + +// Columns holds all SQL columns for mailbox fields. +var Columns = []string{ + FieldID, + FieldActive, + FieldCreated, + FieldModified, + FieldDomainID, + FieldUsername, + FieldPassword, + FieldName, + FieldQuota, + FieldLocalPart, + FieldHomedir, + FieldMaildir, + FieldUID, + FieldGid, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // DefaultCreated holds the default value on creation for the "created" field. + DefaultCreated func() time.Time + // DefaultModified holds the default value on creation for the "modified" field. + DefaultModified func() time.Time + // UpdateDefaultModified holds the default value on update for the "modified" field. + UpdateDefaultModified func() time.Time +) diff --git a/ent/mailbox/where.go b/ent/mailbox/where.go new file mode 100644 index 0000000..32a4806 --- /dev/null +++ b/ent/mailbox/where.go @@ -0,0 +1,1416 @@ +// Code generated by entc, DO NOT EDIT. + +package mailbox + +import ( + "time" + + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" +) + +// ID filters vertices based on their ID field. +func ID(id int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldID), id)) + }) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldID), id)) + }) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.In(s.C(FieldID), v...)) + }) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(ids) == 0 { + s.Where(sql.False()) + return + } + v := make([]interface{}, len(ids)) + for i := range v { + v[i] = ids[i] + } + s.Where(sql.NotIn(s.C(FieldID), v...)) + }) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldID), id)) + }) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldID), id)) + }) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldID), id)) + }) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldID), id)) + }) +} + +// Active applies equality check predicate on the "active" field. It's identical to ActiveEQ. +func Active(v bool) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldActive), v)) + }) +} + +// Created applies equality check predicate on the "created" field. It's identical to CreatedEQ. +func Created(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldCreated), v)) + }) +} + +// Modified applies equality check predicate on the "modified" field. It's identical to ModifiedEQ. +func Modified(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldModified), v)) + }) +} + +// DomainID applies equality check predicate on the "domain_id" field. It's identical to DomainIDEQ. +func DomainID(v int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDomainID), v)) + }) +} + +// Username applies equality check predicate on the "username" field. It's identical to UsernameEQ. +func Username(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUsername), v)) + }) +} + +// Password applies equality check predicate on the "password" field. It's identical to PasswordEQ. +func Password(v []byte) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPassword), v)) + }) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldName), v)) + }) +} + +// Quota applies equality check predicate on the "quota" field. It's identical to QuotaEQ. +func Quota(v int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldQuota), v)) + }) +} + +// LocalPart applies equality check predicate on the "local_part" field. It's identical to LocalPartEQ. +func LocalPart(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldLocalPart), v)) + }) +} + +// Homedir applies equality check predicate on the "homedir" field. It's identical to HomedirEQ. +func Homedir(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldHomedir), v)) + }) +} + +// Maildir applies equality check predicate on the "maildir" field. It's identical to MaildirEQ. +func Maildir(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldMaildir), v)) + }) +} + +// UID applies equality check predicate on the "uid" field. It's identical to UIDEQ. +func UID(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUID), v)) + }) +} + +// Gid applies equality check predicate on the "gid" field. It's identical to GidEQ. +func Gid(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldGid), v)) + }) +} + +// ActiveEQ applies the EQ predicate on the "active" field. +func ActiveEQ(v bool) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldActive), v)) + }) +} + +// ActiveNEQ applies the NEQ predicate on the "active" field. +func ActiveNEQ(v bool) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldActive), v)) + }) +} + +// CreatedEQ applies the EQ predicate on the "created" field. +func CreatedEQ(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldCreated), v)) + }) +} + +// CreatedNEQ applies the NEQ predicate on the "created" field. +func CreatedNEQ(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldCreated), v)) + }) +} + +// CreatedIn applies the In predicate on the "created" field. +func CreatedIn(vs ...time.Time) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldCreated), v...)) + }) +} + +// CreatedNotIn applies the NotIn predicate on the "created" field. +func CreatedNotIn(vs ...time.Time) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldCreated), v...)) + }) +} + +// CreatedGT applies the GT predicate on the "created" field. +func CreatedGT(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldCreated), v)) + }) +} + +// CreatedGTE applies the GTE predicate on the "created" field. +func CreatedGTE(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldCreated), v)) + }) +} + +// CreatedLT applies the LT predicate on the "created" field. +func CreatedLT(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldCreated), v)) + }) +} + +// CreatedLTE applies the LTE predicate on the "created" field. +func CreatedLTE(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldCreated), v)) + }) +} + +// ModifiedEQ applies the EQ predicate on the "modified" field. +func ModifiedEQ(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldModified), v)) + }) +} + +// ModifiedNEQ applies the NEQ predicate on the "modified" field. +func ModifiedNEQ(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldModified), v)) + }) +} + +// ModifiedIn applies the In predicate on the "modified" field. +func ModifiedIn(vs ...time.Time) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldModified), v...)) + }) +} + +// ModifiedNotIn applies the NotIn predicate on the "modified" field. +func ModifiedNotIn(vs ...time.Time) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldModified), v...)) + }) +} + +// ModifiedGT applies the GT predicate on the "modified" field. +func ModifiedGT(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldModified), v)) + }) +} + +// ModifiedGTE applies the GTE predicate on the "modified" field. +func ModifiedGTE(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldModified), v)) + }) +} + +// ModifiedLT applies the LT predicate on the "modified" field. +func ModifiedLT(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldModified), v)) + }) +} + +// ModifiedLTE applies the LTE predicate on the "modified" field. +func ModifiedLTE(v time.Time) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldModified), v)) + }) +} + +// ModifiedIsNil applies the IsNil predicate on the "modified" field. +func ModifiedIsNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldModified))) + }) +} + +// ModifiedNotNil applies the NotNil predicate on the "modified" field. +func ModifiedNotNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldModified))) + }) +} + +// DomainIDEQ applies the EQ predicate on the "domain_id" field. +func DomainIDEQ(v int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldDomainID), v)) + }) +} + +// DomainIDNEQ applies the NEQ predicate on the "domain_id" field. +func DomainIDNEQ(v int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldDomainID), v)) + }) +} + +// DomainIDIn applies the In predicate on the "domain_id" field. +func DomainIDIn(vs ...int64) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldDomainID), v...)) + }) +} + +// DomainIDNotIn applies the NotIn predicate on the "domain_id" field. +func DomainIDNotIn(vs ...int64) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldDomainID), v...)) + }) +} + +// DomainIDIsNil applies the IsNil predicate on the "domain_id" field. +func DomainIDIsNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldDomainID))) + }) +} + +// DomainIDNotNil applies the NotNil predicate on the "domain_id" field. +func DomainIDNotNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldDomainID))) + }) +} + +// UsernameEQ applies the EQ predicate on the "username" field. +func UsernameEQ(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUsername), v)) + }) +} + +// UsernameNEQ applies the NEQ predicate on the "username" field. +func UsernameNEQ(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldUsername), v)) + }) +} + +// UsernameIn applies the In predicate on the "username" field. +func UsernameIn(vs ...string) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldUsername), v...)) + }) +} + +// UsernameNotIn applies the NotIn predicate on the "username" field. +func UsernameNotIn(vs ...string) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldUsername), v...)) + }) +} + +// UsernameGT applies the GT predicate on the "username" field. +func UsernameGT(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldUsername), v)) + }) +} + +// UsernameGTE applies the GTE predicate on the "username" field. +func UsernameGTE(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldUsername), v)) + }) +} + +// UsernameLT applies the LT predicate on the "username" field. +func UsernameLT(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldUsername), v)) + }) +} + +// UsernameLTE applies the LTE predicate on the "username" field. +func UsernameLTE(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldUsername), v)) + }) +} + +// UsernameContains applies the Contains predicate on the "username" field. +func UsernameContains(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldUsername), v)) + }) +} + +// UsernameHasPrefix applies the HasPrefix predicate on the "username" field. +func UsernameHasPrefix(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldUsername), v)) + }) +} + +// UsernameHasSuffix applies the HasSuffix predicate on the "username" field. +func UsernameHasSuffix(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldUsername), v)) + }) +} + +// UsernameEqualFold applies the EqualFold predicate on the "username" field. +func UsernameEqualFold(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldUsername), v)) + }) +} + +// UsernameContainsFold applies the ContainsFold predicate on the "username" field. +func UsernameContainsFold(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldUsername), v)) + }) +} + +// PasswordEQ applies the EQ predicate on the "password" field. +func PasswordEQ(v []byte) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldPassword), v)) + }) +} + +// PasswordNEQ applies the NEQ predicate on the "password" field. +func PasswordNEQ(v []byte) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldPassword), v)) + }) +} + +// PasswordIn applies the In predicate on the "password" field. +func PasswordIn(vs ...[]byte) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldPassword), v...)) + }) +} + +// PasswordNotIn applies the NotIn predicate on the "password" field. +func PasswordNotIn(vs ...[]byte) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldPassword), v...)) + }) +} + +// PasswordGT applies the GT predicate on the "password" field. +func PasswordGT(v []byte) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldPassword), v)) + }) +} + +// PasswordGTE applies the GTE predicate on the "password" field. +func PasswordGTE(v []byte) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldPassword), v)) + }) +} + +// PasswordLT applies the LT predicate on the "password" field. +func PasswordLT(v []byte) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldPassword), v)) + }) +} + +// PasswordLTE applies the LTE predicate on the "password" field. +func PasswordLTE(v []byte) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldPassword), v)) + }) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldName), v)) + }) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldName), v)) + }) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldName), v...)) + }) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldName), v...)) + }) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldName), v)) + }) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldName), v)) + }) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldName), v)) + }) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldName), v)) + }) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldName), v)) + }) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldName), v)) + }) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldName), v)) + }) +} + +// NameIsNil applies the IsNil predicate on the "name" field. +func NameIsNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldName))) + }) +} + +// NameNotNil applies the NotNil predicate on the "name" field. +func NameNotNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldName))) + }) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldName), v)) + }) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldName), v)) + }) +} + +// QuotaEQ applies the EQ predicate on the "quota" field. +func QuotaEQ(v int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldQuota), v)) + }) +} + +// QuotaNEQ applies the NEQ predicate on the "quota" field. +func QuotaNEQ(v int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldQuota), v)) + }) +} + +// QuotaIn applies the In predicate on the "quota" field. +func QuotaIn(vs ...int64) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldQuota), v...)) + }) +} + +// QuotaNotIn applies the NotIn predicate on the "quota" field. +func QuotaNotIn(vs ...int64) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldQuota), v...)) + }) +} + +// QuotaGT applies the GT predicate on the "quota" field. +func QuotaGT(v int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldQuota), v)) + }) +} + +// QuotaGTE applies the GTE predicate on the "quota" field. +func QuotaGTE(v int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldQuota), v)) + }) +} + +// QuotaLT applies the LT predicate on the "quota" field. +func QuotaLT(v int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldQuota), v)) + }) +} + +// QuotaLTE applies the LTE predicate on the "quota" field. +func QuotaLTE(v int64) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldQuota), v)) + }) +} + +// LocalPartEQ applies the EQ predicate on the "local_part" field. +func LocalPartEQ(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldLocalPart), v)) + }) +} + +// LocalPartNEQ applies the NEQ predicate on the "local_part" field. +func LocalPartNEQ(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldLocalPart), v)) + }) +} + +// LocalPartIn applies the In predicate on the "local_part" field. +func LocalPartIn(vs ...string) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldLocalPart), v...)) + }) +} + +// LocalPartNotIn applies the NotIn predicate on the "local_part" field. +func LocalPartNotIn(vs ...string) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldLocalPart), v...)) + }) +} + +// LocalPartGT applies the GT predicate on the "local_part" field. +func LocalPartGT(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldLocalPart), v)) + }) +} + +// LocalPartGTE applies the GTE predicate on the "local_part" field. +func LocalPartGTE(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldLocalPart), v)) + }) +} + +// LocalPartLT applies the LT predicate on the "local_part" field. +func LocalPartLT(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldLocalPart), v)) + }) +} + +// LocalPartLTE applies the LTE predicate on the "local_part" field. +func LocalPartLTE(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldLocalPart), v)) + }) +} + +// LocalPartContains applies the Contains predicate on the "local_part" field. +func LocalPartContains(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldLocalPart), v)) + }) +} + +// LocalPartHasPrefix applies the HasPrefix predicate on the "local_part" field. +func LocalPartHasPrefix(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldLocalPart), v)) + }) +} + +// LocalPartHasSuffix applies the HasSuffix predicate on the "local_part" field. +func LocalPartHasSuffix(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldLocalPart), v)) + }) +} + +// LocalPartEqualFold applies the EqualFold predicate on the "local_part" field. +func LocalPartEqualFold(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldLocalPart), v)) + }) +} + +// LocalPartContainsFold applies the ContainsFold predicate on the "local_part" field. +func LocalPartContainsFold(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldLocalPart), v)) + }) +} + +// HomedirEQ applies the EQ predicate on the "homedir" field. +func HomedirEQ(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldHomedir), v)) + }) +} + +// HomedirNEQ applies the NEQ predicate on the "homedir" field. +func HomedirNEQ(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldHomedir), v)) + }) +} + +// HomedirIn applies the In predicate on the "homedir" field. +func HomedirIn(vs ...string) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldHomedir), v...)) + }) +} + +// HomedirNotIn applies the NotIn predicate on the "homedir" field. +func HomedirNotIn(vs ...string) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldHomedir), v...)) + }) +} + +// HomedirGT applies the GT predicate on the "homedir" field. +func HomedirGT(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldHomedir), v)) + }) +} + +// HomedirGTE applies the GTE predicate on the "homedir" field. +func HomedirGTE(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldHomedir), v)) + }) +} + +// HomedirLT applies the LT predicate on the "homedir" field. +func HomedirLT(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldHomedir), v)) + }) +} + +// HomedirLTE applies the LTE predicate on the "homedir" field. +func HomedirLTE(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldHomedir), v)) + }) +} + +// HomedirContains applies the Contains predicate on the "homedir" field. +func HomedirContains(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldHomedir), v)) + }) +} + +// HomedirHasPrefix applies the HasPrefix predicate on the "homedir" field. +func HomedirHasPrefix(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldHomedir), v)) + }) +} + +// HomedirHasSuffix applies the HasSuffix predicate on the "homedir" field. +func HomedirHasSuffix(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldHomedir), v)) + }) +} + +// HomedirIsNil applies the IsNil predicate on the "homedir" field. +func HomedirIsNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldHomedir))) + }) +} + +// HomedirNotNil applies the NotNil predicate on the "homedir" field. +func HomedirNotNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldHomedir))) + }) +} + +// HomedirEqualFold applies the EqualFold predicate on the "homedir" field. +func HomedirEqualFold(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldHomedir), v)) + }) +} + +// HomedirContainsFold applies the ContainsFold predicate on the "homedir" field. +func HomedirContainsFold(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldHomedir), v)) + }) +} + +// MaildirEQ applies the EQ predicate on the "maildir" field. +func MaildirEQ(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldMaildir), v)) + }) +} + +// MaildirNEQ applies the NEQ predicate on the "maildir" field. +func MaildirNEQ(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldMaildir), v)) + }) +} + +// MaildirIn applies the In predicate on the "maildir" field. +func MaildirIn(vs ...string) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldMaildir), v...)) + }) +} + +// MaildirNotIn applies the NotIn predicate on the "maildir" field. +func MaildirNotIn(vs ...string) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldMaildir), v...)) + }) +} + +// MaildirGT applies the GT predicate on the "maildir" field. +func MaildirGT(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldMaildir), v)) + }) +} + +// MaildirGTE applies the GTE predicate on the "maildir" field. +func MaildirGTE(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldMaildir), v)) + }) +} + +// MaildirLT applies the LT predicate on the "maildir" field. +func MaildirLT(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldMaildir), v)) + }) +} + +// MaildirLTE applies the LTE predicate on the "maildir" field. +func MaildirLTE(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldMaildir), v)) + }) +} + +// MaildirContains applies the Contains predicate on the "maildir" field. +func MaildirContains(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.Contains(s.C(FieldMaildir), v)) + }) +} + +// MaildirHasPrefix applies the HasPrefix predicate on the "maildir" field. +func MaildirHasPrefix(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.HasPrefix(s.C(FieldMaildir), v)) + }) +} + +// MaildirHasSuffix applies the HasSuffix predicate on the "maildir" field. +func MaildirHasSuffix(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.HasSuffix(s.C(FieldMaildir), v)) + }) +} + +// MaildirIsNil applies the IsNil predicate on the "maildir" field. +func MaildirIsNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldMaildir))) + }) +} + +// MaildirNotNil applies the NotNil predicate on the "maildir" field. +func MaildirNotNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldMaildir))) + }) +} + +// MaildirEqualFold applies the EqualFold predicate on the "maildir" field. +func MaildirEqualFold(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EqualFold(s.C(FieldMaildir), v)) + }) +} + +// MaildirContainsFold applies the ContainsFold predicate on the "maildir" field. +func MaildirContainsFold(v string) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.ContainsFold(s.C(FieldMaildir), v)) + }) +} + +// UIDEQ applies the EQ predicate on the "uid" field. +func UIDEQ(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldUID), v)) + }) +} + +// UIDNEQ applies the NEQ predicate on the "uid" field. +func UIDNEQ(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldUID), v)) + }) +} + +// UIDIn applies the In predicate on the "uid" field. +func UIDIn(vs ...int32) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldUID), v...)) + }) +} + +// UIDNotIn applies the NotIn predicate on the "uid" field. +func UIDNotIn(vs ...int32) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldUID), v...)) + }) +} + +// UIDGT applies the GT predicate on the "uid" field. +func UIDGT(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldUID), v)) + }) +} + +// UIDGTE applies the GTE predicate on the "uid" field. +func UIDGTE(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldUID), v)) + }) +} + +// UIDLT applies the LT predicate on the "uid" field. +func UIDLT(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldUID), v)) + }) +} + +// UIDLTE applies the LTE predicate on the "uid" field. +func UIDLTE(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldUID), v)) + }) +} + +// UIDIsNil applies the IsNil predicate on the "uid" field. +func UIDIsNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldUID))) + }) +} + +// UIDNotNil applies the NotNil predicate on the "uid" field. +func UIDNotNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldUID))) + }) +} + +// GidEQ applies the EQ predicate on the "gid" field. +func GidEQ(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.EQ(s.C(FieldGid), v)) + }) +} + +// GidNEQ applies the NEQ predicate on the "gid" field. +func GidNEQ(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NEQ(s.C(FieldGid), v)) + }) +} + +// GidIn applies the In predicate on the "gid" field. +func GidIn(vs ...int32) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.In(s.C(FieldGid), v...)) + }) +} + +// GidNotIn applies the NotIn predicate on the "gid" field. +func GidNotIn(vs ...int32) predicate.Mailbox { + v := make([]interface{}, len(vs)) + for i := range v { + v[i] = vs[i] + } + return predicate.Mailbox(func(s *sql.Selector) { + // if not arguments were provided, append the FALSE constants, + // since we can't apply "IN ()". This will make this predicate falsy. + if len(v) == 0 { + s.Where(sql.False()) + return + } + s.Where(sql.NotIn(s.C(FieldGid), v...)) + }) +} + +// GidGT applies the GT predicate on the "gid" field. +func GidGT(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GT(s.C(FieldGid), v)) + }) +} + +// GidGTE applies the GTE predicate on the "gid" field. +func GidGTE(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.GTE(s.C(FieldGid), v)) + }) +} + +// GidLT applies the LT predicate on the "gid" field. +func GidLT(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LT(s.C(FieldGid), v)) + }) +} + +// GidLTE applies the LTE predicate on the "gid" field. +func GidLTE(v int32) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.LTE(s.C(FieldGid), v)) + }) +} + +// GidIsNil applies the IsNil predicate on the "gid" field. +func GidIsNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.IsNull(s.C(FieldGid))) + }) +} + +// GidNotNil applies the NotNil predicate on the "gid" field. +func GidNotNil() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s.Where(sql.NotNull(s.C(FieldGid))) + }) +} + +// HasDomain applies the HasEdge predicate on the "domain" edge. +func HasDomain() predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(DomainTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, DomainTable, DomainColumn), + ) + sqlgraph.HasNeighbors(s, step) + }) +} + +// HasDomainWith applies the HasEdge predicate on the "domain" edge with a given conditions (other predicates). +func HasDomainWith(preds ...predicate.Domain) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + step := sqlgraph.NewStep( + sqlgraph.From(Table, FieldID), + sqlgraph.To(DomainInverseTable, FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, DomainTable, DomainColumn), + ) + sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) { + for _, p := range preds { + p(s) + } + }) + }) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.Mailbox) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for _, p := range predicates { + p(s1) + } + s.Where(s1.P()) + }) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.Mailbox) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + s1 := s.Clone().SetP(nil) + for i, p := range predicates { + if i > 0 { + s1.Or() + } + p(s1) + } + s.Where(s1.P()) + }) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.Mailbox) predicate.Mailbox { + return predicate.Mailbox(func(s *sql.Selector) { + p(s.Not()) + }) +} diff --git a/ent/mailbox_create.go b/ent/mailbox_create.go new file mode 100644 index 0000000..d8b5ce2 --- /dev/null +++ b/ent/mailbox_create.go @@ -0,0 +1,512 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/mailbox" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MailboxCreate is the builder for creating a Mailbox entity. +type MailboxCreate struct { + config + mutation *MailboxMutation + hooks []Hook +} + +// SetActive sets the "active" field. +func (mc *MailboxCreate) SetActive(b bool) *MailboxCreate { + mc.mutation.SetActive(b) + return mc +} + +// SetCreated sets the "created" field. +func (mc *MailboxCreate) SetCreated(t time.Time) *MailboxCreate { + mc.mutation.SetCreated(t) + return mc +} + +// SetNillableCreated sets the "created" field if the given value is not nil. +func (mc *MailboxCreate) SetNillableCreated(t *time.Time) *MailboxCreate { + if t != nil { + mc.SetCreated(*t) + } + return mc +} + +// SetModified sets the "modified" field. +func (mc *MailboxCreate) SetModified(t time.Time) *MailboxCreate { + mc.mutation.SetModified(t) + return mc +} + +// SetNillableModified sets the "modified" field if the given value is not nil. +func (mc *MailboxCreate) SetNillableModified(t *time.Time) *MailboxCreate { + if t != nil { + mc.SetModified(*t) + } + return mc +} + +// SetDomainID sets the "domain_id" field. +func (mc *MailboxCreate) SetDomainID(i int64) *MailboxCreate { + mc.mutation.SetDomainID(i) + return mc +} + +// SetNillableDomainID sets the "domain_id" field if the given value is not nil. +func (mc *MailboxCreate) SetNillableDomainID(i *int64) *MailboxCreate { + if i != nil { + mc.SetDomainID(*i) + } + return mc +} + +// SetUsername sets the "username" field. +func (mc *MailboxCreate) SetUsername(s string) *MailboxCreate { + mc.mutation.SetUsername(s) + return mc +} + +// SetPassword sets the "password" field. +func (mc *MailboxCreate) SetPassword(b []byte) *MailboxCreate { + mc.mutation.SetPassword(b) + return mc +} + +// SetName sets the "name" field. +func (mc *MailboxCreate) SetName(s string) *MailboxCreate { + mc.mutation.SetName(s) + return mc +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (mc *MailboxCreate) SetNillableName(s *string) *MailboxCreate { + if s != nil { + mc.SetName(*s) + } + return mc +} + +// SetQuota sets the "quota" field. +func (mc *MailboxCreate) SetQuota(i int64) *MailboxCreate { + mc.mutation.SetQuota(i) + return mc +} + +// SetLocalPart sets the "local_part" field. +func (mc *MailboxCreate) SetLocalPart(s string) *MailboxCreate { + mc.mutation.SetLocalPart(s) + return mc +} + +// SetHomedir sets the "homedir" field. +func (mc *MailboxCreate) SetHomedir(s string) *MailboxCreate { + mc.mutation.SetHomedir(s) + return mc +} + +// SetNillableHomedir sets the "homedir" field if the given value is not nil. +func (mc *MailboxCreate) SetNillableHomedir(s *string) *MailboxCreate { + if s != nil { + mc.SetHomedir(*s) + } + return mc +} + +// SetMaildir sets the "maildir" field. +func (mc *MailboxCreate) SetMaildir(s string) *MailboxCreate { + mc.mutation.SetMaildir(s) + return mc +} + +// SetNillableMaildir sets the "maildir" field if the given value is not nil. +func (mc *MailboxCreate) SetNillableMaildir(s *string) *MailboxCreate { + if s != nil { + mc.SetMaildir(*s) + } + return mc +} + +// SetUID sets the "uid" field. +func (mc *MailboxCreate) SetUID(i int32) *MailboxCreate { + mc.mutation.SetUID(i) + return mc +} + +// SetNillableUID sets the "uid" field if the given value is not nil. +func (mc *MailboxCreate) SetNillableUID(i *int32) *MailboxCreate { + if i != nil { + mc.SetUID(*i) + } + return mc +} + +// SetGid sets the "gid" field. +func (mc *MailboxCreate) SetGid(i int32) *MailboxCreate { + mc.mutation.SetGid(i) + return mc +} + +// SetNillableGid sets the "gid" field if the given value is not nil. +func (mc *MailboxCreate) SetNillableGid(i *int32) *MailboxCreate { + if i != nil { + mc.SetGid(*i) + } + return mc +} + +// SetID sets the "id" field. +func (mc *MailboxCreate) SetID(i int64) *MailboxCreate { + mc.mutation.SetID(i) + return mc +} + +// SetDomain sets the "domain" edge to the Domain entity. +func (mc *MailboxCreate) SetDomain(d *Domain) *MailboxCreate { + return mc.SetDomainID(d.ID) +} + +// Mutation returns the MailboxMutation object of the builder. +func (mc *MailboxCreate) Mutation() *MailboxMutation { + return mc.mutation +} + +// Save creates the Mailbox in the database. +func (mc *MailboxCreate) Save(ctx context.Context) (*Mailbox, error) { + var ( + err error + node *Mailbox + ) + mc.defaults() + if len(mc.hooks) == 0 { + if err = mc.check(); err != nil { + return nil, err + } + node, err = mc.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MailboxMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err = mc.check(); err != nil { + return nil, err + } + mc.mutation = mutation + if node, err = mc.sqlSave(ctx); err != nil { + return nil, err + } + mutation.id = &node.ID + mutation.done = true + return node, err + }) + for i := len(mc.hooks) - 1; i >= 0; i-- { + if mc.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = mc.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, mc.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX calls Save and panics if Save returns an error. +func (mc *MailboxCreate) SaveX(ctx context.Context) *Mailbox { + v, err := mc.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (mc *MailboxCreate) Exec(ctx context.Context) error { + _, err := mc.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mc *MailboxCreate) ExecX(ctx context.Context) { + if err := mc.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (mc *MailboxCreate) defaults() { + if _, ok := mc.mutation.Created(); !ok { + v := mailbox.DefaultCreated() + mc.mutation.SetCreated(v) + } + if _, ok := mc.mutation.Modified(); !ok { + v := mailbox.DefaultModified() + mc.mutation.SetModified(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (mc *MailboxCreate) check() error { + if _, ok := mc.mutation.Active(); !ok { + return &ValidationError{Name: "active", err: errors.New(`ent: missing required field "Mailbox.active"`)} + } + if _, ok := mc.mutation.Created(); !ok { + return &ValidationError{Name: "created", err: errors.New(`ent: missing required field "Mailbox.created"`)} + } + if _, ok := mc.mutation.Username(); !ok { + return &ValidationError{Name: "username", err: errors.New(`ent: missing required field "Mailbox.username"`)} + } + if _, ok := mc.mutation.Password(); !ok { + return &ValidationError{Name: "password", err: errors.New(`ent: missing required field "Mailbox.password"`)} + } + if _, ok := mc.mutation.Quota(); !ok { + return &ValidationError{Name: "quota", err: errors.New(`ent: missing required field "Mailbox.quota"`)} + } + if _, ok := mc.mutation.LocalPart(); !ok { + return &ValidationError{Name: "local_part", err: errors.New(`ent: missing required field "Mailbox.local_part"`)} + } + return nil +} + +func (mc *MailboxCreate) sqlSave(ctx context.Context) (*Mailbox, error) { + _node, _spec := mc.createSpec() + if err := sqlgraph.CreateNode(ctx, mc.driver, _spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + if _spec.ID.Value != _node.ID { + id := _spec.ID.Value.(int64) + _node.ID = int64(id) + } + return _node, nil +} + +func (mc *MailboxCreate) createSpec() (*Mailbox, *sqlgraph.CreateSpec) { + var ( + _node = &Mailbox{config: mc.config} + _spec = &sqlgraph.CreateSpec{ + Table: mailbox.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + } + ) + if id, ok := mc.mutation.ID(); ok { + _node.ID = id + _spec.ID.Value = id + } + if value, ok := mc.mutation.Active(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: mailbox.FieldActive, + }) + _node.Active = value + } + if value, ok := mc.mutation.Created(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: mailbox.FieldCreated, + }) + _node.Created = value + } + if value, ok := mc.mutation.Modified(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: mailbox.FieldModified, + }) + _node.Modified = &value + } + if value, ok := mc.mutation.Username(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldUsername, + }) + _node.Username = value + } + if value, ok := mc.mutation.Password(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Value: value, + Column: mailbox.FieldPassword, + }) + _node.Password = value + } + if value, ok := mc.mutation.Name(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldName, + }) + _node.Name = &value + } + if value, ok := mc.mutation.Quota(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: mailbox.FieldQuota, + }) + _node.Quota = value + } + if value, ok := mc.mutation.LocalPart(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldLocalPart, + }) + _node.LocalPart = value + } + if value, ok := mc.mutation.Homedir(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldHomedir, + }) + _node.Homedir = &value + } + if value, ok := mc.mutation.Maildir(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldMaildir, + }) + _node.Maildir = &value + } + if value, ok := mc.mutation.UID(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Value: value, + Column: mailbox.FieldUID, + }) + _node.UID = &value + } + if value, ok := mc.mutation.Gid(); ok { + _spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Value: value, + Column: mailbox.FieldGid, + }) + _node.Gid = &value + } + if nodes := mc.mutation.DomainIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: mailbox.DomainTable, + Columns: []string{mailbox.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _node.DomainID = nodes[0] + _spec.Edges = append(_spec.Edges, edge) + } + return _node, _spec +} + +// MailboxCreateBulk is the builder for creating many Mailbox entities in bulk. +type MailboxCreateBulk struct { + config + builders []*MailboxCreate +} + +// Save creates the Mailbox entities in the database. +func (mcb *MailboxCreateBulk) Save(ctx context.Context) ([]*Mailbox, error) { + specs := make([]*sqlgraph.CreateSpec, len(mcb.builders)) + nodes := make([]*Mailbox, len(mcb.builders)) + mutators := make([]Mutator, len(mcb.builders)) + for i := range mcb.builders { + func(i int, root context.Context) { + builder := mcb.builders[i] + builder.defaults() + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MailboxMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + if err := builder.check(); err != nil { + return nil, err + } + builder.mutation = mutation + nodes[i], specs[i] = builder.createSpec() + var err error + if i < len(mutators)-1 { + _, err = mutators[i+1].Mutate(root, mcb.builders[i+1].mutation) + } else { + spec := &sqlgraph.BatchCreateSpec{Nodes: specs} + // Invoke the actual operation on the latest mutation in the chain. + if err = sqlgraph.BatchCreate(ctx, mcb.driver, spec); err != nil { + if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + } + } + if err != nil { + return nil, err + } + mutation.id = &nodes[i].ID + mutation.done = true + if specs[i].ID.Value != nil && nodes[i].ID == 0 { + id := specs[i].ID.Value.(int64) + nodes[i].ID = int64(id) + } + return nodes[i], nil + }) + for i := len(builder.hooks) - 1; i >= 0; i-- { + mut = builder.hooks[i](mut) + } + mutators[i] = mut + }(i, ctx) + } + if len(mutators) > 0 { + if _, err := mutators[0].Mutate(ctx, mcb.builders[0].mutation); err != nil { + return nil, err + } + } + return nodes, nil +} + +// SaveX is like Save, but panics if an error occurs. +func (mcb *MailboxCreateBulk) SaveX(ctx context.Context) []*Mailbox { + v, err := mcb.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (mcb *MailboxCreateBulk) Exec(ctx context.Context) error { + _, err := mcb.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mcb *MailboxCreateBulk) ExecX(ctx context.Context) { + if err := mcb.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/ent/mailbox_delete.go b/ent/mailbox_delete.go new file mode 100644 index 0000000..6f1f405 --- /dev/null +++ b/ent/mailbox_delete.go @@ -0,0 +1,111 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "fmt" + + "code.icod.de/postfix/manager/ent/mailbox" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MailboxDelete is the builder for deleting a Mailbox entity. +type MailboxDelete struct { + config + hooks []Hook + mutation *MailboxMutation +} + +// Where appends a list predicates to the MailboxDelete builder. +func (md *MailboxDelete) Where(ps ...predicate.Mailbox) *MailboxDelete { + md.mutation.Where(ps...) + return md +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (md *MailboxDelete) Exec(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + if len(md.hooks) == 0 { + affected, err = md.sqlExec(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MailboxMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + md.mutation = mutation + affected, err = md.sqlExec(ctx) + mutation.done = true + return affected, err + }) + for i := len(md.hooks) - 1; i >= 0; i-- { + if md.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = md.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, md.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// ExecX is like Exec, but panics if an error occurs. +func (md *MailboxDelete) ExecX(ctx context.Context) int { + n, err := md.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (md *MailboxDelete) sqlExec(ctx context.Context) (int, error) { + _spec := &sqlgraph.DeleteSpec{ + Node: &sqlgraph.NodeSpec{ + Table: mailbox.Table, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + } + if ps := md.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return sqlgraph.DeleteNodes(ctx, md.driver, _spec) +} + +// MailboxDeleteOne is the builder for deleting a single Mailbox entity. +type MailboxDeleteOne struct { + md *MailboxDelete +} + +// Exec executes the deletion query. +func (mdo *MailboxDeleteOne) Exec(ctx context.Context) error { + n, err := mdo.md.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{mailbox.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (mdo *MailboxDeleteOne) ExecX(ctx context.Context) { + mdo.md.ExecX(ctx) +} diff --git a/ent/mailbox_query.go b/ent/mailbox_query.go new file mode 100644 index 0000000..e8ad579 --- /dev/null +++ b/ent/mailbox_query.go @@ -0,0 +1,989 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "math" + + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/mailbox" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MailboxQuery is the builder for querying Mailbox entities. +type MailboxQuery struct { + config + limit *int + offset *int + unique *bool + order []OrderFunc + fields []string + predicates []predicate.Mailbox + // eager-loading edges. + withDomain *DomainQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the MailboxQuery builder. +func (mq *MailboxQuery) Where(ps ...predicate.Mailbox) *MailboxQuery { + mq.predicates = append(mq.predicates, ps...) + return mq +} + +// Limit adds a limit step to the query. +func (mq *MailboxQuery) Limit(limit int) *MailboxQuery { + mq.limit = &limit + return mq +} + +// Offset adds an offset step to the query. +func (mq *MailboxQuery) Offset(offset int) *MailboxQuery { + mq.offset = &offset + return mq +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (mq *MailboxQuery) Unique(unique bool) *MailboxQuery { + mq.unique = &unique + return mq +} + +// Order adds an order step to the query. +func (mq *MailboxQuery) Order(o ...OrderFunc) *MailboxQuery { + mq.order = append(mq.order, o...) + return mq +} + +// QueryDomain chains the current query on the "domain" edge. +func (mq *MailboxQuery) QueryDomain() *DomainQuery { + query := &DomainQuery{config: mq.config} + query.path = func(ctx context.Context) (fromU *sql.Selector, err error) { + if err := mq.prepareQuery(ctx); err != nil { + return nil, err + } + selector := mq.sqlQuery(ctx) + if err := selector.Err(); err != nil { + return nil, err + } + step := sqlgraph.NewStep( + sqlgraph.From(mailbox.Table, mailbox.FieldID, selector), + sqlgraph.To(domain.Table, domain.FieldID), + sqlgraph.Edge(sqlgraph.M2O, true, mailbox.DomainTable, mailbox.DomainColumn), + ) + fromU = sqlgraph.SetNeighbors(mq.driver.Dialect(), step) + return fromU, nil + } + return query +} + +// First returns the first Mailbox entity from the query. +// Returns a *NotFoundError when no Mailbox was found. +func (mq *MailboxQuery) First(ctx context.Context) (*Mailbox, error) { + nodes, err := mq.Limit(1).All(ctx) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{mailbox.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (mq *MailboxQuery) FirstX(ctx context.Context) *Mailbox { + node, err := mq.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first Mailbox ID from the query. +// Returns a *NotFoundError when no Mailbox ID was found. +func (mq *MailboxQuery) FirstID(ctx context.Context) (id int64, err error) { + var ids []int64 + if ids, err = mq.Limit(1).IDs(ctx); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{mailbox.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (mq *MailboxQuery) FirstIDX(ctx context.Context) int64 { + id, err := mq.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single Mailbox entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one Mailbox entity is found. +// Returns a *NotFoundError when no Mailbox entities are found. +func (mq *MailboxQuery) Only(ctx context.Context) (*Mailbox, error) { + nodes, err := mq.Limit(2).All(ctx) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{mailbox.Label} + default: + return nil, &NotSingularError{mailbox.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (mq *MailboxQuery) OnlyX(ctx context.Context) *Mailbox { + node, err := mq.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only Mailbox ID in the query. +// Returns a *NotSingularError when more than one Mailbox ID is found. +// Returns a *NotFoundError when no entities are found. +func (mq *MailboxQuery) OnlyID(ctx context.Context) (id int64, err error) { + var ids []int64 + if ids, err = mq.Limit(2).IDs(ctx); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{mailbox.Label} + default: + err = &NotSingularError{mailbox.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (mq *MailboxQuery) OnlyIDX(ctx context.Context) int64 { + id, err := mq.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of Mailboxes. +func (mq *MailboxQuery) All(ctx context.Context) ([]*Mailbox, error) { + if err := mq.prepareQuery(ctx); err != nil { + return nil, err + } + return mq.sqlAll(ctx) +} + +// AllX is like All, but panics if an error occurs. +func (mq *MailboxQuery) AllX(ctx context.Context) []*Mailbox { + nodes, err := mq.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of Mailbox IDs. +func (mq *MailboxQuery) IDs(ctx context.Context) ([]int64, error) { + var ids []int64 + if err := mq.Select(mailbox.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (mq *MailboxQuery) IDsX(ctx context.Context) []int64 { + ids, err := mq.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (mq *MailboxQuery) Count(ctx context.Context) (int, error) { + if err := mq.prepareQuery(ctx); err != nil { + return 0, err + } + return mq.sqlCount(ctx) +} + +// CountX is like Count, but panics if an error occurs. +func (mq *MailboxQuery) CountX(ctx context.Context) int { + count, err := mq.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (mq *MailboxQuery) Exist(ctx context.Context) (bool, error) { + if err := mq.prepareQuery(ctx); err != nil { + return false, err + } + return mq.sqlExist(ctx) +} + +// ExistX is like Exist, but panics if an error occurs. +func (mq *MailboxQuery) ExistX(ctx context.Context) bool { + exist, err := mq.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the MailboxQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (mq *MailboxQuery) Clone() *MailboxQuery { + if mq == nil { + return nil + } + return &MailboxQuery{ + config: mq.config, + limit: mq.limit, + offset: mq.offset, + order: append([]OrderFunc{}, mq.order...), + predicates: append([]predicate.Mailbox{}, mq.predicates...), + withDomain: mq.withDomain.Clone(), + // clone intermediate query. + sql: mq.sql.Clone(), + path: mq.path, + unique: mq.unique, + } +} + +// WithDomain tells the query-builder to eager-load the nodes that are connected to +// the "domain" edge. The optional arguments are used to configure the query builder of the edge. +func (mq *MailboxQuery) WithDomain(opts ...func(*DomainQuery)) *MailboxQuery { + query := &DomainQuery{config: mq.config} + for _, opt := range opts { + opt(query) + } + mq.withDomain = query + return mq +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// Active bool `json:"active,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.Mailbox.Query(). +// GroupBy(mailbox.FieldActive). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +// +func (mq *MailboxQuery) GroupBy(field string, fields ...string) *MailboxGroupBy { + group := &MailboxGroupBy{config: mq.config} + group.fields = append([]string{field}, fields...) + group.path = func(ctx context.Context) (prev *sql.Selector, err error) { + if err := mq.prepareQuery(ctx); err != nil { + return nil, err + } + return mq.sqlQuery(ctx), nil + } + return group +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// Active bool `json:"active,omitempty"` +// } +// +// client.Mailbox.Query(). +// Select(mailbox.FieldActive). +// Scan(ctx, &v) +// +func (mq *MailboxQuery) Select(fields ...string) *MailboxSelect { + mq.fields = append(mq.fields, fields...) + return &MailboxSelect{MailboxQuery: mq} +} + +func (mq *MailboxQuery) prepareQuery(ctx context.Context) error { + for _, f := range mq.fields { + if !mailbox.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if mq.path != nil { + prev, err := mq.path(ctx) + if err != nil { + return err + } + mq.sql = prev + } + return nil +} + +func (mq *MailboxQuery) sqlAll(ctx context.Context) ([]*Mailbox, error) { + var ( + nodes = []*Mailbox{} + _spec = mq.querySpec() + loadedTypes = [1]bool{ + mq.withDomain != nil, + } + ) + _spec.ScanValues = func(columns []string) ([]interface{}, error) { + node := &Mailbox{config: mq.config} + nodes = append(nodes, node) + return node.scanValues(columns) + } + _spec.Assign = func(columns []string, values []interface{}) error { + if len(nodes) == 0 { + return fmt.Errorf("ent: Assign called without calling ScanValues") + } + node := nodes[len(nodes)-1] + node.Edges.loadedTypes = loadedTypes + return node.assignValues(columns, values) + } + if err := sqlgraph.QueryNodes(ctx, mq.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + + if query := mq.withDomain; query != nil { + ids := make([]int64, 0, len(nodes)) + nodeids := make(map[int64][]*Mailbox) + for i := range nodes { + fk := nodes[i].DomainID + if _, ok := nodeids[fk]; !ok { + ids = append(ids, fk) + } + nodeids[fk] = append(nodeids[fk], nodes[i]) + } + query.Where(domain.IDIn(ids...)) + neighbors, err := query.All(ctx) + if err != nil { + return nil, err + } + for _, n := range neighbors { + nodes, ok := nodeids[n.ID] + if !ok { + return nil, fmt.Errorf(`unexpected foreign-key "domain_id" returned %v`, n.ID) + } + for i := range nodes { + nodes[i].Edges.Domain = n + } + } + } + + return nodes, nil +} + +func (mq *MailboxQuery) sqlCount(ctx context.Context) (int, error) { + _spec := mq.querySpec() + _spec.Node.Columns = mq.fields + if len(mq.fields) > 0 { + _spec.Unique = mq.unique != nil && *mq.unique + } + return sqlgraph.CountNodes(ctx, mq.driver, _spec) +} + +func (mq *MailboxQuery) sqlExist(ctx context.Context) (bool, error) { + n, err := mq.sqlCount(ctx) + if err != nil { + return false, fmt.Errorf("ent: check existence: %w", err) + } + return n > 0, nil +} + +func (mq *MailboxQuery) querySpec() *sqlgraph.QuerySpec { + _spec := &sqlgraph.QuerySpec{ + Node: &sqlgraph.NodeSpec{ + Table: mailbox.Table, + Columns: mailbox.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + From: mq.sql, + Unique: true, + } + if unique := mq.unique; unique != nil { + _spec.Unique = *unique + } + if fields := mq.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, mailbox.FieldID) + for i := range fields { + if fields[i] != mailbox.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := mq.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := mq.limit; limit != nil { + _spec.Limit = *limit + } + if offset := mq.offset; offset != nil { + _spec.Offset = *offset + } + if ps := mq.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (mq *MailboxQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(mq.driver.Dialect()) + t1 := builder.Table(mailbox.Table) + columns := mq.fields + if len(columns) == 0 { + columns = mailbox.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if mq.sql != nil { + selector = mq.sql + selector.Select(selector.Columns(columns...)...) + } + if mq.unique != nil && *mq.unique { + selector.Distinct() + } + for _, p := range mq.predicates { + p(selector) + } + for _, p := range mq.order { + p(selector) + } + if offset := mq.offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := mq.limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// MailboxGroupBy is the group-by builder for Mailbox entities. +type MailboxGroupBy struct { + config + fields []string + fns []AggregateFunc + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (mgb *MailboxGroupBy) Aggregate(fns ...AggregateFunc) *MailboxGroupBy { + mgb.fns = append(mgb.fns, fns...) + return mgb +} + +// Scan applies the group-by query and scans the result into the given value. +func (mgb *MailboxGroupBy) Scan(ctx context.Context, v interface{}) error { + query, err := mgb.path(ctx) + if err != nil { + return err + } + mgb.sql = query + return mgb.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (mgb *MailboxGroupBy) ScanX(ctx context.Context, v interface{}) { + if err := mgb.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from group-by. +// It is only allowed when executing a group-by query with one field. +func (mgb *MailboxGroupBy) Strings(ctx context.Context) ([]string, error) { + if len(mgb.fields) > 1 { + return nil, errors.New("ent: MailboxGroupBy.Strings is not achievable when grouping more than 1 field") + } + var v []string + if err := mgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (mgb *MailboxGroupBy) StringsX(ctx context.Context) []string { + v, err := mgb.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (mgb *MailboxGroupBy) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = mgb.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{mailbox.Label} + default: + err = fmt.Errorf("ent: MailboxGroupBy.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (mgb *MailboxGroupBy) StringX(ctx context.Context) string { + v, err := mgb.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from group-by. +// It is only allowed when executing a group-by query with one field. +func (mgb *MailboxGroupBy) Ints(ctx context.Context) ([]int, error) { + if len(mgb.fields) > 1 { + return nil, errors.New("ent: MailboxGroupBy.Ints is not achievable when grouping more than 1 field") + } + var v []int + if err := mgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (mgb *MailboxGroupBy) IntsX(ctx context.Context) []int { + v, err := mgb.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (mgb *MailboxGroupBy) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = mgb.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{mailbox.Label} + default: + err = fmt.Errorf("ent: MailboxGroupBy.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (mgb *MailboxGroupBy) IntX(ctx context.Context) int { + v, err := mgb.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from group-by. +// It is only allowed when executing a group-by query with one field. +func (mgb *MailboxGroupBy) Float64s(ctx context.Context) ([]float64, error) { + if len(mgb.fields) > 1 { + return nil, errors.New("ent: MailboxGroupBy.Float64s is not achievable when grouping more than 1 field") + } + var v []float64 + if err := mgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (mgb *MailboxGroupBy) Float64sX(ctx context.Context) []float64 { + v, err := mgb.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (mgb *MailboxGroupBy) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = mgb.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{mailbox.Label} + default: + err = fmt.Errorf("ent: MailboxGroupBy.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (mgb *MailboxGroupBy) Float64X(ctx context.Context) float64 { + v, err := mgb.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from group-by. +// It is only allowed when executing a group-by query with one field. +func (mgb *MailboxGroupBy) Bools(ctx context.Context) ([]bool, error) { + if len(mgb.fields) > 1 { + return nil, errors.New("ent: MailboxGroupBy.Bools is not achievable when grouping more than 1 field") + } + var v []bool + if err := mgb.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (mgb *MailboxGroupBy) BoolsX(ctx context.Context) []bool { + v, err := mgb.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a group-by query. +// It is only allowed when executing a group-by query with one field. +func (mgb *MailboxGroupBy) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = mgb.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{mailbox.Label} + default: + err = fmt.Errorf("ent: MailboxGroupBy.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (mgb *MailboxGroupBy) BoolX(ctx context.Context) bool { + v, err := mgb.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (mgb *MailboxGroupBy) sqlScan(ctx context.Context, v interface{}) error { + for _, f := range mgb.fields { + if !mailbox.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("invalid field %q for group-by", f)} + } + } + selector := mgb.sqlQuery() + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := mgb.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +func (mgb *MailboxGroupBy) sqlQuery() *sql.Selector { + selector := mgb.sql.Select() + aggregation := make([]string, 0, len(mgb.fns)) + for _, fn := range mgb.fns { + aggregation = append(aggregation, fn(selector)) + } + // If no columns were selected in a custom aggregation function, the default + // selection is the fields used for "group-by", and the aggregation functions. + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(mgb.fields)+len(mgb.fns)) + for _, f := range mgb.fields { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + return selector.GroupBy(selector.Columns(mgb.fields...)...) +} + +// MailboxSelect is the builder for selecting fields of Mailbox entities. +type MailboxSelect struct { + *MailboxQuery + // intermediate query (i.e. traversal path). + sql *sql.Selector +} + +// Scan applies the selector query and scans the result into the given value. +func (ms *MailboxSelect) Scan(ctx context.Context, v interface{}) error { + if err := ms.prepareQuery(ctx); err != nil { + return err + } + ms.sql = ms.MailboxQuery.sqlQuery(ctx) + return ms.sqlScan(ctx, v) +} + +// ScanX is like Scan, but panics if an error occurs. +func (ms *MailboxSelect) ScanX(ctx context.Context, v interface{}) { + if err := ms.Scan(ctx, v); err != nil { + panic(err) + } +} + +// Strings returns list of strings from a selector. It is only allowed when selecting one field. +func (ms *MailboxSelect) Strings(ctx context.Context) ([]string, error) { + if len(ms.fields) > 1 { + return nil, errors.New("ent: MailboxSelect.Strings is not achievable when selecting more than 1 field") + } + var v []string + if err := ms.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// StringsX is like Strings, but panics if an error occurs. +func (ms *MailboxSelect) StringsX(ctx context.Context) []string { + v, err := ms.Strings(ctx) + if err != nil { + panic(err) + } + return v +} + +// String returns a single string from a selector. It is only allowed when selecting one field. +func (ms *MailboxSelect) String(ctx context.Context) (_ string, err error) { + var v []string + if v, err = ms.Strings(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{mailbox.Label} + default: + err = fmt.Errorf("ent: MailboxSelect.Strings returned %d results when one was expected", len(v)) + } + return +} + +// StringX is like String, but panics if an error occurs. +func (ms *MailboxSelect) StringX(ctx context.Context) string { + v, err := ms.String(ctx) + if err != nil { + panic(err) + } + return v +} + +// Ints returns list of ints from a selector. It is only allowed when selecting one field. +func (ms *MailboxSelect) Ints(ctx context.Context) ([]int, error) { + if len(ms.fields) > 1 { + return nil, errors.New("ent: MailboxSelect.Ints is not achievable when selecting more than 1 field") + } + var v []int + if err := ms.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// IntsX is like Ints, but panics if an error occurs. +func (ms *MailboxSelect) IntsX(ctx context.Context) []int { + v, err := ms.Ints(ctx) + if err != nil { + panic(err) + } + return v +} + +// Int returns a single int from a selector. It is only allowed when selecting one field. +func (ms *MailboxSelect) Int(ctx context.Context) (_ int, err error) { + var v []int + if v, err = ms.Ints(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{mailbox.Label} + default: + err = fmt.Errorf("ent: MailboxSelect.Ints returned %d results when one was expected", len(v)) + } + return +} + +// IntX is like Int, but panics if an error occurs. +func (ms *MailboxSelect) IntX(ctx context.Context) int { + v, err := ms.Int(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64s returns list of float64s from a selector. It is only allowed when selecting one field. +func (ms *MailboxSelect) Float64s(ctx context.Context) ([]float64, error) { + if len(ms.fields) > 1 { + return nil, errors.New("ent: MailboxSelect.Float64s is not achievable when selecting more than 1 field") + } + var v []float64 + if err := ms.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// Float64sX is like Float64s, but panics if an error occurs. +func (ms *MailboxSelect) Float64sX(ctx context.Context) []float64 { + v, err := ms.Float64s(ctx) + if err != nil { + panic(err) + } + return v +} + +// Float64 returns a single float64 from a selector. It is only allowed when selecting one field. +func (ms *MailboxSelect) Float64(ctx context.Context) (_ float64, err error) { + var v []float64 + if v, err = ms.Float64s(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{mailbox.Label} + default: + err = fmt.Errorf("ent: MailboxSelect.Float64s returned %d results when one was expected", len(v)) + } + return +} + +// Float64X is like Float64, but panics if an error occurs. +func (ms *MailboxSelect) Float64X(ctx context.Context) float64 { + v, err := ms.Float64(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bools returns list of bools from a selector. It is only allowed when selecting one field. +func (ms *MailboxSelect) Bools(ctx context.Context) ([]bool, error) { + if len(ms.fields) > 1 { + return nil, errors.New("ent: MailboxSelect.Bools is not achievable when selecting more than 1 field") + } + var v []bool + if err := ms.Scan(ctx, &v); err != nil { + return nil, err + } + return v, nil +} + +// BoolsX is like Bools, but panics if an error occurs. +func (ms *MailboxSelect) BoolsX(ctx context.Context) []bool { + v, err := ms.Bools(ctx) + if err != nil { + panic(err) + } + return v +} + +// Bool returns a single bool from a selector. It is only allowed when selecting one field. +func (ms *MailboxSelect) Bool(ctx context.Context) (_ bool, err error) { + var v []bool + if v, err = ms.Bools(ctx); err != nil { + return + } + switch len(v) { + case 1: + return v[0], nil + case 0: + err = &NotFoundError{mailbox.Label} + default: + err = fmt.Errorf("ent: MailboxSelect.Bools returned %d results when one was expected", len(v)) + } + return +} + +// BoolX is like Bool, but panics if an error occurs. +func (ms *MailboxSelect) BoolX(ctx context.Context) bool { + v, err := ms.Bool(ctx) + if err != nil { + panic(err) + } + return v +} + +func (ms *MailboxSelect) sqlScan(ctx context.Context, v interface{}) error { + rows := &sql.Rows{} + query, args := ms.sql.Query() + if err := ms.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} diff --git a/ent/mailbox_update.go b/ent/mailbox_update.go new file mode 100644 index 0000000..e34e3cd --- /dev/null +++ b/ent/mailbox_update.go @@ -0,0 +1,985 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "errors" + "fmt" + "time" + + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/mailbox" + "code.icod.de/postfix/manager/ent/predicate" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// MailboxUpdate is the builder for updating Mailbox entities. +type MailboxUpdate struct { + config + hooks []Hook + mutation *MailboxMutation +} + +// Where appends a list predicates to the MailboxUpdate builder. +func (mu *MailboxUpdate) Where(ps ...predicate.Mailbox) *MailboxUpdate { + mu.mutation.Where(ps...) + return mu +} + +// SetActive sets the "active" field. +func (mu *MailboxUpdate) SetActive(b bool) *MailboxUpdate { + mu.mutation.SetActive(b) + return mu +} + +// SetModified sets the "modified" field. +func (mu *MailboxUpdate) SetModified(t time.Time) *MailboxUpdate { + mu.mutation.SetModified(t) + return mu +} + +// ClearModified clears the value of the "modified" field. +func (mu *MailboxUpdate) ClearModified() *MailboxUpdate { + mu.mutation.ClearModified() + return mu +} + +// SetDomainID sets the "domain_id" field. +func (mu *MailboxUpdate) SetDomainID(i int64) *MailboxUpdate { + mu.mutation.SetDomainID(i) + return mu +} + +// SetNillableDomainID sets the "domain_id" field if the given value is not nil. +func (mu *MailboxUpdate) SetNillableDomainID(i *int64) *MailboxUpdate { + if i != nil { + mu.SetDomainID(*i) + } + return mu +} + +// ClearDomainID clears the value of the "domain_id" field. +func (mu *MailboxUpdate) ClearDomainID() *MailboxUpdate { + mu.mutation.ClearDomainID() + return mu +} + +// SetUsername sets the "username" field. +func (mu *MailboxUpdate) SetUsername(s string) *MailboxUpdate { + mu.mutation.SetUsername(s) + return mu +} + +// SetPassword sets the "password" field. +func (mu *MailboxUpdate) SetPassword(b []byte) *MailboxUpdate { + mu.mutation.SetPassword(b) + return mu +} + +// SetName sets the "name" field. +func (mu *MailboxUpdate) SetName(s string) *MailboxUpdate { + mu.mutation.SetName(s) + return mu +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (mu *MailboxUpdate) SetNillableName(s *string) *MailboxUpdate { + if s != nil { + mu.SetName(*s) + } + return mu +} + +// ClearName clears the value of the "name" field. +func (mu *MailboxUpdate) ClearName() *MailboxUpdate { + mu.mutation.ClearName() + return mu +} + +// SetQuota sets the "quota" field. +func (mu *MailboxUpdate) SetQuota(i int64) *MailboxUpdate { + mu.mutation.ResetQuota() + mu.mutation.SetQuota(i) + return mu +} + +// AddQuota adds i to the "quota" field. +func (mu *MailboxUpdate) AddQuota(i int64) *MailboxUpdate { + mu.mutation.AddQuota(i) + return mu +} + +// SetLocalPart sets the "local_part" field. +func (mu *MailboxUpdate) SetLocalPart(s string) *MailboxUpdate { + mu.mutation.SetLocalPart(s) + return mu +} + +// SetHomedir sets the "homedir" field. +func (mu *MailboxUpdate) SetHomedir(s string) *MailboxUpdate { + mu.mutation.SetHomedir(s) + return mu +} + +// SetNillableHomedir sets the "homedir" field if the given value is not nil. +func (mu *MailboxUpdate) SetNillableHomedir(s *string) *MailboxUpdate { + if s != nil { + mu.SetHomedir(*s) + } + return mu +} + +// ClearHomedir clears the value of the "homedir" field. +func (mu *MailboxUpdate) ClearHomedir() *MailboxUpdate { + mu.mutation.ClearHomedir() + return mu +} + +// SetMaildir sets the "maildir" field. +func (mu *MailboxUpdate) SetMaildir(s string) *MailboxUpdate { + mu.mutation.SetMaildir(s) + return mu +} + +// SetNillableMaildir sets the "maildir" field if the given value is not nil. +func (mu *MailboxUpdate) SetNillableMaildir(s *string) *MailboxUpdate { + if s != nil { + mu.SetMaildir(*s) + } + return mu +} + +// ClearMaildir clears the value of the "maildir" field. +func (mu *MailboxUpdate) ClearMaildir() *MailboxUpdate { + mu.mutation.ClearMaildir() + return mu +} + +// SetUID sets the "uid" field. +func (mu *MailboxUpdate) SetUID(i int32) *MailboxUpdate { + mu.mutation.ResetUID() + mu.mutation.SetUID(i) + return mu +} + +// SetNillableUID sets the "uid" field if the given value is not nil. +func (mu *MailboxUpdate) SetNillableUID(i *int32) *MailboxUpdate { + if i != nil { + mu.SetUID(*i) + } + return mu +} + +// AddUID adds i to the "uid" field. +func (mu *MailboxUpdate) AddUID(i int32) *MailboxUpdate { + mu.mutation.AddUID(i) + return mu +} + +// ClearUID clears the value of the "uid" field. +func (mu *MailboxUpdate) ClearUID() *MailboxUpdate { + mu.mutation.ClearUID() + return mu +} + +// SetGid sets the "gid" field. +func (mu *MailboxUpdate) SetGid(i int32) *MailboxUpdate { + mu.mutation.ResetGid() + mu.mutation.SetGid(i) + return mu +} + +// SetNillableGid sets the "gid" field if the given value is not nil. +func (mu *MailboxUpdate) SetNillableGid(i *int32) *MailboxUpdate { + if i != nil { + mu.SetGid(*i) + } + return mu +} + +// AddGid adds i to the "gid" field. +func (mu *MailboxUpdate) AddGid(i int32) *MailboxUpdate { + mu.mutation.AddGid(i) + return mu +} + +// ClearGid clears the value of the "gid" field. +func (mu *MailboxUpdate) ClearGid() *MailboxUpdate { + mu.mutation.ClearGid() + return mu +} + +// SetDomain sets the "domain" edge to the Domain entity. +func (mu *MailboxUpdate) SetDomain(d *Domain) *MailboxUpdate { + return mu.SetDomainID(d.ID) +} + +// Mutation returns the MailboxMutation object of the builder. +func (mu *MailboxUpdate) Mutation() *MailboxMutation { + return mu.mutation +} + +// ClearDomain clears the "domain" edge to the Domain entity. +func (mu *MailboxUpdate) ClearDomain() *MailboxUpdate { + mu.mutation.ClearDomain() + return mu +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (mu *MailboxUpdate) Save(ctx context.Context) (int, error) { + var ( + err error + affected int + ) + mu.defaults() + if len(mu.hooks) == 0 { + affected, err = mu.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MailboxMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + mu.mutation = mutation + affected, err = mu.sqlSave(ctx) + mutation.done = true + return affected, err + }) + for i := len(mu.hooks) - 1; i >= 0; i-- { + if mu.hooks[i] == nil { + return 0, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = mu.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, mu.mutation); err != nil { + return 0, err + } + } + return affected, err +} + +// SaveX is like Save, but panics if an error occurs. +func (mu *MailboxUpdate) SaveX(ctx context.Context) int { + affected, err := mu.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (mu *MailboxUpdate) Exec(ctx context.Context) error { + _, err := mu.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (mu *MailboxUpdate) ExecX(ctx context.Context) { + if err := mu.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (mu *MailboxUpdate) defaults() { + if _, ok := mu.mutation.Modified(); !ok && !mu.mutation.ModifiedCleared() { + v := mailbox.UpdateDefaultModified() + mu.mutation.SetModified(v) + } +} + +func (mu *MailboxUpdate) sqlSave(ctx context.Context) (n int, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: mailbox.Table, + Columns: mailbox.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + } + if ps := mu.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := mu.mutation.Active(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: mailbox.FieldActive, + }) + } + if value, ok := mu.mutation.Modified(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: mailbox.FieldModified, + }) + } + if mu.mutation.ModifiedCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: mailbox.FieldModified, + }) + } + if value, ok := mu.mutation.Username(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldUsername, + }) + } + if value, ok := mu.mutation.Password(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Value: value, + Column: mailbox.FieldPassword, + }) + } + if value, ok := mu.mutation.Name(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldName, + }) + } + if mu.mutation.NameCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: mailbox.FieldName, + }) + } + if value, ok := mu.mutation.Quota(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: mailbox.FieldQuota, + }) + } + if value, ok := mu.mutation.AddedQuota(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: mailbox.FieldQuota, + }) + } + if value, ok := mu.mutation.LocalPart(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldLocalPart, + }) + } + if value, ok := mu.mutation.Homedir(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldHomedir, + }) + } + if mu.mutation.HomedirCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: mailbox.FieldHomedir, + }) + } + if value, ok := mu.mutation.Maildir(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldMaildir, + }) + } + if mu.mutation.MaildirCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: mailbox.FieldMaildir, + }) + } + if value, ok := mu.mutation.UID(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Value: value, + Column: mailbox.FieldUID, + }) + } + if value, ok := mu.mutation.AddedUID(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Value: value, + Column: mailbox.FieldUID, + }) + } + if mu.mutation.UIDCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Column: mailbox.FieldUID, + }) + } + if value, ok := mu.mutation.Gid(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Value: value, + Column: mailbox.FieldGid, + }) + } + if value, ok := mu.mutation.AddedGid(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Value: value, + Column: mailbox.FieldGid, + }) + } + if mu.mutation.GidCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Column: mailbox.FieldGid, + }) + } + if mu.mutation.DomainCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: mailbox.DomainTable, + Columns: []string{mailbox.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := mu.mutation.DomainIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: mailbox.DomainTable, + Columns: []string{mailbox.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + if n, err = sqlgraph.UpdateNodes(ctx, mu.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{mailbox.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return 0, err + } + return n, nil +} + +// MailboxUpdateOne is the builder for updating a single Mailbox entity. +type MailboxUpdateOne struct { + config + fields []string + hooks []Hook + mutation *MailboxMutation +} + +// SetActive sets the "active" field. +func (muo *MailboxUpdateOne) SetActive(b bool) *MailboxUpdateOne { + muo.mutation.SetActive(b) + return muo +} + +// SetModified sets the "modified" field. +func (muo *MailboxUpdateOne) SetModified(t time.Time) *MailboxUpdateOne { + muo.mutation.SetModified(t) + return muo +} + +// ClearModified clears the value of the "modified" field. +func (muo *MailboxUpdateOne) ClearModified() *MailboxUpdateOne { + muo.mutation.ClearModified() + return muo +} + +// SetDomainID sets the "domain_id" field. +func (muo *MailboxUpdateOne) SetDomainID(i int64) *MailboxUpdateOne { + muo.mutation.SetDomainID(i) + return muo +} + +// SetNillableDomainID sets the "domain_id" field if the given value is not nil. +func (muo *MailboxUpdateOne) SetNillableDomainID(i *int64) *MailboxUpdateOne { + if i != nil { + muo.SetDomainID(*i) + } + return muo +} + +// ClearDomainID clears the value of the "domain_id" field. +func (muo *MailboxUpdateOne) ClearDomainID() *MailboxUpdateOne { + muo.mutation.ClearDomainID() + return muo +} + +// SetUsername sets the "username" field. +func (muo *MailboxUpdateOne) SetUsername(s string) *MailboxUpdateOne { + muo.mutation.SetUsername(s) + return muo +} + +// SetPassword sets the "password" field. +func (muo *MailboxUpdateOne) SetPassword(b []byte) *MailboxUpdateOne { + muo.mutation.SetPassword(b) + return muo +} + +// SetName sets the "name" field. +func (muo *MailboxUpdateOne) SetName(s string) *MailboxUpdateOne { + muo.mutation.SetName(s) + return muo +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (muo *MailboxUpdateOne) SetNillableName(s *string) *MailboxUpdateOne { + if s != nil { + muo.SetName(*s) + } + return muo +} + +// ClearName clears the value of the "name" field. +func (muo *MailboxUpdateOne) ClearName() *MailboxUpdateOne { + muo.mutation.ClearName() + return muo +} + +// SetQuota sets the "quota" field. +func (muo *MailboxUpdateOne) SetQuota(i int64) *MailboxUpdateOne { + muo.mutation.ResetQuota() + muo.mutation.SetQuota(i) + return muo +} + +// AddQuota adds i to the "quota" field. +func (muo *MailboxUpdateOne) AddQuota(i int64) *MailboxUpdateOne { + muo.mutation.AddQuota(i) + return muo +} + +// SetLocalPart sets the "local_part" field. +func (muo *MailboxUpdateOne) SetLocalPart(s string) *MailboxUpdateOne { + muo.mutation.SetLocalPart(s) + return muo +} + +// SetHomedir sets the "homedir" field. +func (muo *MailboxUpdateOne) SetHomedir(s string) *MailboxUpdateOne { + muo.mutation.SetHomedir(s) + return muo +} + +// SetNillableHomedir sets the "homedir" field if the given value is not nil. +func (muo *MailboxUpdateOne) SetNillableHomedir(s *string) *MailboxUpdateOne { + if s != nil { + muo.SetHomedir(*s) + } + return muo +} + +// ClearHomedir clears the value of the "homedir" field. +func (muo *MailboxUpdateOne) ClearHomedir() *MailboxUpdateOne { + muo.mutation.ClearHomedir() + return muo +} + +// SetMaildir sets the "maildir" field. +func (muo *MailboxUpdateOne) SetMaildir(s string) *MailboxUpdateOne { + muo.mutation.SetMaildir(s) + return muo +} + +// SetNillableMaildir sets the "maildir" field if the given value is not nil. +func (muo *MailboxUpdateOne) SetNillableMaildir(s *string) *MailboxUpdateOne { + if s != nil { + muo.SetMaildir(*s) + } + return muo +} + +// ClearMaildir clears the value of the "maildir" field. +func (muo *MailboxUpdateOne) ClearMaildir() *MailboxUpdateOne { + muo.mutation.ClearMaildir() + return muo +} + +// SetUID sets the "uid" field. +func (muo *MailboxUpdateOne) SetUID(i int32) *MailboxUpdateOne { + muo.mutation.ResetUID() + muo.mutation.SetUID(i) + return muo +} + +// SetNillableUID sets the "uid" field if the given value is not nil. +func (muo *MailboxUpdateOne) SetNillableUID(i *int32) *MailboxUpdateOne { + if i != nil { + muo.SetUID(*i) + } + return muo +} + +// AddUID adds i to the "uid" field. +func (muo *MailboxUpdateOne) AddUID(i int32) *MailboxUpdateOne { + muo.mutation.AddUID(i) + return muo +} + +// ClearUID clears the value of the "uid" field. +func (muo *MailboxUpdateOne) ClearUID() *MailboxUpdateOne { + muo.mutation.ClearUID() + return muo +} + +// SetGid sets the "gid" field. +func (muo *MailboxUpdateOne) SetGid(i int32) *MailboxUpdateOne { + muo.mutation.ResetGid() + muo.mutation.SetGid(i) + return muo +} + +// SetNillableGid sets the "gid" field if the given value is not nil. +func (muo *MailboxUpdateOne) SetNillableGid(i *int32) *MailboxUpdateOne { + if i != nil { + muo.SetGid(*i) + } + return muo +} + +// AddGid adds i to the "gid" field. +func (muo *MailboxUpdateOne) AddGid(i int32) *MailboxUpdateOne { + muo.mutation.AddGid(i) + return muo +} + +// ClearGid clears the value of the "gid" field. +func (muo *MailboxUpdateOne) ClearGid() *MailboxUpdateOne { + muo.mutation.ClearGid() + return muo +} + +// SetDomain sets the "domain" edge to the Domain entity. +func (muo *MailboxUpdateOne) SetDomain(d *Domain) *MailboxUpdateOne { + return muo.SetDomainID(d.ID) +} + +// Mutation returns the MailboxMutation object of the builder. +func (muo *MailboxUpdateOne) Mutation() *MailboxMutation { + return muo.mutation +} + +// ClearDomain clears the "domain" edge to the Domain entity. +func (muo *MailboxUpdateOne) ClearDomain() *MailboxUpdateOne { + muo.mutation.ClearDomain() + return muo +} + +// Select allows selecting one or more fields (columns) of the returned entity. +// The default is selecting all fields defined in the entity schema. +func (muo *MailboxUpdateOne) Select(field string, fields ...string) *MailboxUpdateOne { + muo.fields = append([]string{field}, fields...) + return muo +} + +// Save executes the query and returns the updated Mailbox entity. +func (muo *MailboxUpdateOne) Save(ctx context.Context) (*Mailbox, error) { + var ( + err error + node *Mailbox + ) + muo.defaults() + if len(muo.hooks) == 0 { + node, err = muo.sqlSave(ctx) + } else { + var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) { + mutation, ok := m.(*MailboxMutation) + if !ok { + return nil, fmt.Errorf("unexpected mutation type %T", m) + } + muo.mutation = mutation + node, err = muo.sqlSave(ctx) + mutation.done = true + return node, err + }) + for i := len(muo.hooks) - 1; i >= 0; i-- { + if muo.hooks[i] == nil { + return nil, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)") + } + mut = muo.hooks[i](mut) + } + if _, err := mut.Mutate(ctx, muo.mutation); err != nil { + return nil, err + } + } + return node, err +} + +// SaveX is like Save, but panics if an error occurs. +func (muo *MailboxUpdateOne) SaveX(ctx context.Context) *Mailbox { + node, err := muo.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (muo *MailboxUpdateOne) Exec(ctx context.Context) error { + _, err := muo.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (muo *MailboxUpdateOne) ExecX(ctx context.Context) { + if err := muo.Exec(ctx); err != nil { + panic(err) + } +} + +// defaults sets the default values of the builder before save. +func (muo *MailboxUpdateOne) defaults() { + if _, ok := muo.mutation.Modified(); !ok && !muo.mutation.ModifiedCleared() { + v := mailbox.UpdateDefaultModified() + muo.mutation.SetModified(v) + } +} + +func (muo *MailboxUpdateOne) sqlSave(ctx context.Context) (_node *Mailbox, err error) { + _spec := &sqlgraph.UpdateSpec{ + Node: &sqlgraph.NodeSpec{ + Table: mailbox.Table, + Columns: mailbox.Columns, + ID: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: mailbox.FieldID, + }, + }, + } + id, ok := muo.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Mailbox.id" for update`)} + } + _spec.Node.ID.Value = id + if fields := muo.fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, mailbox.FieldID) + for _, f := range fields { + if !mailbox.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != mailbox.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, f) + } + } + } + if ps := muo.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if value, ok := muo.mutation.Active(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBool, + Value: value, + Column: mailbox.FieldActive, + }) + } + if value, ok := muo.mutation.Modified(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Value: value, + Column: mailbox.FieldModified, + }) + } + if muo.mutation.ModifiedCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeTime, + Column: mailbox.FieldModified, + }) + } + if value, ok := muo.mutation.Username(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldUsername, + }) + } + if value, ok := muo.mutation.Password(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeBytes, + Value: value, + Column: mailbox.FieldPassword, + }) + } + if value, ok := muo.mutation.Name(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldName, + }) + } + if muo.mutation.NameCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: mailbox.FieldName, + }) + } + if value, ok := muo.mutation.Quota(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: mailbox.FieldQuota, + }) + } + if value, ok := muo.mutation.AddedQuota(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Value: value, + Column: mailbox.FieldQuota, + }) + } + if value, ok := muo.mutation.LocalPart(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldLocalPart, + }) + } + if value, ok := muo.mutation.Homedir(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldHomedir, + }) + } + if muo.mutation.HomedirCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: mailbox.FieldHomedir, + }) + } + if value, ok := muo.mutation.Maildir(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Value: value, + Column: mailbox.FieldMaildir, + }) + } + if muo.mutation.MaildirCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeString, + Column: mailbox.FieldMaildir, + }) + } + if value, ok := muo.mutation.UID(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Value: value, + Column: mailbox.FieldUID, + }) + } + if value, ok := muo.mutation.AddedUID(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Value: value, + Column: mailbox.FieldUID, + }) + } + if muo.mutation.UIDCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Column: mailbox.FieldUID, + }) + } + if value, ok := muo.mutation.Gid(); ok { + _spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Value: value, + Column: mailbox.FieldGid, + }) + } + if value, ok := muo.mutation.AddedGid(); ok { + _spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Value: value, + Column: mailbox.FieldGid, + }) + } + if muo.mutation.GidCleared() { + _spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{ + Type: field.TypeInt32, + Column: mailbox.FieldGid, + }) + } + if muo.mutation.DomainCleared() { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: mailbox.DomainTable, + Columns: []string{mailbox.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + _spec.Edges.Clear = append(_spec.Edges.Clear, edge) + } + if nodes := muo.mutation.DomainIDs(); len(nodes) > 0 { + edge := &sqlgraph.EdgeSpec{ + Rel: sqlgraph.M2O, + Inverse: true, + Table: mailbox.DomainTable, + Columns: []string{mailbox.DomainColumn}, + Bidi: false, + Target: &sqlgraph.EdgeTarget{ + IDSpec: &sqlgraph.FieldSpec{ + Type: field.TypeInt64, + Column: domain.FieldID, + }, + }, + } + for _, k := range nodes { + edge.Target.Nodes = append(edge.Target.Nodes, k) + } + _spec.Edges.Add = append(_spec.Edges.Add, edge) + } + _node = &Mailbox{config: muo.config} + _spec.Assign = _node.assignValues + _spec.ScanValues = _node.scanValues + if err = sqlgraph.UpdateNode(ctx, muo.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{mailbox.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{err.Error(), err} + } + return nil, err + } + return _node, nil +} diff --git a/ent/migrate/migrate.go b/ent/migrate/migrate.go new file mode 100644 index 0000000..9bdaf52 --- /dev/null +++ b/ent/migrate/migrate.go @@ -0,0 +1,71 @@ +// Code generated by entc, DO NOT EDIT. + +package migrate + +import ( + "context" + "fmt" + "io" + + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql/schema" +) + +var ( + // WithGlobalUniqueID sets the universal ids options to the migration. + // If this option is enabled, ent migration will allocate a 1<<32 range + // for the ids of each entity (table). + // Note that this option cannot be applied on tables that already exist. + WithGlobalUniqueID = schema.WithGlobalUniqueID + // WithDropColumn sets the drop column option to the migration. + // If this option is enabled, ent migration will drop old columns + // that were used for both fields and edges. This defaults to false. + WithDropColumn = schema.WithDropColumn + // WithDropIndex sets the drop index option to the migration. + // If this option is enabled, ent migration will drop old indexes + // that were defined in the schema. This defaults to false. + // Note that unique constraints are defined using `UNIQUE INDEX`, + // and therefore, it's recommended to enable this option to get more + // flexibility in the schema changes. + WithDropIndex = schema.WithDropIndex + // WithFixture sets the foreign-key renaming option to the migration when upgrading + // ent from v0.1.0 (issue-#285). Defaults to false. + WithFixture = schema.WithFixture + // WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true. + WithForeignKeys = schema.WithForeignKeys +) + +// Schema is the API for creating, migrating and dropping a schema. +type Schema struct { + drv dialect.Driver +} + +// NewSchema creates a new schema client. +func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} } + +// Create creates all schema resources. +func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error { + migrate, err := schema.NewMigrate(s.drv, opts...) + if err != nil { + return fmt.Errorf("ent/migrate: %w", err) + } + return migrate.Create(ctx, Tables...) +} + +// WriteTo writes the schema changes to w instead of running them against the database. +// +// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil { +// log.Fatal(err) +// } +// +func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error { + drv := &schema.WriteDriver{ + Writer: w, + Driver: s.drv, + } + migrate, err := schema.NewMigrate(drv, opts...) + if err != nil { + return fmt.Errorf("ent/migrate: %w", err) + } + return migrate.Create(ctx, Tables...) +} diff --git a/ent/migrate/schema.go b/ent/migrate/schema.go new file mode 100644 index 0000000..86cdf29 --- /dev/null +++ b/ent/migrate/schema.go @@ -0,0 +1,174 @@ +// Code generated by entc, DO NOT EDIT. + +package migrate + +import ( + "entgo.io/ent/dialect/sql/schema" + "entgo.io/ent/schema/field" +) + +var ( + // AccountsColumns holds the columns for the "accounts" table. + AccountsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt64, Increment: true}, + {Name: "created", Type: field.TypeTime}, + {Name: "modified", Type: field.TypeTime, Nullable: true}, + {Name: "username", Type: field.TypeString}, + {Name: "password", Type: field.TypeBytes}, + {Name: "super", Type: field.TypeBool}, + {Name: "active", Type: field.TypeBool}, + } + // AccountsTable holds the schema information for the "accounts" table. + AccountsTable = &schema.Table{ + Name: "accounts", + Columns: AccountsColumns, + PrimaryKey: []*schema.Column{AccountsColumns[0]}, + } + // AliasColumns holds the columns for the "alias" table. + AliasColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt64, Increment: true}, + {Name: "created", Type: field.TypeTime}, + {Name: "modified", Type: field.TypeTime, Nullable: true}, + {Name: "goto", Type: field.TypeString, Size: 2147483647}, + {Name: "active", Type: field.TypeBool}, + {Name: "domain_id", Type: field.TypeInt64, Nullable: true}, + } + // AliasTable holds the schema information for the "alias" table. + AliasTable = &schema.Table{ + Name: "alias", + Columns: AliasColumns, + PrimaryKey: []*schema.Column{AliasColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "alias_domains_aliases", + Columns: []*schema.Column{AliasColumns[5]}, + RefColumns: []*schema.Column{DomainsColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } + // DomainsColumns holds the columns for the "domains" table. + DomainsColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt64, Increment: true}, + {Name: "created", Type: field.TypeTime}, + {Name: "modified", Type: field.TypeTime, Nullable: true}, + {Name: "domain", Type: field.TypeString}, + {Name: "description", Type: field.TypeString, Nullable: true}, + {Name: "max_aliases", Type: field.TypeInt64}, + {Name: "max_mailboxes", Type: field.TypeInt64}, + {Name: "max_quota", Type: field.TypeInt64}, + {Name: "quota", Type: field.TypeInt64}, + {Name: "transport", Type: field.TypeString}, + {Name: "backup_mx", Type: field.TypeBool}, + {Name: "active", Type: field.TypeBool}, + } + // DomainsTable holds the schema information for the "domains" table. + DomainsTable = &schema.Table{ + Name: "domains", + Columns: DomainsColumns, + PrimaryKey: []*schema.Column{DomainsColumns[0]}, + } + // LogentriesColumns holds the columns for the "logentries" table. + LogentriesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt64, Increment: true}, + {Name: "timestamp", Type: field.TypeTime}, + {Name: "action", Type: field.TypeString}, + {Name: "data", Type: field.TypeString, Nullable: true, Size: 2147483647}, + {Name: "account_id", Type: field.TypeInt64, Nullable: true}, + {Name: "domain_id", Type: field.TypeInt64, Nullable: true}, + } + // LogentriesTable holds the schema information for the "logentries" table. + LogentriesTable = &schema.Table{ + Name: "logentries", + Columns: LogentriesColumns, + PrimaryKey: []*schema.Column{LogentriesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "logentries_accounts_logs", + Columns: []*schema.Column{LogentriesColumns[4]}, + RefColumns: []*schema.Column{AccountsColumns[0]}, + OnDelete: schema.SetNull, + }, + { + Symbol: "logentries_domains_logs", + Columns: []*schema.Column{LogentriesColumns[5]}, + RefColumns: []*schema.Column{DomainsColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } + // MailboxesColumns holds the columns for the "mailboxes" table. + MailboxesColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt64, Increment: true}, + {Name: "active", Type: field.TypeBool}, + {Name: "created", Type: field.TypeTime}, + {Name: "modified", Type: field.TypeTime, Nullable: true}, + {Name: "username", Type: field.TypeString}, + {Name: "password", Type: field.TypeBytes}, + {Name: "name", Type: field.TypeString, Nullable: true}, + {Name: "quota", Type: field.TypeInt64}, + {Name: "local_part", Type: field.TypeString}, + {Name: "homedir", Type: field.TypeString, Nullable: true}, + {Name: "maildir", Type: field.TypeString, Nullable: true}, + {Name: "uid", Type: field.TypeInt32, Nullable: true}, + {Name: "gid", Type: field.TypeInt32, Nullable: true}, + {Name: "domain_id", Type: field.TypeInt64, Nullable: true}, + } + // MailboxesTable holds the schema information for the "mailboxes" table. + MailboxesTable = &schema.Table{ + Name: "mailboxes", + Columns: MailboxesColumns, + PrimaryKey: []*schema.Column{MailboxesColumns[0]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "mailboxes_domains_mailboxes", + Columns: []*schema.Column{MailboxesColumns[13]}, + RefColumns: []*schema.Column{DomainsColumns[0]}, + OnDelete: schema.SetNull, + }, + }, + } + // AccountDomainsColumns holds the columns for the "account_domains" table. + AccountDomainsColumns = []*schema.Column{ + {Name: "account_id", Type: field.TypeInt64}, + {Name: "domain_id", Type: field.TypeInt64}, + } + // AccountDomainsTable holds the schema information for the "account_domains" table. + AccountDomainsTable = &schema.Table{ + Name: "account_domains", + Columns: AccountDomainsColumns, + PrimaryKey: []*schema.Column{AccountDomainsColumns[0], AccountDomainsColumns[1]}, + ForeignKeys: []*schema.ForeignKey{ + { + Symbol: "account_domains_account_id", + Columns: []*schema.Column{AccountDomainsColumns[0]}, + RefColumns: []*schema.Column{AccountsColumns[0]}, + OnDelete: schema.Cascade, + }, + { + Symbol: "account_domains_domain_id", + Columns: []*schema.Column{AccountDomainsColumns[1]}, + RefColumns: []*schema.Column{DomainsColumns[0]}, + OnDelete: schema.Cascade, + }, + }, + } + // Tables holds all the tables in the schema. + Tables = []*schema.Table{ + AccountsTable, + AliasTable, + DomainsTable, + LogentriesTable, + MailboxesTable, + AccountDomainsTable, + } +) + +func init() { + AliasTable.ForeignKeys[0].RefTable = DomainsTable + LogentriesTable.ForeignKeys[0].RefTable = AccountsTable + LogentriesTable.ForeignKeys[1].RefTable = DomainsTable + MailboxesTable.ForeignKeys[0].RefTable = DomainsTable + AccountDomainsTable.ForeignKeys[0].RefTable = AccountsTable + AccountDomainsTable.ForeignKeys[1].RefTable = DomainsTable +} diff --git a/ent/mutation.go b/ent/mutation.go new file mode 100644 index 0000000..8fa4d9b --- /dev/null +++ b/ent/mutation.go @@ -0,0 +1,4784 @@ +// 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) +} diff --git a/ent/predicate/predicate.go b/ent/predicate/predicate.go new file mode 100644 index 0000000..a66c741 --- /dev/null +++ b/ent/predicate/predicate.go @@ -0,0 +1,22 @@ +// Code generated by entc, DO NOT EDIT. + +package predicate + +import ( + "entgo.io/ent/dialect/sql" +) + +// Account is the predicate function for account builders. +type Account func(*sql.Selector) + +// Alias is the predicate function for alias builders. +type Alias func(*sql.Selector) + +// Domain is the predicate function for domain builders. +type Domain func(*sql.Selector) + +// Logentry is the predicate function for logentry builders. +type Logentry func(*sql.Selector) + +// Mailbox is the predicate function for mailbox builders. +type Mailbox func(*sql.Selector) diff --git a/ent/runtime.go b/ent/runtime.go new file mode 100644 index 0000000..00c6ccf --- /dev/null +++ b/ent/runtime.go @@ -0,0 +1,74 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "time" + + "code.icod.de/postfix/manager/ent/account" + "code.icod.de/postfix/manager/ent/alias" + "code.icod.de/postfix/manager/ent/domain" + "code.icod.de/postfix/manager/ent/logentry" + "code.icod.de/postfix/manager/ent/mailbox" + "code.icod.de/postfix/manager/ent/schema" +) + +// The init function reads all schema descriptors with runtime code +// (default values, validators, hooks and policies) and stitches it +// to their package variables. +func init() { + accountFields := schema.Account{}.Fields() + _ = accountFields + // accountDescCreated is the schema descriptor for created field. + accountDescCreated := accountFields[1].Descriptor() + // account.DefaultCreated holds the default value on creation for the created field. + account.DefaultCreated = accountDescCreated.Default.(func() time.Time) + // accountDescModified is the schema descriptor for modified field. + accountDescModified := accountFields[2].Descriptor() + // account.DefaultModified holds the default value on creation for the modified field. + account.DefaultModified = accountDescModified.Default.(func() time.Time) + // account.UpdateDefaultModified holds the default value on update for the modified field. + account.UpdateDefaultModified = accountDescModified.UpdateDefault.(func() time.Time) + aliasFields := schema.Alias{}.Fields() + _ = aliasFields + // aliasDescCreated is the schema descriptor for created field. + aliasDescCreated := aliasFields[1].Descriptor() + // alias.DefaultCreated holds the default value on creation for the created field. + alias.DefaultCreated = aliasDescCreated.Default.(func() time.Time) + // aliasDescModified is the schema descriptor for modified field. + aliasDescModified := aliasFields[2].Descriptor() + // alias.DefaultModified holds the default value on creation for the modified field. + alias.DefaultModified = aliasDescModified.Default.(func() time.Time) + // alias.UpdateDefaultModified holds the default value on update for the modified field. + alias.UpdateDefaultModified = aliasDescModified.UpdateDefault.(func() time.Time) + domainFields := schema.Domain{}.Fields() + _ = domainFields + // domainDescCreated is the schema descriptor for created field. + domainDescCreated := domainFields[1].Descriptor() + // domain.DefaultCreated holds the default value on creation for the created field. + domain.DefaultCreated = domainDescCreated.Default.(func() time.Time) + // domainDescModified is the schema descriptor for modified field. + domainDescModified := domainFields[2].Descriptor() + // domain.DefaultModified holds the default value on creation for the modified field. + domain.DefaultModified = domainDescModified.Default.(func() time.Time) + // domain.UpdateDefaultModified holds the default value on update for the modified field. + domain.UpdateDefaultModified = domainDescModified.UpdateDefault.(func() time.Time) + logentryFields := schema.Logentry{}.Fields() + _ = logentryFields + // logentryDescTimestamp is the schema descriptor for timestamp field. + logentryDescTimestamp := logentryFields[1].Descriptor() + // logentry.DefaultTimestamp holds the default value on creation for the timestamp field. + logentry.DefaultTimestamp = logentryDescTimestamp.Default.(func() time.Time) + mailboxFields := schema.Mailbox{}.Fields() + _ = mailboxFields + // mailboxDescCreated is the schema descriptor for created field. + mailboxDescCreated := mailboxFields[2].Descriptor() + // mailbox.DefaultCreated holds the default value on creation for the created field. + mailbox.DefaultCreated = mailboxDescCreated.Default.(func() time.Time) + // mailboxDescModified is the schema descriptor for modified field. + mailboxDescModified := mailboxFields[3].Descriptor() + // mailbox.DefaultModified holds the default value on creation for the modified field. + mailbox.DefaultModified = mailboxDescModified.Default.(func() time.Time) + // mailbox.UpdateDefaultModified holds the default value on update for the modified field. + mailbox.UpdateDefaultModified = mailboxDescModified.UpdateDefault.(func() time.Time) +} diff --git a/ent/runtime/runtime.go b/ent/runtime/runtime.go new file mode 100644 index 0000000..ec247e6 --- /dev/null +++ b/ent/runtime/runtime.go @@ -0,0 +1,10 @@ +// Code generated by entc, DO NOT EDIT. + +package runtime + +// The schema-stitching logic is generated in code.icod.de/postfix/manager/ent/runtime.go + +const ( + Version = "v0.10.1" // Version of ent codegen. + Sum = "h1:dM5h4Zk6yHGIgw4dCqVzGw3nWgpGYJiV4/kyHEF6PFo=" // Sum of ent codegen. +) diff --git a/ent/tx.go b/ent/tx.go new file mode 100644 index 0000000..47a6e22 --- /dev/null +++ b/ent/tx.go @@ -0,0 +1,222 @@ +// Code generated by entc, DO NOT EDIT. + +package ent + +import ( + "context" + "sync" + + "entgo.io/ent/dialect" +) + +// Tx is a transactional client that is created by calling Client.Tx(). +type Tx struct { + config + // Account is the client for interacting with the Account builders. + Account *AccountClient + // Alias is the client for interacting with the Alias builders. + Alias *AliasClient + // Domain is the client for interacting with the Domain builders. + Domain *DomainClient + // Logentry is the client for interacting with the Logentry builders. + Logentry *LogentryClient + // Mailbox is the client for interacting with the Mailbox builders. + Mailbox *MailboxClient + + // lazily loaded. + client *Client + clientOnce sync.Once + + // completion callbacks. + mu sync.Mutex + onCommit []CommitHook + onRollback []RollbackHook + + // ctx lives for the life of the transaction. It is + // the same context used by the underlying connection. + ctx context.Context +} + +type ( + // Committer is the interface that wraps the Commit method. + Committer interface { + Commit(context.Context, *Tx) error + } + + // The CommitFunc type is an adapter to allow the use of ordinary + // function as a Committer. If f is a function with the appropriate + // signature, CommitFunc(f) is a Committer that calls f. + CommitFunc func(context.Context, *Tx) error + + // CommitHook defines the "commit middleware". A function that gets a Committer + // and returns a Committer. For example: + // + // hook := func(next ent.Committer) ent.Committer { + // return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Commit(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + CommitHook func(Committer) Committer +) + +// Commit calls f(ctx, m). +func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Commit commits the transaction. +func (tx *Tx) Commit() error { + txDriver := tx.config.driver.(*txDriver) + var fn Committer = CommitFunc(func(context.Context, *Tx) error { + return txDriver.tx.Commit() + }) + tx.mu.Lock() + hooks := append([]CommitHook(nil), tx.onCommit...) + tx.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Commit(tx.ctx, tx) +} + +// OnCommit adds a hook to call on commit. +func (tx *Tx) OnCommit(f CommitHook) { + tx.mu.Lock() + defer tx.mu.Unlock() + tx.onCommit = append(tx.onCommit, f) +} + +type ( + // Rollbacker is the interface that wraps the Rollback method. + Rollbacker interface { + Rollback(context.Context, *Tx) error + } + + // The RollbackFunc type is an adapter to allow the use of ordinary + // function as a Rollbacker. If f is a function with the appropriate + // signature, RollbackFunc(f) is a Rollbacker that calls f. + RollbackFunc func(context.Context, *Tx) error + + // RollbackHook defines the "rollback middleware". A function that gets a Rollbacker + // and returns a Rollbacker. For example: + // + // hook := func(next ent.Rollbacker) ent.Rollbacker { + // return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error { + // // Do some stuff before. + // if err := next.Rollback(ctx, tx); err != nil { + // return err + // } + // // Do some stuff after. + // return nil + // }) + // } + // + RollbackHook func(Rollbacker) Rollbacker +) + +// Rollback calls f(ctx, m). +func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error { + return f(ctx, tx) +} + +// Rollback rollbacks the transaction. +func (tx *Tx) Rollback() error { + txDriver := tx.config.driver.(*txDriver) + var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error { + return txDriver.tx.Rollback() + }) + tx.mu.Lock() + hooks := append([]RollbackHook(nil), tx.onRollback...) + tx.mu.Unlock() + for i := len(hooks) - 1; i >= 0; i-- { + fn = hooks[i](fn) + } + return fn.Rollback(tx.ctx, tx) +} + +// OnRollback adds a hook to call on rollback. +func (tx *Tx) OnRollback(f RollbackHook) { + tx.mu.Lock() + defer tx.mu.Unlock() + tx.onRollback = append(tx.onRollback, f) +} + +// Client returns a Client that binds to current transaction. +func (tx *Tx) Client() *Client { + tx.clientOnce.Do(func() { + tx.client = &Client{config: tx.config} + tx.client.init() + }) + return tx.client +} + +func (tx *Tx) init() { + tx.Account = NewAccountClient(tx.config) + tx.Alias = NewAliasClient(tx.config) + tx.Domain = NewDomainClient(tx.config) + tx.Logentry = NewLogentryClient(tx.config) + tx.Mailbox = NewMailboxClient(tx.config) +} + +// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation. +// The idea is to support transactions without adding any extra code to the builders. +// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance. +// Commit and Rollback are nop for the internal builders and the user must call one +// of them in order to commit or rollback the transaction. +// +// If a closed transaction is embedded in one of the generated entities, and the entity +// applies a query, for example: Account.QueryXXX(), the query will be executed +// through the driver which created this transaction. +// +// Note that txDriver is not goroutine safe. +type txDriver struct { + // the driver we started the transaction from. + drv dialect.Driver + // tx is the underlying transaction. + tx dialect.Tx +} + +// newTx creates a new transactional driver. +func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) { + tx, err := drv.Tx(ctx) + if err != nil { + return nil, err + } + return &txDriver{tx: tx, drv: drv}, nil +} + +// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls +// from the internal builders. Should be called only by the internal builders. +func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil } + +// Dialect returns the dialect of the driver we started the transaction from. +func (tx *txDriver) Dialect() string { return tx.drv.Dialect() } + +// Close is a nop close. +func (*txDriver) Close() error { return nil } + +// Commit is a nop commit for the internal builders. +// User must call `Tx.Commit` in order to commit the transaction. +func (*txDriver) Commit() error { return nil } + +// Rollback is a nop rollback for the internal builders. +// User must call `Tx.Rollback` in order to rollback the transaction. +func (*txDriver) Rollback() error { return nil } + +// Exec calls tx.Exec. +func (tx *txDriver) Exec(ctx context.Context, query string, args, v interface{}) error { + return tx.tx.Exec(ctx, query, args, v) +} + +// Query calls tx.Query. +func (tx *txDriver) Query(ctx context.Context, query string, args, v interface{}) error { + return tx.tx.Query(ctx, query, args, v) +} + +var _ dialect.Driver = (*txDriver)(nil)