上传皮肤
This commit is contained in:
parent
ebfd0d325f
commit
bc0d32d5b4
@ -18,4 +18,5 @@ type Config struct {
|
||||
RaelIP bool
|
||||
MaxIpUser int
|
||||
RsaPriKey string
|
||||
TexturePath string
|
||||
}
|
||||
|
190
db/ent/client.go
190
db/ent/client.go
@ -14,7 +14,7 @@ import (
|
||||
"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/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/usertoken"
|
||||
@ -25,8 +25,8 @@ 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
|
||||
// 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.
|
||||
@ -46,7 +46,7 @@ func NewClient(opts ...Option) *Client {
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.Skin = NewSkinClient(c.config)
|
||||
c.Texture = NewTextureClient(c.config)
|
||||
c.User = NewUserClient(c.config)
|
||||
c.UserProfile = NewUserProfileClient(c.config)
|
||||
c.UserToken = NewUserTokenClient(c.config)
|
||||
@ -132,7 +132,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Skin: NewSkinClient(cfg),
|
||||
Texture: NewTextureClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
UserProfile: NewUserProfileClient(cfg),
|
||||
UserToken: NewUserTokenClient(cfg),
|
||||
@ -155,7 +155,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Skin: NewSkinClient(cfg),
|
||||
Texture: NewTextureClient(cfg),
|
||||
User: NewUserClient(cfg),
|
||||
UserProfile: NewUserProfileClient(cfg),
|
||||
UserToken: NewUserTokenClient(cfg),
|
||||
@ -165,7 +165,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// Skin.
|
||||
// Texture.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
func (c *Client) Debug() *Client {
|
||||
@ -187,7 +187,7 @@ func (c *Client) Close() error {
|
||||
// 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.Texture.Use(hooks...)
|
||||
c.User.Use(hooks...)
|
||||
c.UserProfile.Use(hooks...)
|
||||
c.UserToken.Use(hooks...)
|
||||
@ -196,7 +196,7 @@ func (c *Client) Use(hooks ...Hook) {
|
||||
// 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.Texture.Intercept(interceptors...)
|
||||
c.User.Intercept(interceptors...)
|
||||
c.UserProfile.Intercept(interceptors...)
|
||||
c.UserToken.Intercept(interceptors...)
|
||||
@ -205,8 +205,8 @@ func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
// 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 *TextureMutation:
|
||||
return c.Texture.mutate(ctx, m)
|
||||
case *UserMutation:
|
||||
return c.User.mutate(ctx, m)
|
||||
case *UserProfileMutation:
|
||||
@ -218,92 +218,92 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// SkinClient is a client for the Skin schema.
|
||||
type SkinClient struct {
|
||||
// TextureClient is a client for the Texture schema.
|
||||
type TextureClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewSkinClient returns a client for the Skin from the given config.
|
||||
func NewSkinClient(c config) *SkinClient {
|
||||
return &SkinClient{config: c}
|
||||
// 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 `skin.Hooks(f(g(h())))`.
|
||||
func (c *SkinClient) Use(hooks ...Hook) {
|
||||
c.hooks.Skin = append(c.hooks.Skin, hooks...)
|
||||
// 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 `skin.Intercept(f(g(h())))`.
|
||||
func (c *SkinClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Skin = append(c.inters.Skin, interceptors...)
|
||||
// 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 Skin entity.
|
||||
func (c *SkinClient) Create() *SkinCreate {
|
||||
mutation := newSkinMutation(c.config, OpCreate)
|
||||
return &SkinCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
// 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 Skin entities.
|
||||
func (c *SkinClient) CreateBulk(builders ...*SkinCreate) *SkinCreateBulk {
|
||||
return &SkinCreateBulk{config: c.config, builders: builders}
|
||||
// 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 Skin.
|
||||
func (c *SkinClient) Update() *SkinUpdate {
|
||||
mutation := newSkinMutation(c.config, OpUpdate)
|
||||
return &SkinUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
// 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 *SkinClient) UpdateOne(s *Skin) *SkinUpdateOne {
|
||||
mutation := newSkinMutation(c.config, OpUpdateOne, withSkin(s))
|
||||
return &SkinUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
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 *SkinClient) UpdateOneID(id int) *SkinUpdateOne {
|
||||
mutation := newSkinMutation(c.config, OpUpdateOne, withSkinID(id))
|
||||
return &SkinUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
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 Skin.
|
||||
func (c *SkinClient) Delete() *SkinDelete {
|
||||
mutation := newSkinMutation(c.config, OpDelete)
|
||||
return &SkinDelete{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 *SkinClient) DeleteOne(s *Skin) *SkinDeleteOne {
|
||||
return c.DeleteOneID(s.ID)
|
||||
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 *SkinClient) DeleteOneID(id int) *SkinDeleteOne {
|
||||
builder := c.Delete().Where(skin.ID(id))
|
||||
func (c *TextureClient) DeleteOneID(id int) *TextureDeleteOne {
|
||||
builder := c.Delete().Where(texture.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &SkinDeleteOne{builder}
|
||||
return &TextureDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Skin.
|
||||
func (c *SkinClient) Query() *SkinQuery {
|
||||
return &SkinQuery{
|
||||
// Query returns a query builder for Texture.
|
||||
func (c *TextureClient) Query() *TextureQuery {
|
||||
return &TextureQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeSkin},
|
||||
ctx: &QueryContext{Type: TypeTexture},
|
||||
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)
|
||||
// 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 *SkinClient) GetX(ctx context.Context, id int) *Skin {
|
||||
func (c *TextureClient) GetX(ctx context.Context, id int) *Texture {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -311,44 +311,44 @@ func (c *SkinClient) GetX(ctx context.Context, id int) *Skin {
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryCreatedUser queries the created_user edge of a Skin.
|
||||
func (c *SkinClient) QueryCreatedUser(s *Skin) *UserQuery {
|
||||
// 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 := s.ID
|
||||
id := t.ID
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(skin.Table, skin.FieldID, id),
|
||||
sqlgraph.From(texture.Table, texture.FieldID, id),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, skin.CreatedUserTable, skin.CreatedUserColumn),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, texture.CreatedUserTable, texture.CreatedUserColumn),
|
||||
)
|
||||
fromV = sqlgraph.Neighbors(s.driver.Dialect(), step)
|
||||
fromV = sqlgraph.Neighbors(t.driver.Dialect(), step)
|
||||
return fromV, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *SkinClient) Hooks() []Hook {
|
||||
return c.hooks.Skin
|
||||
func (c *TextureClient) Hooks() []Hook {
|
||||
return c.hooks.Texture
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *SkinClient) Interceptors() []Interceptor {
|
||||
return c.inters.Skin
|
||||
func (c *TextureClient) Interceptors() []Interceptor {
|
||||
return c.inters.Texture
|
||||
}
|
||||
|
||||
func (c *SkinClient) mutate(ctx context.Context, m *SkinMutation) (Value, error) {
|
||||
func (c *TextureClient) mutate(ctx context.Context, m *TextureMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&SkinCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
return (&TextureCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&SkinUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
return (&TextureUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&SkinUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
return (&TextureUpdateOne{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)
|
||||
return (&TextureDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Skin mutation op: %q", m.Op())
|
||||
return nil, fmt.Errorf("ent: unknown Texture mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
@ -445,15 +445,15 @@ func (c *UserClient) GetX(ctx context.Context, id int) *User {
|
||||
return obj
|
||||
}
|
||||
|
||||
// QueryCreatedSkin queries the created_skin edge of a User.
|
||||
func (c *UserClient) QueryCreatedSkin(u *User) *SkinQuery {
|
||||
query := (&SkinClient{config: c.config}).Query()
|
||||
// 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(skin.Table, skin.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, user.CreatedSkinTable, user.CreatedSkinColumn),
|
||||
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
|
||||
@ -493,22 +493,6 @@ func (c *UserClient) QueryToken(u *User) *UserTokenQuery {
|
||||
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
|
||||
@ -643,6 +627,22 @@ func (c *UserProfileClient) QueryUser(up *UserProfile) *UserQuery {
|
||||
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.O2M, false, userprofile.TextureTable, userprofile.TextureColumn),
|
||||
)
|
||||
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
|
||||
@ -789,9 +789,9 @@ func (c *UserTokenClient) mutate(ctx context.Context, m *UserTokenMutation) (Val
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
Skin, User, UserProfile, UserToken []ent.Hook
|
||||
Texture, User, UserProfile, UserToken []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
Skin, User, UserProfile, UserToken []ent.Interceptor
|
||||
Texture, User, UserProfile, UserToken []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"entgo.io/ent"
|
||||
"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/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/usertoken"
|
||||
@ -76,7 +76,7 @@ var (
|
||||
func checkColumn(table, column string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
skin.Table: skin.ValidColumn,
|
||||
texture.Table: texture.ValidColumn,
|
||||
user.Table: user.ValidColumn,
|
||||
userprofile.Table: userprofile.ValidColumn,
|
||||
usertoken.Table: usertoken.ValidColumn,
|
||||
|
@ -9,16 +9,16 @@ import (
|
||||
"github.com/xmdhs/authlib-skin/db/ent"
|
||||
)
|
||||
|
||||
// The SkinFunc type is an adapter to allow the use of ordinary
|
||||
// function as Skin mutator.
|
||||
type SkinFunc func(context.Context, *ent.SkinMutation) (ent.Value, error)
|
||||
// The TextureFunc type is an adapter to allow the use of ordinary
|
||||
// function as Texture mutator.
|
||||
type TextureFunc func(context.Context, *ent.TextureMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f SkinFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.SkinMutation); ok {
|
||||
func (f TextureFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.TextureMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SkinMutation", m)
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.TextureMutation", m)
|
||||
}
|
||||
|
||||
// The UserFunc type is an adapter to allow the use of ordinary
|
||||
|
@ -8,32 +8,39 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// SkinsColumns holds the columns for the "skins" table.
|
||||
SkinsColumns = []*schema.Column{
|
||||
// TexturesColumns holds the columns for the "textures" table.
|
||||
TexturesColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "skin_hash", Type: field.TypeString, SchemaType: map[string]string{"mysql": "VARCHAR(100)"}},
|
||||
{Name: "type", Type: field.TypeUint8},
|
||||
{Name: "variant", Type: field.TypeString},
|
||||
{Name: "skin_created_user", Type: field.TypeInt},
|
||||
{Name: "texture_hash", Type: field.TypeString, SchemaType: map[string]string{"mysql": "VARCHAR(100)"}},
|
||||
{Name: "type", Type: field.TypeString, SchemaType: map[string]string{"mysql": "VARCHAR(10)"}},
|
||||
{Name: "variant", Type: field.TypeString, SchemaType: map[string]string{"mysql": "VARCHAR(10)"}},
|
||||
{Name: "texture_created_user", Type: field.TypeInt},
|
||||
{Name: "user_profile_texture", Type: field.TypeInt, Nullable: true},
|
||||
}
|
||||
// SkinsTable holds the schema information for the "skins" table.
|
||||
SkinsTable = &schema.Table{
|
||||
Name: "skins",
|
||||
Columns: SkinsColumns,
|
||||
PrimaryKey: []*schema.Column{SkinsColumns[0]},
|
||||
// TexturesTable holds the schema information for the "textures" table.
|
||||
TexturesTable = &schema.Table{
|
||||
Name: "textures",
|
||||
Columns: TexturesColumns,
|
||||
PrimaryKey: []*schema.Column{TexturesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "skins_users_created_user",
|
||||
Columns: []*schema.Column{SkinsColumns[4]},
|
||||
Symbol: "textures_users_created_user",
|
||||
Columns: []*schema.Column{TexturesColumns[4]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
{
|
||||
Symbol: "textures_user_profiles_texture",
|
||||
Columns: []*schema.Column{TexturesColumns[5]},
|
||||
RefColumns: []*schema.Column{UserProfilesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
Name: "skin_skin_hash",
|
||||
Name: "texture_texture_hash",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{SkinsColumns[1]},
|
||||
Columns: []*schema.Column{TexturesColumns[1]},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -47,7 +54,6 @@ var (
|
||||
{Name: "state", Type: field.TypeInt},
|
||||
{Name: "reg_time", Type: field.TypeInt64},
|
||||
{Name: "user_token", Type: field.TypeInt, Nullable: true},
|
||||
{Name: "user_skin", Type: field.TypeInt, Nullable: true},
|
||||
}
|
||||
// UsersTable holds the schema information for the "users" table.
|
||||
UsersTable = &schema.Table{
|
||||
@ -61,12 +67,6 @@ var (
|
||||
RefColumns: []*schema.Column{UserTokensColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "users_skins_skin",
|
||||
Columns: []*schema.Column{UsersColumns[8]},
|
||||
RefColumns: []*schema.Column{SkinsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
},
|
||||
Indexes: []*schema.Index{
|
||||
{
|
||||
@ -74,6 +74,11 @@ var (
|
||||
Unique: true,
|
||||
Columns: []*schema.Column{UsersColumns[1]},
|
||||
},
|
||||
{
|
||||
Name: "user_reg_ip",
|
||||
Unique: false,
|
||||
Columns: []*schema.Column{UsersColumns[4]},
|
||||
},
|
||||
},
|
||||
}
|
||||
// UserProfilesColumns holds the columns for the "user_profiles" table.
|
||||
@ -125,7 +130,7 @@ var (
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
SkinsTable,
|
||||
TexturesTable,
|
||||
UsersTable,
|
||||
UserProfilesTable,
|
||||
UserTokensTable,
|
||||
@ -133,8 +138,8 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
SkinsTable.ForeignKeys[0].RefTable = UsersTable
|
||||
TexturesTable.ForeignKeys[0].RefTable = UsersTable
|
||||
TexturesTable.ForeignKeys[1].RefTable = UserProfilesTable
|
||||
UsersTable.ForeignKeys[0].RefTable = UserTokensTable
|
||||
UsersTable.ForeignKeys[1].RefTable = SkinsTable
|
||||
UserProfilesTable.ForeignKeys[0].RefTable = UsersTable
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,8 +6,8 @@ import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Skin is the predicate function for skin builders.
|
||||
type Skin func(*sql.Selector)
|
||||
// Texture is the predicate function for texture builders.
|
||||
type Texture func(*sql.Selector)
|
||||
|
||||
// User is the predicate function for user builders.
|
||||
type User func(*sql.Selector)
|
||||
|
@ -1,38 +0,0 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// Skin holds the schema definition for the Skin entity.
|
||||
type Skin struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Skin.
|
||||
func (Skin) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("skin_hash").SchemaType(map[string]string{
|
||||
dialect.MySQL: "VARCHAR(100)",
|
||||
}),
|
||||
field.Uint8("type"),
|
||||
field.String("variant"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Skin.
|
||||
func (Skin) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("created_user", User.Type).Unique().Required(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Skin) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("skin_hash"),
|
||||
}
|
||||
}
|
44
db/ent/schema/texture.go
Normal file
44
db/ent/schema/texture.go
Normal file
@ -0,0 +1,44 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/schema/edge"
|
||||
"entgo.io/ent/schema/field"
|
||||
"entgo.io/ent/schema/index"
|
||||
)
|
||||
|
||||
// Texture holds the schema definition for the Texture entity.
|
||||
type Texture struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Texture.
|
||||
func (Texture) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.String("texture_hash").SchemaType(map[string]string{
|
||||
dialect.MySQL: "VARCHAR(100)",
|
||||
}),
|
||||
// 皮肤 or 披风
|
||||
field.String("type").SchemaType(map[string]string{
|
||||
dialect.MySQL: "VARCHAR(10)",
|
||||
}),
|
||||
// slim or 空
|
||||
field.String("variant").SchemaType(map[string]string{
|
||||
dialect.MySQL: "VARCHAR(10)",
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Texture.
|
||||
func (Texture) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.To("created_user", User.Type).Unique().Required(),
|
||||
}
|
||||
}
|
||||
|
||||
func (Texture) Indexes() []ent.Index {
|
||||
return []ent.Index{
|
||||
index.Fields("texture_hash"),
|
||||
}
|
||||
}
|
@ -38,10 +38,9 @@ func (User) Fields() []ent.Field {
|
||||
// Edges of the User.
|
||||
func (User) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("created_skin", Skin.Type).Ref("created_user"),
|
||||
edge.From("created_texture", Texture.Type).Ref("created_user"),
|
||||
edge.To("profile", UserProfile.Type).Unique().Annotations(entsql.OnDelete(entsql.Cascade)),
|
||||
edge.To("token", UserToken.Type).Unique().Annotations(entsql.OnDelete(entsql.Cascade)),
|
||||
edge.To("skin", Skin.Type).Unique(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ func (UserProfile) Fields() []ent.Field {
|
||||
func (UserProfile) Edges() []ent.Edge {
|
||||
return []ent.Edge{
|
||||
edge.From("user", User.Type).Ref("profile").Required().Unique(),
|
||||
edge.To("texture", Texture.Type),
|
||||
}
|
||||
}
|
||||
|
||||
|
166
db/ent/skin.go
166
db/ent/skin.go
@ -1,166 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/skin"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
)
|
||||
|
||||
// Skin is the model entity for the Skin schema.
|
||||
type Skin struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// SkinHash holds the value of the "skin_hash" field.
|
||||
SkinHash string `json:"skin_hash,omitempty"`
|
||||
// Type holds the value of the "type" field.
|
||||
Type uint8 `json:"type,omitempty"`
|
||||
// Variant holds the value of the "variant" field.
|
||||
Variant string `json:"variant,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the SkinQuery when eager-loading is set.
|
||||
Edges SkinEdges `json:"edges"`
|
||||
skin_created_user *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// SkinEdges holds the relations/edges for other nodes in the graph.
|
||||
type SkinEdges struct {
|
||||
// CreatedUser holds the value of the created_user edge.
|
||||
CreatedUser *User `json:"created_user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// CreatedUserOrErr returns the CreatedUser value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e SkinEdges) CreatedUserOrErr() (*User, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.CreatedUser == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return e.CreatedUser, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "created_user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Skin) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case skin.FieldID, skin.FieldType:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case skin.FieldSkinHash, skin.FieldVariant:
|
||||
values[i] = new(sql.NullString)
|
||||
case skin.ForeignKeys[0]: // skin_created_user
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Skin fields.
|
||||
func (s *Skin) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case skin.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
s.ID = int(value.Int64)
|
||||
case skin.FieldSkinHash:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field skin_hash", values[i])
|
||||
} else if value.Valid {
|
||||
s.SkinHash = value.String
|
||||
}
|
||||
case skin.FieldType:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||
} else if value.Valid {
|
||||
s.Type = uint8(value.Int64)
|
||||
}
|
||||
case skin.FieldVariant:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field variant", values[i])
|
||||
} else if value.Valid {
|
||||
s.Variant = value.String
|
||||
}
|
||||
case skin.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field skin_created_user", value)
|
||||
} else if value.Valid {
|
||||
s.skin_created_user = new(int)
|
||||
*s.skin_created_user = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
s.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Skin.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (s *Skin) Value(name string) (ent.Value, error) {
|
||||
return s.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryCreatedUser queries the "created_user" edge of the Skin entity.
|
||||
func (s *Skin) QueryCreatedUser() *UserQuery {
|
||||
return NewSkinClient(s.config).QueryCreatedUser(s)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Skin.
|
||||
// Note that you need to call Skin.Unwrap() before calling this method if this Skin
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (s *Skin) Update() *SkinUpdateOne {
|
||||
return NewSkinClient(s.config).UpdateOne(s)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Skin entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (s *Skin) Unwrap() *Skin {
|
||||
_tx, ok := s.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Skin is not a transactional entity")
|
||||
}
|
||||
s.config.driver = _tx.drv
|
||||
return s
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (s *Skin) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Skin(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", s.ID))
|
||||
builder.WriteString("skin_hash=")
|
||||
builder.WriteString(s.SkinHash)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", s.Type))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("variant=")
|
||||
builder.WriteString(s.Variant)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Skins is a parsable slice of Skin.
|
||||
type Skins []*Skin
|
@ -1,294 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package skin
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// SkinHash applies equality check predicate on the "skin_hash" field. It's identical to SkinHashEQ.
|
||||
func SkinHash(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldEQ(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
|
||||
func Type(v uint8) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// Variant applies equality check predicate on the "variant" field. It's identical to VariantEQ.
|
||||
func Variant(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldEQ(FieldVariant, v))
|
||||
}
|
||||
|
||||
// SkinHashEQ applies the EQ predicate on the "skin_hash" field.
|
||||
func SkinHashEQ(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldEQ(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// SkinHashNEQ applies the NEQ predicate on the "skin_hash" field.
|
||||
func SkinHashNEQ(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldNEQ(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// SkinHashIn applies the In predicate on the "skin_hash" field.
|
||||
func SkinHashIn(vs ...string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldIn(FieldSkinHash, vs...))
|
||||
}
|
||||
|
||||
// SkinHashNotIn applies the NotIn predicate on the "skin_hash" field.
|
||||
func SkinHashNotIn(vs ...string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldNotIn(FieldSkinHash, vs...))
|
||||
}
|
||||
|
||||
// SkinHashGT applies the GT predicate on the "skin_hash" field.
|
||||
func SkinHashGT(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldGT(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// SkinHashGTE applies the GTE predicate on the "skin_hash" field.
|
||||
func SkinHashGTE(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldGTE(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// SkinHashLT applies the LT predicate on the "skin_hash" field.
|
||||
func SkinHashLT(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldLT(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// SkinHashLTE applies the LTE predicate on the "skin_hash" field.
|
||||
func SkinHashLTE(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldLTE(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// SkinHashContains applies the Contains predicate on the "skin_hash" field.
|
||||
func SkinHashContains(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldContains(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// SkinHashHasPrefix applies the HasPrefix predicate on the "skin_hash" field.
|
||||
func SkinHashHasPrefix(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldHasPrefix(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// SkinHashHasSuffix applies the HasSuffix predicate on the "skin_hash" field.
|
||||
func SkinHashHasSuffix(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldHasSuffix(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// SkinHashEqualFold applies the EqualFold predicate on the "skin_hash" field.
|
||||
func SkinHashEqualFold(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldEqualFold(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// SkinHashContainsFold applies the ContainsFold predicate on the "skin_hash" field.
|
||||
func SkinHashContainsFold(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldContainsFold(FieldSkinHash, v))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v uint8) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||
func TypeNEQ(v uint8) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldNEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeIn applies the In predicate on the "type" field.
|
||||
func TypeIn(vs ...uint8) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||
func TypeNotIn(vs ...uint8) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeGT applies the GT predicate on the "type" field.
|
||||
func TypeGT(v uint8) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldGT(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeGTE applies the GTE predicate on the "type" field.
|
||||
func TypeGTE(v uint8) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldGTE(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeLT applies the LT predicate on the "type" field.
|
||||
func TypeLT(v uint8) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldLT(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeLTE applies the LTE predicate on the "type" field.
|
||||
func TypeLTE(v uint8) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldLTE(FieldType, v))
|
||||
}
|
||||
|
||||
// VariantEQ applies the EQ predicate on the "variant" field.
|
||||
func VariantEQ(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldEQ(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantNEQ applies the NEQ predicate on the "variant" field.
|
||||
func VariantNEQ(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldNEQ(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantIn applies the In predicate on the "variant" field.
|
||||
func VariantIn(vs ...string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldIn(FieldVariant, vs...))
|
||||
}
|
||||
|
||||
// VariantNotIn applies the NotIn predicate on the "variant" field.
|
||||
func VariantNotIn(vs ...string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldNotIn(FieldVariant, vs...))
|
||||
}
|
||||
|
||||
// VariantGT applies the GT predicate on the "variant" field.
|
||||
func VariantGT(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldGT(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantGTE applies the GTE predicate on the "variant" field.
|
||||
func VariantGTE(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldGTE(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantLT applies the LT predicate on the "variant" field.
|
||||
func VariantLT(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldLT(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantLTE applies the LTE predicate on the "variant" field.
|
||||
func VariantLTE(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldLTE(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantContains applies the Contains predicate on the "variant" field.
|
||||
func VariantContains(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldContains(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantHasPrefix applies the HasPrefix predicate on the "variant" field.
|
||||
func VariantHasPrefix(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldHasPrefix(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantHasSuffix applies the HasSuffix predicate on the "variant" field.
|
||||
func VariantHasSuffix(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldHasSuffix(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantEqualFold applies the EqualFold predicate on the "variant" field.
|
||||
func VariantEqualFold(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldEqualFold(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantContainsFold applies the ContainsFold predicate on the "variant" field.
|
||||
func VariantContainsFold(v string) predicate.Skin {
|
||||
return predicate.Skin(sql.FieldContainsFold(FieldVariant, v))
|
||||
}
|
||||
|
||||
// HasCreatedUser applies the HasEdge predicate on the "created_user" edge.
|
||||
func HasCreatedUser() predicate.Skin {
|
||||
return predicate.Skin(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, CreatedUserTable, CreatedUserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasCreatedUserWith applies the HasEdge predicate on the "created_user" edge with a given conditions (other predicates).
|
||||
func HasCreatedUserWith(preds ...predicate.User) predicate.Skin {
|
||||
return predicate.Skin(func(s *sql.Selector) {
|
||||
step := newCreatedUserStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Skin) predicate.Skin {
|
||||
return predicate.Skin(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for _, p := range predicates {
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Skin) predicate.Skin {
|
||||
return predicate.Skin(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for i, p := range predicates {
|
||||
if i > 0 {
|
||||
s1.Or()
|
||||
}
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Skin) predicate.Skin {
|
||||
return predicate.Skin(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
@ -1,237 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/skin"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
)
|
||||
|
||||
// SkinCreate is the builder for creating a Skin entity.
|
||||
type SkinCreate struct {
|
||||
config
|
||||
mutation *SkinMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetSkinHash sets the "skin_hash" field.
|
||||
func (sc *SkinCreate) SetSkinHash(s string) *SkinCreate {
|
||||
sc.mutation.SetSkinHash(s)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (sc *SkinCreate) SetType(u uint8) *SkinCreate {
|
||||
sc.mutation.SetType(u)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetVariant sets the "variant" field.
|
||||
func (sc *SkinCreate) SetVariant(s string) *SkinCreate {
|
||||
sc.mutation.SetVariant(s)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetCreatedUserID sets the "created_user" edge to the User entity by ID.
|
||||
func (sc *SkinCreate) SetCreatedUserID(id int) *SkinCreate {
|
||||
sc.mutation.SetCreatedUserID(id)
|
||||
return sc
|
||||
}
|
||||
|
||||
// SetCreatedUser sets the "created_user" edge to the User entity.
|
||||
func (sc *SkinCreate) SetCreatedUser(u *User) *SkinCreate {
|
||||
return sc.SetCreatedUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SkinMutation object of the builder.
|
||||
func (sc *SkinCreate) Mutation() *SkinMutation {
|
||||
return sc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Skin in the database.
|
||||
func (sc *SkinCreate) Save(ctx context.Context) (*Skin, error) {
|
||||
return withHooks(ctx, sc.sqlSave, sc.mutation, sc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (sc *SkinCreate) SaveX(ctx context.Context) *Skin {
|
||||
v, err := sc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (sc *SkinCreate) Exec(ctx context.Context) error {
|
||||
_, err := sc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sc *SkinCreate) ExecX(ctx context.Context) {
|
||||
if err := sc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (sc *SkinCreate) check() error {
|
||||
if _, ok := sc.mutation.SkinHash(); !ok {
|
||||
return &ValidationError{Name: "skin_hash", err: errors.New(`ent: missing required field "Skin.skin_hash"`)}
|
||||
}
|
||||
if _, ok := sc.mutation.GetType(); !ok {
|
||||
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Skin.type"`)}
|
||||
}
|
||||
if _, ok := sc.mutation.Variant(); !ok {
|
||||
return &ValidationError{Name: "variant", err: errors.New(`ent: missing required field "Skin.variant"`)}
|
||||
}
|
||||
if _, ok := sc.mutation.CreatedUserID(); !ok {
|
||||
return &ValidationError{Name: "created_user", err: errors.New(`ent: missing required edge "Skin.created_user"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sc *SkinCreate) sqlSave(ctx context.Context) (*Skin, error) {
|
||||
if err := sc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := sc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, sc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
sc.mutation.id = &_node.ID
|
||||
sc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (sc *SkinCreate) createSpec() (*Skin, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Skin{config: sc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(skin.Table, sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := sc.mutation.SkinHash(); ok {
|
||||
_spec.SetField(skin.FieldSkinHash, field.TypeString, value)
|
||||
_node.SkinHash = value
|
||||
}
|
||||
if value, ok := sc.mutation.GetType(); ok {
|
||||
_spec.SetField(skin.FieldType, field.TypeUint8, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := sc.mutation.Variant(); ok {
|
||||
_spec.SetField(skin.FieldVariant, field.TypeString, value)
|
||||
_node.Variant = value
|
||||
}
|
||||
if nodes := sc.mutation.CreatedUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: skin.CreatedUserTable,
|
||||
Columns: []string{skin.CreatedUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.skin_created_user = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// SkinCreateBulk is the builder for creating many Skin entities in bulk.
|
||||
type SkinCreateBulk struct {
|
||||
config
|
||||
builders []*SkinCreate
|
||||
}
|
||||
|
||||
// Save creates the Skin entities in the database.
|
||||
func (scb *SkinCreateBulk) Save(ctx context.Context) ([]*Skin, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(scb.builders))
|
||||
nodes := make([]*Skin, len(scb.builders))
|
||||
mutators := make([]Mutator, len(scb.builders))
|
||||
for i := range scb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := scb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*SkinMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, scb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, scb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, scb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (scb *SkinCreateBulk) SaveX(ctx context.Context) []*Skin {
|
||||
v, err := scb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (scb *SkinCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := scb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (scb *SkinCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := scb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/skin"
|
||||
)
|
||||
|
||||
// SkinDelete is the builder for deleting a Skin entity.
|
||||
type SkinDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SkinMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SkinDelete builder.
|
||||
func (sd *SkinDelete) Where(ps ...predicate.Skin) *SkinDelete {
|
||||
sd.mutation.Where(ps...)
|
||||
return sd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (sd *SkinDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, sd.sqlExec, sd.mutation, sd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sd *SkinDelete) ExecX(ctx context.Context) int {
|
||||
n, err := sd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (sd *SkinDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(skin.Table, sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt))
|
||||
if ps := sd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, sd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
sd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// SkinDeleteOne is the builder for deleting a single Skin entity.
|
||||
type SkinDeleteOne struct {
|
||||
sd *SkinDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SkinDelete builder.
|
||||
func (sdo *SkinDeleteOne) Where(ps ...predicate.Skin) *SkinDeleteOne {
|
||||
sdo.sd.mutation.Where(ps...)
|
||||
return sdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (sdo *SkinDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := sdo.sd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{skin.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (sdo *SkinDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := sdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@ -1,650 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/skin"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
)
|
||||
|
||||
// SkinQuery is the builder for querying Skin entities.
|
||||
type SkinQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []skin.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Skin
|
||||
withCreatedUser *UserQuery
|
||||
withFKs bool
|
||||
modifiers []func(*sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the SkinQuery builder.
|
||||
func (sq *SkinQuery) Where(ps ...predicate.Skin) *SkinQuery {
|
||||
sq.predicates = append(sq.predicates, ps...)
|
||||
return sq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (sq *SkinQuery) Limit(limit int) *SkinQuery {
|
||||
sq.ctx.Limit = &limit
|
||||
return sq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (sq *SkinQuery) Offset(offset int) *SkinQuery {
|
||||
sq.ctx.Offset = &offset
|
||||
return sq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (sq *SkinQuery) Unique(unique bool) *SkinQuery {
|
||||
sq.ctx.Unique = &unique
|
||||
return sq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (sq *SkinQuery) Order(o ...skin.OrderOption) *SkinQuery {
|
||||
sq.order = append(sq.order, o...)
|
||||
return sq
|
||||
}
|
||||
|
||||
// QueryCreatedUser chains the current query on the "created_user" edge.
|
||||
func (sq *SkinQuery) QueryCreatedUser() *UserQuery {
|
||||
query := (&UserClient{config: sq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := sq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(skin.Table, skin.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, skin.CreatedUserTable, skin.CreatedUserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(sq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Skin entity from the query.
|
||||
// Returns a *NotFoundError when no Skin was found.
|
||||
func (sq *SkinQuery) First(ctx context.Context) (*Skin, error) {
|
||||
nodes, err := sq.Limit(1).All(setContextOp(ctx, sq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{skin.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (sq *SkinQuery) FirstX(ctx context.Context) *Skin {
|
||||
node, err := sq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Skin ID from the query.
|
||||
// Returns a *NotFoundError when no Skin ID was found.
|
||||
func (sq *SkinQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = sq.Limit(1).IDs(setContextOp(ctx, sq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{skin.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (sq *SkinQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := sq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Skin entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Skin entity is found.
|
||||
// Returns a *NotFoundError when no Skin entities are found.
|
||||
func (sq *SkinQuery) Only(ctx context.Context) (*Skin, error) {
|
||||
nodes, err := sq.Limit(2).All(setContextOp(ctx, sq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{skin.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{skin.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (sq *SkinQuery) OnlyX(ctx context.Context) *Skin {
|
||||
node, err := sq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Skin ID in the query.
|
||||
// Returns a *NotSingularError when more than one Skin ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (sq *SkinQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = sq.Limit(2).IDs(setContextOp(ctx, sq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{skin.Label}
|
||||
default:
|
||||
err = &NotSingularError{skin.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (sq *SkinQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := sq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Skins.
|
||||
func (sq *SkinQuery) All(ctx context.Context) ([]*Skin, error) {
|
||||
ctx = setContextOp(ctx, sq.ctx, "All")
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Skin, *SkinQuery]()
|
||||
return withInterceptors[[]*Skin](ctx, sq, qr, sq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (sq *SkinQuery) AllX(ctx context.Context) []*Skin {
|
||||
nodes, err := sq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Skin IDs.
|
||||
func (sq *SkinQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if sq.ctx.Unique == nil && sq.path != nil {
|
||||
sq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, sq.ctx, "IDs")
|
||||
if err = sq.Select(skin.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (sq *SkinQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := sq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (sq *SkinQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, sq.ctx, "Count")
|
||||
if err := sq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, sq, querierCount[*SkinQuery](), sq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (sq *SkinQuery) CountX(ctx context.Context) int {
|
||||
count, err := sq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (sq *SkinQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, sq.ctx, "Exist")
|
||||
switch _, err := sq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (sq *SkinQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := sq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the SkinQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (sq *SkinQuery) Clone() *SkinQuery {
|
||||
if sq == nil {
|
||||
return nil
|
||||
}
|
||||
return &SkinQuery{
|
||||
config: sq.config,
|
||||
ctx: sq.ctx.Clone(),
|
||||
order: append([]skin.OrderOption{}, sq.order...),
|
||||
inters: append([]Interceptor{}, sq.inters...),
|
||||
predicates: append([]predicate.Skin{}, sq.predicates...),
|
||||
withCreatedUser: sq.withCreatedUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: sq.sql.Clone(),
|
||||
path: sq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithCreatedUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "created_user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (sq *SkinQuery) WithCreatedUser(opts ...func(*UserQuery)) *SkinQuery {
|
||||
query := (&UserClient{config: sq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
sq.withCreatedUser = query
|
||||
return sq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// SkinHash string `json:"skin_hash,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Skin.Query().
|
||||
// GroupBy(skin.FieldSkinHash).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (sq *SkinQuery) GroupBy(field string, fields ...string) *SkinGroupBy {
|
||||
sq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &SkinGroupBy{build: sq}
|
||||
grbuild.flds = &sq.ctx.Fields
|
||||
grbuild.label = skin.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// SkinHash string `json:"skin_hash,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Skin.Query().
|
||||
// Select(skin.FieldSkinHash).
|
||||
// Scan(ctx, &v)
|
||||
func (sq *SkinQuery) Select(fields ...string) *SkinSelect {
|
||||
sq.ctx.Fields = append(sq.ctx.Fields, fields...)
|
||||
sbuild := &SkinSelect{SkinQuery: sq}
|
||||
sbuild.label = skin.Label
|
||||
sbuild.flds, sbuild.scan = &sq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a SkinSelect configured with the given aggregations.
|
||||
func (sq *SkinQuery) Aggregate(fns ...AggregateFunc) *SkinSelect {
|
||||
return sq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (sq *SkinQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range sq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, sq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range sq.ctx.Fields {
|
||||
if !skin.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if sq.path != nil {
|
||||
prev, err := sq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sq *SkinQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Skin, error) {
|
||||
var (
|
||||
nodes = []*Skin{}
|
||||
withFKs = sq.withFKs
|
||||
_spec = sq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
sq.withCreatedUser != nil,
|
||||
}
|
||||
)
|
||||
if sq.withCreatedUser != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, skin.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Skin).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Skin{config: sq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
if len(sq.modifiers) > 0 {
|
||||
_spec.Modifiers = sq.modifiers
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, sq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := sq.withCreatedUser; query != nil {
|
||||
if err := sq.loadCreatedUser(ctx, query, nodes, nil,
|
||||
func(n *Skin, e *User) { n.Edges.CreatedUser = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (sq *SkinQuery) loadCreatedUser(ctx context.Context, query *UserQuery, nodes []*Skin, init func(*Skin), assign func(*Skin, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Skin)
|
||||
for i := range nodes {
|
||||
if nodes[i].skin_created_user == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].skin_created_user
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "skin_created_user" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sq *SkinQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := sq.querySpec()
|
||||
if len(sq.modifiers) > 0 {
|
||||
_spec.Modifiers = sq.modifiers
|
||||
}
|
||||
_spec.Node.Columns = sq.ctx.Fields
|
||||
if len(sq.ctx.Fields) > 0 {
|
||||
_spec.Unique = sq.ctx.Unique != nil && *sq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, sq.driver, _spec)
|
||||
}
|
||||
|
||||
func (sq *SkinQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(skin.Table, skin.Columns, sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt))
|
||||
_spec.From = sq.sql
|
||||
if unique := sq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if sq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := sq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, skin.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != skin.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := sq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := sq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := sq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := sq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (sq *SkinQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(sq.driver.Dialect())
|
||||
t1 := builder.Table(skin.Table)
|
||||
columns := sq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = skin.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if sq.sql != nil {
|
||||
selector = sq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if sq.ctx.Unique != nil && *sq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, m := range sq.modifiers {
|
||||
m(selector)
|
||||
}
|
||||
for _, p := range sq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range sq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := sq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := sq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
|
||||
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
|
||||
// either committed or rolled-back.
|
||||
func (sq *SkinQuery) ForUpdate(opts ...sql.LockOption) *SkinQuery {
|
||||
if sq.driver.Dialect() == dialect.Postgres {
|
||||
sq.Unique(false)
|
||||
}
|
||||
sq.modifiers = append(sq.modifiers, func(s *sql.Selector) {
|
||||
s.ForUpdate(opts...)
|
||||
})
|
||||
return sq
|
||||
}
|
||||
|
||||
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
|
||||
// on any rows that are read. Other sessions can read the rows, but cannot modify them
|
||||
// until your transaction commits.
|
||||
func (sq *SkinQuery) ForShare(opts ...sql.LockOption) *SkinQuery {
|
||||
if sq.driver.Dialect() == dialect.Postgres {
|
||||
sq.Unique(false)
|
||||
}
|
||||
sq.modifiers = append(sq.modifiers, func(s *sql.Selector) {
|
||||
s.ForShare(opts...)
|
||||
})
|
||||
return sq
|
||||
}
|
||||
|
||||
// SkinGroupBy is the group-by builder for Skin entities.
|
||||
type SkinGroupBy struct {
|
||||
selector
|
||||
build *SkinQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (sgb *SkinGroupBy) Aggregate(fns ...AggregateFunc) *SkinGroupBy {
|
||||
sgb.fns = append(sgb.fns, fns...)
|
||||
return sgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (sgb *SkinGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, sgb.build.ctx, "GroupBy")
|
||||
if err := sgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*SkinQuery, *SkinGroupBy](ctx, sgb.build, sgb, sgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (sgb *SkinGroupBy) sqlScan(ctx context.Context, root *SkinQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(sgb.fns))
|
||||
for _, fn := range sgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*sgb.flds)+len(sgb.fns))
|
||||
for _, f := range *sgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*sgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := sgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// SkinSelect is the builder for selecting fields of Skin entities.
|
||||
type SkinSelect struct {
|
||||
*SkinQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ss *SkinSelect) Aggregate(fns ...AggregateFunc) *SkinSelect {
|
||||
ss.fns = append(ss.fns, fns...)
|
||||
return ss
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ss *SkinSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ss.ctx, "Select")
|
||||
if err := ss.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*SkinQuery, *SkinSelect](ctx, ss.SkinQuery, ss, ss.inters, v)
|
||||
}
|
||||
|
||||
func (ss *SkinSelect) sqlScan(ctx context.Context, root *SkinQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ss.fns))
|
||||
for _, fn := range ss.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ss.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ss.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
@ -1,364 +0,0 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/skin"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
)
|
||||
|
||||
// SkinUpdate is the builder for updating Skin entities.
|
||||
type SkinUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *SkinMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SkinUpdate builder.
|
||||
func (su *SkinUpdate) Where(ps ...predicate.Skin) *SkinUpdate {
|
||||
su.mutation.Where(ps...)
|
||||
return su
|
||||
}
|
||||
|
||||
// SetSkinHash sets the "skin_hash" field.
|
||||
func (su *SkinUpdate) SetSkinHash(s string) *SkinUpdate {
|
||||
su.mutation.SetSkinHash(s)
|
||||
return su
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (su *SkinUpdate) SetType(u uint8) *SkinUpdate {
|
||||
su.mutation.ResetType()
|
||||
su.mutation.SetType(u)
|
||||
return su
|
||||
}
|
||||
|
||||
// AddType adds u to the "type" field.
|
||||
func (su *SkinUpdate) AddType(u int8) *SkinUpdate {
|
||||
su.mutation.AddType(u)
|
||||
return su
|
||||
}
|
||||
|
||||
// SetVariant sets the "variant" field.
|
||||
func (su *SkinUpdate) SetVariant(s string) *SkinUpdate {
|
||||
su.mutation.SetVariant(s)
|
||||
return su
|
||||
}
|
||||
|
||||
// SetCreatedUserID sets the "created_user" edge to the User entity by ID.
|
||||
func (su *SkinUpdate) SetCreatedUserID(id int) *SkinUpdate {
|
||||
su.mutation.SetCreatedUserID(id)
|
||||
return su
|
||||
}
|
||||
|
||||
// SetCreatedUser sets the "created_user" edge to the User entity.
|
||||
func (su *SkinUpdate) SetCreatedUser(u *User) *SkinUpdate {
|
||||
return su.SetCreatedUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SkinMutation object of the builder.
|
||||
func (su *SkinUpdate) Mutation() *SkinMutation {
|
||||
return su.mutation
|
||||
}
|
||||
|
||||
// ClearCreatedUser clears the "created_user" edge to the User entity.
|
||||
func (su *SkinUpdate) ClearCreatedUser() *SkinUpdate {
|
||||
su.mutation.ClearCreatedUser()
|
||||
return su
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (su *SkinUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, su.sqlSave, su.mutation, su.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (su *SkinUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := su.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (su *SkinUpdate) Exec(ctx context.Context) error {
|
||||
_, err := su.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (su *SkinUpdate) ExecX(ctx context.Context) {
|
||||
if err := su.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (su *SkinUpdate) check() error {
|
||||
if _, ok := su.mutation.CreatedUserID(); su.mutation.CreatedUserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Skin.created_user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (su *SkinUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := su.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(skin.Table, skin.Columns, sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt))
|
||||
if ps := su.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := su.mutation.SkinHash(); ok {
|
||||
_spec.SetField(skin.FieldSkinHash, field.TypeString, value)
|
||||
}
|
||||
if value, ok := su.mutation.GetType(); ok {
|
||||
_spec.SetField(skin.FieldType, field.TypeUint8, value)
|
||||
}
|
||||
if value, ok := su.mutation.AddedType(); ok {
|
||||
_spec.AddField(skin.FieldType, field.TypeUint8, value)
|
||||
}
|
||||
if value, ok := su.mutation.Variant(); ok {
|
||||
_spec.SetField(skin.FieldVariant, field.TypeString, value)
|
||||
}
|
||||
if su.mutation.CreatedUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: skin.CreatedUserTable,
|
||||
Columns: []string{skin.CreatedUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := su.mutation.CreatedUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: skin.CreatedUserTable,
|
||||
Columns: []string{skin.CreatedUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, su.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{skin.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
su.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// SkinUpdateOne is the builder for updating a single Skin entity.
|
||||
type SkinUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *SkinMutation
|
||||
}
|
||||
|
||||
// SetSkinHash sets the "skin_hash" field.
|
||||
func (suo *SkinUpdateOne) SetSkinHash(s string) *SkinUpdateOne {
|
||||
suo.mutation.SetSkinHash(s)
|
||||
return suo
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (suo *SkinUpdateOne) SetType(u uint8) *SkinUpdateOne {
|
||||
suo.mutation.ResetType()
|
||||
suo.mutation.SetType(u)
|
||||
return suo
|
||||
}
|
||||
|
||||
// AddType adds u to the "type" field.
|
||||
func (suo *SkinUpdateOne) AddType(u int8) *SkinUpdateOne {
|
||||
suo.mutation.AddType(u)
|
||||
return suo
|
||||
}
|
||||
|
||||
// SetVariant sets the "variant" field.
|
||||
func (suo *SkinUpdateOne) SetVariant(s string) *SkinUpdateOne {
|
||||
suo.mutation.SetVariant(s)
|
||||
return suo
|
||||
}
|
||||
|
||||
// SetCreatedUserID sets the "created_user" edge to the User entity by ID.
|
||||
func (suo *SkinUpdateOne) SetCreatedUserID(id int) *SkinUpdateOne {
|
||||
suo.mutation.SetCreatedUserID(id)
|
||||
return suo
|
||||
}
|
||||
|
||||
// SetCreatedUser sets the "created_user" edge to the User entity.
|
||||
func (suo *SkinUpdateOne) SetCreatedUser(u *User) *SkinUpdateOne {
|
||||
return suo.SetCreatedUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the SkinMutation object of the builder.
|
||||
func (suo *SkinUpdateOne) Mutation() *SkinMutation {
|
||||
return suo.mutation
|
||||
}
|
||||
|
||||
// ClearCreatedUser clears the "created_user" edge to the User entity.
|
||||
func (suo *SkinUpdateOne) ClearCreatedUser() *SkinUpdateOne {
|
||||
suo.mutation.ClearCreatedUser()
|
||||
return suo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the SkinUpdate builder.
|
||||
func (suo *SkinUpdateOne) Where(ps ...predicate.Skin) *SkinUpdateOne {
|
||||
suo.mutation.Where(ps...)
|
||||
return suo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (suo *SkinUpdateOne) Select(field string, fields ...string) *SkinUpdateOne {
|
||||
suo.fields = append([]string{field}, fields...)
|
||||
return suo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Skin entity.
|
||||
func (suo *SkinUpdateOne) Save(ctx context.Context) (*Skin, error) {
|
||||
return withHooks(ctx, suo.sqlSave, suo.mutation, suo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (suo *SkinUpdateOne) SaveX(ctx context.Context) *Skin {
|
||||
node, err := suo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (suo *SkinUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := suo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (suo *SkinUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := suo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (suo *SkinUpdateOne) check() error {
|
||||
if _, ok := suo.mutation.CreatedUserID(); suo.mutation.CreatedUserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Skin.created_user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (suo *SkinUpdateOne) sqlSave(ctx context.Context) (_node *Skin, err error) {
|
||||
if err := suo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(skin.Table, skin.Columns, sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt))
|
||||
id, ok := suo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Skin.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := suo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, skin.FieldID)
|
||||
for _, f := range fields {
|
||||
if !skin.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != skin.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := suo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := suo.mutation.SkinHash(); ok {
|
||||
_spec.SetField(skin.FieldSkinHash, field.TypeString, value)
|
||||
}
|
||||
if value, ok := suo.mutation.GetType(); ok {
|
||||
_spec.SetField(skin.FieldType, field.TypeUint8, value)
|
||||
}
|
||||
if value, ok := suo.mutation.AddedType(); ok {
|
||||
_spec.AddField(skin.FieldType, field.TypeUint8, value)
|
||||
}
|
||||
if value, ok := suo.mutation.Variant(); ok {
|
||||
_spec.SetField(skin.FieldVariant, field.TypeString, value)
|
||||
}
|
||||
if suo.mutation.CreatedUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: skin.CreatedUserTable,
|
||||
Columns: []string{skin.CreatedUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := suo.mutation.CreatedUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: skin.CreatedUserTable,
|
||||
Columns: []string{skin.CreatedUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Skin{config: suo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, suo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{skin.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
suo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
176
db/ent/texture.go
Normal file
176
db/ent/texture.go
Normal file
@ -0,0 +1,176 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
)
|
||||
|
||||
// Texture is the model entity for the Texture schema.
|
||||
type Texture struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// TextureHash holds the value of the "texture_hash" field.
|
||||
TextureHash string `json:"texture_hash,omitempty"`
|
||||
// Type holds the value of the "type" field.
|
||||
Type string `json:"type,omitempty"`
|
||||
// Variant holds the value of the "variant" field.
|
||||
Variant string `json:"variant,omitempty"`
|
||||
// Edges holds the relations/edges for other nodes in the graph.
|
||||
// The values are being populated by the TextureQuery when eager-loading is set.
|
||||
Edges TextureEdges `json:"edges"`
|
||||
texture_created_user *int
|
||||
user_profile_texture *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// TextureEdges holds the relations/edges for other nodes in the graph.
|
||||
type TextureEdges struct {
|
||||
// CreatedUser holds the value of the created_user edge.
|
||||
CreatedUser *User `json:"created_user,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
}
|
||||
|
||||
// CreatedUserOrErr returns the CreatedUser value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e TextureEdges) CreatedUserOrErr() (*User, error) {
|
||||
if e.loadedTypes[0] {
|
||||
if e.CreatedUser == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: user.Label}
|
||||
}
|
||||
return e.CreatedUser, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "created_user"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Texture) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case texture.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case texture.FieldTextureHash, texture.FieldType, texture.FieldVariant:
|
||||
values[i] = new(sql.NullString)
|
||||
case texture.ForeignKeys[0]: // texture_created_user
|
||||
values[i] = new(sql.NullInt64)
|
||||
case texture.ForeignKeys[1]: // user_profile_texture
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Texture fields.
|
||||
func (t *Texture) assignValues(columns []string, values []any) error {
|
||||
if m, n := len(values), len(columns); m < n {
|
||||
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
||||
}
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case texture.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
t.ID = int(value.Int64)
|
||||
case texture.FieldTextureHash:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field texture_hash", values[i])
|
||||
} else if value.Valid {
|
||||
t.TextureHash = value.String
|
||||
}
|
||||
case texture.FieldType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||
} else if value.Valid {
|
||||
t.Type = value.String
|
||||
}
|
||||
case texture.FieldVariant:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field variant", values[i])
|
||||
} else if value.Valid {
|
||||
t.Variant = value.String
|
||||
}
|
||||
case texture.ForeignKeys[0]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field texture_created_user", value)
|
||||
} else if value.Valid {
|
||||
t.texture_created_user = new(int)
|
||||
*t.texture_created_user = int(value.Int64)
|
||||
}
|
||||
case texture.ForeignKeys[1]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field user_profile_texture", value)
|
||||
} else if value.Valid {
|
||||
t.user_profile_texture = new(int)
|
||||
*t.user_profile_texture = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
t.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Value returns the ent.Value that was dynamically selected and assigned to the Texture.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (t *Texture) Value(name string) (ent.Value, error) {
|
||||
return t.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryCreatedUser queries the "created_user" edge of the Texture entity.
|
||||
func (t *Texture) QueryCreatedUser() *UserQuery {
|
||||
return NewTextureClient(t.config).QueryCreatedUser(t)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Texture.
|
||||
// Note that you need to call Texture.Unwrap() before calling this method if this Texture
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (t *Texture) Update() *TextureUpdateOne {
|
||||
return NewTextureClient(t.config).UpdateOne(t)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Texture entity that was returned from a transaction after it was closed,
|
||||
// so that all future queries will be executed through the driver which created the transaction.
|
||||
func (t *Texture) Unwrap() *Texture {
|
||||
_tx, ok := t.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Texture is not a transactional entity")
|
||||
}
|
||||
t.config.driver = _tx.drv
|
||||
return t
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (t *Texture) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Texture(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", t.ID))
|
||||
builder.WriteString("texture_hash=")
|
||||
builder.WriteString(t.TextureHash)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(t.Type)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("variant=")
|
||||
builder.WriteString(t.Variant)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Textures is a parsable slice of Texture.
|
||||
type Textures []*Texture
|
@ -1,6 +1,6 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package skin
|
||||
package texture
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
@ -8,41 +8,42 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the skin type in the database.
|
||||
Label = "skin"
|
||||
// Label holds the string label denoting the texture type in the database.
|
||||
Label = "texture"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldSkinHash holds the string denoting the skin_hash field in the database.
|
||||
FieldSkinHash = "skin_hash"
|
||||
// FieldTextureHash holds the string denoting the texture_hash field in the database.
|
||||
FieldTextureHash = "texture_hash"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldVariant holds the string denoting the variant field in the database.
|
||||
FieldVariant = "variant"
|
||||
// EdgeCreatedUser holds the string denoting the created_user edge name in mutations.
|
||||
EdgeCreatedUser = "created_user"
|
||||
// Table holds the table name of the skin in the database.
|
||||
Table = "skins"
|
||||
// Table holds the table name of the texture in the database.
|
||||
Table = "textures"
|
||||
// CreatedUserTable is the table that holds the created_user relation/edge.
|
||||
CreatedUserTable = "skins"
|
||||
CreatedUserTable = "textures"
|
||||
// CreatedUserInverseTable is the table name for the User entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "user" package.
|
||||
CreatedUserInverseTable = "users"
|
||||
// CreatedUserColumn is the table column denoting the created_user relation/edge.
|
||||
CreatedUserColumn = "skin_created_user"
|
||||
CreatedUserColumn = "texture_created_user"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for skin fields.
|
||||
// Columns holds all SQL columns for texture fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldSkinHash,
|
||||
FieldTextureHash,
|
||||
FieldType,
|
||||
FieldVariant,
|
||||
}
|
||||
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "skins"
|
||||
// ForeignKeys holds the SQL foreign-keys that are owned by the "textures"
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"skin_created_user",
|
||||
"texture_created_user",
|
||||
"user_profile_texture",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@ -60,7 +61,7 @@ func ValidColumn(column string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Skin queries.
|
||||
// OrderOption defines the ordering options for the Texture queries.
|
||||
type OrderOption func(*sql.Selector)
|
||||
|
||||
// ByID orders the results by the id field.
|
||||
@ -68,9 +69,9 @@ func ByID(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldID, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// BySkinHash orders the results by the skin_hash field.
|
||||
func BySkinHash(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldSkinHash, opts...).ToFunc()
|
||||
// ByTextureHash orders the results by the texture_hash field.
|
||||
func ByTextureHash(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldTextureHash, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByType orders the results by the type field.
|
319
db/ent/texture/where.go
Normal file
319
db/ent/texture/where.go
Normal file
@ -0,0 +1,319 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package texture
|
||||
|
||||
import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// TextureHash applies equality check predicate on the "texture_hash" field. It's identical to TextureHashEQ.
|
||||
func TextureHash(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEQ(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// Type applies equality check predicate on the "type" field. It's identical to TypeEQ.
|
||||
func Type(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// Variant applies equality check predicate on the "variant" field. It's identical to VariantEQ.
|
||||
func Variant(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEQ(FieldVariant, v))
|
||||
}
|
||||
|
||||
// TextureHashEQ applies the EQ predicate on the "texture_hash" field.
|
||||
func TextureHashEQ(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEQ(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TextureHashNEQ applies the NEQ predicate on the "texture_hash" field.
|
||||
func TextureHashNEQ(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldNEQ(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TextureHashIn applies the In predicate on the "texture_hash" field.
|
||||
func TextureHashIn(vs ...string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldIn(FieldTextureHash, vs...))
|
||||
}
|
||||
|
||||
// TextureHashNotIn applies the NotIn predicate on the "texture_hash" field.
|
||||
func TextureHashNotIn(vs ...string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldNotIn(FieldTextureHash, vs...))
|
||||
}
|
||||
|
||||
// TextureHashGT applies the GT predicate on the "texture_hash" field.
|
||||
func TextureHashGT(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldGT(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TextureHashGTE applies the GTE predicate on the "texture_hash" field.
|
||||
func TextureHashGTE(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldGTE(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TextureHashLT applies the LT predicate on the "texture_hash" field.
|
||||
func TextureHashLT(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldLT(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TextureHashLTE applies the LTE predicate on the "texture_hash" field.
|
||||
func TextureHashLTE(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldLTE(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TextureHashContains applies the Contains predicate on the "texture_hash" field.
|
||||
func TextureHashContains(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldContains(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TextureHashHasPrefix applies the HasPrefix predicate on the "texture_hash" field.
|
||||
func TextureHashHasPrefix(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldHasPrefix(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TextureHashHasSuffix applies the HasSuffix predicate on the "texture_hash" field.
|
||||
func TextureHashHasSuffix(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldHasSuffix(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TextureHashEqualFold applies the EqualFold predicate on the "texture_hash" field.
|
||||
func TextureHashEqualFold(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEqualFold(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TextureHashContainsFold applies the ContainsFold predicate on the "texture_hash" field.
|
||||
func TextureHashContainsFold(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldContainsFold(FieldTextureHash, v))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||
func TypeNEQ(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldNEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeIn applies the In predicate on the "type" field.
|
||||
func TypeIn(vs ...string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||
func TypeNotIn(vs ...string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeGT applies the GT predicate on the "type" field.
|
||||
func TypeGT(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldGT(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeGTE applies the GTE predicate on the "type" field.
|
||||
func TypeGTE(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldGTE(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeLT applies the LT predicate on the "type" field.
|
||||
func TypeLT(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldLT(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeLTE applies the LTE predicate on the "type" field.
|
||||
func TypeLTE(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldLTE(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeContains applies the Contains predicate on the "type" field.
|
||||
func TypeContains(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldContains(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeHasPrefix applies the HasPrefix predicate on the "type" field.
|
||||
func TypeHasPrefix(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldHasPrefix(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeHasSuffix applies the HasSuffix predicate on the "type" field.
|
||||
func TypeHasSuffix(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldHasSuffix(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeEqualFold applies the EqualFold predicate on the "type" field.
|
||||
func TypeEqualFold(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEqualFold(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeContainsFold applies the ContainsFold predicate on the "type" field.
|
||||
func TypeContainsFold(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldContainsFold(FieldType, v))
|
||||
}
|
||||
|
||||
// VariantEQ applies the EQ predicate on the "variant" field.
|
||||
func VariantEQ(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEQ(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantNEQ applies the NEQ predicate on the "variant" field.
|
||||
func VariantNEQ(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldNEQ(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantIn applies the In predicate on the "variant" field.
|
||||
func VariantIn(vs ...string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldIn(FieldVariant, vs...))
|
||||
}
|
||||
|
||||
// VariantNotIn applies the NotIn predicate on the "variant" field.
|
||||
func VariantNotIn(vs ...string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldNotIn(FieldVariant, vs...))
|
||||
}
|
||||
|
||||
// VariantGT applies the GT predicate on the "variant" field.
|
||||
func VariantGT(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldGT(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantGTE applies the GTE predicate on the "variant" field.
|
||||
func VariantGTE(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldGTE(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantLT applies the LT predicate on the "variant" field.
|
||||
func VariantLT(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldLT(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantLTE applies the LTE predicate on the "variant" field.
|
||||
func VariantLTE(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldLTE(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantContains applies the Contains predicate on the "variant" field.
|
||||
func VariantContains(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldContains(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantHasPrefix applies the HasPrefix predicate on the "variant" field.
|
||||
func VariantHasPrefix(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldHasPrefix(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantHasSuffix applies the HasSuffix predicate on the "variant" field.
|
||||
func VariantHasSuffix(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldHasSuffix(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantEqualFold applies the EqualFold predicate on the "variant" field.
|
||||
func VariantEqualFold(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldEqualFold(FieldVariant, v))
|
||||
}
|
||||
|
||||
// VariantContainsFold applies the ContainsFold predicate on the "variant" field.
|
||||
func VariantContainsFold(v string) predicate.Texture {
|
||||
return predicate.Texture(sql.FieldContainsFold(FieldVariant, v))
|
||||
}
|
||||
|
||||
// HasCreatedUser applies the HasEdge predicate on the "created_user" edge.
|
||||
func HasCreatedUser() predicate.Texture {
|
||||
return predicate.Texture(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, CreatedUserTable, CreatedUserColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasCreatedUserWith applies the HasEdge predicate on the "created_user" edge with a given conditions (other predicates).
|
||||
func HasCreatedUserWith(preds ...predicate.User) predicate.Texture {
|
||||
return predicate.Texture(func(s *sql.Selector) {
|
||||
step := newCreatedUserStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Texture) predicate.Texture {
|
||||
return predicate.Texture(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for _, p := range predicates {
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Texture) predicate.Texture {
|
||||
return predicate.Texture(func(s *sql.Selector) {
|
||||
s1 := s.Clone().SetP(nil)
|
||||
for i, p := range predicates {
|
||||
if i > 0 {
|
||||
s1.Or()
|
||||
}
|
||||
p(s1)
|
||||
}
|
||||
s.Where(s1.P())
|
||||
})
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Texture) predicate.Texture {
|
||||
return predicate.Texture(func(s *sql.Selector) {
|
||||
p(s.Not())
|
||||
})
|
||||
}
|
237
db/ent/texture_create.go
Normal file
237
db/ent/texture_create.go
Normal file
@ -0,0 +1,237 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
)
|
||||
|
||||
// TextureCreate is the builder for creating a Texture entity.
|
||||
type TextureCreate struct {
|
||||
config
|
||||
mutation *TextureMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetTextureHash sets the "texture_hash" field.
|
||||
func (tc *TextureCreate) SetTextureHash(s string) *TextureCreate {
|
||||
tc.mutation.SetTextureHash(s)
|
||||
return tc
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (tc *TextureCreate) SetType(s string) *TextureCreate {
|
||||
tc.mutation.SetType(s)
|
||||
return tc
|
||||
}
|
||||
|
||||
// SetVariant sets the "variant" field.
|
||||
func (tc *TextureCreate) SetVariant(s string) *TextureCreate {
|
||||
tc.mutation.SetVariant(s)
|
||||
return tc
|
||||
}
|
||||
|
||||
// SetCreatedUserID sets the "created_user" edge to the User entity by ID.
|
||||
func (tc *TextureCreate) SetCreatedUserID(id int) *TextureCreate {
|
||||
tc.mutation.SetCreatedUserID(id)
|
||||
return tc
|
||||
}
|
||||
|
||||
// SetCreatedUser sets the "created_user" edge to the User entity.
|
||||
func (tc *TextureCreate) SetCreatedUser(u *User) *TextureCreate {
|
||||
return tc.SetCreatedUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the TextureMutation object of the builder.
|
||||
func (tc *TextureCreate) Mutation() *TextureMutation {
|
||||
return tc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Texture in the database.
|
||||
func (tc *TextureCreate) Save(ctx context.Context) (*Texture, error) {
|
||||
return withHooks(ctx, tc.sqlSave, tc.mutation, tc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (tc *TextureCreate) SaveX(ctx context.Context) *Texture {
|
||||
v, err := tc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (tc *TextureCreate) Exec(ctx context.Context) error {
|
||||
_, err := tc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tc *TextureCreate) ExecX(ctx context.Context) {
|
||||
if err := tc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (tc *TextureCreate) check() error {
|
||||
if _, ok := tc.mutation.TextureHash(); !ok {
|
||||
return &ValidationError{Name: "texture_hash", err: errors.New(`ent: missing required field "Texture.texture_hash"`)}
|
||||
}
|
||||
if _, ok := tc.mutation.GetType(); !ok {
|
||||
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Texture.type"`)}
|
||||
}
|
||||
if _, ok := tc.mutation.Variant(); !ok {
|
||||
return &ValidationError{Name: "variant", err: errors.New(`ent: missing required field "Texture.variant"`)}
|
||||
}
|
||||
if _, ok := tc.mutation.CreatedUserID(); !ok {
|
||||
return &ValidationError{Name: "created_user", err: errors.New(`ent: missing required edge "Texture.created_user"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tc *TextureCreate) sqlSave(ctx context.Context) (*Texture, error) {
|
||||
if err := tc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := tc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, tc.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
tc.mutation.id = &_node.ID
|
||||
tc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (tc *TextureCreate) createSpec() (*Texture, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Texture{config: tc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(texture.Table, sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := tc.mutation.TextureHash(); ok {
|
||||
_spec.SetField(texture.FieldTextureHash, field.TypeString, value)
|
||||
_node.TextureHash = value
|
||||
}
|
||||
if value, ok := tc.mutation.GetType(); ok {
|
||||
_spec.SetField(texture.FieldType, field.TypeString, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := tc.mutation.Variant(); ok {
|
||||
_spec.SetField(texture.FieldVariant, field.TypeString, value)
|
||||
_node.Variant = value
|
||||
}
|
||||
if nodes := tc.mutation.CreatedUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: texture.CreatedUserTable,
|
||||
Columns: []string{texture.CreatedUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.texture_created_user = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// TextureCreateBulk is the builder for creating many Texture entities in bulk.
|
||||
type TextureCreateBulk struct {
|
||||
config
|
||||
builders []*TextureCreate
|
||||
}
|
||||
|
||||
// Save creates the Texture entities in the database.
|
||||
func (tcb *TextureCreateBulk) Save(ctx context.Context) ([]*Texture, error) {
|
||||
specs := make([]*sqlgraph.CreateSpec, len(tcb.builders))
|
||||
nodes := make([]*Texture, len(tcb.builders))
|
||||
mutators := make([]Mutator, len(tcb.builders))
|
||||
for i := range tcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := tcb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*TextureMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, tcb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, tcb.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, tcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tcb *TextureCreateBulk) SaveX(ctx context.Context) []*Texture {
|
||||
v, err := tcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (tcb *TextureCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := tcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tcb *TextureCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := tcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
88
db/ent/texture_delete.go
Normal file
88
db/ent/texture_delete.go
Normal file
@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
)
|
||||
|
||||
// TextureDelete is the builder for deleting a Texture entity.
|
||||
type TextureDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *TextureMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TextureDelete builder.
|
||||
func (td *TextureDelete) Where(ps ...predicate.Texture) *TextureDelete {
|
||||
td.mutation.Where(ps...)
|
||||
return td
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (td *TextureDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, td.sqlExec, td.mutation, td.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (td *TextureDelete) ExecX(ctx context.Context) int {
|
||||
n, err := td.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (td *TextureDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(texture.Table, sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt))
|
||||
if ps := td.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, td.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
td.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// TextureDeleteOne is the builder for deleting a single Texture entity.
|
||||
type TextureDeleteOne struct {
|
||||
td *TextureDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TextureDelete builder.
|
||||
func (tdo *TextureDeleteOne) Where(ps ...predicate.Texture) *TextureDeleteOne {
|
||||
tdo.td.mutation.Where(ps...)
|
||||
return tdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (tdo *TextureDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := tdo.td.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{texture.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tdo *TextureDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := tdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
650
db/ent/texture_query.go
Normal file
650
db/ent/texture_query.go
Normal file
@ -0,0 +1,650 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
)
|
||||
|
||||
// TextureQuery is the builder for querying Texture entities.
|
||||
type TextureQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []texture.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Texture
|
||||
withCreatedUser *UserQuery
|
||||
withFKs bool
|
||||
modifiers []func(*sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the TextureQuery builder.
|
||||
func (tq *TextureQuery) Where(ps ...predicate.Texture) *TextureQuery {
|
||||
tq.predicates = append(tq.predicates, ps...)
|
||||
return tq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (tq *TextureQuery) Limit(limit int) *TextureQuery {
|
||||
tq.ctx.Limit = &limit
|
||||
return tq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (tq *TextureQuery) Offset(offset int) *TextureQuery {
|
||||
tq.ctx.Offset = &offset
|
||||
return tq
|
||||
}
|
||||
|
||||
// Unique configures the query builder to filter duplicate records on query.
|
||||
// By default, unique is set to true, and can be disabled using this method.
|
||||
func (tq *TextureQuery) Unique(unique bool) *TextureQuery {
|
||||
tq.ctx.Unique = &unique
|
||||
return tq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (tq *TextureQuery) Order(o ...texture.OrderOption) *TextureQuery {
|
||||
tq.order = append(tq.order, o...)
|
||||
return tq
|
||||
}
|
||||
|
||||
// QueryCreatedUser chains the current query on the "created_user" edge.
|
||||
func (tq *TextureQuery) QueryCreatedUser() *UserQuery {
|
||||
query := (&UserClient{config: tq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := tq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := tq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(texture.Table, texture.FieldID, selector),
|
||||
sqlgraph.To(user.Table, user.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, texture.CreatedUserTable, texture.CreatedUserColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(tq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first Texture entity from the query.
|
||||
// Returns a *NotFoundError when no Texture was found.
|
||||
func (tq *TextureQuery) First(ctx context.Context) (*Texture, error) {
|
||||
nodes, err := tq.Limit(1).All(setContextOp(ctx, tq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{texture.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (tq *TextureQuery) FirstX(ctx context.Context) *Texture {
|
||||
node, err := tq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Texture ID from the query.
|
||||
// Returns a *NotFoundError when no Texture ID was found.
|
||||
func (tq *TextureQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = tq.Limit(1).IDs(setContextOp(ctx, tq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{texture.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (tq *TextureQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := tq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Texture entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Texture entity is found.
|
||||
// Returns a *NotFoundError when no Texture entities are found.
|
||||
func (tq *TextureQuery) Only(ctx context.Context) (*Texture, error) {
|
||||
nodes, err := tq.Limit(2).All(setContextOp(ctx, tq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{texture.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{texture.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (tq *TextureQuery) OnlyX(ctx context.Context) *Texture {
|
||||
node, err := tq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Texture ID in the query.
|
||||
// Returns a *NotSingularError when more than one Texture ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (tq *TextureQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = tq.Limit(2).IDs(setContextOp(ctx, tq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{texture.Label}
|
||||
default:
|
||||
err = &NotSingularError{texture.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (tq *TextureQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := tq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Textures.
|
||||
func (tq *TextureQuery) All(ctx context.Context) ([]*Texture, error) {
|
||||
ctx = setContextOp(ctx, tq.ctx, "All")
|
||||
if err := tq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Texture, *TextureQuery]()
|
||||
return withInterceptors[[]*Texture](ctx, tq, qr, tq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (tq *TextureQuery) AllX(ctx context.Context) []*Texture {
|
||||
nodes, err := tq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Texture IDs.
|
||||
func (tq *TextureQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if tq.ctx.Unique == nil && tq.path != nil {
|
||||
tq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, tq.ctx, "IDs")
|
||||
if err = tq.Select(texture.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (tq *TextureQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := tq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (tq *TextureQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, tq.ctx, "Count")
|
||||
if err := tq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, tq, querierCount[*TextureQuery](), tq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (tq *TextureQuery) CountX(ctx context.Context) int {
|
||||
count, err := tq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (tq *TextureQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, tq.ctx, "Exist")
|
||||
switch _, err := tq.FirstID(ctx); {
|
||||
case IsNotFound(err):
|
||||
return false, nil
|
||||
case err != nil:
|
||||
return false, fmt.Errorf("ent: check existence: %w", err)
|
||||
default:
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExistX is like Exist, but panics if an error occurs.
|
||||
func (tq *TextureQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := tq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the TextureQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (tq *TextureQuery) Clone() *TextureQuery {
|
||||
if tq == nil {
|
||||
return nil
|
||||
}
|
||||
return &TextureQuery{
|
||||
config: tq.config,
|
||||
ctx: tq.ctx.Clone(),
|
||||
order: append([]texture.OrderOption{}, tq.order...),
|
||||
inters: append([]Interceptor{}, tq.inters...),
|
||||
predicates: append([]predicate.Texture{}, tq.predicates...),
|
||||
withCreatedUser: tq.withCreatedUser.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: tq.sql.Clone(),
|
||||
path: tq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithCreatedUser tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "created_user" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (tq *TextureQuery) WithCreatedUser(opts ...func(*UserQuery)) *TextureQuery {
|
||||
query := (&UserClient{config: tq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
tq.withCreatedUser = query
|
||||
return tq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// TextureHash string `json:"texture_hash,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Texture.Query().
|
||||
// GroupBy(texture.FieldTextureHash).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (tq *TextureQuery) GroupBy(field string, fields ...string) *TextureGroupBy {
|
||||
tq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &TextureGroupBy{build: tq}
|
||||
grbuild.flds = &tq.ctx.Fields
|
||||
grbuild.label = texture.Label
|
||||
grbuild.scan = grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
// instead of selecting all fields in the entity.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// var v []struct {
|
||||
// TextureHash string `json:"texture_hash,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Texture.Query().
|
||||
// Select(texture.FieldTextureHash).
|
||||
// Scan(ctx, &v)
|
||||
func (tq *TextureQuery) Select(fields ...string) *TextureSelect {
|
||||
tq.ctx.Fields = append(tq.ctx.Fields, fields...)
|
||||
sbuild := &TextureSelect{TextureQuery: tq}
|
||||
sbuild.label = texture.Label
|
||||
sbuild.flds, sbuild.scan = &tq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a TextureSelect configured with the given aggregations.
|
||||
func (tq *TextureQuery) Aggregate(fns ...AggregateFunc) *TextureSelect {
|
||||
return tq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (tq *TextureQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range tq.inters {
|
||||
if inter == nil {
|
||||
return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)")
|
||||
}
|
||||
if trv, ok := inter.(Traverser); ok {
|
||||
if err := trv.Traverse(ctx, tq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range tq.ctx.Fields {
|
||||
if !texture.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if tq.path != nil {
|
||||
prev, err := tq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tq *TextureQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Texture, error) {
|
||||
var (
|
||||
nodes = []*Texture{}
|
||||
withFKs = tq.withFKs
|
||||
_spec = tq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
tq.withCreatedUser != nil,
|
||||
}
|
||||
)
|
||||
if tq.withCreatedUser != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, texture.ForeignKeys...)
|
||||
}
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Texture).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Texture{config: tq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
if len(tq.modifiers) > 0 {
|
||||
_spec.Modifiers = tq.modifiers
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, tq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := tq.withCreatedUser; query != nil {
|
||||
if err := tq.loadCreatedUser(ctx, query, nodes, nil,
|
||||
func(n *Texture, e *User) { n.Edges.CreatedUser = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (tq *TextureQuery) loadCreatedUser(ctx context.Context, query *UserQuery, nodes []*Texture, init func(*Texture), assign func(*Texture, *User)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Texture)
|
||||
for i := range nodes {
|
||||
if nodes[i].texture_created_user == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].texture_created_user
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(user.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "texture_created_user" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tq *TextureQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := tq.querySpec()
|
||||
if len(tq.modifiers) > 0 {
|
||||
_spec.Modifiers = tq.modifiers
|
||||
}
|
||||
_spec.Node.Columns = tq.ctx.Fields
|
||||
if len(tq.ctx.Fields) > 0 {
|
||||
_spec.Unique = tq.ctx.Unique != nil && *tq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, tq.driver, _spec)
|
||||
}
|
||||
|
||||
func (tq *TextureQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(texture.Table, texture.Columns, sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt))
|
||||
_spec.From = tq.sql
|
||||
if unique := tq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if tq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := tq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, texture.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != texture.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := tq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := tq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := tq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := tq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (tq *TextureQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(tq.driver.Dialect())
|
||||
t1 := builder.Table(texture.Table)
|
||||
columns := tq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = texture.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if tq.sql != nil {
|
||||
selector = tq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if tq.ctx.Unique != nil && *tq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, m := range tq.modifiers {
|
||||
m(selector)
|
||||
}
|
||||
for _, p := range tq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range tq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := tq.ctx.Offset; offset != nil {
|
||||
// limit is mandatory for offset clause. We start
|
||||
// with default value, and override it below if needed.
|
||||
selector.Offset(*offset).Limit(math.MaxInt32)
|
||||
}
|
||||
if limit := tq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
|
||||
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
|
||||
// either committed or rolled-back.
|
||||
func (tq *TextureQuery) ForUpdate(opts ...sql.LockOption) *TextureQuery {
|
||||
if tq.driver.Dialect() == dialect.Postgres {
|
||||
tq.Unique(false)
|
||||
}
|
||||
tq.modifiers = append(tq.modifiers, func(s *sql.Selector) {
|
||||
s.ForUpdate(opts...)
|
||||
})
|
||||
return tq
|
||||
}
|
||||
|
||||
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
|
||||
// on any rows that are read. Other sessions can read the rows, but cannot modify them
|
||||
// until your transaction commits.
|
||||
func (tq *TextureQuery) ForShare(opts ...sql.LockOption) *TextureQuery {
|
||||
if tq.driver.Dialect() == dialect.Postgres {
|
||||
tq.Unique(false)
|
||||
}
|
||||
tq.modifiers = append(tq.modifiers, func(s *sql.Selector) {
|
||||
s.ForShare(opts...)
|
||||
})
|
||||
return tq
|
||||
}
|
||||
|
||||
// TextureGroupBy is the group-by builder for Texture entities.
|
||||
type TextureGroupBy struct {
|
||||
selector
|
||||
build *TextureQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (tgb *TextureGroupBy) Aggregate(fns ...AggregateFunc) *TextureGroupBy {
|
||||
tgb.fns = append(tgb.fns, fns...)
|
||||
return tgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (tgb *TextureGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, tgb.build.ctx, "GroupBy")
|
||||
if err := tgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*TextureQuery, *TextureGroupBy](ctx, tgb.build, tgb, tgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (tgb *TextureGroupBy) sqlScan(ctx context.Context, root *TextureQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(tgb.fns))
|
||||
for _, fn := range tgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*tgb.flds)+len(tgb.fns))
|
||||
for _, f := range *tgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*tgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := tgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// TextureSelect is the builder for selecting fields of Texture entities.
|
||||
type TextureSelect struct {
|
||||
*TextureQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (ts *TextureSelect) Aggregate(fns ...AggregateFunc) *TextureSelect {
|
||||
ts.fns = append(ts.fns, fns...)
|
||||
return ts
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (ts *TextureSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, ts.ctx, "Select")
|
||||
if err := ts.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*TextureQuery, *TextureSelect](ctx, ts.TextureQuery, ts, ts.inters, v)
|
||||
}
|
||||
|
||||
func (ts *TextureSelect) sqlScan(ctx context.Context, root *TextureQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(ts.fns))
|
||||
for _, fn := range ts.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*ts.selector.flds); {
|
||||
case n == 0 && len(aggregation) > 0:
|
||||
selector.Select(aggregation...)
|
||||
case n != 0 && len(aggregation) > 0:
|
||||
selector.AppendSelect(aggregation...)
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := ts.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
344
db/ent/texture_update.go
Normal file
344
db/ent/texture_update.go
Normal file
@ -0,0 +1,344 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
)
|
||||
|
||||
// TextureUpdate is the builder for updating Texture entities.
|
||||
type TextureUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *TextureMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TextureUpdate builder.
|
||||
func (tu *TextureUpdate) Where(ps ...predicate.Texture) *TextureUpdate {
|
||||
tu.mutation.Where(ps...)
|
||||
return tu
|
||||
}
|
||||
|
||||
// SetTextureHash sets the "texture_hash" field.
|
||||
func (tu *TextureUpdate) SetTextureHash(s string) *TextureUpdate {
|
||||
tu.mutation.SetTextureHash(s)
|
||||
return tu
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (tu *TextureUpdate) SetType(s string) *TextureUpdate {
|
||||
tu.mutation.SetType(s)
|
||||
return tu
|
||||
}
|
||||
|
||||
// SetVariant sets the "variant" field.
|
||||
func (tu *TextureUpdate) SetVariant(s string) *TextureUpdate {
|
||||
tu.mutation.SetVariant(s)
|
||||
return tu
|
||||
}
|
||||
|
||||
// SetCreatedUserID sets the "created_user" edge to the User entity by ID.
|
||||
func (tu *TextureUpdate) SetCreatedUserID(id int) *TextureUpdate {
|
||||
tu.mutation.SetCreatedUserID(id)
|
||||
return tu
|
||||
}
|
||||
|
||||
// SetCreatedUser sets the "created_user" edge to the User entity.
|
||||
func (tu *TextureUpdate) SetCreatedUser(u *User) *TextureUpdate {
|
||||
return tu.SetCreatedUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the TextureMutation object of the builder.
|
||||
func (tu *TextureUpdate) Mutation() *TextureMutation {
|
||||
return tu.mutation
|
||||
}
|
||||
|
||||
// ClearCreatedUser clears the "created_user" edge to the User entity.
|
||||
func (tu *TextureUpdate) ClearCreatedUser() *TextureUpdate {
|
||||
tu.mutation.ClearCreatedUser()
|
||||
return tu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (tu *TextureUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, tu.sqlSave, tu.mutation, tu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tu *TextureUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := tu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (tu *TextureUpdate) Exec(ctx context.Context) error {
|
||||
_, err := tu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tu *TextureUpdate) ExecX(ctx context.Context) {
|
||||
if err := tu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (tu *TextureUpdate) check() error {
|
||||
if _, ok := tu.mutation.CreatedUserID(); tu.mutation.CreatedUserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Texture.created_user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tu *TextureUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := tu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(texture.Table, texture.Columns, sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt))
|
||||
if ps := tu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := tu.mutation.TextureHash(); ok {
|
||||
_spec.SetField(texture.FieldTextureHash, field.TypeString, value)
|
||||
}
|
||||
if value, ok := tu.mutation.GetType(); ok {
|
||||
_spec.SetField(texture.FieldType, field.TypeString, value)
|
||||
}
|
||||
if value, ok := tu.mutation.Variant(); ok {
|
||||
_spec.SetField(texture.FieldVariant, field.TypeString, value)
|
||||
}
|
||||
if tu.mutation.CreatedUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: texture.CreatedUserTable,
|
||||
Columns: []string{texture.CreatedUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tu.mutation.CreatedUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: texture.CreatedUserTable,
|
||||
Columns: []string{texture.CreatedUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, tu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{texture.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
tu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// TextureUpdateOne is the builder for updating a single Texture entity.
|
||||
type TextureUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *TextureMutation
|
||||
}
|
||||
|
||||
// SetTextureHash sets the "texture_hash" field.
|
||||
func (tuo *TextureUpdateOne) SetTextureHash(s string) *TextureUpdateOne {
|
||||
tuo.mutation.SetTextureHash(s)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (tuo *TextureUpdateOne) SetType(s string) *TextureUpdateOne {
|
||||
tuo.mutation.SetType(s)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// SetVariant sets the "variant" field.
|
||||
func (tuo *TextureUpdateOne) SetVariant(s string) *TextureUpdateOne {
|
||||
tuo.mutation.SetVariant(s)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// SetCreatedUserID sets the "created_user" edge to the User entity by ID.
|
||||
func (tuo *TextureUpdateOne) SetCreatedUserID(id int) *TextureUpdateOne {
|
||||
tuo.mutation.SetCreatedUserID(id)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// SetCreatedUser sets the "created_user" edge to the User entity.
|
||||
func (tuo *TextureUpdateOne) SetCreatedUser(u *User) *TextureUpdateOne {
|
||||
return tuo.SetCreatedUserID(u.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the TextureMutation object of the builder.
|
||||
func (tuo *TextureUpdateOne) Mutation() *TextureMutation {
|
||||
return tuo.mutation
|
||||
}
|
||||
|
||||
// ClearCreatedUser clears the "created_user" edge to the User entity.
|
||||
func (tuo *TextureUpdateOne) ClearCreatedUser() *TextureUpdateOne {
|
||||
tuo.mutation.ClearCreatedUser()
|
||||
return tuo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the TextureUpdate builder.
|
||||
func (tuo *TextureUpdateOne) Where(ps ...predicate.Texture) *TextureUpdateOne {
|
||||
tuo.mutation.Where(ps...)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (tuo *TextureUpdateOne) Select(field string, fields ...string) *TextureUpdateOne {
|
||||
tuo.fields = append([]string{field}, fields...)
|
||||
return tuo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Texture entity.
|
||||
func (tuo *TextureUpdateOne) Save(ctx context.Context) (*Texture, error) {
|
||||
return withHooks(ctx, tuo.sqlSave, tuo.mutation, tuo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (tuo *TextureUpdateOne) SaveX(ctx context.Context) *Texture {
|
||||
node, err := tuo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (tuo *TextureUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := tuo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (tuo *TextureUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := tuo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (tuo *TextureUpdateOne) check() error {
|
||||
if _, ok := tuo.mutation.CreatedUserID(); tuo.mutation.CreatedUserCleared() && !ok {
|
||||
return errors.New(`ent: clearing a required unique edge "Texture.created_user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (tuo *TextureUpdateOne) sqlSave(ctx context.Context) (_node *Texture, err error) {
|
||||
if err := tuo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(texture.Table, texture.Columns, sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt))
|
||||
id, ok := tuo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Texture.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := tuo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, texture.FieldID)
|
||||
for _, f := range fields {
|
||||
if !texture.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != texture.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := tuo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := tuo.mutation.TextureHash(); ok {
|
||||
_spec.SetField(texture.FieldTextureHash, field.TypeString, value)
|
||||
}
|
||||
if value, ok := tuo.mutation.GetType(); ok {
|
||||
_spec.SetField(texture.FieldType, field.TypeString, value)
|
||||
}
|
||||
if value, ok := tuo.mutation.Variant(); ok {
|
||||
_spec.SetField(texture.FieldVariant, field.TypeString, value)
|
||||
}
|
||||
if tuo.mutation.CreatedUserCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: texture.CreatedUserTable,
|
||||
Columns: []string{texture.CreatedUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := tuo.mutation.CreatedUserIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: texture.CreatedUserTable,
|
||||
Columns: []string{texture.CreatedUserColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &Texture{config: tuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, tuo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{texture.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
tuo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
@ -12,8 +12,8 @@ import (
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// Skin is the client for interacting with the Skin builders.
|
||||
Skin *SkinClient
|
||||
// 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.
|
||||
@ -151,7 +151,7 @@ func (tx *Tx) Client() *Client {
|
||||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.Skin = NewSkinClient(tx.config)
|
||||
tx.Texture = NewTextureClient(tx.config)
|
||||
tx.User = NewUserClient(tx.config)
|
||||
tx.UserProfile = NewUserProfileClient(tx.config)
|
||||
tx.UserToken = NewUserTokenClient(tx.config)
|
||||
@ -164,7 +164,7 @@ func (tx *Tx) init() {
|
||||
// of them in order to commit or rollback the transaction.
|
||||
//
|
||||
// If a closed transaction is embedded in one of the generated entities, and the entity
|
||||
// applies a query, for example: Skin.QueryXXX(), the query will be executed
|
||||
// applies a query, for example: Texture.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"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"
|
||||
@ -35,32 +34,29 @@ type User struct {
|
||||
// The values are being populated by the UserQuery when eager-loading is set.
|
||||
Edges UserEdges `json:"edges"`
|
||||
user_token *int
|
||||
user_skin *int
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// UserEdges holds the relations/edges for other nodes in the graph.
|
||||
type UserEdges struct {
|
||||
// CreatedSkin holds the value of the created_skin edge.
|
||||
CreatedSkin []*Skin `json:"created_skin,omitempty"`
|
||||
// CreatedTexture holds the value of the created_texture edge.
|
||||
CreatedTexture []*Texture `json:"created_texture,omitempty"`
|
||||
// Profile holds the value of the profile edge.
|
||||
Profile *UserProfile `json:"profile,omitempty"`
|
||||
// Token holds the value of the token edge.
|
||||
Token *UserToken `json:"token,omitempty"`
|
||||
// Skin holds the value of the skin edge.
|
||||
Skin *Skin `json:"skin,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [4]bool
|
||||
loadedTypes [3]bool
|
||||
}
|
||||
|
||||
// CreatedSkinOrErr returns the CreatedSkin value or an error if the edge
|
||||
// CreatedTextureOrErr returns the CreatedTexture value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserEdges) CreatedSkinOrErr() ([]*Skin, error) {
|
||||
func (e UserEdges) CreatedTextureOrErr() ([]*Texture, error) {
|
||||
if e.loadedTypes[0] {
|
||||
return e.CreatedSkin, nil
|
||||
return e.CreatedTexture, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "created_skin"}
|
||||
return nil, &NotLoadedError{edge: "created_texture"}
|
||||
}
|
||||
|
||||
// ProfileOrErr returns the Profile value or an error if the edge
|
||||
@ -89,19 +85,6 @@ func (e UserEdges) TokenOrErr() (*UserToken, error) {
|
||||
return nil, &NotLoadedError{edge: "token"}
|
||||
}
|
||||
|
||||
// SkinOrErr returns the Skin value or an error if the edge
|
||||
// was not loaded in eager-loading, or loaded but was not found.
|
||||
func (e UserEdges) SkinOrErr() (*Skin, error) {
|
||||
if e.loadedTypes[3] {
|
||||
if e.Skin == nil {
|
||||
// Edge was loaded but was not found.
|
||||
return nil, &NotFoundError{label: skin.Label}
|
||||
}
|
||||
return e.Skin, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "skin"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*User) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
@ -113,8 +96,6 @@ func (*User) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(sql.NullString)
|
||||
case user.ForeignKeys[0]: // user_token
|
||||
values[i] = new(sql.NullInt64)
|
||||
case user.ForeignKeys[1]: // user_skin
|
||||
values[i] = new(sql.NullInt64)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
@ -179,13 +160,6 @@ func (u *User) assignValues(columns []string, values []any) error {
|
||||
u.user_token = new(int)
|
||||
*u.user_token = int(value.Int64)
|
||||
}
|
||||
case user.ForeignKeys[1]:
|
||||
if value, ok := values[i].(*sql.NullInt64); !ok {
|
||||
return fmt.Errorf("unexpected type %T for edge-field user_skin", value)
|
||||
} else if value.Valid {
|
||||
u.user_skin = new(int)
|
||||
*u.user_skin = int(value.Int64)
|
||||
}
|
||||
default:
|
||||
u.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
@ -199,9 +173,9 @@ func (u *User) Value(name string) (ent.Value, error) {
|
||||
return u.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// QueryCreatedSkin queries the "created_skin" edge of the User entity.
|
||||
func (u *User) QueryCreatedSkin() *SkinQuery {
|
||||
return NewUserClient(u.config).QueryCreatedSkin(u)
|
||||
// QueryCreatedTexture queries the "created_texture" edge of the User entity.
|
||||
func (u *User) QueryCreatedTexture() *TextureQuery {
|
||||
return NewUserClient(u.config).QueryCreatedTexture(u)
|
||||
}
|
||||
|
||||
// QueryProfile queries the "profile" edge of the User entity.
|
||||
@ -214,11 +188,6 @@ func (u *User) QueryToken() *UserTokenQuery {
|
||||
return NewUserClient(u.config).QueryToken(u)
|
||||
}
|
||||
|
||||
// QuerySkin queries the "skin" edge of the User entity.
|
||||
func (u *User) QuerySkin() *SkinQuery {
|
||||
return NewUserClient(u.config).QuerySkin(u)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this User.
|
||||
// Note that you need to call User.Unwrap() before calling this method if this User
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
|
@ -24,23 +24,21 @@ const (
|
||||
FieldState = "state"
|
||||
// FieldRegTime holds the string denoting the reg_time field in the database.
|
||||
FieldRegTime = "reg_time"
|
||||
// EdgeCreatedSkin holds the string denoting the created_skin edge name in mutations.
|
||||
EdgeCreatedSkin = "created_skin"
|
||||
// EdgeCreatedTexture holds the string denoting the created_texture edge name in mutations.
|
||||
EdgeCreatedTexture = "created_texture"
|
||||
// EdgeProfile holds the string denoting the profile edge name in mutations.
|
||||
EdgeProfile = "profile"
|
||||
// EdgeToken holds the string denoting the token edge name in mutations.
|
||||
EdgeToken = "token"
|
||||
// EdgeSkin holds the string denoting the skin edge name in mutations.
|
||||
EdgeSkin = "skin"
|
||||
// Table holds the table name of the user in the database.
|
||||
Table = "users"
|
||||
// CreatedSkinTable is the table that holds the created_skin relation/edge.
|
||||
CreatedSkinTable = "skins"
|
||||
// CreatedSkinInverseTable is the table name for the Skin entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "skin" package.
|
||||
CreatedSkinInverseTable = "skins"
|
||||
// CreatedSkinColumn is the table column denoting the created_skin relation/edge.
|
||||
CreatedSkinColumn = "skin_created_user"
|
||||
// CreatedTextureTable is the table that holds the created_texture relation/edge.
|
||||
CreatedTextureTable = "textures"
|
||||
// CreatedTextureInverseTable is the table name for the Texture entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "texture" package.
|
||||
CreatedTextureInverseTable = "textures"
|
||||
// CreatedTextureColumn is the table column denoting the created_texture relation/edge.
|
||||
CreatedTextureColumn = "texture_created_user"
|
||||
// ProfileTable is the table that holds the profile relation/edge.
|
||||
ProfileTable = "user_profiles"
|
||||
// ProfileInverseTable is the table name for the UserProfile entity.
|
||||
@ -55,13 +53,6 @@ const (
|
||||
TokenInverseTable = "user_tokens"
|
||||
// TokenColumn is the table column denoting the token relation/edge.
|
||||
TokenColumn = "user_token"
|
||||
// SkinTable is the table that holds the skin relation/edge.
|
||||
SkinTable = "users"
|
||||
// SkinInverseTable is the table name for the Skin entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "skin" package.
|
||||
SkinInverseTable = "skins"
|
||||
// SkinColumn is the table column denoting the skin relation/edge.
|
||||
SkinColumn = "user_skin"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for user fields.
|
||||
@ -79,7 +70,6 @@ var Columns = []string{
|
||||
// table and are not defined as standalone fields in the schema.
|
||||
var ForeignKeys = []string{
|
||||
"user_token",
|
||||
"user_skin",
|
||||
}
|
||||
|
||||
// ValidColumn reports if the column name is valid (part of the table columns).
|
||||
@ -135,17 +125,17 @@ func ByRegTime(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldRegTime, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByCreatedSkinCount orders the results by created_skin count.
|
||||
func ByCreatedSkinCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
// ByCreatedTextureCount orders the results by created_texture count.
|
||||
func ByCreatedTextureCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newCreatedSkinStep(), opts...)
|
||||
sqlgraph.OrderByNeighborsCount(s, newCreatedTextureStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByCreatedSkin orders the results by created_skin terms.
|
||||
func ByCreatedSkin(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
// ByCreatedTexture orders the results by created_texture terms.
|
||||
func ByCreatedTexture(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newCreatedSkinStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
sqlgraph.OrderByNeighborTerms(s, newCreatedTextureStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
|
||||
@ -162,18 +152,11 @@ func ByTokenField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
sqlgraph.OrderByNeighborTerms(s, newTokenStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// BySkinField orders the results by skin field.
|
||||
func BySkinField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newSkinStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
func newCreatedSkinStep() *sqlgraph.Step {
|
||||
func newCreatedTextureStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(CreatedSkinInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, CreatedSkinTable, CreatedSkinColumn),
|
||||
sqlgraph.To(CreatedTextureInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, CreatedTextureTable, CreatedTextureColumn),
|
||||
)
|
||||
}
|
||||
func newProfileStep() *sqlgraph.Step {
|
||||
@ -190,10 +173,3 @@ func newTokenStep() *sqlgraph.Step {
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, TokenTable, TokenColumn),
|
||||
)
|
||||
}
|
||||
func newSkinStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(SkinInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, SkinTable, SkinColumn),
|
||||
)
|
||||
}
|
||||
|
@ -423,21 +423,21 @@ func RegTimeLTE(v int64) predicate.User {
|
||||
return predicate.User(sql.FieldLTE(FieldRegTime, v))
|
||||
}
|
||||
|
||||
// HasCreatedSkin applies the HasEdge predicate on the "created_skin" edge.
|
||||
func HasCreatedSkin() predicate.User {
|
||||
// HasCreatedTexture applies the HasEdge predicate on the "created_texture" edge.
|
||||
func HasCreatedTexture() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, CreatedSkinTable, CreatedSkinColumn),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, CreatedTextureTable, CreatedTextureColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasCreatedSkinWith applies the HasEdge predicate on the "created_skin" edge with a given conditions (other predicates).
|
||||
func HasCreatedSkinWith(preds ...predicate.Skin) predicate.User {
|
||||
// HasCreatedTextureWith applies the HasEdge predicate on the "created_texture" edge with a given conditions (other predicates).
|
||||
func HasCreatedTextureWith(preds ...predicate.Texture) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newCreatedSkinStep()
|
||||
step := newCreatedTextureStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
@ -492,29 +492,6 @@ func HasTokenWith(preds ...predicate.UserToken) predicate.User {
|
||||
})
|
||||
}
|
||||
|
||||
// HasSkin applies the HasEdge predicate on the "skin" edge.
|
||||
func HasSkin() predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, SkinTable, SkinColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasSkinWith applies the HasEdge predicate on the "skin" edge with a given conditions (other predicates).
|
||||
func HasSkinWith(preds ...predicate.Skin) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
step := newSkinStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.User) predicate.User {
|
||||
return predicate.User(func(s *sql.Selector) {
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/skin"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/usertoken"
|
||||
@ -58,19 +58,19 @@ func (uc *UserCreate) SetRegTime(i int64) *UserCreate {
|
||||
return uc
|
||||
}
|
||||
|
||||
// AddCreatedSkinIDs adds the "created_skin" edge to the Skin entity by IDs.
|
||||
func (uc *UserCreate) AddCreatedSkinIDs(ids ...int) *UserCreate {
|
||||
uc.mutation.AddCreatedSkinIDs(ids...)
|
||||
// AddCreatedTextureIDs adds the "created_texture" edge to the Texture entity by IDs.
|
||||
func (uc *UserCreate) AddCreatedTextureIDs(ids ...int) *UserCreate {
|
||||
uc.mutation.AddCreatedTextureIDs(ids...)
|
||||
return uc
|
||||
}
|
||||
|
||||
// AddCreatedSkin adds the "created_skin" edges to the Skin entity.
|
||||
func (uc *UserCreate) AddCreatedSkin(s ...*Skin) *UserCreate {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
// AddCreatedTexture adds the "created_texture" edges to the Texture entity.
|
||||
func (uc *UserCreate) AddCreatedTexture(t ...*Texture) *UserCreate {
|
||||
ids := make([]int, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return uc.AddCreatedSkinIDs(ids...)
|
||||
return uc.AddCreatedTextureIDs(ids...)
|
||||
}
|
||||
|
||||
// SetProfileID sets the "profile" edge to the UserProfile entity by ID.
|
||||
@ -111,25 +111,6 @@ func (uc *UserCreate) SetToken(u *UserToken) *UserCreate {
|
||||
return uc.SetTokenID(u.ID)
|
||||
}
|
||||
|
||||
// SetSkinID sets the "skin" edge to the Skin entity by ID.
|
||||
func (uc *UserCreate) SetSkinID(id int) *UserCreate {
|
||||
uc.mutation.SetSkinID(id)
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetNillableSkinID sets the "skin" edge to the Skin entity by ID if the given value is not nil.
|
||||
func (uc *UserCreate) SetNillableSkinID(id *int) *UserCreate {
|
||||
if id != nil {
|
||||
uc = uc.SetSkinID(*id)
|
||||
}
|
||||
return uc
|
||||
}
|
||||
|
||||
// SetSkin sets the "skin" edge to the Skin entity.
|
||||
func (uc *UserCreate) SetSkin(s *Skin) *UserCreate {
|
||||
return uc.SetSkinID(s.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uc *UserCreate) Mutation() *UserMutation {
|
||||
return uc.mutation
|
||||
@ -232,15 +213,15 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(user.FieldRegTime, field.TypeInt64, value)
|
||||
_node.RegTime = value
|
||||
}
|
||||
if nodes := uc.mutation.CreatedSkinIDs(); len(nodes) > 0 {
|
||||
if nodes := uc.mutation.CreatedTextureIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: user.CreatedSkinTable,
|
||||
Columns: []string{user.CreatedSkinColumn},
|
||||
Table: user.CreatedTextureTable,
|
||||
Columns: []string{user.CreatedTextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
@ -281,23 +262,6 @@ func (uc *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
|
||||
_node.user_token = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := uc.mutation.SkinIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: user.SkinTable,
|
||||
Columns: []string{user.SkinColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_node.user_skin = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/skin"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/usertoken"
|
||||
@ -26,10 +26,9 @@ type UserQuery struct {
|
||||
order []user.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.User
|
||||
withCreatedSkin *SkinQuery
|
||||
withCreatedTexture *TextureQuery
|
||||
withProfile *UserProfileQuery
|
||||
withToken *UserTokenQuery
|
||||
withSkin *SkinQuery
|
||||
withFKs bool
|
||||
modifiers []func(*sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
@ -68,9 +67,9 @@ func (uq *UserQuery) Order(o ...user.OrderOption) *UserQuery {
|
||||
return uq
|
||||
}
|
||||
|
||||
// QueryCreatedSkin chains the current query on the "created_skin" edge.
|
||||
func (uq *UserQuery) QueryCreatedSkin() *SkinQuery {
|
||||
query := (&SkinClient{config: uq.config}).Query()
|
||||
// QueryCreatedTexture chains the current query on the "created_texture" edge.
|
||||
func (uq *UserQuery) QueryCreatedTexture() *TextureQuery {
|
||||
query := (&TextureClient{config: uq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
@ -81,8 +80,8 @@ func (uq *UserQuery) QueryCreatedSkin() *SkinQuery {
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(skin.Table, skin.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, user.CreatedSkinTable, user.CreatedSkinColumn),
|
||||
sqlgraph.To(texture.Table, texture.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, true, user.CreatedTextureTable, user.CreatedTextureColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
@ -134,28 +133,6 @@ func (uq *UserQuery) QueryToken() *UserTokenQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QuerySkin chains the current query on the "skin" edge.
|
||||
func (uq *UserQuery) QuerySkin() *SkinQuery {
|
||||
query := (&SkinClient{config: uq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := uq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := uq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(user.Table, user.FieldID, selector),
|
||||
sqlgraph.To(skin.Table, skin.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.M2O, false, user.SkinTable, user.SkinColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(uq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first User entity from the query.
|
||||
// Returns a *NotFoundError when no User was found.
|
||||
func (uq *UserQuery) First(ctx context.Context) (*User, error) {
|
||||
@ -348,24 +325,23 @@ func (uq *UserQuery) Clone() *UserQuery {
|
||||
order: append([]user.OrderOption{}, uq.order...),
|
||||
inters: append([]Interceptor{}, uq.inters...),
|
||||
predicates: append([]predicate.User{}, uq.predicates...),
|
||||
withCreatedSkin: uq.withCreatedSkin.Clone(),
|
||||
withCreatedTexture: uq.withCreatedTexture.Clone(),
|
||||
withProfile: uq.withProfile.Clone(),
|
||||
withToken: uq.withToken.Clone(),
|
||||
withSkin: uq.withSkin.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: uq.sql.Clone(),
|
||||
path: uq.path,
|
||||
}
|
||||
}
|
||||
|
||||
// WithCreatedSkin tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "created_skin" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithCreatedSkin(opts ...func(*SkinQuery)) *UserQuery {
|
||||
query := (&SkinClient{config: uq.config}).Query()
|
||||
// WithCreatedTexture tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "created_texture" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithCreatedTexture(opts ...func(*TextureQuery)) *UserQuery {
|
||||
query := (&TextureClient{config: uq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
uq.withCreatedSkin = query
|
||||
uq.withCreatedTexture = query
|
||||
return uq
|
||||
}
|
||||
|
||||
@ -391,17 +367,6 @@ func (uq *UserQuery) WithToken(opts ...func(*UserTokenQuery)) *UserQuery {
|
||||
return uq
|
||||
}
|
||||
|
||||
// WithSkin tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "skin" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (uq *UserQuery) WithSkin(opts ...func(*SkinQuery)) *UserQuery {
|
||||
query := (&SkinClient{config: uq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
uq.withSkin = query
|
||||
return uq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
@ -481,14 +446,13 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
|
||||
nodes = []*User{}
|
||||
withFKs = uq.withFKs
|
||||
_spec = uq.querySpec()
|
||||
loadedTypes = [4]bool{
|
||||
uq.withCreatedSkin != nil,
|
||||
loadedTypes = [3]bool{
|
||||
uq.withCreatedTexture != nil,
|
||||
uq.withProfile != nil,
|
||||
uq.withToken != nil,
|
||||
uq.withSkin != nil,
|
||||
}
|
||||
)
|
||||
if uq.withToken != nil || uq.withSkin != nil {
|
||||
if uq.withToken != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
@ -515,10 +479,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
if query := uq.withCreatedSkin; query != nil {
|
||||
if err := uq.loadCreatedSkin(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.CreatedSkin = []*Skin{} },
|
||||
func(n *User, e *Skin) { n.Edges.CreatedSkin = append(n.Edges.CreatedSkin, e) }); err != nil {
|
||||
if query := uq.withCreatedTexture; query != nil {
|
||||
if err := uq.loadCreatedTexture(ctx, query, nodes,
|
||||
func(n *User) { n.Edges.CreatedTexture = []*Texture{} },
|
||||
func(n *User, e *Texture) { n.Edges.CreatedTexture = append(n.Edges.CreatedTexture, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@ -534,16 +498,10 @@ func (uq *UserQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*User, e
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := uq.withSkin; query != nil {
|
||||
if err := uq.loadSkin(ctx, query, nodes, nil,
|
||||
func(n *User, e *Skin) { n.Edges.Skin = e }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) loadCreatedSkin(ctx context.Context, query *SkinQuery, nodes []*User, init func(*User), assign func(*User, *Skin)) error {
|
||||
func (uq *UserQuery) loadCreatedTexture(ctx context.Context, query *TextureQuery, nodes []*User, init func(*User), assign func(*User, *Texture)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*User)
|
||||
for i := range nodes {
|
||||
@ -554,21 +512,21 @@ func (uq *UserQuery) loadCreatedSkin(ctx context.Context, query *SkinQuery, node
|
||||
}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.Skin(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.CreatedSkinColumn), fks...))
|
||||
query.Where(predicate.Texture(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(user.CreatedTextureColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.skin_created_user
|
||||
fk := n.texture_created_user
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "skin_created_user" is nil for node %v`, n.ID)
|
||||
return fmt.Errorf(`foreign-key "texture_created_user" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "skin_created_user" returned %v for node %v`, *fk, n.ID)
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "texture_created_user" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
@ -634,38 +592,6 @@ func (uq *UserQuery) loadToken(ctx context.Context, query *UserTokenQuery, nodes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (uq *UserQuery) loadSkin(ctx context.Context, query *SkinQuery, nodes []*User, init func(*User), assign func(*User, *Skin)) error {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*User)
|
||||
for i := range nodes {
|
||||
if nodes[i].user_skin == nil {
|
||||
continue
|
||||
}
|
||||
fk := *nodes[i].user_skin
|
||||
if _, ok := nodeids[fk]; !ok {
|
||||
ids = append(ids, fk)
|
||||
}
|
||||
nodeids[fk] = append(nodeids[fk], nodes[i])
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
return nil
|
||||
}
|
||||
query.Where(skin.IDIn(ids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nodeids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "user_skin" returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
assign(nodes[i], n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := uq.querySpec()
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/skin"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/usertoken"
|
||||
@ -80,19 +80,19 @@ func (uu *UserUpdate) AddRegTime(i int64) *UserUpdate {
|
||||
return uu
|
||||
}
|
||||
|
||||
// AddCreatedSkinIDs adds the "created_skin" edge to the Skin entity by IDs.
|
||||
func (uu *UserUpdate) AddCreatedSkinIDs(ids ...int) *UserUpdate {
|
||||
uu.mutation.AddCreatedSkinIDs(ids...)
|
||||
// AddCreatedTextureIDs adds the "created_texture" edge to the Texture entity by IDs.
|
||||
func (uu *UserUpdate) AddCreatedTextureIDs(ids ...int) *UserUpdate {
|
||||
uu.mutation.AddCreatedTextureIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// AddCreatedSkin adds the "created_skin" edges to the Skin entity.
|
||||
func (uu *UserUpdate) AddCreatedSkin(s ...*Skin) *UserUpdate {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
// AddCreatedTexture adds the "created_texture" edges to the Texture entity.
|
||||
func (uu *UserUpdate) AddCreatedTexture(t ...*Texture) *UserUpdate {
|
||||
ids := make([]int, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return uu.AddCreatedSkinIDs(ids...)
|
||||
return uu.AddCreatedTextureIDs(ids...)
|
||||
}
|
||||
|
||||
// SetProfileID sets the "profile" edge to the UserProfile entity by ID.
|
||||
@ -133,49 +133,30 @@ func (uu *UserUpdate) SetToken(u *UserToken) *UserUpdate {
|
||||
return uu.SetTokenID(u.ID)
|
||||
}
|
||||
|
||||
// SetSkinID sets the "skin" edge to the Skin entity by ID.
|
||||
func (uu *UserUpdate) SetSkinID(id int) *UserUpdate {
|
||||
uu.mutation.SetSkinID(id)
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetNillableSkinID sets the "skin" edge to the Skin entity by ID if the given value is not nil.
|
||||
func (uu *UserUpdate) SetNillableSkinID(id *int) *UserUpdate {
|
||||
if id != nil {
|
||||
uu = uu.SetSkinID(*id)
|
||||
}
|
||||
return uu
|
||||
}
|
||||
|
||||
// SetSkin sets the "skin" edge to the Skin entity.
|
||||
func (uu *UserUpdate) SetSkin(s *Skin) *UserUpdate {
|
||||
return uu.SetSkinID(s.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uu *UserUpdate) Mutation() *UserMutation {
|
||||
return uu.mutation
|
||||
}
|
||||
|
||||
// ClearCreatedSkin clears all "created_skin" edges to the Skin entity.
|
||||
func (uu *UserUpdate) ClearCreatedSkin() *UserUpdate {
|
||||
uu.mutation.ClearCreatedSkin()
|
||||
// ClearCreatedTexture clears all "created_texture" edges to the Texture entity.
|
||||
func (uu *UserUpdate) ClearCreatedTexture() *UserUpdate {
|
||||
uu.mutation.ClearCreatedTexture()
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveCreatedSkinIDs removes the "created_skin" edge to Skin entities by IDs.
|
||||
func (uu *UserUpdate) RemoveCreatedSkinIDs(ids ...int) *UserUpdate {
|
||||
uu.mutation.RemoveCreatedSkinIDs(ids...)
|
||||
// RemoveCreatedTextureIDs removes the "created_texture" edge to Texture entities by IDs.
|
||||
func (uu *UserUpdate) RemoveCreatedTextureIDs(ids ...int) *UserUpdate {
|
||||
uu.mutation.RemoveCreatedTextureIDs(ids...)
|
||||
return uu
|
||||
}
|
||||
|
||||
// RemoveCreatedSkin removes "created_skin" edges to Skin entities.
|
||||
func (uu *UserUpdate) RemoveCreatedSkin(s ...*Skin) *UserUpdate {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
// RemoveCreatedTexture removes "created_texture" edges to Texture entities.
|
||||
func (uu *UserUpdate) RemoveCreatedTexture(t ...*Texture) *UserUpdate {
|
||||
ids := make([]int, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return uu.RemoveCreatedSkinIDs(ids...)
|
||||
return uu.RemoveCreatedTextureIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearProfile clears the "profile" edge to the UserProfile entity.
|
||||
@ -190,12 +171,6 @@ func (uu *UserUpdate) ClearToken() *UserUpdate {
|
||||
return uu
|
||||
}
|
||||
|
||||
// ClearSkin clears the "skin" edge to the Skin entity.
|
||||
func (uu *UserUpdate) ClearSkin() *UserUpdate {
|
||||
uu.mutation.ClearSkin()
|
||||
return uu
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (uu *UserUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, uu.sqlSave, uu.mutation, uu.hooks)
|
||||
@ -256,28 +231,28 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if value, ok := uu.mutation.AddedRegTime(); ok {
|
||||
_spec.AddField(user.FieldRegTime, field.TypeInt64, value)
|
||||
}
|
||||
if uu.mutation.CreatedSkinCleared() {
|
||||
if uu.mutation.CreatedTextureCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: user.CreatedSkinTable,
|
||||
Columns: []string{user.CreatedSkinColumn},
|
||||
Table: user.CreatedTextureTable,
|
||||
Columns: []string{user.CreatedTextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.RemovedCreatedSkinIDs(); len(nodes) > 0 && !uu.mutation.CreatedSkinCleared() {
|
||||
if nodes := uu.mutation.RemovedCreatedTextureIDs(); len(nodes) > 0 && !uu.mutation.CreatedTextureCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: user.CreatedSkinTable,
|
||||
Columns: []string{user.CreatedSkinColumn},
|
||||
Table: user.CreatedTextureTable,
|
||||
Columns: []string{user.CreatedTextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
@ -285,15 +260,15 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.CreatedSkinIDs(); len(nodes) > 0 {
|
||||
if nodes := uu.mutation.CreatedTextureIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: user.CreatedSkinTable,
|
||||
Columns: []string{user.CreatedSkinColumn},
|
||||
Table: user.CreatedTextureTable,
|
||||
Columns: []string{user.CreatedTextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
@ -359,35 +334,6 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if uu.mutation.SkinCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: user.SkinTable,
|
||||
Columns: []string{user.SkinColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.mutation.SkinIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: user.SkinTable,
|
||||
Columns: []string{user.SkinColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{user.Label}
|
||||
@ -458,19 +404,19 @@ func (uuo *UserUpdateOne) AddRegTime(i int64) *UserUpdateOne {
|
||||
return uuo
|
||||
}
|
||||
|
||||
// AddCreatedSkinIDs adds the "created_skin" edge to the Skin entity by IDs.
|
||||
func (uuo *UserUpdateOne) AddCreatedSkinIDs(ids ...int) *UserUpdateOne {
|
||||
uuo.mutation.AddCreatedSkinIDs(ids...)
|
||||
// AddCreatedTextureIDs adds the "created_texture" edge to the Texture entity by IDs.
|
||||
func (uuo *UserUpdateOne) AddCreatedTextureIDs(ids ...int) *UserUpdateOne {
|
||||
uuo.mutation.AddCreatedTextureIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// AddCreatedSkin adds the "created_skin" edges to the Skin entity.
|
||||
func (uuo *UserUpdateOne) AddCreatedSkin(s ...*Skin) *UserUpdateOne {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
// AddCreatedTexture adds the "created_texture" edges to the Texture entity.
|
||||
func (uuo *UserUpdateOne) AddCreatedTexture(t ...*Texture) *UserUpdateOne {
|
||||
ids := make([]int, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return uuo.AddCreatedSkinIDs(ids...)
|
||||
return uuo.AddCreatedTextureIDs(ids...)
|
||||
}
|
||||
|
||||
// SetProfileID sets the "profile" edge to the UserProfile entity by ID.
|
||||
@ -511,49 +457,30 @@ func (uuo *UserUpdateOne) SetToken(u *UserToken) *UserUpdateOne {
|
||||
return uuo.SetTokenID(u.ID)
|
||||
}
|
||||
|
||||
// SetSkinID sets the "skin" edge to the Skin entity by ID.
|
||||
func (uuo *UserUpdateOne) SetSkinID(id int) *UserUpdateOne {
|
||||
uuo.mutation.SetSkinID(id)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetNillableSkinID sets the "skin" edge to the Skin entity by ID if the given value is not nil.
|
||||
func (uuo *UserUpdateOne) SetNillableSkinID(id *int) *UserUpdateOne {
|
||||
if id != nil {
|
||||
uuo = uuo.SetSkinID(*id)
|
||||
}
|
||||
return uuo
|
||||
}
|
||||
|
||||
// SetSkin sets the "skin" edge to the Skin entity.
|
||||
func (uuo *UserUpdateOne) SetSkin(s *Skin) *UserUpdateOne {
|
||||
return uuo.SetSkinID(s.ID)
|
||||
}
|
||||
|
||||
// Mutation returns the UserMutation object of the builder.
|
||||
func (uuo *UserUpdateOne) Mutation() *UserMutation {
|
||||
return uuo.mutation
|
||||
}
|
||||
|
||||
// ClearCreatedSkin clears all "created_skin" edges to the Skin entity.
|
||||
func (uuo *UserUpdateOne) ClearCreatedSkin() *UserUpdateOne {
|
||||
uuo.mutation.ClearCreatedSkin()
|
||||
// ClearCreatedTexture clears all "created_texture" edges to the Texture entity.
|
||||
func (uuo *UserUpdateOne) ClearCreatedTexture() *UserUpdateOne {
|
||||
uuo.mutation.ClearCreatedTexture()
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveCreatedSkinIDs removes the "created_skin" edge to Skin entities by IDs.
|
||||
func (uuo *UserUpdateOne) RemoveCreatedSkinIDs(ids ...int) *UserUpdateOne {
|
||||
uuo.mutation.RemoveCreatedSkinIDs(ids...)
|
||||
// RemoveCreatedTextureIDs removes the "created_texture" edge to Texture entities by IDs.
|
||||
func (uuo *UserUpdateOne) RemoveCreatedTextureIDs(ids ...int) *UserUpdateOne {
|
||||
uuo.mutation.RemoveCreatedTextureIDs(ids...)
|
||||
return uuo
|
||||
}
|
||||
|
||||
// RemoveCreatedSkin removes "created_skin" edges to Skin entities.
|
||||
func (uuo *UserUpdateOne) RemoveCreatedSkin(s ...*Skin) *UserUpdateOne {
|
||||
ids := make([]int, len(s))
|
||||
for i := range s {
|
||||
ids[i] = s[i].ID
|
||||
// RemoveCreatedTexture removes "created_texture" edges to Texture entities.
|
||||
func (uuo *UserUpdateOne) RemoveCreatedTexture(t ...*Texture) *UserUpdateOne {
|
||||
ids := make([]int, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return uuo.RemoveCreatedSkinIDs(ids...)
|
||||
return uuo.RemoveCreatedTextureIDs(ids...)
|
||||
}
|
||||
|
||||
// ClearProfile clears the "profile" edge to the UserProfile entity.
|
||||
@ -568,12 +495,6 @@ func (uuo *UserUpdateOne) ClearToken() *UserUpdateOne {
|
||||
return uuo
|
||||
}
|
||||
|
||||
// ClearSkin clears the "skin" edge to the Skin entity.
|
||||
func (uuo *UserUpdateOne) ClearSkin() *UserUpdateOne {
|
||||
uuo.mutation.ClearSkin()
|
||||
return uuo
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserUpdate builder.
|
||||
func (uuo *UserUpdateOne) Where(ps ...predicate.User) *UserUpdateOne {
|
||||
uuo.mutation.Where(ps...)
|
||||
@ -664,28 +585,28 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
|
||||
if value, ok := uuo.mutation.AddedRegTime(); ok {
|
||||
_spec.AddField(user.FieldRegTime, field.TypeInt64, value)
|
||||
}
|
||||
if uuo.mutation.CreatedSkinCleared() {
|
||||
if uuo.mutation.CreatedTextureCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: user.CreatedSkinTable,
|
||||
Columns: []string{user.CreatedSkinColumn},
|
||||
Table: user.CreatedTextureTable,
|
||||
Columns: []string{user.CreatedTextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.RemovedCreatedSkinIDs(); len(nodes) > 0 && !uuo.mutation.CreatedSkinCleared() {
|
||||
if nodes := uuo.mutation.RemovedCreatedTextureIDs(); len(nodes) > 0 && !uuo.mutation.CreatedTextureCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: user.CreatedSkinTable,
|
||||
Columns: []string{user.CreatedSkinColumn},
|
||||
Table: user.CreatedTextureTable,
|
||||
Columns: []string{user.CreatedTextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
@ -693,15 +614,15 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.CreatedSkinIDs(); len(nodes) > 0 {
|
||||
if nodes := uuo.mutation.CreatedTextureIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: true,
|
||||
Table: user.CreatedSkinTable,
|
||||
Columns: []string{user.CreatedSkinColumn},
|
||||
Table: user.CreatedTextureTable,
|
||||
Columns: []string{user.CreatedTextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
@ -767,35 +688,6 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if uuo.mutation.SkinCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: user.SkinTable,
|
||||
Columns: []string{user.SkinColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.mutation.SkinIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.M2O,
|
||||
Inverse: false,
|
||||
Table: user.SkinTable,
|
||||
Columns: []string{user.SkinColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(skin.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &User{config: uuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
@ -32,9 +32,11 @@ type UserProfile struct {
|
||||
type UserProfileEdges struct {
|
||||
// User holds the value of the user edge.
|
||||
User *User `json:"user,omitempty"`
|
||||
// Texture holds the value of the texture edge.
|
||||
Texture []*Texture `json:"texture,omitempty"`
|
||||
// loadedTypes holds the information for reporting if a
|
||||
// type was loaded (or requested) in eager-loading or not.
|
||||
loadedTypes [1]bool
|
||||
loadedTypes [2]bool
|
||||
}
|
||||
|
||||
// UserOrErr returns the User value or an error if the edge
|
||||
@ -50,6 +52,15 @@ func (e UserProfileEdges) UserOrErr() (*User, error) {
|
||||
return nil, &NotLoadedError{edge: "user"}
|
||||
}
|
||||
|
||||
// TextureOrErr returns the Texture value or an error if the edge
|
||||
// was not loaded in eager-loading.
|
||||
func (e UserProfileEdges) TextureOrErr() ([]*Texture, error) {
|
||||
if e.loadedTypes[1] {
|
||||
return e.Texture, nil
|
||||
}
|
||||
return nil, &NotLoadedError{edge: "texture"}
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*UserProfile) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
@ -119,6 +130,11 @@ func (up *UserProfile) QueryUser() *UserQuery {
|
||||
return NewUserProfileClient(up.config).QueryUser(up)
|
||||
}
|
||||
|
||||
// QueryTexture queries the "texture" edge of the UserProfile entity.
|
||||
func (up *UserProfile) QueryTexture() *TextureQuery {
|
||||
return NewUserProfileClient(up.config).QueryTexture(up)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this UserProfile.
|
||||
// Note that you need to call UserProfile.Unwrap() before calling this method if this UserProfile
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
|
@ -18,6 +18,8 @@ const (
|
||||
FieldUUID = "uuid"
|
||||
// EdgeUser holds the string denoting the user edge name in mutations.
|
||||
EdgeUser = "user"
|
||||
// EdgeTexture holds the string denoting the texture edge name in mutations.
|
||||
EdgeTexture = "texture"
|
||||
// Table holds the table name of the userprofile in the database.
|
||||
Table = "user_profiles"
|
||||
// UserTable is the table that holds the user relation/edge.
|
||||
@ -27,6 +29,13 @@ const (
|
||||
UserInverseTable = "users"
|
||||
// UserColumn is the table column denoting the user relation/edge.
|
||||
UserColumn = "user_profile"
|
||||
// TextureTable is the table that holds the texture relation/edge.
|
||||
TextureTable = "textures"
|
||||
// TextureInverseTable is the table name for the Texture entity.
|
||||
// It exists in this package in order to avoid circular dependency with the "texture" package.
|
||||
TextureInverseTable = "textures"
|
||||
// TextureColumn is the table column denoting the texture relation/edge.
|
||||
TextureColumn = "user_profile_texture"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for userprofile fields.
|
||||
@ -81,6 +90,20 @@ func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
|
||||
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
|
||||
}
|
||||
}
|
||||
|
||||
// ByTextureCount orders the results by texture count.
|
||||
func ByTextureCount(opts ...sql.OrderTermOption) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborsCount(s, newTextureStep(), opts...)
|
||||
}
|
||||
}
|
||||
|
||||
// ByTexture orders the results by texture terms.
|
||||
func ByTexture(term sql.OrderTerm, terms ...sql.OrderTerm) OrderOption {
|
||||
return func(s *sql.Selector) {
|
||||
sqlgraph.OrderByNeighborTerms(s, newTextureStep(), append([]sql.OrderTerm{term}, terms...)...)
|
||||
}
|
||||
}
|
||||
func newUserStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
@ -88,3 +111,10 @@ func newUserStep() *sqlgraph.Step {
|
||||
sqlgraph.Edge(sqlgraph.O2O, true, UserTable, UserColumn),
|
||||
)
|
||||
}
|
||||
func newTextureStep() *sqlgraph.Step {
|
||||
return sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.To(TextureInverseTable, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, TextureTable, TextureColumn),
|
||||
)
|
||||
}
|
||||
|
@ -216,6 +216,29 @@ func HasUserWith(preds ...predicate.User) predicate.UserProfile {
|
||||
})
|
||||
}
|
||||
|
||||
// HasTexture applies the HasEdge predicate on the "texture" edge.
|
||||
func HasTexture() predicate.UserProfile {
|
||||
return predicate.UserProfile(func(s *sql.Selector) {
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(Table, FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, TextureTable, TextureColumn),
|
||||
)
|
||||
sqlgraph.HasNeighbors(s, step)
|
||||
})
|
||||
}
|
||||
|
||||
// HasTextureWith applies the HasEdge predicate on the "texture" edge with a given conditions (other predicates).
|
||||
func HasTextureWith(preds ...predicate.Texture) predicate.UserProfile {
|
||||
return predicate.UserProfile(func(s *sql.Selector) {
|
||||
step := newTextureStep()
|
||||
sqlgraph.HasNeighborsWith(s, step, func(s *sql.Selector) {
|
||||
for _, p := range preds {
|
||||
p(s)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.UserProfile) predicate.UserProfile {
|
||||
return predicate.UserProfile(func(s *sql.Selector) {
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
||||
)
|
||||
@ -43,6 +44,21 @@ func (upc *UserProfileCreate) SetUser(u *User) *UserProfileCreate {
|
||||
return upc.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// AddTextureIDs adds the "texture" edge to the Texture entity by IDs.
|
||||
func (upc *UserProfileCreate) AddTextureIDs(ids ...int) *UserProfileCreate {
|
||||
upc.mutation.AddTextureIDs(ids...)
|
||||
return upc
|
||||
}
|
||||
|
||||
// AddTexture adds the "texture" edges to the Texture entity.
|
||||
func (upc *UserProfileCreate) AddTexture(t ...*Texture) *UserProfileCreate {
|
||||
ids := make([]int, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return upc.AddTextureIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserProfileMutation object of the builder.
|
||||
func (upc *UserProfileCreate) Mutation() *UserProfileMutation {
|
||||
return upc.mutation
|
||||
@ -137,6 +153,22 @@ func (upc *UserProfileCreate) createSpec() (*UserProfile, *sqlgraph.CreateSpec)
|
||||
_node.user_profile = &nodes[0]
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if nodes := upc.mutation.TextureIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: userprofile.TextureTable,
|
||||
Columns: []string{userprofile.TextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
@ -12,6 +13,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
||||
)
|
||||
@ -24,6 +26,7 @@ type UserProfileQuery struct {
|
||||
inters []Interceptor
|
||||
predicates []predicate.UserProfile
|
||||
withUser *UserQuery
|
||||
withTexture *TextureQuery
|
||||
withFKs bool
|
||||
modifiers []func(*sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
@ -84,6 +87,28 @@ func (upq *UserProfileQuery) QueryUser() *UserQuery {
|
||||
return query
|
||||
}
|
||||
|
||||
// QueryTexture chains the current query on the "texture" edge.
|
||||
func (upq *UserProfileQuery) QueryTexture() *TextureQuery {
|
||||
query := (&TextureClient{config: upq.config}).Query()
|
||||
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
|
||||
if err := upq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
selector := upq.sqlQuery(ctx)
|
||||
if err := selector.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
step := sqlgraph.NewStep(
|
||||
sqlgraph.From(userprofile.Table, userprofile.FieldID, selector),
|
||||
sqlgraph.To(texture.Table, texture.FieldID),
|
||||
sqlgraph.Edge(sqlgraph.O2M, false, userprofile.TextureTable, userprofile.TextureColumn),
|
||||
)
|
||||
fromU = sqlgraph.SetNeighbors(upq.driver.Dialect(), step)
|
||||
return fromU, nil
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
// First returns the first UserProfile entity from the query.
|
||||
// Returns a *NotFoundError when no UserProfile was found.
|
||||
func (upq *UserProfileQuery) First(ctx context.Context) (*UserProfile, error) {
|
||||
@ -277,6 +302,7 @@ func (upq *UserProfileQuery) Clone() *UserProfileQuery {
|
||||
inters: append([]Interceptor{}, upq.inters...),
|
||||
predicates: append([]predicate.UserProfile{}, upq.predicates...),
|
||||
withUser: upq.withUser.Clone(),
|
||||
withTexture: upq.withTexture.Clone(),
|
||||
// clone intermediate query.
|
||||
sql: upq.sql.Clone(),
|
||||
path: upq.path,
|
||||
@ -294,6 +320,17 @@ func (upq *UserProfileQuery) WithUser(opts ...func(*UserQuery)) *UserProfileQuer
|
||||
return upq
|
||||
}
|
||||
|
||||
// WithTexture tells the query-builder to eager-load the nodes that are connected to
|
||||
// the "texture" edge. The optional arguments are used to configure the query builder of the edge.
|
||||
func (upq *UserProfileQuery) WithTexture(opts ...func(*TextureQuery)) *UserProfileQuery {
|
||||
query := (&TextureClient{config: upq.config}).Query()
|
||||
for _, opt := range opts {
|
||||
opt(query)
|
||||
}
|
||||
upq.withTexture = query
|
||||
return upq
|
||||
}
|
||||
|
||||
// GroupBy is used to group vertices by one or more fields/columns.
|
||||
// It is often used with aggregate functions, like: count, max, mean, min, sum.
|
||||
//
|
||||
@ -373,8 +410,9 @@ func (upq *UserProfileQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]
|
||||
nodes = []*UserProfile{}
|
||||
withFKs = upq.withFKs
|
||||
_spec = upq.querySpec()
|
||||
loadedTypes = [1]bool{
|
||||
loadedTypes = [2]bool{
|
||||
upq.withUser != nil,
|
||||
upq.withTexture != nil,
|
||||
}
|
||||
)
|
||||
if upq.withUser != nil {
|
||||
@ -410,6 +448,13 @@ func (upq *UserProfileQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if query := upq.withTexture; query != nil {
|
||||
if err := upq.loadTexture(ctx, query, nodes,
|
||||
func(n *UserProfile) { n.Edges.Texture = []*Texture{} },
|
||||
func(n *UserProfile, e *Texture) { n.Edges.Texture = append(n.Edges.Texture, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
@ -445,6 +490,37 @@ func (upq *UserProfileQuery) loadUser(ctx context.Context, query *UserQuery, nod
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (upq *UserProfileQuery) loadTexture(ctx context.Context, query *TextureQuery, nodes []*UserProfile, init func(*UserProfile), assign func(*UserProfile, *Texture)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[int]*UserProfile)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
query.withFKs = true
|
||||
query.Where(predicate.Texture(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(s.C(userprofile.TextureColumn), fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.user_profile_texture
|
||||
if fk == nil {
|
||||
return fmt.Errorf(`foreign-key "user_profile_texture" is nil for node %v`, n.ID)
|
||||
}
|
||||
node, ok := nodeids[*fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected referenced foreign-key "user_profile_texture" returned %v for node %v`, *fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (upq *UserProfileQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := upq.querySpec()
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/predicate"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/user"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
||||
)
|
||||
@ -51,6 +52,21 @@ func (upu *UserProfileUpdate) SetUser(u *User) *UserProfileUpdate {
|
||||
return upu.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// AddTextureIDs adds the "texture" edge to the Texture entity by IDs.
|
||||
func (upu *UserProfileUpdate) AddTextureIDs(ids ...int) *UserProfileUpdate {
|
||||
upu.mutation.AddTextureIDs(ids...)
|
||||
return upu
|
||||
}
|
||||
|
||||
// AddTexture adds the "texture" edges to the Texture entity.
|
||||
func (upu *UserProfileUpdate) AddTexture(t ...*Texture) *UserProfileUpdate {
|
||||
ids := make([]int, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return upu.AddTextureIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserProfileMutation object of the builder.
|
||||
func (upu *UserProfileUpdate) Mutation() *UserProfileMutation {
|
||||
return upu.mutation
|
||||
@ -62,6 +78,27 @@ func (upu *UserProfileUpdate) ClearUser() *UserProfileUpdate {
|
||||
return upu
|
||||
}
|
||||
|
||||
// ClearTexture clears all "texture" edges to the Texture entity.
|
||||
func (upu *UserProfileUpdate) ClearTexture() *UserProfileUpdate {
|
||||
upu.mutation.ClearTexture()
|
||||
return upu
|
||||
}
|
||||
|
||||
// RemoveTextureIDs removes the "texture" edge to Texture entities by IDs.
|
||||
func (upu *UserProfileUpdate) RemoveTextureIDs(ids ...int) *UserProfileUpdate {
|
||||
upu.mutation.RemoveTextureIDs(ids...)
|
||||
return upu
|
||||
}
|
||||
|
||||
// RemoveTexture removes "texture" edges to Texture entities.
|
||||
func (upu *UserProfileUpdate) RemoveTexture(t ...*Texture) *UserProfileUpdate {
|
||||
ids := make([]int, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return upu.RemoveTextureIDs(ids...)
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (upu *UserProfileUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, upu.sqlSave, upu.mutation, upu.hooks)
|
||||
@ -144,6 +181,51 @@ func (upu *UserProfileUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if upu.mutation.TextureCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: userprofile.TextureTable,
|
||||
Columns: []string{userprofile.TextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := upu.mutation.RemovedTextureIDs(); len(nodes) > 0 && !upu.mutation.TextureCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: userprofile.TextureTable,
|
||||
Columns: []string{userprofile.TextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := upu.mutation.TextureIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: userprofile.TextureTable,
|
||||
Columns: []string{userprofile.TextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, upu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{userprofile.Label}
|
||||
@ -187,6 +269,21 @@ func (upuo *UserProfileUpdateOne) SetUser(u *User) *UserProfileUpdateOne {
|
||||
return upuo.SetUserID(u.ID)
|
||||
}
|
||||
|
||||
// AddTextureIDs adds the "texture" edge to the Texture entity by IDs.
|
||||
func (upuo *UserProfileUpdateOne) AddTextureIDs(ids ...int) *UserProfileUpdateOne {
|
||||
upuo.mutation.AddTextureIDs(ids...)
|
||||
return upuo
|
||||
}
|
||||
|
||||
// AddTexture adds the "texture" edges to the Texture entity.
|
||||
func (upuo *UserProfileUpdateOne) AddTexture(t ...*Texture) *UserProfileUpdateOne {
|
||||
ids := make([]int, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return upuo.AddTextureIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the UserProfileMutation object of the builder.
|
||||
func (upuo *UserProfileUpdateOne) Mutation() *UserProfileMutation {
|
||||
return upuo.mutation
|
||||
@ -198,6 +295,27 @@ func (upuo *UserProfileUpdateOne) ClearUser() *UserProfileUpdateOne {
|
||||
return upuo
|
||||
}
|
||||
|
||||
// ClearTexture clears all "texture" edges to the Texture entity.
|
||||
func (upuo *UserProfileUpdateOne) ClearTexture() *UserProfileUpdateOne {
|
||||
upuo.mutation.ClearTexture()
|
||||
return upuo
|
||||
}
|
||||
|
||||
// RemoveTextureIDs removes the "texture" edge to Texture entities by IDs.
|
||||
func (upuo *UserProfileUpdateOne) RemoveTextureIDs(ids ...int) *UserProfileUpdateOne {
|
||||
upuo.mutation.RemoveTextureIDs(ids...)
|
||||
return upuo
|
||||
}
|
||||
|
||||
// RemoveTexture removes "texture" edges to Texture entities.
|
||||
func (upuo *UserProfileUpdateOne) RemoveTexture(t ...*Texture) *UserProfileUpdateOne {
|
||||
ids := make([]int, len(t))
|
||||
for i := range t {
|
||||
ids[i] = t[i].ID
|
||||
}
|
||||
return upuo.RemoveTextureIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the UserProfileUpdate builder.
|
||||
func (upuo *UserProfileUpdateOne) Where(ps ...predicate.UserProfile) *UserProfileUpdateOne {
|
||||
upuo.mutation.Where(ps...)
|
||||
@ -310,6 +428,51 @@ func (upuo *UserProfileUpdateOne) sqlSave(ctx context.Context) (_node *UserProfi
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if upuo.mutation.TextureCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: userprofile.TextureTable,
|
||||
Columns: []string{userprofile.TextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := upuo.mutation.RemovedTextureIDs(); len(nodes) > 0 && !upuo.mutation.TextureCleared() {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: userprofile.TextureTable,
|
||||
Columns: []string{userprofile.TextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := upuo.mutation.TextureIDs(); len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
Rel: sqlgraph.O2M,
|
||||
Inverse: false,
|
||||
Table: userprofile.TextureTable,
|
||||
Columns: []string{userprofile.TextureColumn},
|
||||
Bidi: false,
|
||||
Target: &sqlgraph.EdgeTarget{
|
||||
IDSpec: sqlgraph.NewFieldSpec(texture.FieldID, field.TypeInt),
|
||||
},
|
||||
}
|
||||
for _, k := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &UserProfile{config: upuo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
|
2
go.mod
2
go.mod
@ -14,6 +14,7 @@ require (
|
||||
github.com/julienschmidt/httprouter v1.3.0
|
||||
github.com/samber/lo v1.38.1
|
||||
golang.org/x/crypto v0.7.0
|
||||
lukechampine.com/blake3 v1.2.1
|
||||
)
|
||||
|
||||
require (
|
||||
@ -28,6 +29,7 @@ require (
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/go-cmp v0.5.6 // indirect
|
||||
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
|
||||
github.com/leodido/go-urn v1.2.4 // indirect
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
|
||||
github.com/zclconf/go-cty v1.8.0 // indirect
|
||||
|
4
go.sum
4
go.sum
@ -54,6 +54,8 @@ github.com/hashicorp/hcl/v2 v2.13.0 h1:0Apadu1w6M11dyGFxWnmhhcMjkbAiKCv7G1r/2QgC
|
||||
github.com/hashicorp/hcl/v2 v2.13.0/go.mod h1:e4z5nxYlWNPdDSNYX+ph14EvWYMFm3eP0zIUqPc2jr0=
|
||||
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
|
||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
@ -118,3 +120,5 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
lukechampine.com/blake3 v1.2.1 h1:YuqqRuaqsGV71BV/nm9xlI0MKUv4QC54jQnBChWbGnI=
|
||||
lukechampine.com/blake3 v1.2.1/go.mod h1:0OFRp7fBtAylGVCO40o87sbupkyIGgbpv1+M1k1LM6k=
|
||||
|
116
handle/yggdrasil/texture.go
Normal file
116
handle/yggdrasil/texture.go
Normal file
@ -0,0 +1,116 @@
|
||||
package yggdrasil
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image/png"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/xmdhs/authlib-skin/model/yggdrasil"
|
||||
"github.com/xmdhs/authlib-skin/service/utils"
|
||||
)
|
||||
|
||||
func (y *Yggdrasil) getTokenbyAuthorization(ctx context.Context, w http.ResponseWriter, r *http.Request) string {
|
||||
auth := r.Header.Get("Authorization")
|
||||
if auth == "" {
|
||||
y.logger.DebugContext(ctx, "缺少 Authorization")
|
||||
w.WriteHeader(401)
|
||||
return ""
|
||||
}
|
||||
al := strings.Split(auth, " ")
|
||||
if len(al) != 2 || al[0] != "Bearer" {
|
||||
y.logger.DebugContext(ctx, "Authorization 格式错误")
|
||||
w.WriteHeader(401)
|
||||
return ""
|
||||
}
|
||||
return al[1]
|
||||
}
|
||||
|
||||
func (y *Yggdrasil) validTextureType(ctx context.Context, w http.ResponseWriter, textureType string) bool {
|
||||
switch textureType {
|
||||
case "skin":
|
||||
case "cape":
|
||||
default:
|
||||
y.logger.DebugContext(ctx, "错误的材质类型")
|
||||
handleYgError(ctx, w, yggdrasil.Error{ErrorMessage: "错误的材质类型"}, 400)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (y *Yggdrasil) PutTexture() httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
ctx := r.Context()
|
||||
uuid := p.ByName("uuid")
|
||||
textureType := p.ByName("textureType")
|
||||
if uuid == "" || textureType == "" {
|
||||
y.logger.DebugContext(ctx, "路径中缺少参数 uuid / textureType")
|
||||
handleYgError(ctx, w, yggdrasil.Error{ErrorMessage: "路径中缺少参数 uuid / textureType"}, 400)
|
||||
return
|
||||
}
|
||||
token := y.getTokenbyAuthorization(ctx, w, r)
|
||||
|
||||
model := r.FormValue("model")
|
||||
|
||||
skin, err := func() ([]byte, error) {
|
||||
f, _, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
b, err := io.ReadAll(io.LimitReader(f, 5*1000*1000))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pc, err := png.DecodeConfig(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if pc.Height > 200 || pc.Width > 200 {
|
||||
return nil, fmt.Errorf("材质大小超过限制")
|
||||
}
|
||||
p, err := png.Decode(bytes.NewReader(b))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bw := bytes.NewBuffer(nil)
|
||||
err = png.Encode(bw, p)
|
||||
return bw.Bytes(), err
|
||||
}()
|
||||
if err != nil {
|
||||
y.logger.DebugContext(ctx, err.Error())
|
||||
handleYgError(ctx, w, yggdrasil.Error{ErrorMessage: err.Error()}, 400)
|
||||
return
|
||||
}
|
||||
if !y.validTextureType(ctx, w, textureType) {
|
||||
return
|
||||
}
|
||||
|
||||
switch model {
|
||||
case "slim":
|
||||
case "":
|
||||
default:
|
||||
y.logger.DebugContext(ctx, "错误的皮肤的材质模型")
|
||||
handleYgError(ctx, w, yggdrasil.Error{ErrorMessage: "错误的皮肤的材质模型"}, 400)
|
||||
return
|
||||
}
|
||||
|
||||
err = y.yggdrasilService.PutTexture(ctx, token, skin, model, uuid, textureType)
|
||||
if err != nil {
|
||||
if errors.Is(err, utils.ErrTokenInvalid) {
|
||||
y.logger.DebugContext(ctx, err.Error())
|
||||
w.WriteHeader(401)
|
||||
return
|
||||
}
|
||||
|
||||
y.logger.WarnContext(ctx, err.Error())
|
||||
handleYgError(ctx, w, yggdrasil.Error{ErrorMessage: err.Error()}, 500)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(204)
|
||||
}
|
||||
}
|
@ -15,7 +15,9 @@ type User struct {
|
||||
}
|
||||
|
||||
type TokenClaims struct {
|
||||
// token id 验证 token 是否过期
|
||||
Tid string `json:"tid"`
|
||||
// ClientToken Yggdrasil 协议中使用
|
||||
CID string `json:"cid"`
|
||||
jwt.RegisteredClaims
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ type TokenUser struct {
|
||||
}
|
||||
|
||||
type ValidateToken struct {
|
||||
// jwt
|
||||
AccessToken string `json:"accessToken" validate:"required,jwt"`
|
||||
ClientToken string `json:"clientToken"`
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ func newYggdrasil(r *httprouter.Router, handelY yggdrasil.Yggdrasil) error {
|
||||
r.POST("/api/yggdrasil/authserver/signout", warpHJSON(handelY.Signout()))
|
||||
r.POST("/api/yggdrasil/authserver/invalidate", handelY.Invalidate())
|
||||
r.POST("/api/yggdrasil/authserver/refresh", handelY.Refresh())
|
||||
r.PUT("/api/yggdrasil/api/user/profile/:uuid/:textureType", handelY.PutTexture())
|
||||
r.GET("/api/yggdrasil", func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
w.Write([]byte(`{
|
||||
"meta": {
|
||||
|
119
service/yggdrasil/texture.go
Normal file
119
service/yggdrasil/texture.go
Normal file
@ -0,0 +1,119 @@
|
||||
package yggdrasil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/samber/lo"
|
||||
"github.com/xmdhs/authlib-skin/db/ent"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/texture"
|
||||
"github.com/xmdhs/authlib-skin/db/ent/userprofile"
|
||||
"github.com/xmdhs/authlib-skin/model/yggdrasil"
|
||||
utilsService "github.com/xmdhs/authlib-skin/service/utils"
|
||||
"github.com/xmdhs/authlib-skin/utils"
|
||||
"lukechampine.com/blake3"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUUIDNotEq = errors.New("uuid 不相同")
|
||||
)
|
||||
|
||||
func (y *Yggdrasil) PutTexture(ctx context.Context, token string, texturebyte []byte, model string, uuid string, textureType string) error {
|
||||
t, err := utilsService.Auth(ctx, yggdrasil.ValidateToken{AccessToken: token}, y.client, &y.prikey.PublicKey, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("PutTexture: %w", err)
|
||||
}
|
||||
if uuid != t.Subject {
|
||||
return fmt.Errorf("PutTexture: %w", ErrUUIDNotEq)
|
||||
}
|
||||
|
||||
up, err := y.client.UserProfile.Query().Where(userprofile.UUIDEQ(uuid)).WithUser().First(ctx)
|
||||
|
||||
err = utils.WithTx(ctx, y.client, func(tx *ent.Tx) error {
|
||||
// 查找此用户该类型下是否已经存在皮肤
|
||||
tl, err := tx.UserProfile.QueryTexture(up).Where(texture.TypeEQ(textureType)).ForUpdate().All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(tl) == 0 {
|
||||
return nil
|
||||
}
|
||||
// 若存在,查找是否被引用
|
||||
for _, v := range tl {
|
||||
c, err := tx.UserProfile.Query().Where(userprofile.HasTextureWith(texture.IDEQ(v.ID))).Count(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c == 1 {
|
||||
// 若没有其他用户使用该皮肤,删除文件和记录
|
||||
path := filepath.Join(y.TexturePath, v.TextureHash[:2], v.TextureHash[2:4], v.TextureHash)
|
||||
err = os.Remove(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tx.Texture.DeleteOneID(v.ID).Exec(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
ids := lo.Map[*ent.Texture, int](tl, func(item *ent.Texture, index int) int {
|
||||
return item.ID
|
||||
})
|
||||
return tx.UserProfile.UpdateOne(up).RemoveTextureIDs(ids...).Exec(ctx)
|
||||
})
|
||||
|
||||
hashstr, err := createTextureFile(y.config.TexturePath, texturebyte)
|
||||
if err != nil {
|
||||
return fmt.Errorf("PutTexture: %w", err)
|
||||
}
|
||||
|
||||
var textureEnt *ent.Texture
|
||||
err = utils.WithTx(ctx, y.client, func(tx *ent.Tx) error {
|
||||
textureEnt, err = tx.Texture.Query().Where(texture.TextureHashEQ(hashstr)).ForUpdate().First(ctx)
|
||||
var nr *ent.NotFoundError
|
||||
if err != nil && !errors.As(err, &nr) {
|
||||
return err
|
||||
}
|
||||
if textureEnt == nil {
|
||||
textureEnt, err = tx.Texture.Create().SetCreatedUser(up.Edges.User).
|
||||
SetTextureHash(hashstr).
|
||||
SetType(textureType).
|
||||
SetVariant(model).
|
||||
Save(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return tx.UserProfile.UpdateOne(up).AddTexture(textureEnt).Exec(ctx)
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("PutTexture: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createTextureFile(path string, b []byte) (string, error) {
|
||||
hashed := blake3.Sum256(b)
|
||||
hashstr := hex.EncodeToString(hashed[:])
|
||||
p := filepath.Join(path, hashstr[:2], hashstr[2:4], hashstr)
|
||||
err := os.MkdirAll(filepath.Dir(p), 0755)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("createTextureFile: %w", err)
|
||||
}
|
||||
f, err := os.Stat(p)
|
||||
if err != nil && !errors.Is(err, os.ErrNotExist) {
|
||||
return "", fmt.Errorf("createTextureFile: %w", err)
|
||||
}
|
||||
if f == nil {
|
||||
err := os.WriteFile(p, b, 0644)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("createTextureFile: %w", err)
|
||||
}
|
||||
}
|
||||
return hashstr, nil
|
||||
}
|
@ -18,6 +18,7 @@ type Yggdrasil struct {
|
||||
cache cache.Cache
|
||||
config config.Config
|
||||
prikey *rsa.PrivateKey
|
||||
TexturePath string
|
||||
}
|
||||
|
||||
func NewYggdrasil(client *ent.Client, cache cache.Cache, c config.Config, prikey *rsa.PrivateKey) *Yggdrasil {
|
||||
|
@ -65,3 +65,16 @@ func TestLittleskinSign(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestAuthlibNew(t *testing.T) {
|
||||
rsa2048, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
as := NewAuthlibSignWithKey(rsa2048)
|
||||
|
||||
_, err = NewAuthlibSign([]byte(lo.Must1(as.GetPriKey())))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user