1803 lines
59 KiB
Go
1803 lines
59 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/entc/integration/edgefield/ent/migrate"
|
|
"github.com/google/uuid"
|
|
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/entc/integration/edgefield/ent/car"
|
|
"entgo.io/ent/entc/integration/edgefield/ent/card"
|
|
"entgo.io/ent/entc/integration/edgefield/ent/info"
|
|
"entgo.io/ent/entc/integration/edgefield/ent/metadata"
|
|
"entgo.io/ent/entc/integration/edgefield/ent/node"
|
|
"entgo.io/ent/entc/integration/edgefield/ent/pet"
|
|
"entgo.io/ent/entc/integration/edgefield/ent/post"
|
|
"entgo.io/ent/entc/integration/edgefield/ent/rental"
|
|
"entgo.io/ent/entc/integration/edgefield/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
|
|
// Car is the client for interacting with the Car builders.
|
|
Car *CarClient
|
|
// Card is the client for interacting with the Card builders.
|
|
Card *CardClient
|
|
// Info is the client for interacting with the Info builders.
|
|
Info *InfoClient
|
|
// Metadata is the client for interacting with the Metadata builders.
|
|
Metadata *MetadataClient
|
|
// Node is the client for interacting with the Node builders.
|
|
Node *NodeClient
|
|
// Pet is the client for interacting with the Pet builders.
|
|
Pet *PetClient
|
|
// Post is the client for interacting with the Post builders.
|
|
Post *PostClient
|
|
// Rental is the client for interacting with the Rental builders.
|
|
Rental *RentalClient
|
|
// 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.Car = NewCarClient(c.config)
|
|
c.Card = NewCardClient(c.config)
|
|
c.Info = NewInfoClient(c.config)
|
|
c.Metadata = NewMetadataClient(c.config)
|
|
c.Node = NewNodeClient(c.config)
|
|
c.Pet = NewPetClient(c.config)
|
|
c.Post = NewPostClient(c.config)
|
|
c.Rental = NewRentalClient(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,
|
|
Car: NewCarClient(cfg),
|
|
Card: NewCardClient(cfg),
|
|
Info: NewInfoClient(cfg),
|
|
Metadata: NewMetadataClient(cfg),
|
|
Node: NewNodeClient(cfg),
|
|
Pet: NewPetClient(cfg),
|
|
Post: NewPostClient(cfg),
|
|
Rental: NewRentalClient(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,
|
|
Car: NewCarClient(cfg),
|
|
Card: NewCardClient(cfg),
|
|
Info: NewInfoClient(cfg),
|
|
Metadata: NewMetadataClient(cfg),
|
|
Node: NewNodeClient(cfg),
|
|
Pet: NewPetClient(cfg),
|
|
Post: NewPostClient(cfg),
|
|
Rental: NewRentalClient(cfg),
|
|
User: NewUserClient(cfg),
|
|
}, nil
|
|
}
|
|
|
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
|
//
|
|
// client.Debug().
|
|
// Car.
|
|
// 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.Car, c.Card, c.Info, c.Metadata, c.Node, c.Pet, c.Post, c.Rental, 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.Car, c.Card, c.Info, c.Metadata, c.Node, c.Pet, c.Post, c.Rental, 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 *CarMutation:
|
|
return c.Car.mutate(ctx, m)
|
|
case *CardMutation:
|
|
return c.Card.mutate(ctx, m)
|
|
case *InfoMutation:
|
|
return c.Info.mutate(ctx, m)
|
|
case *MetadataMutation:
|
|
return c.Metadata.mutate(ctx, m)
|
|
case *NodeMutation:
|
|
return c.Node.mutate(ctx, m)
|
|
case *PetMutation:
|
|
return c.Pet.mutate(ctx, m)
|
|
case *PostMutation:
|
|
return c.Post.mutate(ctx, m)
|
|
case *RentalMutation:
|
|
return c.Rental.mutate(ctx, m)
|
|
case *UserMutation:
|
|
return c.User.mutate(ctx, m)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
|
}
|
|
}
|
|
|
|
// CarClient is a client for the Car schema.
|
|
type CarClient struct {
|
|
config
|
|
}
|
|
|
|
// NewCarClient returns a client for the Car from the given config.
|
|
func NewCarClient(c config) *CarClient {
|
|
return &CarClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `car.Hooks(f(g(h())))`.
|
|
func (c *CarClient) Use(hooks ...Hook) {
|
|
c.hooks.Car = append(c.hooks.Car, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `car.Intercept(f(g(h())))`.
|
|
func (c *CarClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Car = append(c.inters.Car, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Car entity.
|
|
func (c *CarClient) Create() *CarCreate {
|
|
mutation := newCarMutation(c.config, OpCreate)
|
|
return &CarCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Car entities.
|
|
func (c *CarClient) CreateBulk(builders ...*CarCreate) *CarCreateBulk {
|
|
return &CarCreateBulk{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 *CarClient) MapCreateBulk(slice any, setFunc func(*CarCreate, int)) *CarCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &CarCreateBulk{err: fmt.Errorf("calling to CarClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*CarCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &CarCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Car.
|
|
func (c *CarClient) Update() *CarUpdate {
|
|
mutation := newCarMutation(c.config, OpUpdate)
|
|
return &CarUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *CarClient) UpdateOne(_m *Car) *CarUpdateOne {
|
|
mutation := newCarMutation(c.config, OpUpdateOne, withCar(_m))
|
|
return &CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *CarClient) UpdateOneID(id uuid.UUID) *CarUpdateOne {
|
|
mutation := newCarMutation(c.config, OpUpdateOne, withCarID(id))
|
|
return &CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Car.
|
|
func (c *CarClient) Delete() *CarDelete {
|
|
mutation := newCarMutation(c.config, OpDelete)
|
|
return &CarDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *CarClient) DeleteOne(_m *Car) *CarDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *CarClient) DeleteOneID(id uuid.UUID) *CarDeleteOne {
|
|
builder := c.Delete().Where(car.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &CarDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Car.
|
|
func (c *CarClient) Query() *CarQuery {
|
|
return &CarQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeCar},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Car entity by its id.
|
|
func (c *CarClient) Get(ctx context.Context, id uuid.UUID) (*Car, error) {
|
|
return c.Query().Where(car.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *CarClient) GetX(ctx context.Context, id uuid.UUID) *Car {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryRentals queries the rentals edge of a Car.
|
|
func (c *CarClient) QueryRentals(_m *Car) *RentalQuery {
|
|
query := (&RentalClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(car.Table, car.FieldID, id),
|
|
sqlgraph.To(rental.Table, rental.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, car.RentalsTable, car.RentalsColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *CarClient) Hooks() []Hook {
|
|
return c.hooks.Car
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *CarClient) Interceptors() []Interceptor {
|
|
return c.inters.Car
|
|
}
|
|
|
|
func (c *CarClient) mutate(ctx context.Context, m *CarMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&CarCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&CarUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&CarUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&CarDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Car mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// 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.O2O, true, card.OwnerTable, card.OwnerColumn),
|
|
)
|
|
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())
|
|
}
|
|
}
|
|
|
|
// InfoClient is a client for the Info schema.
|
|
type InfoClient struct {
|
|
config
|
|
}
|
|
|
|
// NewInfoClient returns a client for the Info from the given config.
|
|
func NewInfoClient(c config) *InfoClient {
|
|
return &InfoClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `info.Hooks(f(g(h())))`.
|
|
func (c *InfoClient) Use(hooks ...Hook) {
|
|
c.hooks.Info = append(c.hooks.Info, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `info.Intercept(f(g(h())))`.
|
|
func (c *InfoClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Info = append(c.inters.Info, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Info entity.
|
|
func (c *InfoClient) Create() *InfoCreate {
|
|
mutation := newInfoMutation(c.config, OpCreate)
|
|
return &InfoCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Info entities.
|
|
func (c *InfoClient) CreateBulk(builders ...*InfoCreate) *InfoCreateBulk {
|
|
return &InfoCreateBulk{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 *InfoClient) MapCreateBulk(slice any, setFunc func(*InfoCreate, int)) *InfoCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &InfoCreateBulk{err: fmt.Errorf("calling to InfoClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*InfoCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &InfoCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Info.
|
|
func (c *InfoClient) Update() *InfoUpdate {
|
|
mutation := newInfoMutation(c.config, OpUpdate)
|
|
return &InfoUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *InfoClient) UpdateOne(_m *Info) *InfoUpdateOne {
|
|
mutation := newInfoMutation(c.config, OpUpdateOne, withInfo(_m))
|
|
return &InfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *InfoClient) UpdateOneID(id int) *InfoUpdateOne {
|
|
mutation := newInfoMutation(c.config, OpUpdateOne, withInfoID(id))
|
|
return &InfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Info.
|
|
func (c *InfoClient) Delete() *InfoDelete {
|
|
mutation := newInfoMutation(c.config, OpDelete)
|
|
return &InfoDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *InfoClient) DeleteOne(_m *Info) *InfoDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *InfoClient) DeleteOneID(id int) *InfoDeleteOne {
|
|
builder := c.Delete().Where(info.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &InfoDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Info.
|
|
func (c *InfoClient) Query() *InfoQuery {
|
|
return &InfoQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeInfo},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Info entity by its id.
|
|
func (c *InfoClient) Get(ctx context.Context, id int) (*Info, error) {
|
|
return c.Query().Where(info.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *InfoClient) GetX(ctx context.Context, id int) *Info {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryUser queries the user edge of a Info.
|
|
func (c *InfoClient) QueryUser(_m *Info) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(info.Table, info.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, false, info.UserTable, info.UserColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *InfoClient) Hooks() []Hook {
|
|
return c.hooks.Info
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *InfoClient) Interceptors() []Interceptor {
|
|
return c.inters.Info
|
|
}
|
|
|
|
func (c *InfoClient) mutate(ctx context.Context, m *InfoMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&InfoCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&InfoUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&InfoUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&InfoDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Info mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// MetadataClient is a client for the Metadata schema.
|
|
type MetadataClient struct {
|
|
config
|
|
}
|
|
|
|
// NewMetadataClient returns a client for the Metadata from the given config.
|
|
func NewMetadataClient(c config) *MetadataClient {
|
|
return &MetadataClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `metadata.Hooks(f(g(h())))`.
|
|
func (c *MetadataClient) Use(hooks ...Hook) {
|
|
c.hooks.Metadata = append(c.hooks.Metadata, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `metadata.Intercept(f(g(h())))`.
|
|
func (c *MetadataClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Metadata = append(c.inters.Metadata, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Metadata entity.
|
|
func (c *MetadataClient) Create() *MetadataCreate {
|
|
mutation := newMetadataMutation(c.config, OpCreate)
|
|
return &MetadataCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Metadata entities.
|
|
func (c *MetadataClient) CreateBulk(builders ...*MetadataCreate) *MetadataCreateBulk {
|
|
return &MetadataCreateBulk{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 *MetadataClient) MapCreateBulk(slice any, setFunc func(*MetadataCreate, int)) *MetadataCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &MetadataCreateBulk{err: fmt.Errorf("calling to MetadataClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*MetadataCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &MetadataCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Metadata.
|
|
func (c *MetadataClient) Update() *MetadataUpdate {
|
|
mutation := newMetadataMutation(c.config, OpUpdate)
|
|
return &MetadataUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *MetadataClient) UpdateOne(_m *Metadata) *MetadataUpdateOne {
|
|
mutation := newMetadataMutation(c.config, OpUpdateOne, withMetadata(_m))
|
|
return &MetadataUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *MetadataClient) UpdateOneID(id int) *MetadataUpdateOne {
|
|
mutation := newMetadataMutation(c.config, OpUpdateOne, withMetadataID(id))
|
|
return &MetadataUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Metadata.
|
|
func (c *MetadataClient) Delete() *MetadataDelete {
|
|
mutation := newMetadataMutation(c.config, OpDelete)
|
|
return &MetadataDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *MetadataClient) DeleteOne(_m *Metadata) *MetadataDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *MetadataClient) DeleteOneID(id int) *MetadataDeleteOne {
|
|
builder := c.Delete().Where(metadata.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &MetadataDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Metadata.
|
|
func (c *MetadataClient) Query() *MetadataQuery {
|
|
return &MetadataQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeMetadata},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Metadata entity by its id.
|
|
func (c *MetadataClient) Get(ctx context.Context, id int) (*Metadata, error) {
|
|
return c.Query().Where(metadata.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *MetadataClient) GetX(ctx context.Context, id int) *Metadata {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryUser queries the user edge of a Metadata.
|
|
func (c *MetadataClient) QueryUser(_m *Metadata) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(metadata.Table, metadata.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2O, true, metadata.UserTable, metadata.UserColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryChildren queries the children edge of a Metadata.
|
|
func (c *MetadataClient) QueryChildren(_m *Metadata) *MetadataQuery {
|
|
query := (&MetadataClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(metadata.Table, metadata.FieldID, id),
|
|
sqlgraph.To(metadata.Table, metadata.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, true, metadata.ChildrenTable, metadata.ChildrenColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryParent queries the parent edge of a Metadata.
|
|
func (c *MetadataClient) QueryParent(_m *Metadata) *MetadataQuery {
|
|
query := (&MetadataClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(metadata.Table, metadata.FieldID, id),
|
|
sqlgraph.To(metadata.Table, metadata.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, false, metadata.ParentTable, metadata.ParentColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *MetadataClient) Hooks() []Hook {
|
|
return c.hooks.Metadata
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *MetadataClient) Interceptors() []Interceptor {
|
|
return c.inters.Metadata
|
|
}
|
|
|
|
func (c *MetadataClient) mutate(ctx context.Context, m *MetadataMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&MetadataCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&MetadataUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&MetadataUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&MetadataDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Metadata mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// NodeClient is a client for the Node schema.
|
|
type NodeClient struct {
|
|
config
|
|
}
|
|
|
|
// NewNodeClient returns a client for the Node from the given config.
|
|
func NewNodeClient(c config) *NodeClient {
|
|
return &NodeClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `node.Hooks(f(g(h())))`.
|
|
func (c *NodeClient) Use(hooks ...Hook) {
|
|
c.hooks.Node = append(c.hooks.Node, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `node.Intercept(f(g(h())))`.
|
|
func (c *NodeClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Node = append(c.inters.Node, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Node entity.
|
|
func (c *NodeClient) Create() *NodeCreate {
|
|
mutation := newNodeMutation(c.config, OpCreate)
|
|
return &NodeCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Node entities.
|
|
func (c *NodeClient) CreateBulk(builders ...*NodeCreate) *NodeCreateBulk {
|
|
return &NodeCreateBulk{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 *NodeClient) MapCreateBulk(slice any, setFunc func(*NodeCreate, int)) *NodeCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &NodeCreateBulk{err: fmt.Errorf("calling to NodeClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*NodeCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &NodeCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Node.
|
|
func (c *NodeClient) Update() *NodeUpdate {
|
|
mutation := newNodeMutation(c.config, OpUpdate)
|
|
return &NodeUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *NodeClient) UpdateOne(_m *Node) *NodeUpdateOne {
|
|
mutation := newNodeMutation(c.config, OpUpdateOne, withNode(_m))
|
|
return &NodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *NodeClient) UpdateOneID(id int) *NodeUpdateOne {
|
|
mutation := newNodeMutation(c.config, OpUpdateOne, withNodeID(id))
|
|
return &NodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Node.
|
|
func (c *NodeClient) Delete() *NodeDelete {
|
|
mutation := newNodeMutation(c.config, OpDelete)
|
|
return &NodeDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *NodeClient) DeleteOne(_m *Node) *NodeDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *NodeClient) DeleteOneID(id int) *NodeDeleteOne {
|
|
builder := c.Delete().Where(node.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &NodeDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Node.
|
|
func (c *NodeClient) Query() *NodeQuery {
|
|
return &NodeQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeNode},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Node entity by its id.
|
|
func (c *NodeClient) Get(ctx context.Context, id int) (*Node, error) {
|
|
return c.Query().Where(node.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *NodeClient) GetX(ctx context.Context, id int) *Node {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryPrev queries the prev edge of a Node.
|
|
func (c *NodeClient) QueryPrev(_m *Node) *NodeQuery {
|
|
query := (&NodeClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(node.Table, node.FieldID, id),
|
|
sqlgraph.To(node.Table, node.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2O, true, node.PrevTable, node.PrevColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryNext queries the next edge of a Node.
|
|
func (c *NodeClient) QueryNext(_m *Node) *NodeQuery {
|
|
query := (&NodeClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(node.Table, node.FieldID, id),
|
|
sqlgraph.To(node.Table, node.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2O, false, node.NextTable, node.NextColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *NodeClient) Hooks() []Hook {
|
|
return c.hooks.Node
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *NodeClient) Interceptors() []Interceptor {
|
|
return c.inters.Node
|
|
}
|
|
|
|
func (c *NodeClient) mutate(ctx context.Context, m *NodeMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&NodeCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&NodeUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&NodeUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&NodeDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Node 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 int) *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 int) *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 int) (*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 int) *Pet {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// 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, true, 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())
|
|
}
|
|
}
|
|
|
|
// PostClient is a client for the Post schema.
|
|
type PostClient struct {
|
|
config
|
|
}
|
|
|
|
// NewPostClient returns a client for the Post from the given config.
|
|
func NewPostClient(c config) *PostClient {
|
|
return &PostClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `post.Hooks(f(g(h())))`.
|
|
func (c *PostClient) Use(hooks ...Hook) {
|
|
c.hooks.Post = append(c.hooks.Post, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `post.Intercept(f(g(h())))`.
|
|
func (c *PostClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Post = append(c.inters.Post, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Post entity.
|
|
func (c *PostClient) Create() *PostCreate {
|
|
mutation := newPostMutation(c.config, OpCreate)
|
|
return &PostCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Post entities.
|
|
func (c *PostClient) CreateBulk(builders ...*PostCreate) *PostCreateBulk {
|
|
return &PostCreateBulk{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 *PostClient) MapCreateBulk(slice any, setFunc func(*PostCreate, int)) *PostCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &PostCreateBulk{err: fmt.Errorf("calling to PostClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*PostCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &PostCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Post.
|
|
func (c *PostClient) Update() *PostUpdate {
|
|
mutation := newPostMutation(c.config, OpUpdate)
|
|
return &PostUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *PostClient) UpdateOne(_m *Post) *PostUpdateOne {
|
|
mutation := newPostMutation(c.config, OpUpdateOne, withPost(_m))
|
|
return &PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *PostClient) UpdateOneID(id int) *PostUpdateOne {
|
|
mutation := newPostMutation(c.config, OpUpdateOne, withPostID(id))
|
|
return &PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Post.
|
|
func (c *PostClient) Delete() *PostDelete {
|
|
mutation := newPostMutation(c.config, OpDelete)
|
|
return &PostDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *PostClient) DeleteOne(_m *Post) *PostDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *PostClient) DeleteOneID(id int) *PostDeleteOne {
|
|
builder := c.Delete().Where(post.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &PostDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Post.
|
|
func (c *PostClient) Query() *PostQuery {
|
|
return &PostQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypePost},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Post entity by its id.
|
|
func (c *PostClient) Get(ctx context.Context, id int) (*Post, error) {
|
|
return c.Query().Where(post.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *PostClient) GetX(ctx context.Context, id int) *Post {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryAuthor queries the author edge of a Post.
|
|
func (c *PostClient) QueryAuthor(_m *Post) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(post.Table, post.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, false, post.AuthorTable, post.AuthorColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *PostClient) Hooks() []Hook {
|
|
return c.hooks.Post
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *PostClient) Interceptors() []Interceptor {
|
|
return c.inters.Post
|
|
}
|
|
|
|
func (c *PostClient) mutate(ctx context.Context, m *PostMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&PostCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&PostUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&PostUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&PostDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Post mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// RentalClient is a client for the Rental schema.
|
|
type RentalClient struct {
|
|
config
|
|
}
|
|
|
|
// NewRentalClient returns a client for the Rental from the given config.
|
|
func NewRentalClient(c config) *RentalClient {
|
|
return &RentalClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `rental.Hooks(f(g(h())))`.
|
|
func (c *RentalClient) Use(hooks ...Hook) {
|
|
c.hooks.Rental = append(c.hooks.Rental, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `rental.Intercept(f(g(h())))`.
|
|
func (c *RentalClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Rental = append(c.inters.Rental, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Rental entity.
|
|
func (c *RentalClient) Create() *RentalCreate {
|
|
mutation := newRentalMutation(c.config, OpCreate)
|
|
return &RentalCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Rental entities.
|
|
func (c *RentalClient) CreateBulk(builders ...*RentalCreate) *RentalCreateBulk {
|
|
return &RentalCreateBulk{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 *RentalClient) MapCreateBulk(slice any, setFunc func(*RentalCreate, int)) *RentalCreateBulk {
|
|
rv := reflect.ValueOf(slice)
|
|
if rv.Kind() != reflect.Slice {
|
|
return &RentalCreateBulk{err: fmt.Errorf("calling to RentalClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
|
}
|
|
builders := make([]*RentalCreate, rv.Len())
|
|
for i := 0; i < rv.Len(); i++ {
|
|
builders[i] = c.Create()
|
|
setFunc(builders[i], i)
|
|
}
|
|
return &RentalCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Rental.
|
|
func (c *RentalClient) Update() *RentalUpdate {
|
|
mutation := newRentalMutation(c.config, OpUpdate)
|
|
return &RentalUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *RentalClient) UpdateOne(_m *Rental) *RentalUpdateOne {
|
|
mutation := newRentalMutation(c.config, OpUpdateOne, withRental(_m))
|
|
return &RentalUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *RentalClient) UpdateOneID(id int) *RentalUpdateOne {
|
|
mutation := newRentalMutation(c.config, OpUpdateOne, withRentalID(id))
|
|
return &RentalUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Rental.
|
|
func (c *RentalClient) Delete() *RentalDelete {
|
|
mutation := newRentalMutation(c.config, OpDelete)
|
|
return &RentalDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *RentalClient) DeleteOne(_m *Rental) *RentalDeleteOne {
|
|
return c.DeleteOneID(_m.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *RentalClient) DeleteOneID(id int) *RentalDeleteOne {
|
|
builder := c.Delete().Where(rental.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.SetOp(OpDeleteOne)
|
|
return &RentalDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Rental.
|
|
func (c *RentalClient) Query() *RentalQuery {
|
|
return &RentalQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeRental},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Rental entity by its id.
|
|
func (c *RentalClient) Get(ctx context.Context, id int) (*Rental, error) {
|
|
return c.Query().Where(rental.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *RentalClient) GetX(ctx context.Context, id int) *Rental {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryUser queries the user edge of a Rental.
|
|
func (c *RentalClient) QueryUser(_m *Rental) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(rental.Table, rental.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, rental.UserTable, rental.UserColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryCar queries the car edge of a Rental.
|
|
func (c *RentalClient) QueryCar(_m *Rental) *CarQuery {
|
|
query := (&CarClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := _m.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(rental.Table, rental.FieldID, id),
|
|
sqlgraph.To(car.Table, car.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, rental.CarTable, rental.CarColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *RentalClient) Hooks() []Hook {
|
|
return c.hooks.Rental
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *RentalClient) Interceptors() []Interceptor {
|
|
return c.inters.Rental
|
|
}
|
|
|
|
func (c *RentalClient) mutate(ctx context.Context, m *RentalMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&RentalCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&RentalUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&RentalUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&RentalDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Rental 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
|
|
}
|
|
|
|
// QueryPets queries the pets edge of a User.
|
|
func (c *UserClient) QueryPets(_m *User) *PetQuery {
|
|
query := (&PetClient{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(pet.Table, pet.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, user.PetsTable, user.PetsColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryParent queries the parent edge of a User.
|
|
func (c *UserClient) QueryParent(_m *User) *UserQuery {
|
|
query := (&UserClient{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(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, user.ParentTable, user.ParentColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryChildren queries the children edge of a User.
|
|
func (c *UserClient) QueryChildren(_m *User) *UserQuery {
|
|
query := (&UserClient{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(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, user.ChildrenTable, user.ChildrenColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QuerySpouse queries the spouse edge of a User.
|
|
func (c *UserClient) QuerySpouse(_m *User) *UserQuery {
|
|
query := (&UserClient{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(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2O, false, user.SpouseTable, user.SpouseColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryCard queries the card edge of a User.
|
|
func (c *UserClient) QueryCard(_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.O2O, false, user.CardTable, user.CardColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryMetadata queries the metadata edge of a User.
|
|
func (c *UserClient) QueryMetadata(_m *User) *MetadataQuery {
|
|
query := (&MetadataClient{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(metadata.Table, metadata.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2O, false, user.MetadataTable, user.MetadataColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryInfo queries the info edge of a User.
|
|
func (c *UserClient) QueryInfo(_m *User) *InfoQuery {
|
|
query := (&InfoClient{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(info.Table, info.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, true, user.InfoTable, user.InfoColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryRentals queries the rentals edge of a User.
|
|
func (c *UserClient) QueryRentals(_m *User) *RentalQuery {
|
|
query := (&RentalClient{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(rental.Table, rental.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, false, user.RentalsTable, user.RentalsColumn),
|
|
)
|
|
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 {
|
|
Car, Card, Info, Metadata, Node, Pet, Post, Rental, User []ent.Hook
|
|
}
|
|
inters struct {
|
|
Car, Card, Info, Metadata, Node, Pet, Post, Rental, User []ent.Interceptor
|
|
}
|
|
)
|