// Code generated by ent, DO NOT EDIT. package ent import ( "context" "errors" "fmt" "log" "reflect" "github.com/fatedier/frp/pkg/db/ent/migrate" "entgo.io/ent" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" "github.com/fatedier/frp/pkg/db/ent/frpcclient" "github.com/fatedier/frp/pkg/db/ent/proxy" "github.com/fatedier/frp/pkg/db/ent/serverconfig" "github.com/fatedier/frp/pkg/db/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 // FrpcClient is the client for interacting with the FrpcClient builders. FrpcClient *FrpcClientClient // Proxy is the client for interacting with the Proxy builders. Proxy *ProxyClient // ServerConfig is the client for interacting with the ServerConfig builders. ServerConfig *ServerConfigClient // 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.FrpcClient = NewFrpcClientClient(c.config) c.Proxy = NewProxyClient(c.config) c.ServerConfig = NewServerConfigClient(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, FrpcClient: NewFrpcClientClient(cfg), Proxy: NewProxyClient(cfg), ServerConfig: NewServerConfigClient(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, FrpcClient: NewFrpcClientClient(cfg), Proxy: NewProxyClient(cfg), ServerConfig: NewServerConfigClient(cfg), User: NewUserClient(cfg), }, nil } // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). // FrpcClient. // Query(). // Count(ctx) func (c *Client) Debug() *Client { if c.debug { return c } cfg := c.config cfg.driver = dialect.Debug(c.driver, c.log) client := &Client{config: cfg} client.init() return client } // Close closes the database connection and prevents new queries from starting. func (c *Client) Close() error { return c.driver.Close() } // Use adds the mutation hooks to all the entity clients. // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { c.FrpcClient.Use(hooks...) c.Proxy.Use(hooks...) c.ServerConfig.Use(hooks...) c.User.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) { c.FrpcClient.Intercept(interceptors...) c.Proxy.Intercept(interceptors...) c.ServerConfig.Intercept(interceptors...) c.User.Intercept(interceptors...) } // Mutate implements the ent.Mutator interface. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { switch m := m.(type) { case *FrpcClientMutation: return c.FrpcClient.mutate(ctx, m) case *ProxyMutation: return c.Proxy.mutate(ctx, m) case *ServerConfigMutation: return c.ServerConfig.mutate(ctx, m) case *UserMutation: return c.User.mutate(ctx, m) default: return nil, fmt.Errorf("ent: unknown mutation type %T", m) } } // FrpcClientClient is a client for the FrpcClient schema. type FrpcClientClient struct { config } // NewFrpcClientClient returns a client for the FrpcClient from the given config. func NewFrpcClientClient(c config) *FrpcClientClient { return &FrpcClientClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `frpcclient.Hooks(f(g(h())))`. func (c *FrpcClientClient) Use(hooks ...Hook) { c.hooks.FrpcClient = append(c.hooks.FrpcClient, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `frpcclient.Intercept(f(g(h())))`. func (c *FrpcClientClient) Intercept(interceptors ...Interceptor) { c.inters.FrpcClient = append(c.inters.FrpcClient, interceptors...) } // Create returns a builder for creating a FrpcClient entity. func (c *FrpcClientClient) Create() *FrpcClientCreate { mutation := newFrpcClientMutation(c.config, OpCreate) return &FrpcClientCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of FrpcClient entities. func (c *FrpcClientClient) CreateBulk(builders ...*FrpcClientCreate) *FrpcClientCreateBulk { return &FrpcClientCreateBulk{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 *FrpcClientClient) MapCreateBulk(slice any, setFunc func(*FrpcClientCreate, int)) *FrpcClientCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &FrpcClientCreateBulk{err: fmt.Errorf("calling to FrpcClientClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*FrpcClientCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &FrpcClientCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for FrpcClient. func (c *FrpcClientClient) Update() *FrpcClientUpdate { mutation := newFrpcClientMutation(c.config, OpUpdate) return &FrpcClientUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *FrpcClientClient) UpdateOne(_m *FrpcClient) *FrpcClientUpdateOne { mutation := newFrpcClientMutation(c.config, OpUpdateOne, withFrpcClient(_m)) return &FrpcClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *FrpcClientClient) UpdateOneID(id int) *FrpcClientUpdateOne { mutation := newFrpcClientMutation(c.config, OpUpdateOne, withFrpcClientID(id)) return &FrpcClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for FrpcClient. func (c *FrpcClientClient) Delete() *FrpcClientDelete { mutation := newFrpcClientMutation(c.config, OpDelete) return &FrpcClientDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *FrpcClientClient) DeleteOne(_m *FrpcClient) *FrpcClientDeleteOne { return c.DeleteOneID(_m.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *FrpcClientClient) DeleteOneID(id int) *FrpcClientDeleteOne { builder := c.Delete().Where(frpcclient.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &FrpcClientDeleteOne{builder} } // Query returns a query builder for FrpcClient. func (c *FrpcClientClient) Query() *FrpcClientQuery { return &FrpcClientQuery{ config: c.config, ctx: &QueryContext{Type: TypeFrpcClient}, inters: c.Interceptors(), } } // Get returns a FrpcClient entity by its id. func (c *FrpcClientClient) Get(ctx context.Context, id int) (*FrpcClient, error) { return c.Query().Where(frpcclient.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *FrpcClientClient) GetX(ctx context.Context, id int) *FrpcClient { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *FrpcClientClient) Hooks() []Hook { return c.hooks.FrpcClient } // Interceptors returns the client interceptors. func (c *FrpcClientClient) Interceptors() []Interceptor { return c.inters.FrpcClient } func (c *FrpcClientClient) mutate(ctx context.Context, m *FrpcClientMutation) (Value, error) { switch m.Op() { case OpCreate: return (&FrpcClientCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&FrpcClientUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&FrpcClientUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&FrpcClientDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown FrpcClient mutation op: %q", m.Op()) } } // ProxyClient is a client for the Proxy schema. type ProxyClient struct { config } // NewProxyClient returns a client for the Proxy from the given config. func NewProxyClient(c config) *ProxyClient { return &ProxyClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `proxy.Hooks(f(g(h())))`. func (c *ProxyClient) Use(hooks ...Hook) { c.hooks.Proxy = append(c.hooks.Proxy, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `proxy.Intercept(f(g(h())))`. func (c *ProxyClient) Intercept(interceptors ...Interceptor) { c.inters.Proxy = append(c.inters.Proxy, interceptors...) } // Create returns a builder for creating a Proxy entity. func (c *ProxyClient) Create() *ProxyCreate { mutation := newProxyMutation(c.config, OpCreate) return &ProxyCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of Proxy entities. func (c *ProxyClient) CreateBulk(builders ...*ProxyCreate) *ProxyCreateBulk { return &ProxyCreateBulk{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 *ProxyClient) MapCreateBulk(slice any, setFunc func(*ProxyCreate, int)) *ProxyCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &ProxyCreateBulk{err: fmt.Errorf("calling to ProxyClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*ProxyCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &ProxyCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for Proxy. func (c *ProxyClient) Update() *ProxyUpdate { mutation := newProxyMutation(c.config, OpUpdate) return &ProxyUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *ProxyClient) UpdateOne(_m *Proxy) *ProxyUpdateOne { mutation := newProxyMutation(c.config, OpUpdateOne, withProxy(_m)) return &ProxyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *ProxyClient) UpdateOneID(id int) *ProxyUpdateOne { mutation := newProxyMutation(c.config, OpUpdateOne, withProxyID(id)) return &ProxyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for Proxy. func (c *ProxyClient) Delete() *ProxyDelete { mutation := newProxyMutation(c.config, OpDelete) return &ProxyDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *ProxyClient) DeleteOne(_m *Proxy) *ProxyDeleteOne { return c.DeleteOneID(_m.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *ProxyClient) DeleteOneID(id int) *ProxyDeleteOne { builder := c.Delete().Where(proxy.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &ProxyDeleteOne{builder} } // Query returns a query builder for Proxy. func (c *ProxyClient) Query() *ProxyQuery { return &ProxyQuery{ config: c.config, ctx: &QueryContext{Type: TypeProxy}, inters: c.Interceptors(), } } // Get returns a Proxy entity by its id. func (c *ProxyClient) Get(ctx context.Context, id int) (*Proxy, error) { return c.Query().Where(proxy.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *ProxyClient) GetX(ctx context.Context, id int) *Proxy { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *ProxyClient) Hooks() []Hook { return c.hooks.Proxy } // Interceptors returns the client interceptors. func (c *ProxyClient) Interceptors() []Interceptor { return c.inters.Proxy } func (c *ProxyClient) mutate(ctx context.Context, m *ProxyMutation) (Value, error) { switch m.Op() { case OpCreate: return (&ProxyCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&ProxyUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&ProxyUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&ProxyDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown Proxy mutation op: %q", m.Op()) } } // ServerConfigClient is a client for the ServerConfig schema. type ServerConfigClient struct { config } // NewServerConfigClient returns a client for the ServerConfig from the given config. func NewServerConfigClient(c config) *ServerConfigClient { return &ServerConfigClient{config: c} } // Use adds a list of mutation hooks to the hooks stack. // A call to `Use(f, g, h)` equals to `serverconfig.Hooks(f(g(h())))`. func (c *ServerConfigClient) Use(hooks ...Hook) { c.hooks.ServerConfig = append(c.hooks.ServerConfig, hooks...) } // Intercept adds a list of query interceptors to the interceptors stack. // A call to `Intercept(f, g, h)` equals to `serverconfig.Intercept(f(g(h())))`. func (c *ServerConfigClient) Intercept(interceptors ...Interceptor) { c.inters.ServerConfig = append(c.inters.ServerConfig, interceptors...) } // Create returns a builder for creating a ServerConfig entity. func (c *ServerConfigClient) Create() *ServerConfigCreate { mutation := newServerConfigMutation(c.config, OpCreate) return &ServerConfigCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // CreateBulk returns a builder for creating a bulk of ServerConfig entities. func (c *ServerConfigClient) CreateBulk(builders ...*ServerConfigCreate) *ServerConfigCreateBulk { return &ServerConfigCreateBulk{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 *ServerConfigClient) MapCreateBulk(slice any, setFunc func(*ServerConfigCreate, int)) *ServerConfigCreateBulk { rv := reflect.ValueOf(slice) if rv.Kind() != reflect.Slice { return &ServerConfigCreateBulk{err: fmt.Errorf("calling to ServerConfigClient.MapCreateBulk with wrong type %T, need slice", slice)} } builders := make([]*ServerConfigCreate, rv.Len()) for i := 0; i < rv.Len(); i++ { builders[i] = c.Create() setFunc(builders[i], i) } return &ServerConfigCreateBulk{config: c.config, builders: builders} } // Update returns an update builder for ServerConfig. func (c *ServerConfigClient) Update() *ServerConfigUpdate { mutation := newServerConfigMutation(c.config, OpUpdate) return &ServerConfigUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOne returns an update builder for the given entity. func (c *ServerConfigClient) UpdateOne(_m *ServerConfig) *ServerConfigUpdateOne { mutation := newServerConfigMutation(c.config, OpUpdateOne, withServerConfig(_m)) return &ServerConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // UpdateOneID returns an update builder for the given id. func (c *ServerConfigClient) UpdateOneID(id int) *ServerConfigUpdateOne { mutation := newServerConfigMutation(c.config, OpUpdateOne, withServerConfigID(id)) return &ServerConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} } // Delete returns a delete builder for ServerConfig. func (c *ServerConfigClient) Delete() *ServerConfigDelete { mutation := newServerConfigMutation(c.config, OpDelete) return &ServerConfigDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} } // DeleteOne returns a builder for deleting the given entity. func (c *ServerConfigClient) DeleteOne(_m *ServerConfig) *ServerConfigDeleteOne { return c.DeleteOneID(_m.ID) } // DeleteOneID returns a builder for deleting the given entity by its id. func (c *ServerConfigClient) DeleteOneID(id int) *ServerConfigDeleteOne { builder := c.Delete().Where(serverconfig.ID(id)) builder.mutation.id = &id builder.mutation.op = OpDeleteOne return &ServerConfigDeleteOne{builder} } // Query returns a query builder for ServerConfig. func (c *ServerConfigClient) Query() *ServerConfigQuery { return &ServerConfigQuery{ config: c.config, ctx: &QueryContext{Type: TypeServerConfig}, inters: c.Interceptors(), } } // Get returns a ServerConfig entity by its id. func (c *ServerConfigClient) Get(ctx context.Context, id int) (*ServerConfig, error) { return c.Query().Where(serverconfig.ID(id)).Only(ctx) } // GetX is like Get, but panics if an error occurs. func (c *ServerConfigClient) GetX(ctx context.Context, id int) *ServerConfig { obj, err := c.Get(ctx, id) if err != nil { panic(err) } return obj } // Hooks returns the client hooks. func (c *ServerConfigClient) Hooks() []Hook { return c.hooks.ServerConfig } // Interceptors returns the client interceptors. func (c *ServerConfigClient) Interceptors() []Interceptor { return c.inters.ServerConfig } func (c *ServerConfigClient) mutate(ctx context.Context, m *ServerConfigMutation) (Value, error) { switch m.Op() { case OpCreate: return (&ServerConfigCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdate: return (&ServerConfigUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpUpdateOne: return (&ServerConfigUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) case OpDelete, OpDeleteOne: return (&ServerConfigDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) default: return nil, fmt.Errorf("ent: unknown ServerConfig 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.op = 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 } // 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 { FrpcClient, Proxy, ServerConfig, User []ent.Hook } inters struct { FrpcClient, Proxy, ServerConfig, User []ent.Interceptor } )