1022 lines
34 KiB
Go
1022 lines
34 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"log"
|
|
|
|
"tinyskin/db/ent/migrate"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"tinyskin/db/ent/texture"
|
|
"tinyskin/db/ent/user"
|
|
"tinyskin/db/ent/userprofile"
|
|
"tinyskin/db/ent/usertexture"
|
|
"tinyskin/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
|
|
// Texture is the client for interacting with the Texture builders.
|
|
Texture *TextureClient
|
|
// User is the client for interacting with the User builders.
|
|
User *UserClient
|
|
// UserProfile is the client for interacting with the UserProfile builders.
|
|
UserProfile *UserProfileClient
|
|
// UserTexture is the client for interacting with the UserTexture builders.
|
|
UserTexture *UserTextureClient
|
|
// 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.Texture = NewTextureClient(c.config)
|
|
c.User = NewUserClient(c.config)
|
|
c.UserProfile = NewUserProfileClient(c.config)
|
|
c.UserTexture = NewUserTextureClient(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,
|
|
Texture: NewTextureClient(cfg),
|
|
User: NewUserClient(cfg),
|
|
UserProfile: NewUserProfileClient(cfg),
|
|
UserTexture: NewUserTextureClient(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,
|
|
Texture: NewTextureClient(cfg),
|
|
User: NewUserClient(cfg),
|
|
UserProfile: NewUserProfileClient(cfg),
|
|
UserTexture: NewUserTextureClient(cfg),
|
|
UserToken: NewUserTokenClient(cfg),
|
|
}, nil
|
|
}
|
|
|
|
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
|
//
|
|
// client.Debug().
|
|
// Texture.
|
|
// 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.Texture.Use(hooks...)
|
|
c.User.Use(hooks...)
|
|
c.UserProfile.Use(hooks...)
|
|
c.UserTexture.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.Texture.Intercept(interceptors...)
|
|
c.User.Intercept(interceptors...)
|
|
c.UserProfile.Intercept(interceptors...)
|
|
c.UserTexture.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 *TextureMutation:
|
|
return c.Texture.mutate(ctx, m)
|
|
case *UserMutation:
|
|
return c.User.mutate(ctx, m)
|
|
case *UserProfileMutation:
|
|
return c.UserProfile.mutate(ctx, m)
|
|
case *UserTextureMutation:
|
|
return c.UserTexture.mutate(ctx, m)
|
|
case *UserTokenMutation:
|
|
return c.UserToken.mutate(ctx, m)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown mutation type %T", m)
|
|
}
|
|
}
|
|
|
|
// TextureClient is a client for the Texture schema.
|
|
type TextureClient struct {
|
|
config
|
|
}
|
|
|
|
// NewTextureClient returns a client for the Texture from the given config.
|
|
func NewTextureClient(c config) *TextureClient {
|
|
return &TextureClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `texture.Hooks(f(g(h())))`.
|
|
func (c *TextureClient) Use(hooks ...Hook) {
|
|
c.hooks.Texture = append(c.hooks.Texture, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `texture.Intercept(f(g(h())))`.
|
|
func (c *TextureClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.Texture = append(c.inters.Texture, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a Texture entity.
|
|
func (c *TextureClient) Create() *TextureCreate {
|
|
mutation := newTextureMutation(c.config, OpCreate)
|
|
return &TextureCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of Texture entities.
|
|
func (c *TextureClient) CreateBulk(builders ...*TextureCreate) *TextureCreateBulk {
|
|
return &TextureCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for Texture.
|
|
func (c *TextureClient) Update() *TextureUpdate {
|
|
mutation := newTextureMutation(c.config, OpUpdate)
|
|
return &TextureUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *TextureClient) UpdateOne(t *Texture) *TextureUpdateOne {
|
|
mutation := newTextureMutation(c.config, OpUpdateOne, withTexture(t))
|
|
return &TextureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *TextureClient) UpdateOneID(id int) *TextureUpdateOne {
|
|
mutation := newTextureMutation(c.config, OpUpdateOne, withTextureID(id))
|
|
return &TextureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for Texture.
|
|
func (c *TextureClient) Delete() *TextureDelete {
|
|
mutation := newTextureMutation(c.config, OpDelete)
|
|
return &TextureDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *TextureClient) DeleteOne(t *Texture) *TextureDeleteOne {
|
|
return c.DeleteOneID(t.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *TextureClient) DeleteOneID(id int) *TextureDeleteOne {
|
|
builder := c.Delete().Where(texture.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &TextureDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for Texture.
|
|
func (c *TextureClient) Query() *TextureQuery {
|
|
return &TextureQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeTexture},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a Texture entity by its id.
|
|
func (c *TextureClient) Get(ctx context.Context, id int) (*Texture, error) {
|
|
return c.Query().Where(texture.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *TextureClient) GetX(ctx context.Context, id int) *Texture {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryCreatedUser queries the created_user edge of a Texture.
|
|
func (c *TextureClient) QueryCreatedUser(t *Texture) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := t.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(texture.Table, texture.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, false, texture.CreatedUserTable, texture.CreatedUserColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(t.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryUserProfile queries the user_profile edge of a Texture.
|
|
func (c *TextureClient) QueryUserProfile(t *Texture) *UserProfileQuery {
|
|
query := (&UserProfileClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := t.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(texture.Table, texture.FieldID, id),
|
|
sqlgraph.To(userprofile.Table, userprofile.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2M, false, texture.UserProfileTable, texture.UserProfilePrimaryKey...),
|
|
)
|
|
fromV = sqlgraph.Neighbors(t.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryUsertexture queries the usertexture edge of a Texture.
|
|
func (c *TextureClient) QueryUsertexture(t *Texture) *UserTextureQuery {
|
|
query := (&UserTextureClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := t.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(texture.Table, texture.FieldID, id),
|
|
sqlgraph.To(usertexture.Table, usertexture.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, true, texture.UsertextureTable, texture.UsertextureColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(t.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *TextureClient) Hooks() []Hook {
|
|
return c.hooks.Texture
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *TextureClient) Interceptors() []Interceptor {
|
|
return c.inters.Texture
|
|
}
|
|
|
|
func (c *TextureClient) mutate(ctx context.Context, m *TextureMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&TextureCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&TextureUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&TextureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&TextureDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown Texture 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
|
|
}
|
|
|
|
// QueryCreatedTexture queries the created_texture edge of a User.
|
|
func (c *UserClient) QueryCreatedTexture(u *User) *TextureQuery {
|
|
query := (&TextureClient{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(texture.Table, texture.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, true, user.CreatedTextureTable, user.CreatedTextureColumn),
|
|
)
|
|
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.O2O, false, user.TokenTable, user.TokenColumn),
|
|
)
|
|
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
|
|
}
|
|
|
|
// QueryTexture queries the texture edge of a UserProfile.
|
|
func (c *UserProfileClient) QueryTexture(up *UserProfile) *TextureQuery {
|
|
query := (&TextureClient{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(texture.Table, texture.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2M, true, userprofile.TextureTable, userprofile.TexturePrimaryKey...),
|
|
)
|
|
fromV = sqlgraph.Neighbors(up.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryUsertexture queries the usertexture edge of a UserProfile.
|
|
func (c *UserProfileClient) QueryUsertexture(up *UserProfile) *UserTextureQuery {
|
|
query := (&UserTextureClient{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(usertexture.Table, usertexture.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2M, true, userprofile.UsertextureTable, userprofile.UsertextureColumn),
|
|
)
|
|
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())
|
|
}
|
|
}
|
|
|
|
// UserTextureClient is a client for the UserTexture schema.
|
|
type UserTextureClient struct {
|
|
config
|
|
}
|
|
|
|
// NewUserTextureClient returns a client for the UserTexture from the given config.
|
|
func NewUserTextureClient(c config) *UserTextureClient {
|
|
return &UserTextureClient{config: c}
|
|
}
|
|
|
|
// Use adds a list of mutation hooks to the hooks stack.
|
|
// A call to `Use(f, g, h)` equals to `usertexture.Hooks(f(g(h())))`.
|
|
func (c *UserTextureClient) Use(hooks ...Hook) {
|
|
c.hooks.UserTexture = append(c.hooks.UserTexture, hooks...)
|
|
}
|
|
|
|
// Intercept adds a list of query interceptors to the interceptors stack.
|
|
// A call to `Intercept(f, g, h)` equals to `usertexture.Intercept(f(g(h())))`.
|
|
func (c *UserTextureClient) Intercept(interceptors ...Interceptor) {
|
|
c.inters.UserTexture = append(c.inters.UserTexture, interceptors...)
|
|
}
|
|
|
|
// Create returns a builder for creating a UserTexture entity.
|
|
func (c *UserTextureClient) Create() *UserTextureCreate {
|
|
mutation := newUserTextureMutation(c.config, OpCreate)
|
|
return &UserTextureCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// CreateBulk returns a builder for creating a bulk of UserTexture entities.
|
|
func (c *UserTextureClient) CreateBulk(builders ...*UserTextureCreate) *UserTextureCreateBulk {
|
|
return &UserTextureCreateBulk{config: c.config, builders: builders}
|
|
}
|
|
|
|
// Update returns an update builder for UserTexture.
|
|
func (c *UserTextureClient) Update() *UserTextureUpdate {
|
|
mutation := newUserTextureMutation(c.config, OpUpdate)
|
|
return &UserTextureUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOne returns an update builder for the given entity.
|
|
func (c *UserTextureClient) UpdateOne(ut *UserTexture) *UserTextureUpdateOne {
|
|
mutation := newUserTextureMutation(c.config, OpUpdateOne, withUserTexture(ut))
|
|
return &UserTextureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// UpdateOneID returns an update builder for the given id.
|
|
func (c *UserTextureClient) UpdateOneID(id int) *UserTextureUpdateOne {
|
|
mutation := newUserTextureMutation(c.config, OpUpdateOne, withUserTextureID(id))
|
|
return &UserTextureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// Delete returns a delete builder for UserTexture.
|
|
func (c *UserTextureClient) Delete() *UserTextureDelete {
|
|
mutation := newUserTextureMutation(c.config, OpDelete)
|
|
return &UserTextureDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
|
}
|
|
|
|
// DeleteOne returns a builder for deleting the given entity.
|
|
func (c *UserTextureClient) DeleteOne(ut *UserTexture) *UserTextureDeleteOne {
|
|
return c.DeleteOneID(ut.ID)
|
|
}
|
|
|
|
// DeleteOneID returns a builder for deleting the given entity by its id.
|
|
func (c *UserTextureClient) DeleteOneID(id int) *UserTextureDeleteOne {
|
|
builder := c.Delete().Where(usertexture.ID(id))
|
|
builder.mutation.id = &id
|
|
builder.mutation.op = OpDeleteOne
|
|
return &UserTextureDeleteOne{builder}
|
|
}
|
|
|
|
// Query returns a query builder for UserTexture.
|
|
func (c *UserTextureClient) Query() *UserTextureQuery {
|
|
return &UserTextureQuery{
|
|
config: c.config,
|
|
ctx: &QueryContext{Type: TypeUserTexture},
|
|
inters: c.Interceptors(),
|
|
}
|
|
}
|
|
|
|
// Get returns a UserTexture entity by its id.
|
|
func (c *UserTextureClient) Get(ctx context.Context, id int) (*UserTexture, error) {
|
|
return c.Query().Where(usertexture.ID(id)).Only(ctx)
|
|
}
|
|
|
|
// GetX is like Get, but panics if an error occurs.
|
|
func (c *UserTextureClient) GetX(ctx context.Context, id int) *UserTexture {
|
|
obj, err := c.Get(ctx, id)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return obj
|
|
}
|
|
|
|
// QueryUserProfile queries the user_profile edge of a UserTexture.
|
|
func (c *UserTextureClient) QueryUserProfile(ut *UserTexture) *UserProfileQuery {
|
|
query := (&UserProfileClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := ut.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(usertexture.Table, usertexture.FieldID, id),
|
|
sqlgraph.To(userprofile.Table, userprofile.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, false, usertexture.UserProfileTable, usertexture.UserProfileColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(ut.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// QueryTexture queries the texture edge of a UserTexture.
|
|
func (c *UserTextureClient) QueryTexture(ut *UserTexture) *TextureQuery {
|
|
query := (&TextureClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := ut.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(usertexture.Table, usertexture.FieldID, id),
|
|
sqlgraph.To(texture.Table, texture.FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, false, usertexture.TextureTable, usertexture.TextureColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(ut.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// Hooks returns the client hooks.
|
|
func (c *UserTextureClient) Hooks() []Hook {
|
|
return c.hooks.UserTexture
|
|
}
|
|
|
|
// Interceptors returns the client interceptors.
|
|
func (c *UserTextureClient) Interceptors() []Interceptor {
|
|
return c.inters.UserTexture
|
|
}
|
|
|
|
func (c *UserTextureClient) mutate(ctx context.Context, m *UserTextureMutation) (Value, error) {
|
|
switch m.Op() {
|
|
case OpCreate:
|
|
return (&UserTextureCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdate:
|
|
return (&UserTextureUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpUpdateOne:
|
|
return (&UserTextureUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
|
case OpDelete, OpDeleteOne:
|
|
return (&UserTextureDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
|
default:
|
|
return nil, fmt.Errorf("ent: unknown UserTexture 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
|
|
}
|
|
|
|
// QueryUser queries the user edge of a UserToken.
|
|
func (c *UserTokenClient) QueryUser(ut *UserToken) *UserQuery {
|
|
query := (&UserClient{config: c.config}).Query()
|
|
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
|
|
id := ut.ID
|
|
step := sqlgraph.NewStep(
|
|
sqlgraph.From(usertoken.Table, usertoken.FieldID, id),
|
|
sqlgraph.To(user.Table, user.FieldID),
|
|
sqlgraph.Edge(sqlgraph.O2O, true, usertoken.UserTable, usertoken.UserColumn),
|
|
)
|
|
fromV = sqlgraph.Neighbors(ut.driver.Dialect(), step)
|
|
return fromV, nil
|
|
}
|
|
return query
|
|
}
|
|
|
|
// 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 {
|
|
Texture, User, UserProfile, UserTexture, UserToken []ent.Hook
|
|
}
|
|
inters struct {
|
|
Texture, User, UserProfile, UserTexture, UserToken []ent.Interceptor
|
|
}
|
|
)
|