manager/ent/client.go

763 lines
24 KiB
Go
Raw Normal View History

2022-04-08 21:26:25 +02:00
// Code generated by entc, DO NOT EDIT.
package ent
import (
"context"
"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
}