798 lines
26 KiB
Go
798 lines
26 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/xmdhs/authlib-skin/db/ent/migrate"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"github.com/xmdhs/authlib-skin/db/ent/skin"
|
|
"github.com/xmdhs/authlib-skin/db/ent/user"
|
|
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
|
"github.com/xmdhs/authlib-skin/db/ent/usertoken"
|
|
)
|
|
|
|
// 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
|
|
// Skin is the client for interacting with the Skin builders.
|
|
Skin *SkinClient
|
|
// User is the client for interacting with the User builders.
|
|
User *UserClient
|
|
// UserProfile is the client for interacting with the UserProfile builders.
|
|
UserProfile *UserProfileClient
|
|
// UserToken is the client for interacting with the UserToken builders.
|
|
UserToken *UserTokenClient
|
|
}
|
|
|
|
// NewClient creates a new client configured with the given options.
|
|
func NewClient(opts ...Option) *Client {
|
|
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
|
|
cfg.options(opts...)
|
|
client := &Client{config: cfg}
|
|
client.init()
|
|
return client
|
|
}
|
|
|
|
func (c *Client) init() {
|
|
c.Schema = migrate.NewSchema(c.driver)
|
|
c.Skin = NewSkinClient(c.config)
|
|
c.User = NewUserClient(c.config)
|
|
c.UserProfile = NewUserProfileClient(c.config)
|
|
c.UserToken = NewUserTokenClient(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)
|
|
)
|
|
|
|
// 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)
|
|
}
|
|
}
|
|
|
|
// 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, errors.New("ent: cannot start a transaction within a transaction")
|
|
}
|
|
tx, err := newTx(ctx, c.driver)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
|
|
}
|
|
cfg := c.config
|
|
cfg.driver = tx
|
|
return &Tx{
|
|
ctx: ctx,
|
|
config: cfg,
|
|
Skin: NewSkinClient(cfg),
|
|
User: NewUserClient(cfg),
|
|
UserProfile: NewUserProfileClient(cfg),
|
|
UserToken: NewUserTokenClient(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,
|
|
Skin: NewSkinClient(cfg),
|
|
User: NewUserClient(cfg),
|
|
UserProfile: NewUserProfileClient(cfg),
|
|
UserToken: NewUserTokenClient(cfg),
|
|
}, nil
|
|
}
|
|
|
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
|
//
|
|
// client.Debug().
|
|
// Skin.
|
|
// 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.Skin.Use(hooks...)
|
|
c.User.Use(hooks...)
|
|
c.UserProfile.Use(hooks...)
|
|
c.UserToken.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.Skin.Intercept(interceptors...)
|
|
c.User.Intercept(interceptors...)
|
|
c.UserProfile.Intercept(interceptors...)
|
|
c.UserToken.Intercept(interceptors...)
|
|
}
|
|
|
|
// Mutate implements the ent.Mutator interface.
|
|
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
|
switch m := m.(type) {
|
|
case *SkinMutation:
|
|
return c.Skin.mutate(ctx, m)
|
|
case *UserMutation:
|
|
return c.User.mutate(ctx, m)
|
|
case *UserProfileMutation:
|
|
return c.UserProfile.mutate(ctx, m)
|
|
case *UserTokenMutation:
|
|
return c.UserToken.mutate(ctx, m)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
|
}
|
|
}
|
|
|
|
// SkinClient is a client for the Skin schema.
|
|
type SkinClient struct {
|
|
config
|
|
}
|
|
|
|
// NewSkinClient returns a client for the Skin from the given config.
|
|
func NewSkinClient(c config) *SkinClient {
|
|
return &SkinClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `skin.Hooks(f(g(h())))`.
|
|
func (c *SkinClient) Use(hooks ...Hook) {
|
|
c.hooks.Skin = append(c.hooks.Skin, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `skin.Intercept(f(g(h())))`.
|
|
func (c *SkinClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Skin = append(c.inters.Skin, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Skin entity.
|
|
func (c *SkinClient) Create() *SkinCreate {
|
|
mutation := newSkinMutation(c.config, OpCreate)
|
|
return &SkinCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Skin entities.
|
|
func (c *SkinClient) CreateBulk(builders ...*SkinCreate) *SkinCreateBulk {
|
|
return &SkinCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Skin.
|
|
func (c *SkinClient) Update() *SkinUpdate {
|
|
mutation := newSkinMutation(c.config, OpUpdate)
|
|
return &SkinUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *SkinClient) UpdateOne(s *Skin) *SkinUpdateOne {
|
|
mutation := newSkinMutation(c.config, OpUpdateOne, withSkin(s))
|
|
return &SkinUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *SkinClient) UpdateOneID(id int) *SkinUpdateOne {
|
|
mutation := newSkinMutation(c.config, OpUpdateOne, withSkinID(id))
|
|
return &SkinUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Skin.
|
|
func (c *SkinClient) Delete() *SkinDelete {
|
|
mutation := newSkinMutation(c.config, OpDelete)
|
|
return &SkinDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *SkinClient) DeleteOne(s *Skin) *SkinDeleteOne {
|
|
return c.DeleteOneID(s.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *SkinClient) DeleteOneID(id int) *SkinDeleteOne {
|
|
builder := c.Delete().Where(skin.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &SkinDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Skin.
|
|
func (c *SkinClient) Query() *SkinQuery {
|
|
return &SkinQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeSkin},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Skin entity by its id.
|
|
func (c *SkinClient) Get(ctx context.Context, id int) (*Skin, error) {
|
|
return c.Query().Where(skin.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *SkinClient) GetX(ctx context.Context, id int) *Skin {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryCreatedUser queries the created_user edge of a Skin.
|
|
func (c *SkinClient) QueryCreatedUser(s *Skin) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := s.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(skin.Table, skin.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, false, skin.CreatedUserTable, skin.CreatedUserColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *SkinClient) Hooks() []Hook {
|
|
return c.hooks.Skin
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *SkinClient) Interceptors() []Interceptor {
|
|
return c.inters.Skin
|
|
}
|
|
|
|
func (c *SkinClient) mutate(ctx context.Context, m *SkinMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&SkinCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&SkinUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&SkinUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&SkinDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Skin 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}
|
|
}
|
|
|
|
// 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(u *User) *UserUpdateOne {
|
|
mutation := newUserMutation(c.config, OpUpdateOne, withUser(u))
|
|
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(u *User) *UserDeleteOne {
|
|
return c.DeleteOneID(u.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
|
|
}
|
|
|
|
// QueryCreatedSkin queries the created_skin edge of a User.
|
|
func (c *UserClient) QueryCreatedSkin(u *User) *SkinQuery {
|
|
query := (&SkinClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := u.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(user.Table, user.FieldID, id),
|
|
sqlgraph.To(skin.Table, skin.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, true, user.CreatedSkinTable, user.CreatedSkinColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryProfile queries the profile edge of a User.
|
|
func (c *UserClient) QueryProfile(u *User) *UserProfileQuery {
|
|
query := (&UserProfileClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := u.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(user.Table, user.FieldID, id),
|
|
sqlgraph.To(userprofile.Table, userprofile.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2O, false, user.ProfileTable, user.ProfileColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryToken queries the token edge of a User.
|
|
func (c *UserClient) QueryToken(u *User) *UserTokenQuery {
|
|
query := (&UserTokenClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := u.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(user.Table, user.FieldID, id),
|
|
sqlgraph.To(usertoken.Table, usertoken.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, false, user.TokenTable, user.TokenColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(u.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QuerySkin queries the skin edge of a User.
|
|
func (c *UserClient) QuerySkin(u *User) *SkinQuery {
|
|
query := (&SkinClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := u.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(user.Table, user.FieldID, id),
|
|
sqlgraph.To(skin.Table, skin.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, false, user.SkinTable, user.SkinColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(u.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())
|
|
}
|
|
}
|
|
|
|
// UserProfileClient is a client for the UserProfile schema.
|
|
type UserProfileClient struct {
|
|
config
|
|
}
|
|
|
|
// NewUserProfileClient returns a client for the UserProfile from the given config.
|
|
func NewUserProfileClient(c config) *UserProfileClient {
|
|
return &UserProfileClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `userprofile.Hooks(f(g(h())))`.
|
|
func (c *UserProfileClient) Use(hooks ...Hook) {
|
|
c.hooks.UserProfile = append(c.hooks.UserProfile, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `userprofile.Intercept(f(g(h())))`.
|
|
func (c *UserProfileClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.UserProfile = append(c.inters.UserProfile, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a UserProfile entity.
|
|
func (c *UserProfileClient) Create() *UserProfileCreate {
|
|
mutation := newUserProfileMutation(c.config, OpCreate)
|
|
return &UserProfileCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of UserProfile entities.
|
|
func (c *UserProfileClient) CreateBulk(builders ...*UserProfileCreate) *UserProfileCreateBulk {
|
|
return &UserProfileCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for UserProfile.
|
|
func (c *UserProfileClient) Update() *UserProfileUpdate {
|
|
mutation := newUserProfileMutation(c.config, OpUpdate)
|
|
return &UserProfileUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *UserProfileClient) UpdateOne(up *UserProfile) *UserProfileUpdateOne {
|
|
mutation := newUserProfileMutation(c.config, OpUpdateOne, withUserProfile(up))
|
|
return &UserProfileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *UserProfileClient) UpdateOneID(id int) *UserProfileUpdateOne {
|
|
mutation := newUserProfileMutation(c.config, OpUpdateOne, withUserProfileID(id))
|
|
return &UserProfileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for UserProfile.
|
|
func (c *UserProfileClient) Delete() *UserProfileDelete {
|
|
mutation := newUserProfileMutation(c.config, OpDelete)
|
|
return &UserProfileDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *UserProfileClient) DeleteOne(up *UserProfile) *UserProfileDeleteOne {
|
|
return c.DeleteOneID(up.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *UserProfileClient) DeleteOneID(id int) *UserProfileDeleteOne {
|
|
builder := c.Delete().Where(userprofile.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &UserProfileDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for UserProfile.
|
|
func (c *UserProfileClient) Query() *UserProfileQuery {
|
|
return &UserProfileQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeUserProfile},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a UserProfile entity by its id.
|
|
func (c *UserProfileClient) Get(ctx context.Context, id int) (*UserProfile, error) {
|
|
return c.Query().Where(userprofile.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *UserProfileClient) GetX(ctx context.Context, id int) *UserProfile {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryUser queries the user edge of a UserProfile.
|
|
func (c *UserProfileClient) QueryUser(up *UserProfile) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := up.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(userprofile.Table, userprofile.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2O, true, userprofile.UserTable, userprofile.UserColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(up.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *UserProfileClient) Hooks() []Hook {
|
|
return c.hooks.UserProfile
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *UserProfileClient) Interceptors() []Interceptor {
|
|
return c.inters.UserProfile
|
|
}
|
|
|
|
func (c *UserProfileClient) mutate(ctx context.Context, m *UserProfileMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&UserProfileCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&UserProfileUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&UserProfileUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&UserProfileDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown UserProfile mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// UserTokenClient is a client for the UserToken schema.
|
|
type UserTokenClient struct {
|
|
config
|
|
}
|
|
|
|
// NewUserTokenClient returns a client for the UserToken from the given config.
|
|
func NewUserTokenClient(c config) *UserTokenClient {
|
|
return &UserTokenClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `usertoken.Hooks(f(g(h())))`.
|
|
func (c *UserTokenClient) Use(hooks ...Hook) {
|
|
c.hooks.UserToken = append(c.hooks.UserToken, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `usertoken.Intercept(f(g(h())))`.
|
|
func (c *UserTokenClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.UserToken = append(c.inters.UserToken, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a UserToken entity.
|
|
func (c *UserTokenClient) Create() *UserTokenCreate {
|
|
mutation := newUserTokenMutation(c.config, OpCreate)
|
|
return &UserTokenCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of UserToken entities.
|
|
func (c *UserTokenClient) CreateBulk(builders ...*UserTokenCreate) *UserTokenCreateBulk {
|
|
return &UserTokenCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for UserToken.
|
|
func (c *UserTokenClient) Update() *UserTokenUpdate {
|
|
mutation := newUserTokenMutation(c.config, OpUpdate)
|
|
return &UserTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *UserTokenClient) UpdateOne(ut *UserToken) *UserTokenUpdateOne {
|
|
mutation := newUserTokenMutation(c.config, OpUpdateOne, withUserToken(ut))
|
|
return &UserTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *UserTokenClient) UpdateOneID(id int) *UserTokenUpdateOne {
|
|
mutation := newUserTokenMutation(c.config, OpUpdateOne, withUserTokenID(id))
|
|
return &UserTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for UserToken.
|
|
func (c *UserTokenClient) Delete() *UserTokenDelete {
|
|
mutation := newUserTokenMutation(c.config, OpDelete)
|
|
return &UserTokenDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *UserTokenClient) DeleteOne(ut *UserToken) *UserTokenDeleteOne {
|
|
return c.DeleteOneID(ut.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *UserTokenClient) DeleteOneID(id int) *UserTokenDeleteOne {
|
|
builder := c.Delete().Where(usertoken.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &UserTokenDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for UserToken.
|
|
func (c *UserTokenClient) Query() *UserTokenQuery {
|
|
return &UserTokenQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeUserToken},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a UserToken entity by its id.
|
|
func (c *UserTokenClient) Get(ctx context.Context, id int) (*UserToken, error) {
|
|
return c.Query().Where(usertoken.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *UserTokenClient) GetX(ctx context.Context, id int) *UserToken {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *UserTokenClient) Hooks() []Hook {
|
|
return c.hooks.UserToken
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *UserTokenClient) Interceptors() []Interceptor {
|
|
return c.inters.UserToken
|
|
}
|
|
|
|
func (c *UserTokenClient) mutate(ctx context.Context, m *UserTokenMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&UserTokenCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&UserTokenUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&UserTokenUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&UserTokenDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown UserToken mutation op: %q", m.Op())
|
|
}
|
|
}
|
|
|
|
// hooks and interceptors per client, for fast access.
|
|
type (
|
|
hooks struct {
|
|
Skin, User, UserProfile, UserToken []ent.Hook
|
|
}
|
|
inters struct {
|
|
Skin, User, UserProfile, UserToken []ent.Interceptor
|
|
}
|
|
)
|