1188 lines
40 KiB
Go
1188 lines
40 KiB
Go
// Copyright 2019-present Facebook Inc. All rights reserved.
|
|
// This source code is licensed under the Apache 2.0 license found
|
|
// in the LICENSE file in the root directory of this source tree.
|
|
|
|
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
"reflect"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/examples/migration/ent/migrate"
|
|
"github.com/google/uuid"
|
|
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/examples/migration/ent/card"
|
|
"entgo.io/ent/examples/migration/ent/payment"
|
|
"entgo.io/ent/examples/migration/ent/pet"
|
|
"entgo.io/ent/examples/migration/ent/session"
|
|
"entgo.io/ent/examples/migration/ent/sessiondevice"
|
|
"entgo.io/ent/examples/migration/ent/user"
|
|
)
|
|
|
|
// 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
|
|
// Card is the client for interacting with the Card builders.
|
|
Card *CardClient
|
|
// Payment is the client for interacting with the Payment builders.
|
|
Payment *PaymentClient
|
|
// Pet is the client for interacting with the Pet builders.
|
|
Pet *PetClient
|
|
// Session is the client for interacting with the Session builders.
|
|
Session *SessionClient
|
|
// SessionDevice is the client for interacting with the SessionDevice builders.
|
|
SessionDevice *SessionDeviceClient
|
|
// User is the client for interacting with the User builders.
|
|
User *UserClient
|
|
}
|
|
|
|
// NewClient creates a new client configured with the given options.
|
|
func NewClient(opts ...Option) *Client {
|
|
client := &Client{config: newConfig(opts...)}
|
|
client.init()
|
|
return client
|
|
}
|
|
|
|
func (c *Client) init() {
|
|
c.Schema = migrate.NewSchema(c.driver)
|
|
c.Card = NewCardClient(c.config)
|
|
c.Payment = NewPaymentClient(c.config)
|
|
c.Pet = NewPetClient(c.config)
|
|
c.Session = NewSessionClient(c.config)
|
|
c.SessionDevice = NewSessionDeviceClient(c.config)
|
|
c.User = NewUserClient(c.config)
|
|
}
|
|
|
|
type (
|
|
// config is the configuration for the client and its builder.
|
|
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(...any)
|
|
// hooks to execute on mutations.
|
|
hooks *hooks
|
|
// interceptors to execute on queries.
|
|
inters *inters
|
|
}
|
|
// Option function to configure the client.
|
|
Option func(*config)
|
|
)
|
|
|
|
// newConfig creates a new config for the client.
|
|
func newConfig(opts ...Option) config {
|
|
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
|
cfg.options(opts...)
|
|
return cfg
|
|
}
|
|
|
|
// 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(...any)) 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
|
|
}
|
|
}
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
|
|
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
|
|
var ErrTxStarted = errors.New("ent: cannot start a transaction within a transaction")
|
|
|
|
// 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, ErrTxStarted
|
|
}
|
|
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,
|
|
Card: NewCardClient(cfg),
|
|
Payment: NewPaymentClient(cfg),
|
|
Pet: NewPetClient(cfg),
|
|
Session: NewSessionClient(cfg),
|
|
SessionDevice: NewSessionDeviceClient(cfg),
|
|
User: NewUserClient(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, errors.New("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,
|
|
Card: NewCardClient(cfg),
|
|
Payment: NewPaymentClient(cfg),
|
|
Pet: NewPetClient(cfg),
|
|
Session: NewSessionClient(cfg),
|
|
SessionDevice: NewSessionDeviceClient(cfg),
|
|
User: NewUserClient(cfg),
|
|
}, nil
|
|
}
|
|
|
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
|
//
|
|
// client.Debug().
|
|
// Card.
|
|
// 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) {
|
|
for _, n := range []interface{ Use(...Hook) }{
|
|
c.Card, c.Payment, c.Pet, c.Session, c.SessionDevice, c.User,
|
|
} {
|
|
n.Use(hooks...)
|
|
}
|
|
}
|
|
|
|
// Intercept adds the query interceptors to all the entity clients.
|
|
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
|
func (c *Client) Intercept(interceptors ...Interceptor) {
|
|
for _, n := range []interface{ Intercept(...Interceptor) }{
|
|
c.Card, c.Payment, c.Pet, c.Session, c.SessionDevice, c.User,
|
|
} {
|
|
n.Intercept(interceptors...)
|
|
}
|
|
}
|
|
|
|
// Mutate implements the ent.Mutator interface.
|
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
|
switch m := m.(type) {
|
|
case *CardMutation:
|
|
return c.Card.mutate(ctx, m)
|
|
case *PaymentMutation:
|
|
return c.Payment.mutate(ctx, m)
|
|
case *PetMutation:
|
|
return c.Pet.mutate(ctx, m)
|
|
case *SessionMutation:
|
|
return c.Session.mutate(ctx, m)
|
|
case *SessionDeviceMutation:
|
|
return c.SessionDevice.mutate(ctx, m)
|
|
case *UserMutation:
|
|
return c.User.mutate(ctx, m)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
|
}
|
|
}
|
|
|
|
// CardClient is a client for the Card schema.
|
|
type CardClient struct {
|
|
config
|
|
}
|
|
|
|
// NewCardClient returns a client for the Card from the given config.
|
|
func NewCardClient(c config) *CardClient {
|
|
return &CardClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `card.Hooks(f(g(h())))`.
|
|
func (c *CardClient) Use(hooks ...Hook) {
|
|
c.hooks.Card = append(c.hooks.Card, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `card.Intercept(f(g(h())))`.
|
|
func (c *CardClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Card = append(c.inters.Card, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Card entity.
|
|
func (c *CardClient) Create() *CardCreate {
|
|
mutation := newCardMutation(c.config, OpCreate)
|
|
return &CardCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Card entities.
|
|
func (c *CardClient) CreateBulk(builders ...*CardCreate) *CardCreateBulk {
|
|
return &CardCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
|
// a builder and applies setFunc on it.
|
|
func (c *CardClient) MapCreateBulk(slice any, setFunc func(*CardCreate, int)) *CardCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &CardCreateBulk{err: fmt.Errorf("calling to CardClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*CardCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &CardCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Card.
|
|
func (c *CardClient) Update() *CardUpdate {
|
|
mutation := newCardMutation(c.config, OpUpdate)
|
|
return &CardUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *CardClient) UpdateOne(_m *Card) *CardUpdateOne {
|
|
mutation := newCardMutation(c.config, OpUpdateOne, withCard(_m))
|
|
return &CardUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *CardClient) UpdateOneID(id int) *CardUpdateOne {
|
|
mutation := newCardMutation(c.config, OpUpdateOne, withCardID(id))
|
|
return &CardUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Card.
|
|
func (c *CardClient) Delete() *CardDelete {
|
|
mutation := newCardMutation(c.config, OpDelete)
|
|
return &CardDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *CardClient) DeleteOne(_m *Card) *CardDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *CardClient) DeleteOneID(id int) *CardDeleteOne {
|
|
builder := c.Delete().Where(card.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &CardDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Card.
|
|
func (c *CardClient) Query() *CardQuery {
|
|
return &CardQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeCard},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Card entity by its id.
|
|
func (c *CardClient) Get(ctx context.Context, id int) (*Card, error) {
|
|
return c.Query().Where(card.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *CardClient) GetX(ctx context.Context, id int) *Card {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryOwner queries the owner edge of a Card.
|
|
func (c *CardClient) QueryOwner(_m *Card) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(card.Table, card.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, card.OwnerTable, card.OwnerColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryPayments queries the payments edge of a Card.
|
|
func (c *CardClient) QueryPayments(_m *Card) *PaymentQuery {
|
|
query := (&PaymentClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(card.Table, card.FieldID, id),
|
|
sqlgraph.To(payment.Table, payment.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, card.PaymentsTable, card.PaymentsColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *CardClient) Hooks() []Hook {
|
|
return c.hooks.Card
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *CardClient) Interceptors() []Interceptor {
|
|
return c.inters.Card
|
|
}
|
|
|
|
func (c *CardClient) mutate(ctx context.Context, m *CardMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&CardCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&CardUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&CardUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&CardDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Card mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// PaymentClient is a client for the Payment schema.
|
|
type PaymentClient struct {
|
|
config
|
|
}
|
|
|
|
// NewPaymentClient returns a client for the Payment from the given config.
|
|
func NewPaymentClient(c config) *PaymentClient {
|
|
return &PaymentClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `payment.Hooks(f(g(h())))`.
|
|
func (c *PaymentClient) Use(hooks ...Hook) {
|
|
c.hooks.Payment = append(c.hooks.Payment, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `payment.Intercept(f(g(h())))`.
|
|
func (c *PaymentClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Payment = append(c.inters.Payment, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Payment entity.
|
|
func (c *PaymentClient) Create() *PaymentCreate {
|
|
mutation := newPaymentMutation(c.config, OpCreate)
|
|
return &PaymentCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Payment entities.
|
|
func (c *PaymentClient) CreateBulk(builders ...*PaymentCreate) *PaymentCreateBulk {
|
|
return &PaymentCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
|
// a builder and applies setFunc on it.
|
|
func (c *PaymentClient) MapCreateBulk(slice any, setFunc func(*PaymentCreate, int)) *PaymentCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &PaymentCreateBulk{err: fmt.Errorf("calling to PaymentClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*PaymentCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &PaymentCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Payment.
|
|
func (c *PaymentClient) Update() *PaymentUpdate {
|
|
mutation := newPaymentMutation(c.config, OpUpdate)
|
|
return &PaymentUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *PaymentClient) UpdateOne(_m *Payment) *PaymentUpdateOne {
|
|
mutation := newPaymentMutation(c.config, OpUpdateOne, withPayment(_m))
|
|
return &PaymentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *PaymentClient) UpdateOneID(id int) *PaymentUpdateOne {
|
|
mutation := newPaymentMutation(c.config, OpUpdateOne, withPaymentID(id))
|
|
return &PaymentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Payment.
|
|
func (c *PaymentClient) Delete() *PaymentDelete {
|
|
mutation := newPaymentMutation(c.config, OpDelete)
|
|
return &PaymentDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *PaymentClient) DeleteOne(_m *Payment) *PaymentDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *PaymentClient) DeleteOneID(id int) *PaymentDeleteOne {
|
|
builder := c.Delete().Where(payment.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &PaymentDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Payment.
|
|
func (c *PaymentClient) Query() *PaymentQuery {
|
|
return &PaymentQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypePayment},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Payment entity by its id.
|
|
func (c *PaymentClient) Get(ctx context.Context, id int) (*Payment, error) {
|
|
return c.Query().Where(payment.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *PaymentClient) GetX(ctx context.Context, id int) *Payment {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryCard queries the card edge of a Payment.
|
|
func (c *PaymentClient) QueryCard(_m *Payment) *CardQuery {
|
|
query := (&CardClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(payment.Table, payment.FieldID, id),
|
|
sqlgraph.To(card.Table, card.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, payment.CardTable, payment.CardColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *PaymentClient) Hooks() []Hook {
|
|
return c.hooks.Payment
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *PaymentClient) Interceptors() []Interceptor {
|
|
return c.inters.Payment
|
|
}
|
|
|
|
func (c *PaymentClient) mutate(ctx context.Context, m *PaymentMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&PaymentCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&PaymentUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&PaymentUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&PaymentDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Payment mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// PetClient is a client for the Pet schema.
|
|
type PetClient struct {
|
|
config
|
|
}
|
|
|
|
// NewPetClient returns a client for the Pet from the given config.
|
|
func NewPetClient(c config) *PetClient {
|
|
return &PetClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `pet.Hooks(f(g(h())))`.
|
|
func (c *PetClient) Use(hooks ...Hook) {
|
|
c.hooks.Pet = append(c.hooks.Pet, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `pet.Intercept(f(g(h())))`.
|
|
func (c *PetClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Pet = append(c.inters.Pet, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Pet entity.
|
|
func (c *PetClient) Create() *PetCreate {
|
|
mutation := newPetMutation(c.config, OpCreate)
|
|
return &PetCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Pet entities.
|
|
func (c *PetClient) CreateBulk(builders ...*PetCreate) *PetCreateBulk {
|
|
return &PetCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
|
// a builder and applies setFunc on it.
|
|
func (c *PetClient) MapCreateBulk(slice any, setFunc func(*PetCreate, int)) *PetCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &PetCreateBulk{err: fmt.Errorf("calling to PetClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*PetCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &PetCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Pet.
|
|
func (c *PetClient) Update() *PetUpdate {
|
|
mutation := newPetMutation(c.config, OpUpdate)
|
|
return &PetUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *PetClient) UpdateOne(_m *Pet) *PetUpdateOne {
|
|
mutation := newPetMutation(c.config, OpUpdateOne, withPet(_m))
|
|
return &PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *PetClient) UpdateOneID(id uuid.UUID) *PetUpdateOne {
|
|
mutation := newPetMutation(c.config, OpUpdateOne, withPetID(id))
|
|
return &PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Pet.
|
|
func (c *PetClient) Delete() *PetDelete {
|
|
mutation := newPetMutation(c.config, OpDelete)
|
|
return &PetDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *PetClient) DeleteOne(_m *Pet) *PetDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *PetClient) DeleteOneID(id uuid.UUID) *PetDeleteOne {
|
|
builder := c.Delete().Where(pet.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &PetDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Pet.
|
|
func (c *PetClient) Query() *PetQuery {
|
|
return &PetQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypePet},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Pet entity by its id.
|
|
func (c *PetClient) Get(ctx context.Context, id uuid.UUID) (*Pet, error) {
|
|
return c.Query().Where(pet.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *PetClient) GetX(ctx context.Context, id uuid.UUID) *Pet {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryBestFriend queries the best_friend edge of a Pet.
|
|
func (c *PetClient) QueryBestFriend(_m *Pet) *PetQuery {
|
|
query := (&PetClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(pet.Table, pet.FieldID, id),
|
|
sqlgraph.To(pet.Table, pet.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2O, false, pet.BestFriendTable, pet.BestFriendColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryOwner queries the owner edge of a Pet.
|
|
func (c *PetClient) QueryOwner(_m *Pet) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(pet.Table, pet.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, false, pet.OwnerTable, pet.OwnerColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *PetClient) Hooks() []Hook {
|
|
return c.hooks.Pet
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *PetClient) Interceptors() []Interceptor {
|
|
return c.inters.Pet
|
|
}
|
|
|
|
func (c *PetClient) mutate(ctx context.Context, m *PetMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&PetCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&PetUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&PetUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&PetDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Pet mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// SessionClient is a client for the Session schema.
|
|
type SessionClient struct {
|
|
config
|
|
}
|
|
|
|
// NewSessionClient returns a client for the Session from the given config.
|
|
func NewSessionClient(c config) *SessionClient {
|
|
return &SessionClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `session.Hooks(f(g(h())))`.
|
|
func (c *SessionClient) Use(hooks ...Hook) {
|
|
c.hooks.Session = append(c.hooks.Session, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `session.Intercept(f(g(h())))`.
|
|
func (c *SessionClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Session = append(c.inters.Session, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Session entity.
|
|
func (c *SessionClient) Create() *SessionCreate {
|
|
mutation := newSessionMutation(c.config, OpCreate)
|
|
return &SessionCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Session entities.
|
|
func (c *SessionClient) CreateBulk(builders ...*SessionCreate) *SessionCreateBulk {
|
|
return &SessionCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
|
// a builder and applies setFunc on it.
|
|
func (c *SessionClient) MapCreateBulk(slice any, setFunc func(*SessionCreate, int)) *SessionCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &SessionCreateBulk{err: fmt.Errorf("calling to SessionClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*SessionCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &SessionCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Session.
|
|
func (c *SessionClient) Update() *SessionUpdate {
|
|
mutation := newSessionMutation(c.config, OpUpdate)
|
|
return &SessionUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *SessionClient) UpdateOne(_m *Session) *SessionUpdateOne {
|
|
mutation := newSessionMutation(c.config, OpUpdateOne, withSession(_m))
|
|
return &SessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *SessionClient) UpdateOneID(id uuid.UUID) *SessionUpdateOne {
|
|
mutation := newSessionMutation(c.config, OpUpdateOne, withSessionID(id))
|
|
return &SessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Session.
|
|
func (c *SessionClient) Delete() *SessionDelete {
|
|
mutation := newSessionMutation(c.config, OpDelete)
|
|
return &SessionDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *SessionClient) DeleteOne(_m *Session) *SessionDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *SessionClient) DeleteOneID(id uuid.UUID) *SessionDeleteOne {
|
|
builder := c.Delete().Where(session.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &SessionDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Session.
|
|
func (c *SessionClient) Query() *SessionQuery {
|
|
return &SessionQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeSession},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Session entity by its id.
|
|
func (c *SessionClient) Get(ctx context.Context, id uuid.UUID) (*Session, error) {
|
|
return c.Query().Where(session.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *SessionClient) GetX(ctx context.Context, id uuid.UUID) *Session {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryDevice queries the device edge of a Session.
|
|
func (c *SessionClient) QueryDevice(_m *Session) *SessionDeviceQuery {
|
|
query := (&SessionDeviceClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(session.Table, session.FieldID, id),
|
|
sqlgraph.To(sessiondevice.Table, sessiondevice.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, session.DeviceTable, session.DeviceColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *SessionClient) Hooks() []Hook {
|
|
return c.hooks.Session
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *SessionClient) Interceptors() []Interceptor {
|
|
return c.inters.Session
|
|
}
|
|
|
|
func (c *SessionClient) mutate(ctx context.Context, m *SessionMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&SessionCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&SessionUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&SessionUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&SessionDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Session mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// SessionDeviceClient is a client for the SessionDevice schema.
|
|
type SessionDeviceClient struct {
|
|
config
|
|
}
|
|
|
|
// NewSessionDeviceClient returns a client for the SessionDevice from the given config.
|
|
func NewSessionDeviceClient(c config) *SessionDeviceClient {
|
|
return &SessionDeviceClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `sessiondevice.Hooks(f(g(h())))`.
|
|
func (c *SessionDeviceClient) Use(hooks ...Hook) {
|
|
c.hooks.SessionDevice = append(c.hooks.SessionDevice, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `sessiondevice.Intercept(f(g(h())))`.
|
|
func (c *SessionDeviceClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.SessionDevice = append(c.inters.SessionDevice, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a SessionDevice entity.
|
|
func (c *SessionDeviceClient) Create() *SessionDeviceCreate {
|
|
mutation := newSessionDeviceMutation(c.config, OpCreate)
|
|
return &SessionDeviceCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of SessionDevice entities.
|
|
func (c *SessionDeviceClient) CreateBulk(builders ...*SessionDeviceCreate) *SessionDeviceCreateBulk {
|
|
return &SessionDeviceCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
|
// a builder and applies setFunc on it.
|
|
func (c *SessionDeviceClient) MapCreateBulk(slice any, setFunc func(*SessionDeviceCreate, int)) *SessionDeviceCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &SessionDeviceCreateBulk{err: fmt.Errorf("calling to SessionDeviceClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*SessionDeviceCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &SessionDeviceCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for SessionDevice.
|
|
func (c *SessionDeviceClient) Update() *SessionDeviceUpdate {
|
|
mutation := newSessionDeviceMutation(c.config, OpUpdate)
|
|
return &SessionDeviceUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *SessionDeviceClient) UpdateOne(_m *SessionDevice) *SessionDeviceUpdateOne {
|
|
mutation := newSessionDeviceMutation(c.config, OpUpdateOne, withSessionDevice(_m))
|
|
return &SessionDeviceUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *SessionDeviceClient) UpdateOneID(id uuid.UUID) *SessionDeviceUpdateOne {
|
|
mutation := newSessionDeviceMutation(c.config, OpUpdateOne, withSessionDeviceID(id))
|
|
return &SessionDeviceUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for SessionDevice.
|
|
func (c *SessionDeviceClient) Delete() *SessionDeviceDelete {
|
|
mutation := newSessionDeviceMutation(c.config, OpDelete)
|
|
return &SessionDeviceDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *SessionDeviceClient) DeleteOne(_m *SessionDevice) *SessionDeviceDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *SessionDeviceClient) DeleteOneID(id uuid.UUID) *SessionDeviceDeleteOne {
|
|
builder := c.Delete().Where(sessiondevice.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &SessionDeviceDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for SessionDevice.
|
|
func (c *SessionDeviceClient) Query() *SessionDeviceQuery {
|
|
return &SessionDeviceQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeSessionDevice},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a SessionDevice entity by its id.
|
|
func (c *SessionDeviceClient) Get(ctx context.Context, id uuid.UUID) (*SessionDevice, error) {
|
|
return c.Query().Where(sessiondevice.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *SessionDeviceClient) GetX(ctx context.Context, id uuid.UUID) *SessionDevice {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QuerySessions queries the sessions edge of a SessionDevice.
|
|
func (c *SessionDeviceClient) QuerySessions(_m *SessionDevice) *SessionQuery {
|
|
query := (&SessionClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(sessiondevice.Table, sessiondevice.FieldID, id),
|
|
sqlgraph.To(session.Table, session.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, sessiondevice.SessionsTable, sessiondevice.SessionsColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *SessionDeviceClient) Hooks() []Hook {
|
|
return c.hooks.SessionDevice
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *SessionDeviceClient) Interceptors() []Interceptor {
|
|
return c.inters.SessionDevice
|
|
}
|
|
|
|
func (c *SessionDeviceClient) mutate(ctx context.Context, m *SessionDeviceMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&SessionDeviceCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&SessionDeviceUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&SessionDeviceUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&SessionDeviceDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown SessionDevice mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// UserClient is a client for the User schema.
|
|
type UserClient struct {
|
|
config
|
|
}
|
|
|
|
// NewUserClient returns a client for the User from the given config.
|
|
func NewUserClient(c config) *UserClient {
|
|
return &UserClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `user.Hooks(f(g(h())))`.
|
|
func (c *UserClient) Use(hooks ...Hook) {
|
|
c.hooks.User = append(c.hooks.User, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `user.Intercept(f(g(h())))`.
|
|
func (c *UserClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.User = append(c.inters.User, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a User entity.
|
|
func (c *UserClient) Create() *UserCreate {
|
|
mutation := newUserMutation(c.config, OpCreate)
|
|
return &UserCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of User entities.
|
|
func (c *UserClient) CreateBulk(builders ...*UserCreate) *UserCreateBulk {
|
|
return &UserCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
|
// a builder and applies setFunc on it.
|
|
func (c *UserClient) MapCreateBulk(slice any, setFunc func(*UserCreate, int)) *UserCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &UserCreateBulk{err: fmt.Errorf("calling to UserClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*UserCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &UserCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for User.
|
|
func (c *UserClient) Update() *UserUpdate {
|
|
mutation := newUserMutation(c.config, OpUpdate)
|
|
return &UserUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *UserClient) UpdateOne(_m *User) *UserUpdateOne {
|
|
mutation := newUserMutation(c.config, OpUpdateOne, withUser(_m))
|
|
return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *UserClient) UpdateOneID(id int) *UserUpdateOne {
|
|
mutation := newUserMutation(c.config, OpUpdateOne, withUserID(id))
|
|
return &UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for User.
|
|
func (c *UserClient) Delete() *UserDelete {
|
|
mutation := newUserMutation(c.config, OpDelete)
|
|
return &UserDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *UserClient) DeleteOne(_m *User) *UserDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *UserClient) DeleteOneID(id int) *UserDeleteOne {
|
|
builder := c.Delete().Where(user.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &UserDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for User.
|
|
func (c *UserClient) Query() *UserQuery {
|
|
return &UserQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeUser},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a User entity by its id.
|
|
func (c *UserClient) Get(ctx context.Context, id int) (*User, error) {
|
|
return c.Query().Where(user.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *UserClient) GetX(ctx context.Context, id int) *User {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryCards queries the cards edge of a User.
|
|
func (c *UserClient) QueryCards(_m *User) *CardQuery {
|
|
query := (&CardClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(user.Table, user.FieldID, id),
|
|
sqlgraph.To(card.Table, card.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, user.CardsTable, user.CardsColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *UserClient) Hooks() []Hook {
|
|
return c.hooks.User
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *UserClient) Interceptors() []Interceptor {
|
|
return c.inters.User
|
|
}
|
|
|
|
func (c *UserClient) mutate(ctx context.Context, m *UserMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&UserCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&UserUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&UserUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&UserDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown User mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// hooks and interceptors per client, for fast access.
|
|
type (
|
|
hooks struct {
|
|
Card, Payment, Pet, Session, SessionDevice, User []ent.Hook
|
|
}
|
|
inters struct {
|
|
Card, Payment, Pet, Session, SessionDevice, User []ent.Interceptor
|
|
}
|
|
)
|