fix: api descript

This commit is contained in:
wwweww
2026-02-28 05:33:16 +08:00
parent 5930fb0dde
commit d2f33b4b96
243 changed files with 37065 additions and 780 deletions
+16
View File
@@ -0,0 +1,16 @@
package config
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/zrpc"
)
type Config struct {
zrpc.RpcServerConf
SnowflakeRpcConf zrpc.RpcClientConf
DB struct {
Master string
Slaves string
}
CacheConf cache.CacheConf
}
@@ -0,0 +1,48 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type AddShopInvitationsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShopInvitationsLogic {
return &AddShopInvitationsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// -----------------------shopInvitations-----------------------
func (l *AddShopInvitationsLogic) AddShopInvitations(in *pb.AddShopInvitationsReq) (*pb.AddShopInvitationsResp, error) {
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("create player service id failed")
}
_, err = l.svcCtx.ShopModelRW.ShopInvitations.Create().
SetID(idResp.Id).
SetShopID(in.ShopId).
SetPlayerID(in.PlayerId).
SetStatus(in.Status).
SetInvitedBy(in.InvitedBy).
Save(l.ctx)
if err != nil {
return nil, errors.New("add shop invitation failed")
}
return &pb.AddShopInvitationsResp{}, nil
}
@@ -0,0 +1,48 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type AddShopPlayersLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShopPlayersLogic {
return &AddShopPlayersLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// -----------------------shopPlayers-----------------------
func (l *AddShopPlayersLogic) AddShopPlayers(in *pb.AddShopPlayersReq) (*pb.AddShopPlayersResp, error) {
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("create player service id failed")
}
_, err = l.svcCtx.ShopModelRW.ShopPlayers.Create().
SetID(idResp.Id).
SetShopID(in.ShopId).
SetPlayerID(in.PlayerId).
SetIsPrimary(in.IsPrimary).
Save(l.ctx)
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("add player service failed")
}
return &pb.AddShopPlayersResp{}, nil
}
@@ -0,0 +1,68 @@
package logic
import (
"context"
"encoding/json"
"errors"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/shopspring/decimal"
"github.com/zeromicro/go-zero/core/logx"
)
type AddShopsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddShopsLogic {
return &AddShopsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// -----------------------shops-----------------------
func (l *AddShopsLogic) AddShops(in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
idResp, err := l.svcCtx.Snowflake.NextId(l.ctx, &snowflake.NextIdReq{})
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("create player service id failed")
}
var templateConfig map[string]interface{}
err = json.Unmarshal([]byte(in.TemplateConfig), &templateConfig)
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("invalid template config")
}
_, err = l.svcCtx.ShopModelRO.Shops.Create().
SetID(idResp.Id).
SetOwnerID(in.OwnerId).
SetName(in.Name).
SetBanner(in.Banner).
SetDescription(in.Description).
SetRating(decimal.NewFromFloat(in.Rating)).
SetTotalOrders(int(in.TotalOrders)).
SetPlayerCount(int(in.PlayerCount)).
SetNillableCommissionType(&in.CommissionType).
SetCommissionValue(decimal.NewFromFloat(in.CommissionValue)).
SetAllowMultiShop(in.AllowMultiShop).
SetAllowIndependentOrders(in.AllowIndependentOrders).
SetDispatchMode(in.DispatchMode).
SetAnnouncements(in.Announcements).
SetTemplateConfig(templateConfig).
Save(l.ctx)
if err != nil {
logx.Errorf("addPlayerServices err:%v", err)
return nil, errors.New("add player service failed")
}
return &pb.AddShopsResp{}, nil
}
@@ -0,0 +1,35 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type DelShopInvitationsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelShopInvitationsLogic {
return &DelShopInvitationsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelShopInvitationsLogic) DelShopInvitations(in *pb.DelShopInvitationsReq) (*pb.DelShopInvitationsResp, error) {
err := l.svcCtx.ShopModelRW.ShopInvitations.DeleteOneID(in.Id).Exec(l.ctx)
if err != nil {
logx.Errorf("delete shop invitations failed, %s", err.Error())
return nil, errors.New("delete failed")
}
return &pb.DelShopInvitationsResp{}, nil
}
@@ -0,0 +1,35 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type DelShopPlayersLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelShopPlayersLogic {
return &DelShopPlayersLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelShopPlayersLogic) DelShopPlayers(in *pb.DelShopPlayersReq) (*pb.DelShopPlayersResp, error) {
err := l.svcCtx.ShopModelRO.ShopPlayers.DeleteOneID(in.Id).Exec(l.ctx)
if err != nil {
logx.Errorf("delete shop players failed, %s", err.Error())
return nil, errors.New("delete failed")
}
return &pb.DelShopPlayersResp{}, nil
}
@@ -0,0 +1,35 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type DelShopsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDelShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DelShopsLogic {
return &DelShopsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *DelShopsLogic) DelShops(in *pb.DelShopsReq) (*pb.DelShopsResp, error) {
err := l.svcCtx.ShopModelRO.Shops.DeleteOneID(in.Id).Exec(l.ctx)
if err != nil {
logx.Errorf("delete shop failed, %s", err.Error())
return nil, errors.New("delete failed")
}
return &pb.DelShopsResp{}, nil
}
@@ -0,0 +1,50 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
//"juwan-backend/app/game/rpc/internal/models/shopinvitations"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetShopInvitationsByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetShopInvitationsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopInvitationsByIdLogic {
return &GetShopInvitationsByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetShopInvitationsByIdLogic) GetShopInvitationsById(in *pb.GetShopInvitationsByIdReq) (*pb.GetShopInvitationsByIdResp, error) {
shopInvitation, err := l.svcCtx.ShopModelRO.ShopInvitations.Query().Where(shopinvitations.IDEQ(in.Id)).First(l.ctx)
if err != nil {
logx.WithContext(l.ctx).Errorf("GetShopInvitationsByIdLogic err: %v", err)
return nil, errors.New("get shop invitations by id failed")
}
pbShopInvitation := pb.ShopInvitations{
Id: shopInvitation.ID,
ShopId: shopInvitation.ShopID,
PlayerId: shopInvitation.PlayerID,
Status: shopInvitation.Status,
InvitedBy: shopInvitation.InvitedBy,
CreatedAt: shopInvitation.CreatedAt.Unix(),
}
if shopInvitation.RespondedAt != nil {
pbShopInvitation.RespondedAt = shopInvitation.RespondedAt.Unix()
}
return &pb.GetShopInvitationsByIdResp{ShopInvitations: &pbShopInvitation}, nil
}
@@ -0,0 +1,46 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetShopPlayersByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetShopPlayersByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopPlayersByIdLogic {
return &GetShopPlayersByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetShopPlayersByIdLogic) GetShopPlayersById(in *pb.GetShopPlayersByIdReq) (*pb.GetShopPlayersByIdResp, error) {
shopPlayer, err := l.svcCtx.ShopModelRO.ShopPlayers.Query().Where(shopplayers.IDEQ(in.Id)).First(l.ctx)
if err != nil {
logx.WithContext(l.ctx).Errorf("GetShopPlayersByIdLogic err: %v", err)
return nil, errors.New("get shop players by id failed")
}
pbShopPlayer := pb.ShopPlayers{
ShopId: shopPlayer.ShopID,
PlayerId: shopPlayer.PlayerID,
IsPrimary: shopPlayer.IsPrimary,
JoinedAt: shopPlayer.JoinedAt.Unix(),
}
if shopPlayer.LeftAt != nil {
pbShopPlayer.LeftAt = shopPlayer.LeftAt.Unix()
}
return &pb.GetShopPlayersByIdResp{ShopPlayers: &pbShopPlayer}, nil
}
@@ -0,0 +1,67 @@
package logic
import (
"context"
"encoding/json"
"errors"
"juwan-backend/app/shop/rpc/internal/models/shops"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type GetShopsByIdLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetShopsByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetShopsByIdLogic {
return &GetShopsByIdLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *GetShopsByIdLogic) GetShopsById(in *pb.GetShopsByIdReq) (*pb.GetShopsByIdResp, error) {
shop, err := l.svcCtx.ShopModelRO.Shops.Query().Where(shops.IDEQ(in.Id)).First(l.ctx)
if err != nil {
logx.WithContext(l.ctx).Errorf("GetShopsByIdLogic err: %v", err)
return nil, errors.New("get shops by id failed")
}
templateConfigBytes, err := json.Marshal(shop.TemplateConfig)
if err != nil {
logx.WithContext(l.ctx).Errorf("GetShopsByIdLogic marshal template config err: %v", err)
return nil, errors.New("get shops by id failed")
}
pbShop := pb.Shops{
Id: shop.ID,
OwnerId: shop.OwnerID,
Name: shop.Name,
Rating: shop.Rating.InexactFloat64(),
TotalOrders: int64(shop.TotalOrders),
PlayerCount: int64(shop.PlayerCount),
CommissionType: shop.CommissionType,
CommissionValue: shop.CommissionValue.InexactFloat64(),
AllowMultiShop: shop.AllowMultiShop,
AllowIndependentOrders: shop.AllowIndependentOrders,
DispatchMode: shop.DispatchMode,
Announcements: shop.Announcements,
TemplateConfig: string(templateConfigBytes),
CreatedAt: shop.CreatedAt.Unix(),
UpdatedAt: shop.UpdatedAt.Unix(),
}
if shop.Banner != nil {
pbShop.Banner = *shop.Banner
}
if shop.Description != nil {
pbShop.Description = *shop.Description
}
return &pb.GetShopsByIdResp{Shops: &pbShop}, nil
}
@@ -0,0 +1,28 @@
package logic
import (
"context"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchShopInvitationsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchShopInvitationsLogic {
return &SearchShopInvitationsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchShopInvitationsLogic) SearchShopInvitations(in *pb.SearchShopInvitationsReq) (*pb.SearchShopInvitationsResp, error) {
// TODO: implement search logic based on the provided criteria in the request
return &pb.SearchShopInvitationsResp{}, nil
}
@@ -0,0 +1,26 @@
package logic
import (
"context"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchShopPlayersLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchShopPlayersLogic {
return &SearchShopPlayersLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchShopPlayersLogic) SearchShopPlayers(in *pb.SearchShopPlayersReq) (*pb.SearchShopPlayersResp, error) {
}
@@ -0,0 +1,27 @@
package logic
import (
"context"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type SearchShopsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewSearchShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SearchShopsLogic {
return &SearchShopsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *SearchShopsLogic) SearchShops(in *pb.SearchShopsReq) (*pb.SearchShopsResp, error) {
}
@@ -0,0 +1,30 @@
package logic
import (
"context"
"errors"
"time"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateShopInvitationsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateShopInvitationsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopInvitationsLogic {
return &UpdateShopInvitationsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateShopInvitationsLogic) UpdateShopInvitations(in *pb.UpdateShopInvitationsReq) (*pb.UpdateShopInvitationsResp, error) {
}
@@ -0,0 +1,32 @@
package logic
import (
"context"
"errors"
"juwan-backend/app/shop/rpc/internal/models"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"time"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateShopPlayersLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateShopPlayersLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopPlayersLogic {
return &UpdateShopPlayersLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateShopPlayersLogic) UpdateShopPlayers(in *pb.UpdateShopPlayersReq) (*pb.UpdateShopPlayersResp, error) {
}
@@ -0,0 +1,32 @@
package logic
import (
"context"
"encoding/json"
"errors"
"time"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
"github.com/shopspring/decimal"
"github.com/zeromicro/go-zero/core/logx"
)
type UpdateShopsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewUpdateShopsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateShopsLogic {
return &UpdateShopsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *UpdateShopsLogic) UpdateShops(in *pb.UpdateShopsReq) (*pb.UpdateShopsResp, error) {
}
+627
View File
@@ -0,0 +1,627 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"log"
"reflect"
"juwan-backend/app/shop/rpc/internal/models/migrate"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"juwan-backend/app/shop/rpc/internal/models/shops"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
)
// Client is the client that holds all ent builders.
type Client struct {
config
// Schema is the client for creating, migrating and dropping schema.
Schema *migrate.Schema
// ShopInvitations is the client for interacting with the ShopInvitations builders.
ShopInvitations *ShopInvitationsClient
// ShopPlayers is the client for interacting with the ShopPlayers builders.
ShopPlayers *ShopPlayersClient
// Shops is the client for interacting with the Shops builders.
Shops *ShopsClient
}
// NewClient creates a new client configured with the given options.
func NewClient(opts ...Option) *Client {
client := &Client{config: newConfig(opts...)}
client.init()
return client
}
func (c *Client) init() {
c.Schema = migrate.NewSchema(c.driver)
c.ShopInvitations = NewShopInvitationsClient(c.config)
c.ShopPlayers = NewShopPlayersClient(c.config)
c.Shops = NewShopsClient(c.config)
}
type (
// config is the configuration for the client and its builder.
config struct {
// driver used for executing database requests.
driver dialect.Driver
// debug enable a debug logging.
debug bool
// log used for logging on debug mode.
log func(...any)
// hooks to execute on mutations.
hooks *hooks
// interceptors to execute on queries.
inters *inters
}
// Option function to configure the client.
Option func(*config)
)
// newConfig creates a new config for the client.
func newConfig(opts ...Option) config {
cfg := config{log: log.Println, hooks: &hooks{}, inters: &inters{}}
cfg.options(opts...)
return cfg
}
// options applies the options on the config object.
func (c *config) options(opts ...Option) {
for _, opt := range opts {
opt(c)
}
if c.debug {
c.driver = dialect.Debug(c.driver, c.log)
}
}
// Debug enables debug logging on the ent.Driver.
func Debug() Option {
return func(c *config) {
c.debug = true
}
}
// Log sets the logging function for debug mode.
func Log(fn func(...any)) Option {
return func(c *config) {
c.log = fn
}
}
// Driver configures the client driver.
func Driver(driver dialect.Driver) Option {
return func(c *config) {
c.driver = driver
}
}
// Open opens a database/sql.DB specified by the driver name and
// the data source name, and returns a new client attached to it.
// Optional parameters can be added for configuring the client.
func Open(driverName, dataSourceName string, options ...Option) (*Client, error) {
switch driverName {
case dialect.MySQL, dialect.Postgres, dialect.SQLite:
drv, err := sql.Open(driverName, dataSourceName)
if err != nil {
return nil, err
}
return NewClient(append(options, Driver(drv))...), nil
default:
return nil, fmt.Errorf("unsupported driver: %q", driverName)
}
}
// ErrTxStarted is returned when trying to start a new transaction from a transactional client.
var ErrTxStarted = errors.New("models: cannot start a transaction within a transaction")
// Tx returns a new transactional client. The provided context
// is used until the transaction is committed or rolled back.
func (c *Client) Tx(ctx context.Context) (*Tx, error) {
if _, ok := c.driver.(*txDriver); ok {
return nil, ErrTxStarted
}
tx, err := newTx(ctx, c.driver)
if err != nil {
return nil, fmt.Errorf("models: starting a transaction: %w", err)
}
cfg := c.config
cfg.driver = tx
return &Tx{
ctx: ctx,
config: cfg,
ShopInvitations: NewShopInvitationsClient(cfg),
ShopPlayers: NewShopPlayersClient(cfg),
Shops: NewShopsClient(cfg),
}, nil
}
// BeginTx returns a transactional client with specified options.
func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) {
if _, ok := c.driver.(*txDriver); ok {
return nil, errors.New("ent: cannot start a transaction within a transaction")
}
tx, err := c.driver.(interface {
BeginTx(context.Context, *sql.TxOptions) (dialect.Tx, error)
}).BeginTx(ctx, opts)
if err != nil {
return nil, fmt.Errorf("ent: starting a transaction: %w", err)
}
cfg := c.config
cfg.driver = &txDriver{tx: tx, drv: c.driver}
return &Tx{
ctx: ctx,
config: cfg,
ShopInvitations: NewShopInvitationsClient(cfg),
ShopPlayers: NewShopPlayersClient(cfg),
Shops: NewShopsClient(cfg),
}, nil
}
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
//
// client.Debug().
// ShopInvitations.
// Query().
// Count(ctx)
func (c *Client) Debug() *Client {
if c.debug {
return c
}
cfg := c.config
cfg.driver = dialect.Debug(c.driver, c.log)
client := &Client{config: cfg}
client.init()
return client
}
// Close closes the database connection and prevents new queries from starting.
func (c *Client) Close() error {
return c.driver.Close()
}
// Use adds the mutation hooks to all the entity clients.
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
func (c *Client) Use(hooks ...Hook) {
c.ShopInvitations.Use(hooks...)
c.ShopPlayers.Use(hooks...)
c.Shops.Use(hooks...)
}
// Intercept adds the query interceptors to all the entity clients.
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
func (c *Client) Intercept(interceptors ...Interceptor) {
c.ShopInvitations.Intercept(interceptors...)
c.ShopPlayers.Intercept(interceptors...)
c.Shops.Intercept(interceptors...)
}
// Mutate implements the ent.Mutator interface.
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
switch m := m.(type) {
case *ShopInvitationsMutation:
return c.ShopInvitations.mutate(ctx, m)
case *ShopPlayersMutation:
return c.ShopPlayers.mutate(ctx, m)
case *ShopsMutation:
return c.Shops.mutate(ctx, m)
default:
return nil, fmt.Errorf("models: unknown mutation type %T", m)
}
}
// ShopInvitationsClient is a client for the ShopInvitations schema.
type ShopInvitationsClient struct {
config
}
// NewShopInvitationsClient returns a client for the ShopInvitations from the given config.
func NewShopInvitationsClient(c config) *ShopInvitationsClient {
return &ShopInvitationsClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `shopinvitations.Hooks(f(g(h())))`.
func (c *ShopInvitationsClient) Use(hooks ...Hook) {
c.hooks.ShopInvitations = append(c.hooks.ShopInvitations, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `shopinvitations.Intercept(f(g(h())))`.
func (c *ShopInvitationsClient) Intercept(interceptors ...Interceptor) {
c.inters.ShopInvitations = append(c.inters.ShopInvitations, interceptors...)
}
// Create returns a builder for creating a ShopInvitations entity.
func (c *ShopInvitationsClient) Create() *ShopInvitationsCreate {
mutation := newShopInvitationsMutation(c.config, OpCreate)
return &ShopInvitationsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of ShopInvitations entities.
func (c *ShopInvitationsClient) CreateBulk(builders ...*ShopInvitationsCreate) *ShopInvitationsCreateBulk {
return &ShopInvitationsCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *ShopInvitationsClient) MapCreateBulk(slice any, setFunc func(*ShopInvitationsCreate, int)) *ShopInvitationsCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &ShopInvitationsCreateBulk{err: fmt.Errorf("calling to ShopInvitationsClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*ShopInvitationsCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &ShopInvitationsCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for ShopInvitations.
func (c *ShopInvitationsClient) Update() *ShopInvitationsUpdate {
mutation := newShopInvitationsMutation(c.config, OpUpdate)
return &ShopInvitationsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *ShopInvitationsClient) UpdateOne(_m *ShopInvitations) *ShopInvitationsUpdateOne {
mutation := newShopInvitationsMutation(c.config, OpUpdateOne, withShopInvitations(_m))
return &ShopInvitationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *ShopInvitationsClient) UpdateOneID(id int64) *ShopInvitationsUpdateOne {
mutation := newShopInvitationsMutation(c.config, OpUpdateOne, withShopInvitationsID(id))
return &ShopInvitationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for ShopInvitations.
func (c *ShopInvitationsClient) Delete() *ShopInvitationsDelete {
mutation := newShopInvitationsMutation(c.config, OpDelete)
return &ShopInvitationsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *ShopInvitationsClient) DeleteOne(_m *ShopInvitations) *ShopInvitationsDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *ShopInvitationsClient) DeleteOneID(id int64) *ShopInvitationsDeleteOne {
builder := c.Delete().Where(shopinvitations.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &ShopInvitationsDeleteOne{builder}
}
// Query returns a query builder for ShopInvitations.
func (c *ShopInvitationsClient) Query() *ShopInvitationsQuery {
return &ShopInvitationsQuery{
config: c.config,
ctx: &QueryContext{Type: TypeShopInvitations},
inters: c.Interceptors(),
}
}
// Get returns a ShopInvitations entity by its id.
func (c *ShopInvitationsClient) Get(ctx context.Context, id int64) (*ShopInvitations, error) {
return c.Query().Where(shopinvitations.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *ShopInvitationsClient) GetX(ctx context.Context, id int64) *ShopInvitations {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *ShopInvitationsClient) Hooks() []Hook {
return c.hooks.ShopInvitations
}
// Interceptors returns the client interceptors.
func (c *ShopInvitationsClient) Interceptors() []Interceptor {
return c.inters.ShopInvitations
}
func (c *ShopInvitationsClient) mutate(ctx context.Context, m *ShopInvitationsMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&ShopInvitationsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&ShopInvitationsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&ShopInvitationsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&ShopInvitationsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("models: unknown ShopInvitations mutation op: %q", m.Op())
}
}
// ShopPlayersClient is a client for the ShopPlayers schema.
type ShopPlayersClient struct {
config
}
// NewShopPlayersClient returns a client for the ShopPlayers from the given config.
func NewShopPlayersClient(c config) *ShopPlayersClient {
return &ShopPlayersClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `shopplayers.Hooks(f(g(h())))`.
func (c *ShopPlayersClient) Use(hooks ...Hook) {
c.hooks.ShopPlayers = append(c.hooks.ShopPlayers, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `shopplayers.Intercept(f(g(h())))`.
func (c *ShopPlayersClient) Intercept(interceptors ...Interceptor) {
c.inters.ShopPlayers = append(c.inters.ShopPlayers, interceptors...)
}
// Create returns a builder for creating a ShopPlayers entity.
func (c *ShopPlayersClient) Create() *ShopPlayersCreate {
mutation := newShopPlayersMutation(c.config, OpCreate)
return &ShopPlayersCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of ShopPlayers entities.
func (c *ShopPlayersClient) CreateBulk(builders ...*ShopPlayersCreate) *ShopPlayersCreateBulk {
return &ShopPlayersCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *ShopPlayersClient) MapCreateBulk(slice any, setFunc func(*ShopPlayersCreate, int)) *ShopPlayersCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &ShopPlayersCreateBulk{err: fmt.Errorf("calling to ShopPlayersClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*ShopPlayersCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &ShopPlayersCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for ShopPlayers.
func (c *ShopPlayersClient) Update() *ShopPlayersUpdate {
mutation := newShopPlayersMutation(c.config, OpUpdate)
return &ShopPlayersUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *ShopPlayersClient) UpdateOne(_m *ShopPlayers) *ShopPlayersUpdateOne {
mutation := newShopPlayersMutation(c.config, OpUpdateOne, withShopPlayers(_m))
return &ShopPlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *ShopPlayersClient) UpdateOneID(id int64) *ShopPlayersUpdateOne {
mutation := newShopPlayersMutation(c.config, OpUpdateOne, withShopPlayersID(id))
return &ShopPlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for ShopPlayers.
func (c *ShopPlayersClient) Delete() *ShopPlayersDelete {
mutation := newShopPlayersMutation(c.config, OpDelete)
return &ShopPlayersDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *ShopPlayersClient) DeleteOne(_m *ShopPlayers) *ShopPlayersDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *ShopPlayersClient) DeleteOneID(id int64) *ShopPlayersDeleteOne {
builder := c.Delete().Where(shopplayers.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &ShopPlayersDeleteOne{builder}
}
// Query returns a query builder for ShopPlayers.
func (c *ShopPlayersClient) Query() *ShopPlayersQuery {
return &ShopPlayersQuery{
config: c.config,
ctx: &QueryContext{Type: TypeShopPlayers},
inters: c.Interceptors(),
}
}
// Get returns a ShopPlayers entity by its id.
func (c *ShopPlayersClient) Get(ctx context.Context, id int64) (*ShopPlayers, error) {
return c.Query().Where(shopplayers.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *ShopPlayersClient) GetX(ctx context.Context, id int64) *ShopPlayers {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *ShopPlayersClient) Hooks() []Hook {
return c.hooks.ShopPlayers
}
// Interceptors returns the client interceptors.
func (c *ShopPlayersClient) Interceptors() []Interceptor {
return c.inters.ShopPlayers
}
func (c *ShopPlayersClient) mutate(ctx context.Context, m *ShopPlayersMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&ShopPlayersCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&ShopPlayersUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&ShopPlayersUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&ShopPlayersDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("models: unknown ShopPlayers mutation op: %q", m.Op())
}
}
// ShopsClient is a client for the Shops schema.
type ShopsClient struct {
config
}
// NewShopsClient returns a client for the Shops from the given config.
func NewShopsClient(c config) *ShopsClient {
return &ShopsClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `shops.Hooks(f(g(h())))`.
func (c *ShopsClient) Use(hooks ...Hook) {
c.hooks.Shops = append(c.hooks.Shops, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `shops.Intercept(f(g(h())))`.
func (c *ShopsClient) Intercept(interceptors ...Interceptor) {
c.inters.Shops = append(c.inters.Shops, interceptors...)
}
// Create returns a builder for creating a Shops entity.
func (c *ShopsClient) Create() *ShopsCreate {
mutation := newShopsMutation(c.config, OpCreate)
return &ShopsCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of Shops entities.
func (c *ShopsClient) CreateBulk(builders ...*ShopsCreate) *ShopsCreateBulk {
return &ShopsCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *ShopsClient) MapCreateBulk(slice any, setFunc func(*ShopsCreate, int)) *ShopsCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &ShopsCreateBulk{err: fmt.Errorf("calling to ShopsClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*ShopsCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &ShopsCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for Shops.
func (c *ShopsClient) Update() *ShopsUpdate {
mutation := newShopsMutation(c.config, OpUpdate)
return &ShopsUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *ShopsClient) UpdateOne(_m *Shops) *ShopsUpdateOne {
mutation := newShopsMutation(c.config, OpUpdateOne, withShops(_m))
return &ShopsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *ShopsClient) UpdateOneID(id int64) *ShopsUpdateOne {
mutation := newShopsMutation(c.config, OpUpdateOne, withShopsID(id))
return &ShopsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for Shops.
func (c *ShopsClient) Delete() *ShopsDelete {
mutation := newShopsMutation(c.config, OpDelete)
return &ShopsDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *ShopsClient) DeleteOne(_m *Shops) *ShopsDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *ShopsClient) DeleteOneID(id int64) *ShopsDeleteOne {
builder := c.Delete().Where(shops.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &ShopsDeleteOne{builder}
}
// Query returns a query builder for Shops.
func (c *ShopsClient) Query() *ShopsQuery {
return &ShopsQuery{
config: c.config,
ctx: &QueryContext{Type: TypeShops},
inters: c.Interceptors(),
}
}
// Get returns a Shops entity by its id.
func (c *ShopsClient) Get(ctx context.Context, id int64) (*Shops, error) {
return c.Query().Where(shops.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *ShopsClient) GetX(ctx context.Context, id int64) *Shops {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// Hooks returns the client hooks.
func (c *ShopsClient) Hooks() []Hook {
return c.hooks.Shops
}
// Interceptors returns the client interceptors.
func (c *ShopsClient) Interceptors() []Interceptor {
return c.inters.Shops
}
func (c *ShopsClient) mutate(ctx context.Context, m *ShopsMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&ShopsCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&ShopsUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&ShopsUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&ShopsDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("models: unknown Shops mutation op: %q", m.Op())
}
}
// hooks and interceptors per client, for fast access.
type (
hooks struct {
ShopInvitations, ShopPlayers, Shops []ent.Hook
}
inters struct {
ShopInvitations, ShopPlayers, Shops []ent.Interceptor
}
)
+612
View File
@@ -0,0 +1,612 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"juwan-backend/app/shop/rpc/internal/models/shops"
"reflect"
"sync"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
// ent aliases to avoid import conflicts in user's code.
type (
Op = ent.Op
Hook = ent.Hook
Value = ent.Value
Query = ent.Query
QueryContext = ent.QueryContext
Querier = ent.Querier
QuerierFunc = ent.QuerierFunc
Interceptor = ent.Interceptor
InterceptFunc = ent.InterceptFunc
Traverser = ent.Traverser
TraverseFunc = ent.TraverseFunc
Policy = ent.Policy
Mutator = ent.Mutator
Mutation = ent.Mutation
MutateFunc = ent.MutateFunc
)
type clientCtxKey struct{}
// FromContext returns a Client stored inside a context, or nil if there isn't one.
func FromContext(ctx context.Context) *Client {
c, _ := ctx.Value(clientCtxKey{}).(*Client)
return c
}
// NewContext returns a new context with the given Client attached.
func NewContext(parent context.Context, c *Client) context.Context {
return context.WithValue(parent, clientCtxKey{}, c)
}
type txCtxKey struct{}
// TxFromContext returns a Tx stored inside a context, or nil if there isn't one.
func TxFromContext(ctx context.Context) *Tx {
tx, _ := ctx.Value(txCtxKey{}).(*Tx)
return tx
}
// NewTxContext returns a new context with the given Tx attached.
func NewTxContext(parent context.Context, tx *Tx) context.Context {
return context.WithValue(parent, txCtxKey{}, tx)
}
// OrderFunc applies an ordering on the sql selector.
// Deprecated: Use Asc/Desc functions or the package builders instead.
type OrderFunc func(*sql.Selector)
var (
initCheck sync.Once
columnCheck sql.ColumnCheck
)
// checkColumn checks if the column exists in the given table.
func checkColumn(t, c string) error {
initCheck.Do(func() {
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
shopinvitations.Table: shopinvitations.ValidColumn,
shopplayers.Table: shopplayers.ValidColumn,
shops.Table: shops.ValidColumn,
})
})
return columnCheck(t, c)
}
// Asc applies the given fields in ASC order.
func Asc(fields ...string) func(*sql.Selector) {
return func(s *sql.Selector) {
for _, f := range fields {
if err := checkColumn(s.TableName(), f); err != nil {
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
}
s.OrderBy(sql.Asc(s.C(f)))
}
}
}
// Desc applies the given fields in DESC order.
func Desc(fields ...string) func(*sql.Selector) {
return func(s *sql.Selector) {
for _, f := range fields {
if err := checkColumn(s.TableName(), f); err != nil {
s.AddError(&ValidationError{Name: f, err: fmt.Errorf("models: %w", err)})
}
s.OrderBy(sql.Desc(s.C(f)))
}
}
}
// AggregateFunc applies an aggregation step on the group-by traversal/selector.
type AggregateFunc func(*sql.Selector) string
// As is a pseudo aggregation function for renaming another other functions with custom names. For example:
//
// GroupBy(field1, field2).
// Aggregate(models.As(models.Sum(field1), "sum_field1"), (models.As(models.Sum(field2), "sum_field2")).
// Scan(ctx, &v)
func As(fn AggregateFunc, end string) AggregateFunc {
return func(s *sql.Selector) string {
return sql.As(fn(s), end)
}
}
// Count applies the "count" aggregation function on each group.
func Count() AggregateFunc {
return func(s *sql.Selector) string {
return sql.Count("*")
}
}
// Max applies the "max" aggregation function on the given field of each group.
func Max(field string) AggregateFunc {
return func(s *sql.Selector) string {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
return ""
}
return sql.Max(s.C(field))
}
}
// Mean applies the "mean" aggregation function on the given field of each group.
func Mean(field string) AggregateFunc {
return func(s *sql.Selector) string {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
return ""
}
return sql.Avg(s.C(field))
}
}
// Min applies the "min" aggregation function on the given field of each group.
func Min(field string) AggregateFunc {
return func(s *sql.Selector) string {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
return ""
}
return sql.Min(s.C(field))
}
}
// Sum applies the "sum" aggregation function on the given field of each group.
func Sum(field string) AggregateFunc {
return func(s *sql.Selector) string {
if err := checkColumn(s.TableName(), field); err != nil {
s.AddError(&ValidationError{Name: field, err: fmt.Errorf("models: %w", err)})
return ""
}
return sql.Sum(s.C(field))
}
}
// ValidationError returns when validating a field or edge fails.
type ValidationError struct {
Name string // Field or edge name.
err error
}
// Error implements the error interface.
func (e *ValidationError) Error() string {
return e.err.Error()
}
// Unwrap implements the errors.Wrapper interface.
func (e *ValidationError) Unwrap() error {
return e.err
}
// IsValidationError returns a boolean indicating whether the error is a validation error.
func IsValidationError(err error) bool {
if err == nil {
return false
}
var e *ValidationError
return errors.As(err, &e)
}
// NotFoundError returns when trying to fetch a specific entity and it was not found in the database.
type NotFoundError struct {
label string
}
// Error implements the error interface.
func (e *NotFoundError) Error() string {
return "models: " + e.label + " not found"
}
// IsNotFound returns a boolean indicating whether the error is a not found error.
func IsNotFound(err error) bool {
if err == nil {
return false
}
var e *NotFoundError
return errors.As(err, &e)
}
// MaskNotFound masks not found error.
func MaskNotFound(err error) error {
if IsNotFound(err) {
return nil
}
return err
}
// NotSingularError returns when trying to fetch a singular entity and more then one was found in the database.
type NotSingularError struct {
label string
}
// Error implements the error interface.
func (e *NotSingularError) Error() string {
return "models: " + e.label + " not singular"
}
// IsNotSingular returns a boolean indicating whether the error is a not singular error.
func IsNotSingular(err error) bool {
if err == nil {
return false
}
var e *NotSingularError
return errors.As(err, &e)
}
// NotLoadedError returns when trying to get a node that was not loaded by the query.
type NotLoadedError struct {
edge string
}
// Error implements the error interface.
func (e *NotLoadedError) Error() string {
return "models: " + e.edge + " edge was not loaded"
}
// IsNotLoaded returns a boolean indicating whether the error is a not loaded error.
func IsNotLoaded(err error) bool {
if err == nil {
return false
}
var e *NotLoadedError
return errors.As(err, &e)
}
// ConstraintError returns when trying to create/update one or more entities and
// one or more of their constraints failed. For example, violation of edge or
// field uniqueness.
type ConstraintError struct {
msg string
wrap error
}
// Error implements the error interface.
func (e ConstraintError) Error() string {
return "models: constraint failed: " + e.msg
}
// Unwrap implements the errors.Wrapper interface.
func (e *ConstraintError) Unwrap() error {
return e.wrap
}
// IsConstraintError returns a boolean indicating whether the error is a constraint failure.
func IsConstraintError(err error) bool {
if err == nil {
return false
}
var e *ConstraintError
return errors.As(err, &e)
}
// selector embedded by the different Select/GroupBy builders.
type selector struct {
label string
flds *[]string
fns []AggregateFunc
scan func(context.Context, any) error
}
// ScanX is like Scan, but panics if an error occurs.
func (s *selector) ScanX(ctx context.Context, v any) {
if err := s.scan(ctx, v); err != nil {
panic(err)
}
}
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
func (s *selector) Strings(ctx context.Context) ([]string, error) {
if len(*s.flds) > 1 {
return nil, errors.New("models: Strings is not achievable when selecting more than 1 field")
}
var v []string
if err := s.scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// StringsX is like Strings, but panics if an error occurs.
func (s *selector) StringsX(ctx context.Context) []string {
v, err := s.Strings(ctx)
if err != nil {
panic(err)
}
return v
}
// String returns a single string from a selector. It is only allowed when selecting one field.
func (s *selector) String(ctx context.Context) (_ string, err error) {
var v []string
if v, err = s.Strings(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{s.label}
default:
err = fmt.Errorf("models: Strings returned %d results when one was expected", len(v))
}
return
}
// StringX is like String, but panics if an error occurs.
func (s *selector) StringX(ctx context.Context) string {
v, err := s.String(ctx)
if err != nil {
panic(err)
}
return v
}
// Ints returns list of ints from a selector. It is only allowed when selecting one field.
func (s *selector) Ints(ctx context.Context) ([]int, error) {
if len(*s.flds) > 1 {
return nil, errors.New("models: Ints is not achievable when selecting more than 1 field")
}
var v []int
if err := s.scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// IntsX is like Ints, but panics if an error occurs.
func (s *selector) IntsX(ctx context.Context) []int {
v, err := s.Ints(ctx)
if err != nil {
panic(err)
}
return v
}
// Int returns a single int from a selector. It is only allowed when selecting one field.
func (s *selector) Int(ctx context.Context) (_ int, err error) {
var v []int
if v, err = s.Ints(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{s.label}
default:
err = fmt.Errorf("models: Ints returned %d results when one was expected", len(v))
}
return
}
// IntX is like Int, but panics if an error occurs.
func (s *selector) IntX(ctx context.Context) int {
v, err := s.Int(ctx)
if err != nil {
panic(err)
}
return v
}
// Float64s returns list of float64s from a selector. It is only allowed when selecting one field.
func (s *selector) Float64s(ctx context.Context) ([]float64, error) {
if len(*s.flds) > 1 {
return nil, errors.New("models: Float64s is not achievable when selecting more than 1 field")
}
var v []float64
if err := s.scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// Float64sX is like Float64s, but panics if an error occurs.
func (s *selector) Float64sX(ctx context.Context) []float64 {
v, err := s.Float64s(ctx)
if err != nil {
panic(err)
}
return v
}
// Float64 returns a single float64 from a selector. It is only allowed when selecting one field.
func (s *selector) Float64(ctx context.Context) (_ float64, err error) {
var v []float64
if v, err = s.Float64s(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{s.label}
default:
err = fmt.Errorf("models: Float64s returned %d results when one was expected", len(v))
}
return
}
// Float64X is like Float64, but panics if an error occurs.
func (s *selector) Float64X(ctx context.Context) float64 {
v, err := s.Float64(ctx)
if err != nil {
panic(err)
}
return v
}
// Bools returns list of bools from a selector. It is only allowed when selecting one field.
func (s *selector) Bools(ctx context.Context) ([]bool, error) {
if len(*s.flds) > 1 {
return nil, errors.New("models: Bools is not achievable when selecting more than 1 field")
}
var v []bool
if err := s.scan(ctx, &v); err != nil {
return nil, err
}
return v, nil
}
// BoolsX is like Bools, but panics if an error occurs.
func (s *selector) BoolsX(ctx context.Context) []bool {
v, err := s.Bools(ctx)
if err != nil {
panic(err)
}
return v
}
// Bool returns a single bool from a selector. It is only allowed when selecting one field.
func (s *selector) Bool(ctx context.Context) (_ bool, err error) {
var v []bool
if v, err = s.Bools(ctx); err != nil {
return
}
switch len(v) {
case 1:
return v[0], nil
case 0:
err = &NotFoundError{s.label}
default:
err = fmt.Errorf("models: Bools returned %d results when one was expected", len(v))
}
return
}
// BoolX is like Bool, but panics if an error occurs.
func (s *selector) BoolX(ctx context.Context) bool {
v, err := s.Bool(ctx)
if err != nil {
panic(err)
}
return v
}
// withHooks invokes the builder operation with the given hooks, if any.
func withHooks[V Value, M any, PM interface {
*M
Mutation
}](ctx context.Context, exec func(context.Context) (V, error), mutation PM, hooks []Hook) (value V, err error) {
if len(hooks) == 0 {
return exec(ctx)
}
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutationT, ok := any(m).(PM)
if !ok {
return nil, fmt.Errorf("unexpected mutation type %T", m)
}
// Set the mutation to the builder.
*mutation = *mutationT
return exec(ctx)
})
for i := len(hooks) - 1; i >= 0; i-- {
if hooks[i] == nil {
return value, fmt.Errorf("ent: uninitialized hook (forgotten import ent/runtime?)")
}
mut = hooks[i](mut)
}
v, err := mut.Mutate(ctx, mutation)
if err != nil {
return value, err
}
nv, ok := v.(V)
if !ok {
return value, fmt.Errorf("unexpected node type %T returned from %T", v, mutation)
}
return nv, nil
}
// setContextOp returns a new context with the given QueryContext attached (including its op) in case it does not exist.
func setContextOp(ctx context.Context, qc *QueryContext, op string) context.Context {
if ent.QueryFromContext(ctx) == nil {
qc.Op = op
ctx = ent.NewQueryContext(ctx, qc)
}
return ctx
}
func querierAll[V Value, Q interface {
sqlAll(context.Context, ...queryHook) (V, error)
}]() Querier {
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
query, ok := q.(Q)
if !ok {
return nil, fmt.Errorf("unexpected query type %T", q)
}
return query.sqlAll(ctx)
})
}
func querierCount[Q interface {
sqlCount(context.Context) (int, error)
}]() Querier {
return QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
query, ok := q.(Q)
if !ok {
return nil, fmt.Errorf("unexpected query type %T", q)
}
return query.sqlCount(ctx)
})
}
func withInterceptors[V Value](ctx context.Context, q Query, qr Querier, inters []Interceptor) (v V, err error) {
for i := len(inters) - 1; i >= 0; i-- {
qr = inters[i].Intercept(qr)
}
rv, err := qr.Query(ctx, q)
if err != nil {
return v, err
}
vt, ok := rv.(V)
if !ok {
return v, fmt.Errorf("unexpected type %T returned from %T. expected type: %T", vt, q, v)
}
return vt, nil
}
func scanWithInterceptors[Q1 ent.Query, Q2 interface {
sqlScan(context.Context, Q1, any) error
}](ctx context.Context, rootQuery Q1, selectOrGroup Q2, inters []Interceptor, v any) error {
rv := reflect.ValueOf(v)
var qr Querier = QuerierFunc(func(ctx context.Context, q Query) (Value, error) {
query, ok := q.(Q1)
if !ok {
return nil, fmt.Errorf("unexpected query type %T", q)
}
if err := selectOrGroup.sqlScan(ctx, query, v); err != nil {
return nil, err
}
if k := rv.Kind(); k == reflect.Pointer && rv.Elem().CanInterface() {
return rv.Elem().Interface(), nil
}
return v, nil
})
for i := len(inters) - 1; i >= 0; i-- {
qr = inters[i].Intercept(qr)
}
vv, err := qr.Query(ctx, rootQuery)
if err != nil {
return err
}
switch rv2 := reflect.ValueOf(vv); {
case rv.IsNil(), rv2.IsNil(), rv.Kind() != reflect.Pointer:
case rv.Type() == rv2.Type():
rv.Elem().Set(rv2.Elem())
case rv.Elem().Type() == rv2.Type():
rv.Elem().Set(rv2)
}
return nil
}
// queryHook describes an internal hook for the different sqlAll methods.
type queryHook func(context.Context, *sqlgraph.QuerySpec)
@@ -0,0 +1,85 @@
// Code generated by ent, DO NOT EDIT.
package enttest
import (
"context"
"juwan-backend/app/shop/rpc/internal/models"
// required by schema hooks.
_ "juwan-backend/app/shop/rpc/internal/models/runtime"
"juwan-backend/app/shop/rpc/internal/models/migrate"
"entgo.io/ent/dialect/sql/schema"
)
type (
// TestingT is the interface that is shared between
// testing.T and testing.B and used by enttest.
TestingT interface {
FailNow()
Error(...any)
}
// Option configures client creation.
Option func(*options)
options struct {
opts []models.Option
migrateOpts []schema.MigrateOption
}
)
// WithOptions forwards options to client creation.
func WithOptions(opts ...models.Option) Option {
return func(o *options) {
o.opts = append(o.opts, opts...)
}
}
// WithMigrateOptions forwards options to auto migration.
func WithMigrateOptions(opts ...schema.MigrateOption) Option {
return func(o *options) {
o.migrateOpts = append(o.migrateOpts, opts...)
}
}
func newOptions(opts []Option) *options {
o := &options{}
for _, opt := range opts {
opt(o)
}
return o
}
// Open calls models.Open and auto-run migration.
func Open(t TestingT, driverName, dataSourceName string, opts ...Option) *models.Client {
o := newOptions(opts)
c, err := models.Open(driverName, dataSourceName, o.opts...)
if err != nil {
t.Error(err)
t.FailNow()
}
migrateSchema(t, c, o)
return c
}
// NewClient calls models.NewClient and auto-run migration.
func NewClient(t TestingT, opts ...Option) *models.Client {
o := newOptions(opts)
c := models.NewClient(o.opts...)
migrateSchema(t, c, o)
return c
}
func migrateSchema(t TestingT, c *models.Client, o *options) {
tables, err := schema.CopyTables(migrate.Tables)
if err != nil {
t.Error(err)
t.FailNow()
}
if err := migrate.Create(context.Background(), c.Schema, tables, o.migrateOpts...); err != nil {
t.Error(err)
t.FailNow()
}
}
+222
View File
@@ -0,0 +1,222 @@
// Code generated by ent, DO NOT EDIT.
package hook
import (
"context"
"fmt"
"juwan-backend/app/shop/rpc/internal/models"
)
// The ShopInvitationsFunc type is an adapter to allow the use of ordinary
// function as ShopInvitations mutator.
type ShopInvitationsFunc func(context.Context, *models.ShopInvitationsMutation) (models.Value, error)
// Mutate calls f(ctx, m).
func (f ShopInvitationsFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
if mv, ok := m.(*models.ShopInvitationsMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.ShopInvitationsMutation", m)
}
// The ShopPlayersFunc type is an adapter to allow the use of ordinary
// function as ShopPlayers mutator.
type ShopPlayersFunc func(context.Context, *models.ShopPlayersMutation) (models.Value, error)
// Mutate calls f(ctx, m).
func (f ShopPlayersFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
if mv, ok := m.(*models.ShopPlayersMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.ShopPlayersMutation", m)
}
// The ShopsFunc type is an adapter to allow the use of ordinary
// function as Shops mutator.
type ShopsFunc func(context.Context, *models.ShopsMutation) (models.Value, error)
// Mutate calls f(ctx, m).
func (f ShopsFunc) Mutate(ctx context.Context, m models.Mutation) (models.Value, error) {
if mv, ok := m.(*models.ShopsMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *models.ShopsMutation", m)
}
// Condition is a hook condition function.
type Condition func(context.Context, models.Mutation) bool
// And groups conditions with the AND operator.
func And(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m models.Mutation) bool {
if !first(ctx, m) || !second(ctx, m) {
return false
}
for _, cond := range rest {
if !cond(ctx, m) {
return false
}
}
return true
}
}
// Or groups conditions with the OR operator.
func Or(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m models.Mutation) bool {
if first(ctx, m) || second(ctx, m) {
return true
}
for _, cond := range rest {
if cond(ctx, m) {
return true
}
}
return false
}
}
// Not negates a given condition.
func Not(cond Condition) Condition {
return func(ctx context.Context, m models.Mutation) bool {
return !cond(ctx, m)
}
}
// HasOp is a condition testing mutation operation.
func HasOp(op models.Op) Condition {
return func(_ context.Context, m models.Mutation) bool {
return m.Op().Is(op)
}
}
// HasAddedFields is a condition validating `.AddedField` on fields.
func HasAddedFields(field string, fields ...string) Condition {
return func(_ context.Context, m models.Mutation) bool {
if _, exists := m.AddedField(field); !exists {
return false
}
for _, field := range fields {
if _, exists := m.AddedField(field); !exists {
return false
}
}
return true
}
}
// HasClearedFields is a condition validating `.FieldCleared` on fields.
func HasClearedFields(field string, fields ...string) Condition {
return func(_ context.Context, m models.Mutation) bool {
if exists := m.FieldCleared(field); !exists {
return false
}
for _, field := range fields {
if exists := m.FieldCleared(field); !exists {
return false
}
}
return true
}
}
// HasFields is a condition validating `.Field` on fields.
func HasFields(field string, fields ...string) Condition {
return func(_ context.Context, m models.Mutation) bool {
if _, exists := m.Field(field); !exists {
return false
}
for _, field := range fields {
if _, exists := m.Field(field); !exists {
return false
}
}
return true
}
}
// If executes the given hook under condition.
//
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
func If(hk models.Hook, cond Condition) models.Hook {
return func(next models.Mutator) models.Mutator {
return models.MutateFunc(func(ctx context.Context, m models.Mutation) (models.Value, error) {
if cond(ctx, m) {
return hk(next).Mutate(ctx, m)
}
return next.Mutate(ctx, m)
})
}
}
// On executes the given hook only for the given operation.
//
// hook.On(Log, models.Delete|models.Create)
func On(hk models.Hook, op models.Op) models.Hook {
return If(hk, HasOp(op))
}
// Unless skips the given hook only for the given operation.
//
// hook.Unless(Log, models.Update|models.UpdateOne)
func Unless(hk models.Hook, op models.Op) models.Hook {
return If(hk, Not(HasOp(op)))
}
// FixedError is a hook returning a fixed error.
func FixedError(err error) models.Hook {
return func(models.Mutator) models.Mutator {
return models.MutateFunc(func(context.Context, models.Mutation) (models.Value, error) {
return nil, err
})
}
}
// Reject returns a hook that rejects all operations that match op.
//
// func (T) Hooks() []models.Hook {
// return []models.Hook{
// Reject(models.Delete|models.Update),
// }
// }
func Reject(op models.Op) models.Hook {
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
return On(hk, op)
}
// Chain acts as a list of hooks and is effectively immutable.
// Once created, it will always hold the same set of hooks in the same order.
type Chain struct {
hooks []models.Hook
}
// NewChain creates a new chain of hooks.
func NewChain(hooks ...models.Hook) Chain {
return Chain{append([]models.Hook(nil), hooks...)}
}
// Hook chains the list of hooks and returns the final hook.
func (c Chain) Hook() models.Hook {
return func(mutator models.Mutator) models.Mutator {
for i := len(c.hooks) - 1; i >= 0; i-- {
mutator = c.hooks[i](mutator)
}
return mutator
}
}
// Append extends a chain, adding the specified hook
// as the last ones in the mutation flow.
func (c Chain) Append(hooks ...models.Hook) Chain {
newHooks := make([]models.Hook, 0, len(c.hooks)+len(hooks))
newHooks = append(newHooks, c.hooks...)
newHooks = append(newHooks, hooks...)
return Chain{newHooks}
}
// Extend extends a chain, adding the specified chain
// as the last ones in the mutation flow.
func (c Chain) Extend(chain Chain) Chain {
return c.Append(chain.hooks...)
}
@@ -0,0 +1,64 @@
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"context"
"fmt"
"io"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql/schema"
)
var (
// WithGlobalUniqueID sets the universal ids options to the migration.
// If this option is enabled, ent migration will allocate a 1<<32 range
// for the ids of each entity (table).
// Note that this option cannot be applied on tables that already exist.
WithGlobalUniqueID = schema.WithGlobalUniqueID
// WithDropColumn sets the drop column option to the migration.
// If this option is enabled, ent migration will drop old columns
// that were used for both fields and edges. This defaults to false.
WithDropColumn = schema.WithDropColumn
// WithDropIndex sets the drop index option to the migration.
// If this option is enabled, ent migration will drop old indexes
// that were defined in the schema. This defaults to false.
// Note that unique constraints are defined using `UNIQUE INDEX`,
// and therefore, it's recommended to enable this option to get more
// flexibility in the schema changes.
WithDropIndex = schema.WithDropIndex
// WithForeignKeys enables creating foreign-key in schema DDL. This defaults to true.
WithForeignKeys = schema.WithForeignKeys
)
// Schema is the API for creating, migrating and dropping a schema.
type Schema struct {
drv dialect.Driver
}
// NewSchema creates a new schema client.
func NewSchema(drv dialect.Driver) *Schema { return &Schema{drv: drv} }
// Create creates all schema resources.
func (s *Schema) Create(ctx context.Context, opts ...schema.MigrateOption) error {
return Create(ctx, s, Tables, opts...)
}
// Create creates all table resources using the given schema driver.
func Create(ctx context.Context, s *Schema, tables []*schema.Table, opts ...schema.MigrateOption) error {
migrate, err := schema.NewMigrate(s.drv, opts...)
if err != nil {
return fmt.Errorf("ent/migrate: %w", err)
}
return migrate.Create(ctx, tables...)
}
// WriteTo writes the schema changes to w instead of running them against the database.
//
// if err := client.Schema.WriteTo(context.Background(), os.Stdout); err != nil {
// log.Fatal(err)
// }
func (s *Schema) WriteTo(ctx context.Context, w io.Writer, opts ...schema.MigrateOption) error {
return Create(ctx, &Schema{drv: &schema.WriteDriver{Writer: w, Driver: s.drv}}, Tables, opts...)
}
@@ -0,0 +1,131 @@
// Code generated by ent, DO NOT EDIT.
package migrate
import (
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/dialect/sql/schema"
"entgo.io/ent/schema/field"
)
var (
// ShopInvitationsColumns holds the columns for the "shop_invitations" table.
ShopInvitationsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "shop_id", Type: field.TypeInt64},
{Name: "player_id", Type: field.TypeInt64},
{Name: "status", Type: field.TypeString, Size: 20, Default: "pending"},
{Name: "invited_by", Type: field.TypeInt64},
{Name: "created_at", Type: field.TypeTime},
{Name: "responded_at", Type: field.TypeTime, Nullable: true},
}
// ShopInvitationsTable holds the schema information for the "shop_invitations" table.
ShopInvitationsTable = &schema.Table{
Name: "shop_invitations",
Columns: ShopInvitationsColumns,
PrimaryKey: []*schema.Column{ShopInvitationsColumns[0]},
Indexes: []*schema.Index{
{
Name: "shopinvitations_shop_id",
Unique: false,
Columns: []*schema.Column{ShopInvitationsColumns[1]},
},
{
Name: "shopinvitations_player_id",
Unique: false,
Columns: []*schema.Column{ShopInvitationsColumns[2]},
},
{
Name: "shopinvitations_player_id_status_created_at",
Unique: false,
Columns: []*schema.Column{ShopInvitationsColumns[2], ShopInvitationsColumns[3], ShopInvitationsColumns[5]},
},
{
Name: "shopinvitations_shop_id_status_created_at",
Unique: false,
Columns: []*schema.Column{ShopInvitationsColumns[1], ShopInvitationsColumns[3], ShopInvitationsColumns[5]},
},
},
}
// ShopPlayersColumns holds the columns for the "shop_players" table.
ShopPlayersColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "shop_id", Type: field.TypeInt64},
{Name: "player_id", Type: field.TypeInt64},
{Name: "is_primary", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "joined_at", Type: field.TypeTime},
{Name: "left_at", Type: field.TypeTime, Nullable: true},
}
// ShopPlayersTable holds the schema information for the "shop_players" table.
ShopPlayersTable = &schema.Table{
Name: "shop_players",
Columns: ShopPlayersColumns,
PrimaryKey: []*schema.Column{ShopPlayersColumns[0]},
Indexes: []*schema.Index{
{
Name: "shopplayers_shop_id_player_id",
Unique: true,
Columns: []*schema.Column{ShopPlayersColumns[1], ShopPlayersColumns[2]},
},
{
Name: "shopplayers_player_id",
Unique: false,
Columns: []*schema.Column{ShopPlayersColumns[2]},
},
{
Name: "shopplayers_shop_id_joined_at",
Unique: false,
Columns: []*schema.Column{ShopPlayersColumns[1], ShopPlayersColumns[4]},
},
},
}
// ShopsColumns holds the columns for the "shops" table.
ShopsColumns = []*schema.Column{
{Name: "id", Type: field.TypeInt64, Increment: true},
{Name: "owner_id", Type: field.TypeInt64, Unique: true},
{Name: "name", Type: field.TypeString, Size: 200},
{Name: "banner", Type: field.TypeString, Nullable: true},
{Name: "description", Type: field.TypeString, Nullable: true},
{Name: "rating", Type: field.TypeOther, Nullable: true, SchemaType: map[string]string{"postgres": "decimal(3,2)"}},
{Name: "total_orders", Type: field.TypeInt, Nullable: true, Default: 0},
{Name: "player_count", Type: field.TypeInt, Nullable: true, Default: 0},
{Name: "commission_type", Type: field.TypeString, Size: 20, Default: "percentage"},
{Name: "commission_value", Type: field.TypeOther, SchemaType: map[string]string{"postgres": "decimal(10,2)"}},
{Name: "allow_multi_shop", Type: field.TypeBool, Nullable: true, Default: false},
{Name: "allow_independent_orders", Type: field.TypeBool, Nullable: true, Default: true},
{Name: "dispatch_mode", Type: field.TypeString, Size: 20, Default: "manual"},
{Name: "announcements", Type: field.TypeJSON, Nullable: true},
{Name: "template_config", Type: field.TypeJSON, Nullable: true},
{Name: "created_at", Type: field.TypeTime},
{Name: "updated_at", Type: field.TypeTime},
}
// ShopsTable holds the schema information for the "shops" table.
ShopsTable = &schema.Table{
Name: "shops",
Columns: ShopsColumns,
PrimaryKey: []*schema.Column{ShopsColumns[0]},
}
// Tables holds all the tables in the schema.
Tables = []*schema.Table{
ShopInvitationsTable,
ShopPlayersTable,
ShopsTable,
}
)
func init() {
ShopInvitationsTable.Annotation = &entsql.Annotation{
Table: "shop_invitations",
}
ShopInvitationsTable.Annotation.Checks = map[string]string{
"chk_invitation_status": "status IN ('pending', 'accepted', 'rejected', 'cancelled')",
}
ShopsTable.Annotation = &entsql.Annotation{
Table: "shops",
}
ShopsTable.Annotation.Checks = map[string]string{
"chk_commission_type": "commission_type IN ('fixed', 'percentage')",
"chk_dispatch_mode": "dispatch_mode IN ('manual', 'auto')",
"chk_rating_range": "rating >= 0 AND rating <= 5",
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,16 @@
// Code generated by ent, DO NOT EDIT.
package predicate
import (
"entgo.io/ent/dialect/sql"
)
// ShopInvitations is the predicate function for shopinvitations builders.
type ShopInvitations func(*sql.Selector)
// ShopPlayers is the predicate function for shopplayers builders.
type ShopPlayers func(*sql.Selector)
// Shops is the predicate function for shops builders.
type Shops func(*sql.Selector)
+93
View File
@@ -0,0 +1,93 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"juwan-backend/app/shop/rpc/internal/models/schema"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"juwan-backend/app/shop/rpc/internal/models/shops"
"time"
"github.com/shopspring/decimal"
)
// The init function reads all schema descriptors with runtime code
// (default values, validators, hooks and policies) and stitches it
// to their package variables.
func init() {
shopinvitationsFields := schema.ShopInvitations{}.Fields()
_ = shopinvitationsFields
// shopinvitationsDescStatus is the schema descriptor for status field.
shopinvitationsDescStatus := shopinvitationsFields[3].Descriptor()
// shopinvitations.DefaultStatus holds the default value on creation for the status field.
shopinvitations.DefaultStatus = shopinvitationsDescStatus.Default.(string)
// shopinvitations.StatusValidator is a validator for the "status" field. It is called by the builders before save.
shopinvitations.StatusValidator = shopinvitationsDescStatus.Validators[0].(func(string) error)
// shopinvitationsDescCreatedAt is the schema descriptor for created_at field.
shopinvitationsDescCreatedAt := shopinvitationsFields[5].Descriptor()
// shopinvitations.DefaultCreatedAt holds the default value on creation for the created_at field.
shopinvitations.DefaultCreatedAt = shopinvitationsDescCreatedAt.Default.(func() time.Time)
shopplayersFields := schema.ShopPlayers{}.Fields()
_ = shopplayersFields
// shopplayersDescIsPrimary is the schema descriptor for is_primary field.
shopplayersDescIsPrimary := shopplayersFields[3].Descriptor()
// shopplayers.DefaultIsPrimary holds the default value on creation for the is_primary field.
shopplayers.DefaultIsPrimary = shopplayersDescIsPrimary.Default.(bool)
// shopplayersDescJoinedAt is the schema descriptor for joined_at field.
shopplayersDescJoinedAt := shopplayersFields[4].Descriptor()
// shopplayers.DefaultJoinedAt holds the default value on creation for the joined_at field.
shopplayers.DefaultJoinedAt = shopplayersDescJoinedAt.Default.(func() time.Time)
shopsFields := schema.Shops{}.Fields()
_ = shopsFields
// shopsDescName is the schema descriptor for name field.
shopsDescName := shopsFields[2].Descriptor()
// shops.NameValidator is a validator for the "name" field. It is called by the builders before save.
shops.NameValidator = shopsDescName.Validators[0].(func(string) error)
// shopsDescRating is the schema descriptor for rating field.
shopsDescRating := shopsFields[5].Descriptor()
// shops.DefaultRating holds the default value on creation for the rating field.
shops.DefaultRating = shopsDescRating.Default.(decimal.Decimal)
// shopsDescTotalOrders is the schema descriptor for total_orders field.
shopsDescTotalOrders := shopsFields[6].Descriptor()
// shops.DefaultTotalOrders holds the default value on creation for the total_orders field.
shops.DefaultTotalOrders = shopsDescTotalOrders.Default.(int)
// shopsDescPlayerCount is the schema descriptor for player_count field.
shopsDescPlayerCount := shopsFields[7].Descriptor()
// shops.DefaultPlayerCount holds the default value on creation for the player_count field.
shops.DefaultPlayerCount = shopsDescPlayerCount.Default.(int)
// shopsDescCommissionType is the schema descriptor for commission_type field.
shopsDescCommissionType := shopsFields[8].Descriptor()
// shops.DefaultCommissionType holds the default value on creation for the commission_type field.
shops.DefaultCommissionType = shopsDescCommissionType.Default.(string)
// shops.CommissionTypeValidator is a validator for the "commission_type" field. It is called by the builders before save.
shops.CommissionTypeValidator = shopsDescCommissionType.Validators[0].(func(string) error)
// shopsDescAllowMultiShop is the schema descriptor for allow_multi_shop field.
shopsDescAllowMultiShop := shopsFields[10].Descriptor()
// shops.DefaultAllowMultiShop holds the default value on creation for the allow_multi_shop field.
shops.DefaultAllowMultiShop = shopsDescAllowMultiShop.Default.(bool)
// shopsDescAllowIndependentOrders is the schema descriptor for allow_independent_orders field.
shopsDescAllowIndependentOrders := shopsFields[11].Descriptor()
// shops.DefaultAllowIndependentOrders holds the default value on creation for the allow_independent_orders field.
shops.DefaultAllowIndependentOrders = shopsDescAllowIndependentOrders.Default.(bool)
// shopsDescDispatchMode is the schema descriptor for dispatch_mode field.
shopsDescDispatchMode := shopsFields[12].Descriptor()
// shops.DefaultDispatchMode holds the default value on creation for the dispatch_mode field.
shops.DefaultDispatchMode = shopsDescDispatchMode.Default.(string)
// shops.DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save.
shops.DispatchModeValidator = shopsDescDispatchMode.Validators[0].(func(string) error)
// shopsDescAnnouncements is the schema descriptor for announcements field.
shopsDescAnnouncements := shopsFields[13].Descriptor()
// shops.DefaultAnnouncements holds the default value on creation for the announcements field.
shops.DefaultAnnouncements = shopsDescAnnouncements.Default.([]string)
// shopsDescCreatedAt is the schema descriptor for created_at field.
shopsDescCreatedAt := shopsFields[15].Descriptor()
// shops.DefaultCreatedAt holds the default value on creation for the created_at field.
shops.DefaultCreatedAt = shopsDescCreatedAt.Default.(func() time.Time)
// shopsDescUpdatedAt is the schema descriptor for updated_at field.
shopsDescUpdatedAt := shopsFields[16].Descriptor()
// shops.DefaultUpdatedAt holds the default value on creation for the updated_at field.
shops.DefaultUpdatedAt = shopsDescUpdatedAt.Default.(func() time.Time)
// shops.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
shops.UpdateDefaultUpdatedAt = shopsDescUpdatedAt.UpdateDefault.(func() time.Time)
}
@@ -0,0 +1,10 @@
// Code generated by ent, DO NOT EDIT.
package runtime
// The schema-stitching logic is generated in juwan-backend/app/shop/rpc/internal/models/runtime.go
const (
Version = "v0.14.5" // Version of ent codegen.
Sum = "h1:Rj2WOYJtCkWyFo6a+5wB3EfBRP0rnx1fMk6gGA0UUe4=" // Sum of ent codegen.
)
@@ -0,0 +1,56 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// ShopInvitations holds the schema definition for the ShopInvitations entity.
type ShopInvitations struct {
ent.Schema
}
// Annotations of the ShopInvitations.
func (ShopInvitations) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{
Table: "shop_invitations",
Checks: map[string]string{
"chk_invitation_status": "status IN ('pending', 'accepted', 'rejected', 'cancelled')",
},
},
}
}
// Fields of the ShopInvitations.
func (ShopInvitations) Fields() []ent.Field {
return []ent.Field{
field.Int64("id").Immutable().Unique(),
field.Int64("shop_id"),
field.Int64("player_id"),
field.String("status").MaxLen(20).Default("pending"),
field.Int64("invited_by"),
field.Time("created_at").Default(time.Now).Immutable(),
field.Time("responded_at").Optional().Nillable(),
}
}
// Indexes of the ShopInvitations.
func (ShopInvitations) Indexes() []ent.Index {
return []ent.Index{
index.Fields("shop_id"),
index.Fields("player_id"),
index.Fields("player_id", "status", "created_at"),
index.Fields("shop_id", "status", "created_at"),
}
}
// Edges of the ShopInvitations.
func (ShopInvitations) Edges() []ent.Edge {
return nil
}
@@ -0,0 +1,40 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
)
// ShopPlayers holds the schema definition for the ShopPlayers entity.
type ShopPlayers struct {
ent.Schema
}
// Fields of the ShopPlayers.
func (ShopPlayers) Fields() []ent.Field {
return []ent.Field{
field.Int64("id").Immutable().Unique(),
field.Int64("shop_id"),
field.Int64("player_id"),
field.Bool("is_primary").Optional().Default(false),
field.Time("joined_at").Default(time.Now).Immutable(),
field.Time("left_at").Optional().Nillable(),
}
}
// Indexes of the ShopPlayers.
func (ShopPlayers) Indexes() []ent.Index {
return []ent.Index{
index.Fields("shop_id", "player_id").Unique(),
index.Fields("player_id"),
index.Fields("shop_id", "joined_at"),
}
}
// Edges of the ShopPlayers.
func (ShopPlayers) Edges() []ent.Edge {
return nil
}
@@ -0,0 +1,69 @@
package schema
import (
"time"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/entsql"
"entgo.io/ent/schema"
"entgo.io/ent/schema/field"
"github.com/shopspring/decimal"
)
var shopDefaultRating = decimal.RequireFromString("5.00")
// Shops holds the schema definition for the Shops entity.
type Shops struct {
ent.Schema
}
// Annotations of the Shops.
func (Shops) Annotations() []schema.Annotation {
return []schema.Annotation{
entsql.Annotation{
Table: "shops",
Checks: map[string]string{
"chk_commission_type": "commission_type IN ('fixed', 'percentage')",
"chk_dispatch_mode": "dispatch_mode IN ('manual', 'auto')",
"chk_rating_range": "rating >= 0 AND rating <= 5",
},
},
}
}
// Fields of the Shops.
func (Shops) Fields() []ent.Field {
return []ent.Field{
field.Int64("id").Immutable().Unique(),
field.Int64("owner_id").Unique(),
field.String("name").MaxLen(200),
field.String("banner").Optional().Nillable(),
field.String("description").Optional().Nillable(),
field.Other("rating", decimal.Decimal{}).
Optional().
Default(shopDefaultRating).
SchemaType(map[string]string{
dialect.Postgres: "decimal(3,2)",
}),
field.Int("total_orders").Optional().Default(0),
field.Int("player_count").Optional().Default(0),
field.String("commission_type").MaxLen(20).Default("percentage"),
field.Other("commission_value", decimal.Decimal{}).
SchemaType(map[string]string{
dialect.Postgres: "decimal(10,2)",
}),
field.Bool("allow_multi_shop").Optional().Default(false),
field.Bool("allow_independent_orders").Optional().Default(true),
field.String("dispatch_mode").MaxLen(20).Default("manual"),
field.Strings("announcements").Optional().Default([]string{}),
field.JSON("template_config", map[string]any{}).Optional(),
field.Time("created_at").Default(time.Now).Immutable(),
field.Time("updated_at").Default(time.Now).UpdateDefault(time.Now),
}
}
// Edges of the Shops.
func (Shops) Edges() []ent.Edge {
return nil
}
@@ -0,0 +1,164 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"fmt"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// ShopInvitations is the model entity for the ShopInvitations schema.
type ShopInvitations struct {
config `json:"-"`
// ID of the ent.
ID int64 `json:"id,omitempty"`
// ShopID holds the value of the "shop_id" field.
ShopID int64 `json:"shop_id,omitempty"`
// PlayerID holds the value of the "player_id" field.
PlayerID int64 `json:"player_id,omitempty"`
// Status holds the value of the "status" field.
Status string `json:"status,omitempty"`
// InvitedBy holds the value of the "invited_by" field.
InvitedBy int64 `json:"invited_by,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// RespondedAt holds the value of the "responded_at" field.
RespondedAt *time.Time `json:"responded_at,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*ShopInvitations) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case shopinvitations.FieldID, shopinvitations.FieldShopID, shopinvitations.FieldPlayerID, shopinvitations.FieldInvitedBy:
values[i] = new(sql.NullInt64)
case shopinvitations.FieldStatus:
values[i] = new(sql.NullString)
case shopinvitations.FieldCreatedAt, shopinvitations.FieldRespondedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the ShopInvitations fields.
func (_m *ShopInvitations) 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 shopinvitations.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int64(value.Int64)
case shopinvitations.FieldShopID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field shop_id", values[i])
} else if value.Valid {
_m.ShopID = value.Int64
}
case shopinvitations.FieldPlayerID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field player_id", values[i])
} else if value.Valid {
_m.PlayerID = value.Int64
}
case shopinvitations.FieldStatus:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field status", values[i])
} else if value.Valid {
_m.Status = value.String
}
case shopinvitations.FieldInvitedBy:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field invited_by", values[i])
} else if value.Valid {
_m.InvitedBy = value.Int64
}
case shopinvitations.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case shopinvitations.FieldRespondedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field responded_at", values[i])
} else if value.Valid {
_m.RespondedAt = new(time.Time)
*_m.RespondedAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the ShopInvitations.
// This includes values selected through modifiers, order, etc.
func (_m *ShopInvitations) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// Update returns a builder for updating this ShopInvitations.
// Note that you need to call ShopInvitations.Unwrap() before calling this method if this ShopInvitations
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *ShopInvitations) Update() *ShopInvitationsUpdateOne {
return NewShopInvitationsClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the ShopInvitations 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 (_m *ShopInvitations) Unwrap() *ShopInvitations {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("models: ShopInvitations is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *ShopInvitations) String() string {
var builder strings.Builder
builder.WriteString("ShopInvitations(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("shop_id=")
builder.WriteString(fmt.Sprintf("%v", _m.ShopID))
builder.WriteString(", ")
builder.WriteString("player_id=")
builder.WriteString(fmt.Sprintf("%v", _m.PlayerID))
builder.WriteString(", ")
builder.WriteString("status=")
builder.WriteString(_m.Status)
builder.WriteString(", ")
builder.WriteString("invited_by=")
builder.WriteString(fmt.Sprintf("%v", _m.InvitedBy))
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.RespondedAt; v != nil {
builder.WriteString("responded_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteByte(')')
return builder.String()
}
// ShopInvitationsSlice is a parsable slice of ShopInvitations.
type ShopInvitationsSlice []*ShopInvitations
@@ -0,0 +1,98 @@
// Code generated by ent, DO NOT EDIT.
package shopinvitations
import (
"time"
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the shopinvitations type in the database.
Label = "shop_invitations"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldShopID holds the string denoting the shop_id field in the database.
FieldShopID = "shop_id"
// FieldPlayerID holds the string denoting the player_id field in the database.
FieldPlayerID = "player_id"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldInvitedBy holds the string denoting the invited_by field in the database.
FieldInvitedBy = "invited_by"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldRespondedAt holds the string denoting the responded_at field in the database.
FieldRespondedAt = "responded_at"
// Table holds the table name of the shopinvitations in the database.
Table = "shop_invitations"
)
// Columns holds all SQL columns for shopinvitations fields.
var Columns = []string{
FieldID,
FieldShopID,
FieldPlayerID,
FieldStatus,
FieldInvitedBy,
FieldCreatedAt,
FieldRespondedAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus string
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator func(string) error
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
)
// OrderOption defines the ordering options for the ShopInvitations queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByShopID orders the results by the shop_id field.
func ByShopID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldShopID, opts...).ToFunc()
}
// ByPlayerID orders the results by the player_id field.
func ByPlayerID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPlayerID, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByInvitedBy orders the results by the invited_by field.
func ByInvitedBy(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldInvitedBy, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByRespondedAt orders the results by the responded_at field.
func ByRespondedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldRespondedAt, opts...).ToFunc()
}
@@ -0,0 +1,375 @@
// Code generated by ent, DO NOT EDIT.
package shopinvitations
import (
"juwan-backend/app/shop/rpc/internal/models/predicate"
"time"
"entgo.io/ent/dialect/sql"
)
// ID filters vertices based on their ID field.
func ID(id int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLTE(FieldID, id))
}
// ShopID applies equality check predicate on the "shop_id" field. It's identical to ShopIDEQ.
func ShopID(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldShopID, v))
}
// PlayerID applies equality check predicate on the "player_id" field. It's identical to PlayerIDEQ.
func PlayerID(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldPlayerID, v))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func Status(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldStatus, v))
}
// InvitedBy applies equality check predicate on the "invited_by" field. It's identical to InvitedByEQ.
func InvitedBy(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldInvitedBy, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldCreatedAt, v))
}
// RespondedAt applies equality check predicate on the "responded_at" field. It's identical to RespondedAtEQ.
func RespondedAt(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldRespondedAt, v))
}
// ShopIDEQ applies the EQ predicate on the "shop_id" field.
func ShopIDEQ(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldShopID, v))
}
// ShopIDNEQ applies the NEQ predicate on the "shop_id" field.
func ShopIDNEQ(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNEQ(FieldShopID, v))
}
// ShopIDIn applies the In predicate on the "shop_id" field.
func ShopIDIn(vs ...int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldIn(FieldShopID, vs...))
}
// ShopIDNotIn applies the NotIn predicate on the "shop_id" field.
func ShopIDNotIn(vs ...int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNotIn(FieldShopID, vs...))
}
// ShopIDGT applies the GT predicate on the "shop_id" field.
func ShopIDGT(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGT(FieldShopID, v))
}
// ShopIDGTE applies the GTE predicate on the "shop_id" field.
func ShopIDGTE(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGTE(FieldShopID, v))
}
// ShopIDLT applies the LT predicate on the "shop_id" field.
func ShopIDLT(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLT(FieldShopID, v))
}
// ShopIDLTE applies the LTE predicate on the "shop_id" field.
func ShopIDLTE(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLTE(FieldShopID, v))
}
// PlayerIDEQ applies the EQ predicate on the "player_id" field.
func PlayerIDEQ(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldPlayerID, v))
}
// PlayerIDNEQ applies the NEQ predicate on the "player_id" field.
func PlayerIDNEQ(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNEQ(FieldPlayerID, v))
}
// PlayerIDIn applies the In predicate on the "player_id" field.
func PlayerIDIn(vs ...int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldIn(FieldPlayerID, vs...))
}
// PlayerIDNotIn applies the NotIn predicate on the "player_id" field.
func PlayerIDNotIn(vs ...int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNotIn(FieldPlayerID, vs...))
}
// PlayerIDGT applies the GT predicate on the "player_id" field.
func PlayerIDGT(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGT(FieldPlayerID, v))
}
// PlayerIDGTE applies the GTE predicate on the "player_id" field.
func PlayerIDGTE(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGTE(FieldPlayerID, v))
}
// PlayerIDLT applies the LT predicate on the "player_id" field.
func PlayerIDLT(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLT(FieldPlayerID, v))
}
// PlayerIDLTE applies the LTE predicate on the "player_id" field.
func PlayerIDLTE(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLTE(FieldPlayerID, v))
}
// StatusEQ applies the EQ predicate on the "status" field.
func StatusEQ(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldStatus, v))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func StatusNEQ(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNEQ(FieldStatus, v))
}
// StatusIn applies the In predicate on the "status" field.
func StatusIn(vs ...string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldIn(FieldStatus, vs...))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func StatusNotIn(vs ...string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNotIn(FieldStatus, vs...))
}
// StatusGT applies the GT predicate on the "status" field.
func StatusGT(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGT(FieldStatus, v))
}
// StatusGTE applies the GTE predicate on the "status" field.
func StatusGTE(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGTE(FieldStatus, v))
}
// StatusLT applies the LT predicate on the "status" field.
func StatusLT(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLT(FieldStatus, v))
}
// StatusLTE applies the LTE predicate on the "status" field.
func StatusLTE(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLTE(FieldStatus, v))
}
// StatusContains applies the Contains predicate on the "status" field.
func StatusContains(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldContains(FieldStatus, v))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func StatusHasPrefix(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldHasPrefix(FieldStatus, v))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func StatusHasSuffix(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldHasSuffix(FieldStatus, v))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func StatusEqualFold(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEqualFold(FieldStatus, v))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func StatusContainsFold(v string) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldContainsFold(FieldStatus, v))
}
// InvitedByEQ applies the EQ predicate on the "invited_by" field.
func InvitedByEQ(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldInvitedBy, v))
}
// InvitedByNEQ applies the NEQ predicate on the "invited_by" field.
func InvitedByNEQ(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNEQ(FieldInvitedBy, v))
}
// InvitedByIn applies the In predicate on the "invited_by" field.
func InvitedByIn(vs ...int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldIn(FieldInvitedBy, vs...))
}
// InvitedByNotIn applies the NotIn predicate on the "invited_by" field.
func InvitedByNotIn(vs ...int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNotIn(FieldInvitedBy, vs...))
}
// InvitedByGT applies the GT predicate on the "invited_by" field.
func InvitedByGT(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGT(FieldInvitedBy, v))
}
// InvitedByGTE applies the GTE predicate on the "invited_by" field.
func InvitedByGTE(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGTE(FieldInvitedBy, v))
}
// InvitedByLT applies the LT predicate on the "invited_by" field.
func InvitedByLT(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLT(FieldInvitedBy, v))
}
// InvitedByLTE applies the LTE predicate on the "invited_by" field.
func InvitedByLTE(v int64) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLTE(FieldInvitedBy, v))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLTE(FieldCreatedAt, v))
}
// RespondedAtEQ applies the EQ predicate on the "responded_at" field.
func RespondedAtEQ(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldEQ(FieldRespondedAt, v))
}
// RespondedAtNEQ applies the NEQ predicate on the "responded_at" field.
func RespondedAtNEQ(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNEQ(FieldRespondedAt, v))
}
// RespondedAtIn applies the In predicate on the "responded_at" field.
func RespondedAtIn(vs ...time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldIn(FieldRespondedAt, vs...))
}
// RespondedAtNotIn applies the NotIn predicate on the "responded_at" field.
func RespondedAtNotIn(vs ...time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNotIn(FieldRespondedAt, vs...))
}
// RespondedAtGT applies the GT predicate on the "responded_at" field.
func RespondedAtGT(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGT(FieldRespondedAt, v))
}
// RespondedAtGTE applies the GTE predicate on the "responded_at" field.
func RespondedAtGTE(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldGTE(FieldRespondedAt, v))
}
// RespondedAtLT applies the LT predicate on the "responded_at" field.
func RespondedAtLT(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLT(FieldRespondedAt, v))
}
// RespondedAtLTE applies the LTE predicate on the "responded_at" field.
func RespondedAtLTE(v time.Time) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldLTE(FieldRespondedAt, v))
}
// RespondedAtIsNil applies the IsNil predicate on the "responded_at" field.
func RespondedAtIsNil() predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldIsNull(FieldRespondedAt))
}
// RespondedAtNotNil applies the NotNil predicate on the "responded_at" field.
func RespondedAtNotNil() predicate.ShopInvitations {
return predicate.ShopInvitations(sql.FieldNotNull(FieldRespondedAt))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.ShopInvitations) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.ShopInvitations) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.ShopInvitations) predicate.ShopInvitations {
return predicate.ShopInvitations(sql.NotPredicates(p))
}
@@ -0,0 +1,301 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ShopInvitationsCreate is the builder for creating a ShopInvitations entity.
type ShopInvitationsCreate struct {
config
mutation *ShopInvitationsMutation
hooks []Hook
}
// SetShopID sets the "shop_id" field.
func (_c *ShopInvitationsCreate) SetShopID(v int64) *ShopInvitationsCreate {
_c.mutation.SetShopID(v)
return _c
}
// SetPlayerID sets the "player_id" field.
func (_c *ShopInvitationsCreate) SetPlayerID(v int64) *ShopInvitationsCreate {
_c.mutation.SetPlayerID(v)
return _c
}
// SetStatus sets the "status" field.
func (_c *ShopInvitationsCreate) SetStatus(v string) *ShopInvitationsCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *ShopInvitationsCreate) SetNillableStatus(v *string) *ShopInvitationsCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetInvitedBy sets the "invited_by" field.
func (_c *ShopInvitationsCreate) SetInvitedBy(v int64) *ShopInvitationsCreate {
_c.mutation.SetInvitedBy(v)
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *ShopInvitationsCreate) SetCreatedAt(v time.Time) *ShopInvitationsCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *ShopInvitationsCreate) SetNillableCreatedAt(v *time.Time) *ShopInvitationsCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetRespondedAt sets the "responded_at" field.
func (_c *ShopInvitationsCreate) SetRespondedAt(v time.Time) *ShopInvitationsCreate {
_c.mutation.SetRespondedAt(v)
return _c
}
// SetNillableRespondedAt sets the "responded_at" field if the given value is not nil.
func (_c *ShopInvitationsCreate) SetNillableRespondedAt(v *time.Time) *ShopInvitationsCreate {
if v != nil {
_c.SetRespondedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *ShopInvitationsCreate) SetID(v int64) *ShopInvitationsCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the ShopInvitationsMutation object of the builder.
func (_c *ShopInvitationsCreate) Mutation() *ShopInvitationsMutation {
return _c.mutation
}
// Save creates the ShopInvitations in the database.
func (_c *ShopInvitationsCreate) Save(ctx context.Context) (*ShopInvitations, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *ShopInvitationsCreate) SaveX(ctx context.Context) *ShopInvitations {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ShopInvitationsCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ShopInvitationsCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *ShopInvitationsCreate) defaults() {
if _, ok := _c.mutation.Status(); !ok {
v := shopinvitations.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := shopinvitations.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *ShopInvitationsCreate) check() error {
if _, ok := _c.mutation.ShopID(); !ok {
return &ValidationError{Name: "shop_id", err: errors.New(`models: missing required field "ShopInvitations.shop_id"`)}
}
if _, ok := _c.mutation.PlayerID(); !ok {
return &ValidationError{Name: "player_id", err: errors.New(`models: missing required field "ShopInvitations.player_id"`)}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`models: missing required field "ShopInvitations.status"`)}
}
if v, ok := _c.mutation.Status(); ok {
if err := shopinvitations.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "ShopInvitations.status": %w`, err)}
}
}
if _, ok := _c.mutation.InvitedBy(); !ok {
return &ValidationError{Name: "invited_by", err: errors.New(`models: missing required field "ShopInvitations.invited_by"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "ShopInvitations.created_at"`)}
}
return nil
}
func (_c *ShopInvitationsCreate) sqlSave(ctx context.Context) (*ShopInvitations, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
if _spec.ID.Value != _node.ID {
id := _spec.ID.Value.(int64)
_node.ID = int64(id)
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *ShopInvitationsCreate) createSpec() (*ShopInvitations, *sqlgraph.CreateSpec) {
var (
_node = &ShopInvitations{config: _c.config}
_spec = sqlgraph.NewCreateSpec(shopinvitations.Table, sqlgraph.NewFieldSpec(shopinvitations.FieldID, field.TypeInt64))
)
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.ShopID(); ok {
_spec.SetField(shopinvitations.FieldShopID, field.TypeInt64, value)
_node.ShopID = value
}
if value, ok := _c.mutation.PlayerID(); ok {
_spec.SetField(shopinvitations.FieldPlayerID, field.TypeInt64, value)
_node.PlayerID = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(shopinvitations.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.InvitedBy(); ok {
_spec.SetField(shopinvitations.FieldInvitedBy, field.TypeInt64, value)
_node.InvitedBy = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(shopinvitations.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.RespondedAt(); ok {
_spec.SetField(shopinvitations.FieldRespondedAt, field.TypeTime, value)
_node.RespondedAt = &value
}
return _node, _spec
}
// ShopInvitationsCreateBulk is the builder for creating many ShopInvitations entities in bulk.
type ShopInvitationsCreateBulk struct {
config
err error
builders []*ShopInvitationsCreate
}
// Save creates the ShopInvitations entities in the database.
func (_c *ShopInvitationsCreateBulk) Save(ctx context.Context) ([]*ShopInvitations, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*ShopInvitations, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*ShopInvitationsMutation)
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, _c.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, _c.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 && nodes[i].ID == 0 {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int64(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, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *ShopInvitationsCreateBulk) SaveX(ctx context.Context) []*ShopInvitations {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ShopInvitationsCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ShopInvitationsCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ShopInvitationsDelete is the builder for deleting a ShopInvitations entity.
type ShopInvitationsDelete struct {
config
hooks []Hook
mutation *ShopInvitationsMutation
}
// Where appends a list predicates to the ShopInvitationsDelete builder.
func (_d *ShopInvitationsDelete) Where(ps ...predicate.ShopInvitations) *ShopInvitationsDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *ShopInvitationsDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ShopInvitationsDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *ShopInvitationsDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(shopinvitations.Table, sqlgraph.NewFieldSpec(shopinvitations.FieldID, field.TypeInt64))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// ShopInvitationsDeleteOne is the builder for deleting a single ShopInvitations entity.
type ShopInvitationsDeleteOne struct {
_d *ShopInvitationsDelete
}
// Where appends a list predicates to the ShopInvitationsDelete builder.
func (_d *ShopInvitationsDeleteOne) Where(ps ...predicate.ShopInvitations) *ShopInvitationsDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *ShopInvitationsDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{shopinvitations.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ShopInvitationsDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
@@ -0,0 +1,527 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ShopInvitationsQuery is the builder for querying ShopInvitations entities.
type ShopInvitationsQuery struct {
config
ctx *QueryContext
order []shopinvitations.OrderOption
inters []Interceptor
predicates []predicate.ShopInvitations
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the ShopInvitationsQuery builder.
func (_q *ShopInvitationsQuery) Where(ps ...predicate.ShopInvitations) *ShopInvitationsQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *ShopInvitationsQuery) Limit(limit int) *ShopInvitationsQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *ShopInvitationsQuery) Offset(offset int) *ShopInvitationsQuery {
_q.ctx.Offset = &offset
return _q
}
// 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 (_q *ShopInvitationsQuery) Unique(unique bool) *ShopInvitationsQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *ShopInvitationsQuery) Order(o ...shopinvitations.OrderOption) *ShopInvitationsQuery {
_q.order = append(_q.order, o...)
return _q
}
// First returns the first ShopInvitations entity from the query.
// Returns a *NotFoundError when no ShopInvitations was found.
func (_q *ShopInvitationsQuery) First(ctx context.Context) (*ShopInvitations, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{shopinvitations.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *ShopInvitationsQuery) FirstX(ctx context.Context) *ShopInvitations {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first ShopInvitations ID from the query.
// Returns a *NotFoundError when no ShopInvitations ID was found.
func (_q *ShopInvitationsQuery) FirstID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{shopinvitations.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *ShopInvitationsQuery) FirstIDX(ctx context.Context) int64 {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single ShopInvitations entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one ShopInvitations entity is found.
// Returns a *NotFoundError when no ShopInvitations entities are found.
func (_q *ShopInvitationsQuery) Only(ctx context.Context) (*ShopInvitations, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{shopinvitations.Label}
default:
return nil, &NotSingularError{shopinvitations.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *ShopInvitationsQuery) OnlyX(ctx context.Context) *ShopInvitations {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only ShopInvitations ID in the query.
// Returns a *NotSingularError when more than one ShopInvitations ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *ShopInvitationsQuery) OnlyID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{shopinvitations.Label}
default:
err = &NotSingularError{shopinvitations.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *ShopInvitationsQuery) OnlyIDX(ctx context.Context) int64 {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of ShopInvitationsSlice.
func (_q *ShopInvitationsQuery) All(ctx context.Context) ([]*ShopInvitations, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*ShopInvitations, *ShopInvitationsQuery]()
return withInterceptors[[]*ShopInvitations](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *ShopInvitationsQuery) AllX(ctx context.Context) []*ShopInvitations {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of ShopInvitations IDs.
func (_q *ShopInvitationsQuery) IDs(ctx context.Context) (ids []int64, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(shopinvitations.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *ShopInvitationsQuery) IDsX(ctx context.Context) []int64 {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *ShopInvitationsQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*ShopInvitationsQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *ShopInvitationsQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *ShopInvitationsQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("models: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *ShopInvitationsQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the ShopInvitationsQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *ShopInvitationsQuery) Clone() *ShopInvitationsQuery {
if _q == nil {
return nil
}
return &ShopInvitationsQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]shopinvitations.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.ShopInvitations{}, _q.predicates...),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// 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 {
// ShopID int64 `json:"shop_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.ShopInvitations.Query().
// GroupBy(shopinvitations.FieldShopID).
// Aggregate(models.Count()).
// Scan(ctx, &v)
func (_q *ShopInvitationsQuery) GroupBy(field string, fields ...string) *ShopInvitationsGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &ShopInvitationsGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = shopinvitations.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 {
// ShopID int64 `json:"shop_id,omitempty"`
// }
//
// client.ShopInvitations.Query().
// Select(shopinvitations.FieldShopID).
// Scan(ctx, &v)
func (_q *ShopInvitationsQuery) Select(fields ...string) *ShopInvitationsSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &ShopInvitationsSelect{ShopInvitationsQuery: _q}
sbuild.label = shopinvitations.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ShopInvitationsSelect configured with the given aggregations.
func (_q *ShopInvitationsQuery) Aggregate(fns ...AggregateFunc) *ShopInvitationsSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *ShopInvitationsQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("models: uninitialized interceptor (forgotten import models/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !shopinvitations.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *ShopInvitationsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ShopInvitations, error) {
var (
nodes = []*ShopInvitations{}
_spec = _q.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*ShopInvitations).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &ShopInvitations{config: _q.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (_q *ShopInvitationsQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *ShopInvitationsQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(shopinvitations.Table, shopinvitations.Columns, sqlgraph.NewFieldSpec(shopinvitations.FieldID, field.TypeInt64))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, shopinvitations.FieldID)
for i := range fields {
if fields[i] != shopinvitations.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *ShopInvitationsQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(shopinvitations.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = shopinvitations.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.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 := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ShopInvitationsGroupBy is the group-by builder for ShopInvitations entities.
type ShopInvitationsGroupBy struct {
selector
build *ShopInvitationsQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *ShopInvitationsGroupBy) Aggregate(fns ...AggregateFunc) *ShopInvitationsGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *ShopInvitationsGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ShopInvitationsQuery, *ShopInvitationsGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *ShopInvitationsGroupBy) sqlScan(ctx context.Context, root *ShopInvitationsQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// ShopInvitationsSelect is the builder for selecting fields of ShopInvitations entities.
type ShopInvitationsSelect struct {
*ShopInvitationsQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *ShopInvitationsSelect) Aggregate(fns ...AggregateFunc) *ShopInvitationsSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *ShopInvitationsSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ShopInvitationsQuery, *ShopInvitationsSelect](ctx, _s.ShopInvitationsQuery, _s, _s.inters, v)
}
func (_s *ShopInvitationsSelect) sqlScan(ctx context.Context, root *ShopInvitationsQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.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 := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
@@ -0,0 +1,450 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/shopinvitations"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ShopInvitationsUpdate is the builder for updating ShopInvitations entities.
type ShopInvitationsUpdate struct {
config
hooks []Hook
mutation *ShopInvitationsMutation
}
// Where appends a list predicates to the ShopInvitationsUpdate builder.
func (_u *ShopInvitationsUpdate) Where(ps ...predicate.ShopInvitations) *ShopInvitationsUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetShopID sets the "shop_id" field.
func (_u *ShopInvitationsUpdate) SetShopID(v int64) *ShopInvitationsUpdate {
_u.mutation.ResetShopID()
_u.mutation.SetShopID(v)
return _u
}
// SetNillableShopID sets the "shop_id" field if the given value is not nil.
func (_u *ShopInvitationsUpdate) SetNillableShopID(v *int64) *ShopInvitationsUpdate {
if v != nil {
_u.SetShopID(*v)
}
return _u
}
// AddShopID adds value to the "shop_id" field.
func (_u *ShopInvitationsUpdate) AddShopID(v int64) *ShopInvitationsUpdate {
_u.mutation.AddShopID(v)
return _u
}
// SetPlayerID sets the "player_id" field.
func (_u *ShopInvitationsUpdate) SetPlayerID(v int64) *ShopInvitationsUpdate {
_u.mutation.ResetPlayerID()
_u.mutation.SetPlayerID(v)
return _u
}
// SetNillablePlayerID sets the "player_id" field if the given value is not nil.
func (_u *ShopInvitationsUpdate) SetNillablePlayerID(v *int64) *ShopInvitationsUpdate {
if v != nil {
_u.SetPlayerID(*v)
}
return _u
}
// AddPlayerID adds value to the "player_id" field.
func (_u *ShopInvitationsUpdate) AddPlayerID(v int64) *ShopInvitationsUpdate {
_u.mutation.AddPlayerID(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *ShopInvitationsUpdate) SetStatus(v string) *ShopInvitationsUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *ShopInvitationsUpdate) SetNillableStatus(v *string) *ShopInvitationsUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetInvitedBy sets the "invited_by" field.
func (_u *ShopInvitationsUpdate) SetInvitedBy(v int64) *ShopInvitationsUpdate {
_u.mutation.ResetInvitedBy()
_u.mutation.SetInvitedBy(v)
return _u
}
// SetNillableInvitedBy sets the "invited_by" field if the given value is not nil.
func (_u *ShopInvitationsUpdate) SetNillableInvitedBy(v *int64) *ShopInvitationsUpdate {
if v != nil {
_u.SetInvitedBy(*v)
}
return _u
}
// AddInvitedBy adds value to the "invited_by" field.
func (_u *ShopInvitationsUpdate) AddInvitedBy(v int64) *ShopInvitationsUpdate {
_u.mutation.AddInvitedBy(v)
return _u
}
// SetRespondedAt sets the "responded_at" field.
func (_u *ShopInvitationsUpdate) SetRespondedAt(v time.Time) *ShopInvitationsUpdate {
_u.mutation.SetRespondedAt(v)
return _u
}
// SetNillableRespondedAt sets the "responded_at" field if the given value is not nil.
func (_u *ShopInvitationsUpdate) SetNillableRespondedAt(v *time.Time) *ShopInvitationsUpdate {
if v != nil {
_u.SetRespondedAt(*v)
}
return _u
}
// ClearRespondedAt clears the value of the "responded_at" field.
func (_u *ShopInvitationsUpdate) ClearRespondedAt() *ShopInvitationsUpdate {
_u.mutation.ClearRespondedAt()
return _u
}
// Mutation returns the ShopInvitationsMutation object of the builder.
func (_u *ShopInvitationsUpdate) Mutation() *ShopInvitationsMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ShopInvitationsUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ShopInvitationsUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ShopInvitationsUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ShopInvitationsUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *ShopInvitationsUpdate) check() error {
if v, ok := _u.mutation.Status(); ok {
if err := shopinvitations.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "ShopInvitations.status": %w`, err)}
}
}
return nil
}
func (_u *ShopInvitationsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(shopinvitations.Table, shopinvitations.Columns, sqlgraph.NewFieldSpec(shopinvitations.FieldID, field.TypeInt64))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.ShopID(); ok {
_spec.SetField(shopinvitations.FieldShopID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedShopID(); ok {
_spec.AddField(shopinvitations.FieldShopID, field.TypeInt64, value)
}
if value, ok := _u.mutation.PlayerID(); ok {
_spec.SetField(shopinvitations.FieldPlayerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedPlayerID(); ok {
_spec.AddField(shopinvitations.FieldPlayerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(shopinvitations.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.InvitedBy(); ok {
_spec.SetField(shopinvitations.FieldInvitedBy, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedInvitedBy(); ok {
_spec.AddField(shopinvitations.FieldInvitedBy, field.TypeInt64, value)
}
if value, ok := _u.mutation.RespondedAt(); ok {
_spec.SetField(shopinvitations.FieldRespondedAt, field.TypeTime, value)
}
if _u.mutation.RespondedAtCleared() {
_spec.ClearField(shopinvitations.FieldRespondedAt, field.TypeTime)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{shopinvitations.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ShopInvitationsUpdateOne is the builder for updating a single ShopInvitations entity.
type ShopInvitationsUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ShopInvitationsMutation
}
// SetShopID sets the "shop_id" field.
func (_u *ShopInvitationsUpdateOne) SetShopID(v int64) *ShopInvitationsUpdateOne {
_u.mutation.ResetShopID()
_u.mutation.SetShopID(v)
return _u
}
// SetNillableShopID sets the "shop_id" field if the given value is not nil.
func (_u *ShopInvitationsUpdateOne) SetNillableShopID(v *int64) *ShopInvitationsUpdateOne {
if v != nil {
_u.SetShopID(*v)
}
return _u
}
// AddShopID adds value to the "shop_id" field.
func (_u *ShopInvitationsUpdateOne) AddShopID(v int64) *ShopInvitationsUpdateOne {
_u.mutation.AddShopID(v)
return _u
}
// SetPlayerID sets the "player_id" field.
func (_u *ShopInvitationsUpdateOne) SetPlayerID(v int64) *ShopInvitationsUpdateOne {
_u.mutation.ResetPlayerID()
_u.mutation.SetPlayerID(v)
return _u
}
// SetNillablePlayerID sets the "player_id" field if the given value is not nil.
func (_u *ShopInvitationsUpdateOne) SetNillablePlayerID(v *int64) *ShopInvitationsUpdateOne {
if v != nil {
_u.SetPlayerID(*v)
}
return _u
}
// AddPlayerID adds value to the "player_id" field.
func (_u *ShopInvitationsUpdateOne) AddPlayerID(v int64) *ShopInvitationsUpdateOne {
_u.mutation.AddPlayerID(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *ShopInvitationsUpdateOne) SetStatus(v string) *ShopInvitationsUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *ShopInvitationsUpdateOne) SetNillableStatus(v *string) *ShopInvitationsUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetInvitedBy sets the "invited_by" field.
func (_u *ShopInvitationsUpdateOne) SetInvitedBy(v int64) *ShopInvitationsUpdateOne {
_u.mutation.ResetInvitedBy()
_u.mutation.SetInvitedBy(v)
return _u
}
// SetNillableInvitedBy sets the "invited_by" field if the given value is not nil.
func (_u *ShopInvitationsUpdateOne) SetNillableInvitedBy(v *int64) *ShopInvitationsUpdateOne {
if v != nil {
_u.SetInvitedBy(*v)
}
return _u
}
// AddInvitedBy adds value to the "invited_by" field.
func (_u *ShopInvitationsUpdateOne) AddInvitedBy(v int64) *ShopInvitationsUpdateOne {
_u.mutation.AddInvitedBy(v)
return _u
}
// SetRespondedAt sets the "responded_at" field.
func (_u *ShopInvitationsUpdateOne) SetRespondedAt(v time.Time) *ShopInvitationsUpdateOne {
_u.mutation.SetRespondedAt(v)
return _u
}
// SetNillableRespondedAt sets the "responded_at" field if the given value is not nil.
func (_u *ShopInvitationsUpdateOne) SetNillableRespondedAt(v *time.Time) *ShopInvitationsUpdateOne {
if v != nil {
_u.SetRespondedAt(*v)
}
return _u
}
// ClearRespondedAt clears the value of the "responded_at" field.
func (_u *ShopInvitationsUpdateOne) ClearRespondedAt() *ShopInvitationsUpdateOne {
_u.mutation.ClearRespondedAt()
return _u
}
// Mutation returns the ShopInvitationsMutation object of the builder.
func (_u *ShopInvitationsUpdateOne) Mutation() *ShopInvitationsMutation {
return _u.mutation
}
// Where appends a list predicates to the ShopInvitationsUpdate builder.
func (_u *ShopInvitationsUpdateOne) Where(ps ...predicate.ShopInvitations) *ShopInvitationsUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *ShopInvitationsUpdateOne) Select(field string, fields ...string) *ShopInvitationsUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated ShopInvitations entity.
func (_u *ShopInvitationsUpdateOne) Save(ctx context.Context) (*ShopInvitations, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ShopInvitationsUpdateOne) SaveX(ctx context.Context) *ShopInvitations {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ShopInvitationsUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ShopInvitationsUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *ShopInvitationsUpdateOne) check() error {
if v, ok := _u.mutation.Status(); ok {
if err := shopinvitations.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`models: validator failed for field "ShopInvitations.status": %w`, err)}
}
}
return nil
}
func (_u *ShopInvitationsUpdateOne) sqlSave(ctx context.Context) (_node *ShopInvitations, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(shopinvitations.Table, shopinvitations.Columns, sqlgraph.NewFieldSpec(shopinvitations.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "ShopInvitations.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, shopinvitations.FieldID)
for _, f := range fields {
if !shopinvitations.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
}
if f != shopinvitations.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.ShopID(); ok {
_spec.SetField(shopinvitations.FieldShopID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedShopID(); ok {
_spec.AddField(shopinvitations.FieldShopID, field.TypeInt64, value)
}
if value, ok := _u.mutation.PlayerID(); ok {
_spec.SetField(shopinvitations.FieldPlayerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedPlayerID(); ok {
_spec.AddField(shopinvitations.FieldPlayerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(shopinvitations.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.InvitedBy(); ok {
_spec.SetField(shopinvitations.FieldInvitedBy, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedInvitedBy(); ok {
_spec.AddField(shopinvitations.FieldInvitedBy, field.TypeInt64, value)
}
if value, ok := _u.mutation.RespondedAt(); ok {
_spec.SetField(shopinvitations.FieldRespondedAt, field.TypeTime, value)
}
if _u.mutation.RespondedAtCleared() {
_spec.ClearField(shopinvitations.FieldRespondedAt, field.TypeTime)
}
_node = &ShopInvitations{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{shopinvitations.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+153
View File
@@ -0,0 +1,153 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"fmt"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
)
// ShopPlayers is the model entity for the ShopPlayers schema.
type ShopPlayers struct {
config `json:"-"`
// ID of the ent.
ID int64 `json:"id,omitempty"`
// ShopID holds the value of the "shop_id" field.
ShopID int64 `json:"shop_id,omitempty"`
// PlayerID holds the value of the "player_id" field.
PlayerID int64 `json:"player_id,omitempty"`
// IsPrimary holds the value of the "is_primary" field.
IsPrimary bool `json:"is_primary,omitempty"`
// JoinedAt holds the value of the "joined_at" field.
JoinedAt time.Time `json:"joined_at,omitempty"`
// LeftAt holds the value of the "left_at" field.
LeftAt *time.Time `json:"left_at,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*ShopPlayers) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case shopplayers.FieldIsPrimary:
values[i] = new(sql.NullBool)
case shopplayers.FieldID, shopplayers.FieldShopID, shopplayers.FieldPlayerID:
values[i] = new(sql.NullInt64)
case shopplayers.FieldJoinedAt, shopplayers.FieldLeftAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the ShopPlayers fields.
func (_m *ShopPlayers) 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 shopplayers.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int64(value.Int64)
case shopplayers.FieldShopID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field shop_id", values[i])
} else if value.Valid {
_m.ShopID = value.Int64
}
case shopplayers.FieldPlayerID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field player_id", values[i])
} else if value.Valid {
_m.PlayerID = value.Int64
}
case shopplayers.FieldIsPrimary:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field is_primary", values[i])
} else if value.Valid {
_m.IsPrimary = value.Bool
}
case shopplayers.FieldJoinedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field joined_at", values[i])
} else if value.Valid {
_m.JoinedAt = value.Time
}
case shopplayers.FieldLeftAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field left_at", values[i])
} else if value.Valid {
_m.LeftAt = new(time.Time)
*_m.LeftAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the ShopPlayers.
// This includes values selected through modifiers, order, etc.
func (_m *ShopPlayers) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// Update returns a builder for updating this ShopPlayers.
// Note that you need to call ShopPlayers.Unwrap() before calling this method if this ShopPlayers
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *ShopPlayers) Update() *ShopPlayersUpdateOne {
return NewShopPlayersClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the ShopPlayers 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 (_m *ShopPlayers) Unwrap() *ShopPlayers {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("models: ShopPlayers is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *ShopPlayers) String() string {
var builder strings.Builder
builder.WriteString("ShopPlayers(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("shop_id=")
builder.WriteString(fmt.Sprintf("%v", _m.ShopID))
builder.WriteString(", ")
builder.WriteString("player_id=")
builder.WriteString(fmt.Sprintf("%v", _m.PlayerID))
builder.WriteString(", ")
builder.WriteString("is_primary=")
builder.WriteString(fmt.Sprintf("%v", _m.IsPrimary))
builder.WriteString(", ")
builder.WriteString("joined_at=")
builder.WriteString(_m.JoinedAt.Format(time.ANSIC))
builder.WriteString(", ")
if v := _m.LeftAt; v != nil {
builder.WriteString("left_at=")
builder.WriteString(v.Format(time.ANSIC))
}
builder.WriteByte(')')
return builder.String()
}
// ShopPlayersSlice is a parsable slice of ShopPlayers.
type ShopPlayersSlice []*ShopPlayers
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package shopplayers
import (
"time"
"entgo.io/ent/dialect/sql"
)
const (
// Label holds the string label denoting the shopplayers type in the database.
Label = "shop_players"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldShopID holds the string denoting the shop_id field in the database.
FieldShopID = "shop_id"
// FieldPlayerID holds the string denoting the player_id field in the database.
FieldPlayerID = "player_id"
// FieldIsPrimary holds the string denoting the is_primary field in the database.
FieldIsPrimary = "is_primary"
// FieldJoinedAt holds the string denoting the joined_at field in the database.
FieldJoinedAt = "joined_at"
// FieldLeftAt holds the string denoting the left_at field in the database.
FieldLeftAt = "left_at"
// Table holds the table name of the shopplayers in the database.
Table = "shop_players"
)
// Columns holds all SQL columns for shopplayers fields.
var Columns = []string{
FieldID,
FieldShopID,
FieldPlayerID,
FieldIsPrimary,
FieldJoinedAt,
FieldLeftAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultIsPrimary holds the default value on creation for the "is_primary" field.
DefaultIsPrimary bool
// DefaultJoinedAt holds the default value on creation for the "joined_at" field.
DefaultJoinedAt func() time.Time
)
// OrderOption defines the ordering options for the ShopPlayers queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByShopID orders the results by the shop_id field.
func ByShopID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldShopID, opts...).ToFunc()
}
// ByPlayerID orders the results by the player_id field.
func ByPlayerID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPlayerID, opts...).ToFunc()
}
// ByIsPrimary orders the results by the is_primary field.
func ByIsPrimary(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldIsPrimary, opts...).ToFunc()
}
// ByJoinedAt orders the results by the joined_at field.
func ByJoinedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldJoinedAt, opts...).ToFunc()
}
// ByLeftAt orders the results by the left_at field.
func ByLeftAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldLeftAt, opts...).ToFunc()
}
@@ -0,0 +1,285 @@
// Code generated by ent, DO NOT EDIT.
package shopplayers
import (
"juwan-backend/app/shop/rpc/internal/models/predicate"
"time"
"entgo.io/ent/dialect/sql"
)
// ID filters vertices based on their ID field.
func ID(id int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldLTE(FieldID, id))
}
// ShopID applies equality check predicate on the "shop_id" field. It's identical to ShopIDEQ.
func ShopID(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldShopID, v))
}
// PlayerID applies equality check predicate on the "player_id" field. It's identical to PlayerIDEQ.
func PlayerID(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldPlayerID, v))
}
// IsPrimary applies equality check predicate on the "is_primary" field. It's identical to IsPrimaryEQ.
func IsPrimary(v bool) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldIsPrimary, v))
}
// JoinedAt applies equality check predicate on the "joined_at" field. It's identical to JoinedAtEQ.
func JoinedAt(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldJoinedAt, v))
}
// LeftAt applies equality check predicate on the "left_at" field. It's identical to LeftAtEQ.
func LeftAt(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldLeftAt, v))
}
// ShopIDEQ applies the EQ predicate on the "shop_id" field.
func ShopIDEQ(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldShopID, v))
}
// ShopIDNEQ applies the NEQ predicate on the "shop_id" field.
func ShopIDNEQ(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNEQ(FieldShopID, v))
}
// ShopIDIn applies the In predicate on the "shop_id" field.
func ShopIDIn(vs ...int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldIn(FieldShopID, vs...))
}
// ShopIDNotIn applies the NotIn predicate on the "shop_id" field.
func ShopIDNotIn(vs ...int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNotIn(FieldShopID, vs...))
}
// ShopIDGT applies the GT predicate on the "shop_id" field.
func ShopIDGT(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldGT(FieldShopID, v))
}
// ShopIDGTE applies the GTE predicate on the "shop_id" field.
func ShopIDGTE(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldGTE(FieldShopID, v))
}
// ShopIDLT applies the LT predicate on the "shop_id" field.
func ShopIDLT(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldLT(FieldShopID, v))
}
// ShopIDLTE applies the LTE predicate on the "shop_id" field.
func ShopIDLTE(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldLTE(FieldShopID, v))
}
// PlayerIDEQ applies the EQ predicate on the "player_id" field.
func PlayerIDEQ(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldPlayerID, v))
}
// PlayerIDNEQ applies the NEQ predicate on the "player_id" field.
func PlayerIDNEQ(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNEQ(FieldPlayerID, v))
}
// PlayerIDIn applies the In predicate on the "player_id" field.
func PlayerIDIn(vs ...int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldIn(FieldPlayerID, vs...))
}
// PlayerIDNotIn applies the NotIn predicate on the "player_id" field.
func PlayerIDNotIn(vs ...int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNotIn(FieldPlayerID, vs...))
}
// PlayerIDGT applies the GT predicate on the "player_id" field.
func PlayerIDGT(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldGT(FieldPlayerID, v))
}
// PlayerIDGTE applies the GTE predicate on the "player_id" field.
func PlayerIDGTE(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldGTE(FieldPlayerID, v))
}
// PlayerIDLT applies the LT predicate on the "player_id" field.
func PlayerIDLT(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldLT(FieldPlayerID, v))
}
// PlayerIDLTE applies the LTE predicate on the "player_id" field.
func PlayerIDLTE(v int64) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldLTE(FieldPlayerID, v))
}
// IsPrimaryEQ applies the EQ predicate on the "is_primary" field.
func IsPrimaryEQ(v bool) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldIsPrimary, v))
}
// IsPrimaryNEQ applies the NEQ predicate on the "is_primary" field.
func IsPrimaryNEQ(v bool) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNEQ(FieldIsPrimary, v))
}
// IsPrimaryIsNil applies the IsNil predicate on the "is_primary" field.
func IsPrimaryIsNil() predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldIsNull(FieldIsPrimary))
}
// IsPrimaryNotNil applies the NotNil predicate on the "is_primary" field.
func IsPrimaryNotNil() predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNotNull(FieldIsPrimary))
}
// JoinedAtEQ applies the EQ predicate on the "joined_at" field.
func JoinedAtEQ(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldJoinedAt, v))
}
// JoinedAtNEQ applies the NEQ predicate on the "joined_at" field.
func JoinedAtNEQ(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNEQ(FieldJoinedAt, v))
}
// JoinedAtIn applies the In predicate on the "joined_at" field.
func JoinedAtIn(vs ...time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldIn(FieldJoinedAt, vs...))
}
// JoinedAtNotIn applies the NotIn predicate on the "joined_at" field.
func JoinedAtNotIn(vs ...time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNotIn(FieldJoinedAt, vs...))
}
// JoinedAtGT applies the GT predicate on the "joined_at" field.
func JoinedAtGT(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldGT(FieldJoinedAt, v))
}
// JoinedAtGTE applies the GTE predicate on the "joined_at" field.
func JoinedAtGTE(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldGTE(FieldJoinedAt, v))
}
// JoinedAtLT applies the LT predicate on the "joined_at" field.
func JoinedAtLT(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldLT(FieldJoinedAt, v))
}
// JoinedAtLTE applies the LTE predicate on the "joined_at" field.
func JoinedAtLTE(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldLTE(FieldJoinedAt, v))
}
// LeftAtEQ applies the EQ predicate on the "left_at" field.
func LeftAtEQ(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldEQ(FieldLeftAt, v))
}
// LeftAtNEQ applies the NEQ predicate on the "left_at" field.
func LeftAtNEQ(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNEQ(FieldLeftAt, v))
}
// LeftAtIn applies the In predicate on the "left_at" field.
func LeftAtIn(vs ...time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldIn(FieldLeftAt, vs...))
}
// LeftAtNotIn applies the NotIn predicate on the "left_at" field.
func LeftAtNotIn(vs ...time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNotIn(FieldLeftAt, vs...))
}
// LeftAtGT applies the GT predicate on the "left_at" field.
func LeftAtGT(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldGT(FieldLeftAt, v))
}
// LeftAtGTE applies the GTE predicate on the "left_at" field.
func LeftAtGTE(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldGTE(FieldLeftAt, v))
}
// LeftAtLT applies the LT predicate on the "left_at" field.
func LeftAtLT(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldLT(FieldLeftAt, v))
}
// LeftAtLTE applies the LTE predicate on the "left_at" field.
func LeftAtLTE(v time.Time) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldLTE(FieldLeftAt, v))
}
// LeftAtIsNil applies the IsNil predicate on the "left_at" field.
func LeftAtIsNil() predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldIsNull(FieldLeftAt))
}
// LeftAtNotNil applies the NotNil predicate on the "left_at" field.
func LeftAtNotNil() predicate.ShopPlayers {
return predicate.ShopPlayers(sql.FieldNotNull(FieldLeftAt))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.ShopPlayers) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.ShopPlayers) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.ShopPlayers) predicate.ShopPlayers {
return predicate.ShopPlayers(sql.NotPredicates(p))
}
@@ -0,0 +1,280 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ShopPlayersCreate is the builder for creating a ShopPlayers entity.
type ShopPlayersCreate struct {
config
mutation *ShopPlayersMutation
hooks []Hook
}
// SetShopID sets the "shop_id" field.
func (_c *ShopPlayersCreate) SetShopID(v int64) *ShopPlayersCreate {
_c.mutation.SetShopID(v)
return _c
}
// SetPlayerID sets the "player_id" field.
func (_c *ShopPlayersCreate) SetPlayerID(v int64) *ShopPlayersCreate {
_c.mutation.SetPlayerID(v)
return _c
}
// SetIsPrimary sets the "is_primary" field.
func (_c *ShopPlayersCreate) SetIsPrimary(v bool) *ShopPlayersCreate {
_c.mutation.SetIsPrimary(v)
return _c
}
// SetNillableIsPrimary sets the "is_primary" field if the given value is not nil.
func (_c *ShopPlayersCreate) SetNillableIsPrimary(v *bool) *ShopPlayersCreate {
if v != nil {
_c.SetIsPrimary(*v)
}
return _c
}
// SetJoinedAt sets the "joined_at" field.
func (_c *ShopPlayersCreate) SetJoinedAt(v time.Time) *ShopPlayersCreate {
_c.mutation.SetJoinedAt(v)
return _c
}
// SetNillableJoinedAt sets the "joined_at" field if the given value is not nil.
func (_c *ShopPlayersCreate) SetNillableJoinedAt(v *time.Time) *ShopPlayersCreate {
if v != nil {
_c.SetJoinedAt(*v)
}
return _c
}
// SetLeftAt sets the "left_at" field.
func (_c *ShopPlayersCreate) SetLeftAt(v time.Time) *ShopPlayersCreate {
_c.mutation.SetLeftAt(v)
return _c
}
// SetNillableLeftAt sets the "left_at" field if the given value is not nil.
func (_c *ShopPlayersCreate) SetNillableLeftAt(v *time.Time) *ShopPlayersCreate {
if v != nil {
_c.SetLeftAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *ShopPlayersCreate) SetID(v int64) *ShopPlayersCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the ShopPlayersMutation object of the builder.
func (_c *ShopPlayersCreate) Mutation() *ShopPlayersMutation {
return _c.mutation
}
// Save creates the ShopPlayers in the database.
func (_c *ShopPlayersCreate) Save(ctx context.Context) (*ShopPlayers, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *ShopPlayersCreate) SaveX(ctx context.Context) *ShopPlayers {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ShopPlayersCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ShopPlayersCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *ShopPlayersCreate) defaults() {
if _, ok := _c.mutation.IsPrimary(); !ok {
v := shopplayers.DefaultIsPrimary
_c.mutation.SetIsPrimary(v)
}
if _, ok := _c.mutation.JoinedAt(); !ok {
v := shopplayers.DefaultJoinedAt()
_c.mutation.SetJoinedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *ShopPlayersCreate) check() error {
if _, ok := _c.mutation.ShopID(); !ok {
return &ValidationError{Name: "shop_id", err: errors.New(`models: missing required field "ShopPlayers.shop_id"`)}
}
if _, ok := _c.mutation.PlayerID(); !ok {
return &ValidationError{Name: "player_id", err: errors.New(`models: missing required field "ShopPlayers.player_id"`)}
}
if _, ok := _c.mutation.JoinedAt(); !ok {
return &ValidationError{Name: "joined_at", err: errors.New(`models: missing required field "ShopPlayers.joined_at"`)}
}
return nil
}
func (_c *ShopPlayersCreate) sqlSave(ctx context.Context) (*ShopPlayers, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
if _spec.ID.Value != _node.ID {
id := _spec.ID.Value.(int64)
_node.ID = int64(id)
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *ShopPlayersCreate) createSpec() (*ShopPlayers, *sqlgraph.CreateSpec) {
var (
_node = &ShopPlayers{config: _c.config}
_spec = sqlgraph.NewCreateSpec(shopplayers.Table, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64))
)
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.ShopID(); ok {
_spec.SetField(shopplayers.FieldShopID, field.TypeInt64, value)
_node.ShopID = value
}
if value, ok := _c.mutation.PlayerID(); ok {
_spec.SetField(shopplayers.FieldPlayerID, field.TypeInt64, value)
_node.PlayerID = value
}
if value, ok := _c.mutation.IsPrimary(); ok {
_spec.SetField(shopplayers.FieldIsPrimary, field.TypeBool, value)
_node.IsPrimary = value
}
if value, ok := _c.mutation.JoinedAt(); ok {
_spec.SetField(shopplayers.FieldJoinedAt, field.TypeTime, value)
_node.JoinedAt = value
}
if value, ok := _c.mutation.LeftAt(); ok {
_spec.SetField(shopplayers.FieldLeftAt, field.TypeTime, value)
_node.LeftAt = &value
}
return _node, _spec
}
// ShopPlayersCreateBulk is the builder for creating many ShopPlayers entities in bulk.
type ShopPlayersCreateBulk struct {
config
err error
builders []*ShopPlayersCreate
}
// Save creates the ShopPlayers entities in the database.
func (_c *ShopPlayersCreateBulk) Save(ctx context.Context) ([]*ShopPlayers, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*ShopPlayers, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*ShopPlayersMutation)
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, _c.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, _c.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 && nodes[i].ID == 0 {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int64(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, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *ShopPlayersCreateBulk) SaveX(ctx context.Context) []*ShopPlayers {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ShopPlayersCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ShopPlayersCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ShopPlayersDelete is the builder for deleting a ShopPlayers entity.
type ShopPlayersDelete struct {
config
hooks []Hook
mutation *ShopPlayersMutation
}
// Where appends a list predicates to the ShopPlayersDelete builder.
func (_d *ShopPlayersDelete) Where(ps ...predicate.ShopPlayers) *ShopPlayersDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *ShopPlayersDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ShopPlayersDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *ShopPlayersDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(shopplayers.Table, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// ShopPlayersDeleteOne is the builder for deleting a single ShopPlayers entity.
type ShopPlayersDeleteOne struct {
_d *ShopPlayersDelete
}
// Where appends a list predicates to the ShopPlayersDelete builder.
func (_d *ShopPlayersDeleteOne) Where(ps ...predicate.ShopPlayers) *ShopPlayersDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *ShopPlayersDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{shopplayers.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ShopPlayersDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
@@ -0,0 +1,527 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ShopPlayersQuery is the builder for querying ShopPlayers entities.
type ShopPlayersQuery struct {
config
ctx *QueryContext
order []shopplayers.OrderOption
inters []Interceptor
predicates []predicate.ShopPlayers
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the ShopPlayersQuery builder.
func (_q *ShopPlayersQuery) Where(ps ...predicate.ShopPlayers) *ShopPlayersQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *ShopPlayersQuery) Limit(limit int) *ShopPlayersQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *ShopPlayersQuery) Offset(offset int) *ShopPlayersQuery {
_q.ctx.Offset = &offset
return _q
}
// 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 (_q *ShopPlayersQuery) Unique(unique bool) *ShopPlayersQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *ShopPlayersQuery) Order(o ...shopplayers.OrderOption) *ShopPlayersQuery {
_q.order = append(_q.order, o...)
return _q
}
// First returns the first ShopPlayers entity from the query.
// Returns a *NotFoundError when no ShopPlayers was found.
func (_q *ShopPlayersQuery) First(ctx context.Context) (*ShopPlayers, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{shopplayers.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *ShopPlayersQuery) FirstX(ctx context.Context) *ShopPlayers {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first ShopPlayers ID from the query.
// Returns a *NotFoundError when no ShopPlayers ID was found.
func (_q *ShopPlayersQuery) FirstID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{shopplayers.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *ShopPlayersQuery) FirstIDX(ctx context.Context) int64 {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single ShopPlayers entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one ShopPlayers entity is found.
// Returns a *NotFoundError when no ShopPlayers entities are found.
func (_q *ShopPlayersQuery) Only(ctx context.Context) (*ShopPlayers, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{shopplayers.Label}
default:
return nil, &NotSingularError{shopplayers.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *ShopPlayersQuery) OnlyX(ctx context.Context) *ShopPlayers {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only ShopPlayers ID in the query.
// Returns a *NotSingularError when more than one ShopPlayers ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *ShopPlayersQuery) OnlyID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{shopplayers.Label}
default:
err = &NotSingularError{shopplayers.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *ShopPlayersQuery) OnlyIDX(ctx context.Context) int64 {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of ShopPlayersSlice.
func (_q *ShopPlayersQuery) All(ctx context.Context) ([]*ShopPlayers, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*ShopPlayers, *ShopPlayersQuery]()
return withInterceptors[[]*ShopPlayers](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *ShopPlayersQuery) AllX(ctx context.Context) []*ShopPlayers {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of ShopPlayers IDs.
func (_q *ShopPlayersQuery) IDs(ctx context.Context) (ids []int64, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(shopplayers.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *ShopPlayersQuery) IDsX(ctx context.Context) []int64 {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *ShopPlayersQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*ShopPlayersQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *ShopPlayersQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *ShopPlayersQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("models: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *ShopPlayersQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the ShopPlayersQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *ShopPlayersQuery) Clone() *ShopPlayersQuery {
if _q == nil {
return nil
}
return &ShopPlayersQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]shopplayers.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.ShopPlayers{}, _q.predicates...),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// 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 {
// ShopID int64 `json:"shop_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.ShopPlayers.Query().
// GroupBy(shopplayers.FieldShopID).
// Aggregate(models.Count()).
// Scan(ctx, &v)
func (_q *ShopPlayersQuery) GroupBy(field string, fields ...string) *ShopPlayersGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &ShopPlayersGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = shopplayers.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 {
// ShopID int64 `json:"shop_id,omitempty"`
// }
//
// client.ShopPlayers.Query().
// Select(shopplayers.FieldShopID).
// Scan(ctx, &v)
func (_q *ShopPlayersQuery) Select(fields ...string) *ShopPlayersSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &ShopPlayersSelect{ShopPlayersQuery: _q}
sbuild.label = shopplayers.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ShopPlayersSelect configured with the given aggregations.
func (_q *ShopPlayersQuery) Aggregate(fns ...AggregateFunc) *ShopPlayersSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *ShopPlayersQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("models: uninitialized interceptor (forgotten import models/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !shopplayers.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *ShopPlayersQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*ShopPlayers, error) {
var (
nodes = []*ShopPlayers{}
_spec = _q.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*ShopPlayers).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &ShopPlayers{config: _q.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (_q *ShopPlayersQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *ShopPlayersQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(shopplayers.Table, shopplayers.Columns, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, shopplayers.FieldID)
for i := range fields {
if fields[i] != shopplayers.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *ShopPlayersQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(shopplayers.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = shopplayers.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.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 := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ShopPlayersGroupBy is the group-by builder for ShopPlayers entities.
type ShopPlayersGroupBy struct {
selector
build *ShopPlayersQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *ShopPlayersGroupBy) Aggregate(fns ...AggregateFunc) *ShopPlayersGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *ShopPlayersGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ShopPlayersQuery, *ShopPlayersGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *ShopPlayersGroupBy) sqlScan(ctx context.Context, root *ShopPlayersQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// ShopPlayersSelect is the builder for selecting fields of ShopPlayers entities.
type ShopPlayersSelect struct {
*ShopPlayersQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *ShopPlayersSelect) Aggregate(fns ...AggregateFunc) *ShopPlayersSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *ShopPlayersSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ShopPlayersQuery, *ShopPlayersSelect](ctx, _s.ShopPlayersQuery, _s, _s.inters, v)
}
func (_s *ShopPlayersSelect) sqlScan(ctx context.Context, root *ShopPlayersQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.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 := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
@@ -0,0 +1,388 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/shopplayers"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ShopPlayersUpdate is the builder for updating ShopPlayers entities.
type ShopPlayersUpdate struct {
config
hooks []Hook
mutation *ShopPlayersMutation
}
// Where appends a list predicates to the ShopPlayersUpdate builder.
func (_u *ShopPlayersUpdate) Where(ps ...predicate.ShopPlayers) *ShopPlayersUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetShopID sets the "shop_id" field.
func (_u *ShopPlayersUpdate) SetShopID(v int64) *ShopPlayersUpdate {
_u.mutation.ResetShopID()
_u.mutation.SetShopID(v)
return _u
}
// SetNillableShopID sets the "shop_id" field if the given value is not nil.
func (_u *ShopPlayersUpdate) SetNillableShopID(v *int64) *ShopPlayersUpdate {
if v != nil {
_u.SetShopID(*v)
}
return _u
}
// AddShopID adds value to the "shop_id" field.
func (_u *ShopPlayersUpdate) AddShopID(v int64) *ShopPlayersUpdate {
_u.mutation.AddShopID(v)
return _u
}
// SetPlayerID sets the "player_id" field.
func (_u *ShopPlayersUpdate) SetPlayerID(v int64) *ShopPlayersUpdate {
_u.mutation.ResetPlayerID()
_u.mutation.SetPlayerID(v)
return _u
}
// SetNillablePlayerID sets the "player_id" field if the given value is not nil.
func (_u *ShopPlayersUpdate) SetNillablePlayerID(v *int64) *ShopPlayersUpdate {
if v != nil {
_u.SetPlayerID(*v)
}
return _u
}
// AddPlayerID adds value to the "player_id" field.
func (_u *ShopPlayersUpdate) AddPlayerID(v int64) *ShopPlayersUpdate {
_u.mutation.AddPlayerID(v)
return _u
}
// SetIsPrimary sets the "is_primary" field.
func (_u *ShopPlayersUpdate) SetIsPrimary(v bool) *ShopPlayersUpdate {
_u.mutation.SetIsPrimary(v)
return _u
}
// SetNillableIsPrimary sets the "is_primary" field if the given value is not nil.
func (_u *ShopPlayersUpdate) SetNillableIsPrimary(v *bool) *ShopPlayersUpdate {
if v != nil {
_u.SetIsPrimary(*v)
}
return _u
}
// ClearIsPrimary clears the value of the "is_primary" field.
func (_u *ShopPlayersUpdate) ClearIsPrimary() *ShopPlayersUpdate {
_u.mutation.ClearIsPrimary()
return _u
}
// SetLeftAt sets the "left_at" field.
func (_u *ShopPlayersUpdate) SetLeftAt(v time.Time) *ShopPlayersUpdate {
_u.mutation.SetLeftAt(v)
return _u
}
// SetNillableLeftAt sets the "left_at" field if the given value is not nil.
func (_u *ShopPlayersUpdate) SetNillableLeftAt(v *time.Time) *ShopPlayersUpdate {
if v != nil {
_u.SetLeftAt(*v)
}
return _u
}
// ClearLeftAt clears the value of the "left_at" field.
func (_u *ShopPlayersUpdate) ClearLeftAt() *ShopPlayersUpdate {
_u.mutation.ClearLeftAt()
return _u
}
// Mutation returns the ShopPlayersMutation object of the builder.
func (_u *ShopPlayersUpdate) Mutation() *ShopPlayersMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ShopPlayersUpdate) Save(ctx context.Context) (int, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ShopPlayersUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ShopPlayersUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ShopPlayersUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *ShopPlayersUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(shopplayers.Table, shopplayers.Columns, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.ShopID(); ok {
_spec.SetField(shopplayers.FieldShopID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedShopID(); ok {
_spec.AddField(shopplayers.FieldShopID, field.TypeInt64, value)
}
if value, ok := _u.mutation.PlayerID(); ok {
_spec.SetField(shopplayers.FieldPlayerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedPlayerID(); ok {
_spec.AddField(shopplayers.FieldPlayerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.IsPrimary(); ok {
_spec.SetField(shopplayers.FieldIsPrimary, field.TypeBool, value)
}
if _u.mutation.IsPrimaryCleared() {
_spec.ClearField(shopplayers.FieldIsPrimary, field.TypeBool)
}
if value, ok := _u.mutation.LeftAt(); ok {
_spec.SetField(shopplayers.FieldLeftAt, field.TypeTime, value)
}
if _u.mutation.LeftAtCleared() {
_spec.ClearField(shopplayers.FieldLeftAt, field.TypeTime)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{shopplayers.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ShopPlayersUpdateOne is the builder for updating a single ShopPlayers entity.
type ShopPlayersUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ShopPlayersMutation
}
// SetShopID sets the "shop_id" field.
func (_u *ShopPlayersUpdateOne) SetShopID(v int64) *ShopPlayersUpdateOne {
_u.mutation.ResetShopID()
_u.mutation.SetShopID(v)
return _u
}
// SetNillableShopID sets the "shop_id" field if the given value is not nil.
func (_u *ShopPlayersUpdateOne) SetNillableShopID(v *int64) *ShopPlayersUpdateOne {
if v != nil {
_u.SetShopID(*v)
}
return _u
}
// AddShopID adds value to the "shop_id" field.
func (_u *ShopPlayersUpdateOne) AddShopID(v int64) *ShopPlayersUpdateOne {
_u.mutation.AddShopID(v)
return _u
}
// SetPlayerID sets the "player_id" field.
func (_u *ShopPlayersUpdateOne) SetPlayerID(v int64) *ShopPlayersUpdateOne {
_u.mutation.ResetPlayerID()
_u.mutation.SetPlayerID(v)
return _u
}
// SetNillablePlayerID sets the "player_id" field if the given value is not nil.
func (_u *ShopPlayersUpdateOne) SetNillablePlayerID(v *int64) *ShopPlayersUpdateOne {
if v != nil {
_u.SetPlayerID(*v)
}
return _u
}
// AddPlayerID adds value to the "player_id" field.
func (_u *ShopPlayersUpdateOne) AddPlayerID(v int64) *ShopPlayersUpdateOne {
_u.mutation.AddPlayerID(v)
return _u
}
// SetIsPrimary sets the "is_primary" field.
func (_u *ShopPlayersUpdateOne) SetIsPrimary(v bool) *ShopPlayersUpdateOne {
_u.mutation.SetIsPrimary(v)
return _u
}
// SetNillableIsPrimary sets the "is_primary" field if the given value is not nil.
func (_u *ShopPlayersUpdateOne) SetNillableIsPrimary(v *bool) *ShopPlayersUpdateOne {
if v != nil {
_u.SetIsPrimary(*v)
}
return _u
}
// ClearIsPrimary clears the value of the "is_primary" field.
func (_u *ShopPlayersUpdateOne) ClearIsPrimary() *ShopPlayersUpdateOne {
_u.mutation.ClearIsPrimary()
return _u
}
// SetLeftAt sets the "left_at" field.
func (_u *ShopPlayersUpdateOne) SetLeftAt(v time.Time) *ShopPlayersUpdateOne {
_u.mutation.SetLeftAt(v)
return _u
}
// SetNillableLeftAt sets the "left_at" field if the given value is not nil.
func (_u *ShopPlayersUpdateOne) SetNillableLeftAt(v *time.Time) *ShopPlayersUpdateOne {
if v != nil {
_u.SetLeftAt(*v)
}
return _u
}
// ClearLeftAt clears the value of the "left_at" field.
func (_u *ShopPlayersUpdateOne) ClearLeftAt() *ShopPlayersUpdateOne {
_u.mutation.ClearLeftAt()
return _u
}
// Mutation returns the ShopPlayersMutation object of the builder.
func (_u *ShopPlayersUpdateOne) Mutation() *ShopPlayersMutation {
return _u.mutation
}
// Where appends a list predicates to the ShopPlayersUpdate builder.
func (_u *ShopPlayersUpdateOne) Where(ps ...predicate.ShopPlayers) *ShopPlayersUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *ShopPlayersUpdateOne) Select(field string, fields ...string) *ShopPlayersUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated ShopPlayers entity.
func (_u *ShopPlayersUpdateOne) Save(ctx context.Context) (*ShopPlayers, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ShopPlayersUpdateOne) SaveX(ctx context.Context) *ShopPlayers {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ShopPlayersUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ShopPlayersUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
func (_u *ShopPlayersUpdateOne) sqlSave(ctx context.Context) (_node *ShopPlayers, err error) {
_spec := sqlgraph.NewUpdateSpec(shopplayers.Table, shopplayers.Columns, sqlgraph.NewFieldSpec(shopplayers.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "ShopPlayers.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, shopplayers.FieldID)
for _, f := range fields {
if !shopplayers.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
}
if f != shopplayers.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.ShopID(); ok {
_spec.SetField(shopplayers.FieldShopID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedShopID(); ok {
_spec.AddField(shopplayers.FieldShopID, field.TypeInt64, value)
}
if value, ok := _u.mutation.PlayerID(); ok {
_spec.SetField(shopplayers.FieldPlayerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedPlayerID(); ok {
_spec.AddField(shopplayers.FieldPlayerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.IsPrimary(); ok {
_spec.SetField(shopplayers.FieldIsPrimary, field.TypeBool, value)
}
if _u.mutation.IsPrimaryCleared() {
_spec.ClearField(shopplayers.FieldIsPrimary, field.TypeBool)
}
if value, ok := _u.mutation.LeftAt(); ok {
_spec.SetField(shopplayers.FieldLeftAt, field.TypeTime, value)
}
if _u.mutation.LeftAtCleared() {
_spec.ClearField(shopplayers.FieldLeftAt, field.TypeTime)
}
_node = &ShopPlayers{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{shopplayers.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+289
View File
@@ -0,0 +1,289 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"encoding/json"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/shops"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/shopspring/decimal"
)
// Shops is the model entity for the Shops schema.
type Shops struct {
config `json:"-"`
// ID of the ent.
ID int64 `json:"id,omitempty"`
// OwnerID holds the value of the "owner_id" field.
OwnerID int64 `json:"owner_id,omitempty"`
// Name holds the value of the "name" field.
Name string `json:"name,omitempty"`
// Banner holds the value of the "banner" field.
Banner *string `json:"banner,omitempty"`
// Description holds the value of the "description" field.
Description *string `json:"description,omitempty"`
// Rating holds the value of the "rating" field.
Rating decimal.Decimal `json:"rating,omitempty"`
// TotalOrders holds the value of the "total_orders" field.
TotalOrders int `json:"total_orders,omitempty"`
// PlayerCount holds the value of the "player_count" field.
PlayerCount int `json:"player_count,omitempty"`
// CommissionType holds the value of the "commission_type" field.
CommissionType string `json:"commission_type,omitempty"`
// CommissionValue holds the value of the "commission_value" field.
CommissionValue decimal.Decimal `json:"commission_value,omitempty"`
// AllowMultiShop holds the value of the "allow_multi_shop" field.
AllowMultiShop bool `json:"allow_multi_shop,omitempty"`
// AllowIndependentOrders holds the value of the "allow_independent_orders" field.
AllowIndependentOrders bool `json:"allow_independent_orders,omitempty"`
// DispatchMode holds the value of the "dispatch_mode" field.
DispatchMode string `json:"dispatch_mode,omitempty"`
// Announcements holds the value of the "announcements" field.
Announcements []string `json:"announcements,omitempty"`
// TemplateConfig holds the value of the "template_config" field.
TemplateConfig map[string]interface{} `json:"template_config,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt time.Time `json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt time.Time `json:"updated_at,omitempty"`
selectValues sql.SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Shops) scanValues(columns []string) ([]any, error) {
values := make([]any, len(columns))
for i := range columns {
switch columns[i] {
case shops.FieldAnnouncements, shops.FieldTemplateConfig:
values[i] = new([]byte)
case shops.FieldRating, shops.FieldCommissionValue:
values[i] = new(decimal.Decimal)
case shops.FieldAllowMultiShop, shops.FieldAllowIndependentOrders:
values[i] = new(sql.NullBool)
case shops.FieldID, shops.FieldOwnerID, shops.FieldTotalOrders, shops.FieldPlayerCount:
values[i] = new(sql.NullInt64)
case shops.FieldName, shops.FieldBanner, shops.FieldDescription, shops.FieldCommissionType, shops.FieldDispatchMode:
values[i] = new(sql.NullString)
case shops.FieldCreatedAt, shops.FieldUpdatedAt:
values[i] = new(sql.NullTime)
default:
values[i] = new(sql.UnknownType)
}
}
return values, nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Shops fields.
func (_m *Shops) 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 shops.FieldID:
value, ok := values[i].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
_m.ID = int64(value.Int64)
case shops.FieldOwnerID:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field owner_id", values[i])
} else if value.Valid {
_m.OwnerID = value.Int64
}
case shops.FieldName:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[i])
} else if value.Valid {
_m.Name = value.String
}
case shops.FieldBanner:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field banner", values[i])
} else if value.Valid {
_m.Banner = new(string)
*_m.Banner = value.String
}
case shops.FieldDescription:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field description", values[i])
} else if value.Valid {
_m.Description = new(string)
*_m.Description = value.String
}
case shops.FieldRating:
if value, ok := values[i].(*decimal.Decimal); !ok {
return fmt.Errorf("unexpected type %T for field rating", values[i])
} else if value != nil {
_m.Rating = *value
}
case shops.FieldTotalOrders:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field total_orders", values[i])
} else if value.Valid {
_m.TotalOrders = int(value.Int64)
}
case shops.FieldPlayerCount:
if value, ok := values[i].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field player_count", values[i])
} else if value.Valid {
_m.PlayerCount = int(value.Int64)
}
case shops.FieldCommissionType:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field commission_type", values[i])
} else if value.Valid {
_m.CommissionType = value.String
}
case shops.FieldCommissionValue:
if value, ok := values[i].(*decimal.Decimal); !ok {
return fmt.Errorf("unexpected type %T for field commission_value", values[i])
} else if value != nil {
_m.CommissionValue = *value
}
case shops.FieldAllowMultiShop:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field allow_multi_shop", values[i])
} else if value.Valid {
_m.AllowMultiShop = value.Bool
}
case shops.FieldAllowIndependentOrders:
if value, ok := values[i].(*sql.NullBool); !ok {
return fmt.Errorf("unexpected type %T for field allow_independent_orders", values[i])
} else if value.Valid {
_m.AllowIndependentOrders = value.Bool
}
case shops.FieldDispatchMode:
if value, ok := values[i].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field dispatch_mode", values[i])
} else if value.Valid {
_m.DispatchMode = value.String
}
case shops.FieldAnnouncements:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field announcements", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &_m.Announcements); err != nil {
return fmt.Errorf("unmarshal field announcements: %w", err)
}
}
case shops.FieldTemplateConfig:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field template_config", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &_m.TemplateConfig); err != nil {
return fmt.Errorf("unmarshal field template_config: %w", err)
}
}
case shops.FieldCreatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field created_at", values[i])
} else if value.Valid {
_m.CreatedAt = value.Time
}
case shops.FieldUpdatedAt:
if value, ok := values[i].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field updated_at", values[i])
} else if value.Valid {
_m.UpdatedAt = value.Time
}
default:
_m.selectValues.Set(columns[i], values[i])
}
}
return nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the Shops.
// This includes values selected through modifiers, order, etc.
func (_m *Shops) Value(name string) (ent.Value, error) {
return _m.selectValues.Get(name)
}
// Update returns a builder for updating this Shops.
// Note that you need to call Shops.Unwrap() before calling this method if this Shops
// was returned from a transaction, and the transaction was committed or rolled back.
func (_m *Shops) Update() *ShopsUpdateOne {
return NewShopsClient(_m.config).UpdateOne(_m)
}
// Unwrap unwraps the Shops 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 (_m *Shops) Unwrap() *Shops {
_tx, ok := _m.config.driver.(*txDriver)
if !ok {
panic("models: Shops is not a transactional entity")
}
_m.config.driver = _tx.drv
return _m
}
// String implements the fmt.Stringer.
func (_m *Shops) String() string {
var builder strings.Builder
builder.WriteString("Shops(")
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
builder.WriteString("owner_id=")
builder.WriteString(fmt.Sprintf("%v", _m.OwnerID))
builder.WriteString(", ")
builder.WriteString("name=")
builder.WriteString(_m.Name)
builder.WriteString(", ")
if v := _m.Banner; v != nil {
builder.WriteString("banner=")
builder.WriteString(*v)
}
builder.WriteString(", ")
if v := _m.Description; v != nil {
builder.WriteString("description=")
builder.WriteString(*v)
}
builder.WriteString(", ")
builder.WriteString("rating=")
builder.WriteString(fmt.Sprintf("%v", _m.Rating))
builder.WriteString(", ")
builder.WriteString("total_orders=")
builder.WriteString(fmt.Sprintf("%v", _m.TotalOrders))
builder.WriteString(", ")
builder.WriteString("player_count=")
builder.WriteString(fmt.Sprintf("%v", _m.PlayerCount))
builder.WriteString(", ")
builder.WriteString("commission_type=")
builder.WriteString(_m.CommissionType)
builder.WriteString(", ")
builder.WriteString("commission_value=")
builder.WriteString(fmt.Sprintf("%v", _m.CommissionValue))
builder.WriteString(", ")
builder.WriteString("allow_multi_shop=")
builder.WriteString(fmt.Sprintf("%v", _m.AllowMultiShop))
builder.WriteString(", ")
builder.WriteString("allow_independent_orders=")
builder.WriteString(fmt.Sprintf("%v", _m.AllowIndependentOrders))
builder.WriteString(", ")
builder.WriteString("dispatch_mode=")
builder.WriteString(_m.DispatchMode)
builder.WriteString(", ")
builder.WriteString("announcements=")
builder.WriteString(fmt.Sprintf("%v", _m.Announcements))
builder.WriteString(", ")
builder.WriteString("template_config=")
builder.WriteString(fmt.Sprintf("%v", _m.TemplateConfig))
builder.WriteString(", ")
builder.WriteString("created_at=")
builder.WriteString(_m.CreatedAt.Format(time.ANSIC))
builder.WriteString(", ")
builder.WriteString("updated_at=")
builder.WriteString(_m.UpdatedAt.Format(time.ANSIC))
builder.WriteByte(')')
return builder.String()
}
// ShopsSlice is a parsable slice of Shops.
type ShopsSlice []*Shops
+191
View File
@@ -0,0 +1,191 @@
// Code generated by ent, DO NOT EDIT.
package shops
import (
"time"
"entgo.io/ent/dialect/sql"
"github.com/shopspring/decimal"
)
const (
// Label holds the string label denoting the shops type in the database.
Label = "shops"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldOwnerID holds the string denoting the owner_id field in the database.
FieldOwnerID = "owner_id"
// FieldName holds the string denoting the name field in the database.
FieldName = "name"
// FieldBanner holds the string denoting the banner field in the database.
FieldBanner = "banner"
// FieldDescription holds the string denoting the description field in the database.
FieldDescription = "description"
// FieldRating holds the string denoting the rating field in the database.
FieldRating = "rating"
// FieldTotalOrders holds the string denoting the total_orders field in the database.
FieldTotalOrders = "total_orders"
// FieldPlayerCount holds the string denoting the player_count field in the database.
FieldPlayerCount = "player_count"
// FieldCommissionType holds the string denoting the commission_type field in the database.
FieldCommissionType = "commission_type"
// FieldCommissionValue holds the string denoting the commission_value field in the database.
FieldCommissionValue = "commission_value"
// FieldAllowMultiShop holds the string denoting the allow_multi_shop field in the database.
FieldAllowMultiShop = "allow_multi_shop"
// FieldAllowIndependentOrders holds the string denoting the allow_independent_orders field in the database.
FieldAllowIndependentOrders = "allow_independent_orders"
// FieldDispatchMode holds the string denoting the dispatch_mode field in the database.
FieldDispatchMode = "dispatch_mode"
// FieldAnnouncements holds the string denoting the announcements field in the database.
FieldAnnouncements = "announcements"
// FieldTemplateConfig holds the string denoting the template_config field in the database.
FieldTemplateConfig = "template_config"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// Table holds the table name of the shops in the database.
Table = "shops"
)
// Columns holds all SQL columns for shops fields.
var Columns = []string{
FieldID,
FieldOwnerID,
FieldName,
FieldBanner,
FieldDescription,
FieldRating,
FieldTotalOrders,
FieldPlayerCount,
FieldCommissionType,
FieldCommissionValue,
FieldAllowMultiShop,
FieldAllowIndependentOrders,
FieldDispatchMode,
FieldAnnouncements,
FieldTemplateConfig,
FieldCreatedAt,
FieldUpdatedAt,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// NameValidator is a validator for the "name" field. It is called by the builders before save.
NameValidator func(string) error
// DefaultRating holds the default value on creation for the "rating" field.
DefaultRating decimal.Decimal
// DefaultTotalOrders holds the default value on creation for the "total_orders" field.
DefaultTotalOrders int
// DefaultPlayerCount holds the default value on creation for the "player_count" field.
DefaultPlayerCount int
// DefaultCommissionType holds the default value on creation for the "commission_type" field.
DefaultCommissionType string
// CommissionTypeValidator is a validator for the "commission_type" field. It is called by the builders before save.
CommissionTypeValidator func(string) error
// DefaultAllowMultiShop holds the default value on creation for the "allow_multi_shop" field.
DefaultAllowMultiShop bool
// DefaultAllowIndependentOrders holds the default value on creation for the "allow_independent_orders" field.
DefaultAllowIndependentOrders bool
// DefaultDispatchMode holds the default value on creation for the "dispatch_mode" field.
DefaultDispatchMode string
// DispatchModeValidator is a validator for the "dispatch_mode" field. It is called by the builders before save.
DispatchModeValidator func(string) error
// DefaultAnnouncements holds the default value on creation for the "announcements" field.
DefaultAnnouncements []string
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
)
// OrderOption defines the ordering options for the Shops queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByOwnerID orders the results by the owner_id field.
func ByOwnerID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldOwnerID, opts...).ToFunc()
}
// ByName orders the results by the name field.
func ByName(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldName, opts...).ToFunc()
}
// ByBanner orders the results by the banner field.
func ByBanner(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldBanner, opts...).ToFunc()
}
// ByDescription orders the results by the description field.
func ByDescription(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDescription, opts...).ToFunc()
}
// ByRating orders the results by the rating field.
func ByRating(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldRating, opts...).ToFunc()
}
// ByTotalOrders orders the results by the total_orders field.
func ByTotalOrders(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldTotalOrders, opts...).ToFunc()
}
// ByPlayerCount orders the results by the player_count field.
func ByPlayerCount(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldPlayerCount, opts...).ToFunc()
}
// ByCommissionType orders the results by the commission_type field.
func ByCommissionType(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCommissionType, opts...).ToFunc()
}
// ByCommissionValue orders the results by the commission_value field.
func ByCommissionValue(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCommissionValue, opts...).ToFunc()
}
// ByAllowMultiShop orders the results by the allow_multi_shop field.
func ByAllowMultiShop(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAllowMultiShop, opts...).ToFunc()
}
// ByAllowIndependentOrders orders the results by the allow_independent_orders field.
func ByAllowIndependentOrders(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAllowIndependentOrders, opts...).ToFunc()
}
// ByDispatchMode orders the results by the dispatch_mode field.
func ByDispatchMode(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDispatchMode, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
+856
View File
@@ -0,0 +1,856 @@
// Code generated by ent, DO NOT EDIT.
package shops
import (
"juwan-backend/app/shop/rpc/internal/models/predicate"
"time"
"entgo.io/ent/dialect/sql"
"github.com/shopspring/decimal"
)
// ID filters vertices based on their ID field.
func ID(id int64) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldID, id))
}
// IDEQ applies the EQ predicate on the ID field.
func IDEQ(id int64) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldID, id))
}
// IDNEQ applies the NEQ predicate on the ID field.
func IDNEQ(id int64) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldID, id))
}
// IDIn applies the In predicate on the ID field.
func IDIn(ids ...int64) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldID, ids...))
}
// IDNotIn applies the NotIn predicate on the ID field.
func IDNotIn(ids ...int64) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldID, ids...))
}
// IDGT applies the GT predicate on the ID field.
func IDGT(id int64) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldID, id))
}
// IDGTE applies the GTE predicate on the ID field.
func IDGTE(id int64) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldID, id))
}
// IDLT applies the LT predicate on the ID field.
func IDLT(id int64) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldID, id))
}
// IDLTE applies the LTE predicate on the ID field.
func IDLTE(id int64) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldID, id))
}
// OwnerID applies equality check predicate on the "owner_id" field. It's identical to OwnerIDEQ.
func OwnerID(v int64) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldOwnerID, v))
}
// Name applies equality check predicate on the "name" field. It's identical to NameEQ.
func Name(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldName, v))
}
// Banner applies equality check predicate on the "banner" field. It's identical to BannerEQ.
func Banner(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldBanner, v))
}
// Description applies equality check predicate on the "description" field. It's identical to DescriptionEQ.
func Description(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldDescription, v))
}
// Rating applies equality check predicate on the "rating" field. It's identical to RatingEQ.
func Rating(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldRating, v))
}
// TotalOrders applies equality check predicate on the "total_orders" field. It's identical to TotalOrdersEQ.
func TotalOrders(v int) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldTotalOrders, v))
}
// PlayerCount applies equality check predicate on the "player_count" field. It's identical to PlayerCountEQ.
func PlayerCount(v int) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldPlayerCount, v))
}
// CommissionType applies equality check predicate on the "commission_type" field. It's identical to CommissionTypeEQ.
func CommissionType(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldCommissionType, v))
}
// CommissionValue applies equality check predicate on the "commission_value" field. It's identical to CommissionValueEQ.
func CommissionValue(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldCommissionValue, v))
}
// AllowMultiShop applies equality check predicate on the "allow_multi_shop" field. It's identical to AllowMultiShopEQ.
func AllowMultiShop(v bool) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldAllowMultiShop, v))
}
// AllowIndependentOrders applies equality check predicate on the "allow_independent_orders" field. It's identical to AllowIndependentOrdersEQ.
func AllowIndependentOrders(v bool) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldAllowIndependentOrders, v))
}
// DispatchMode applies equality check predicate on the "dispatch_mode" field. It's identical to DispatchModeEQ.
func DispatchMode(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldDispatchMode, v))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func CreatedAt(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldCreatedAt, v))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func UpdatedAt(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldUpdatedAt, v))
}
// OwnerIDEQ applies the EQ predicate on the "owner_id" field.
func OwnerIDEQ(v int64) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldOwnerID, v))
}
// OwnerIDNEQ applies the NEQ predicate on the "owner_id" field.
func OwnerIDNEQ(v int64) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldOwnerID, v))
}
// OwnerIDIn applies the In predicate on the "owner_id" field.
func OwnerIDIn(vs ...int64) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldOwnerID, vs...))
}
// OwnerIDNotIn applies the NotIn predicate on the "owner_id" field.
func OwnerIDNotIn(vs ...int64) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldOwnerID, vs...))
}
// OwnerIDGT applies the GT predicate on the "owner_id" field.
func OwnerIDGT(v int64) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldOwnerID, v))
}
// OwnerIDGTE applies the GTE predicate on the "owner_id" field.
func OwnerIDGTE(v int64) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldOwnerID, v))
}
// OwnerIDLT applies the LT predicate on the "owner_id" field.
func OwnerIDLT(v int64) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldOwnerID, v))
}
// OwnerIDLTE applies the LTE predicate on the "owner_id" field.
func OwnerIDLTE(v int64) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldOwnerID, v))
}
// NameEQ applies the EQ predicate on the "name" field.
func NameEQ(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldName, v))
}
// NameNEQ applies the NEQ predicate on the "name" field.
func NameNEQ(v string) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldName, v))
}
// NameIn applies the In predicate on the "name" field.
func NameIn(vs ...string) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldName, vs...))
}
// NameNotIn applies the NotIn predicate on the "name" field.
func NameNotIn(vs ...string) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldName, vs...))
}
// NameGT applies the GT predicate on the "name" field.
func NameGT(v string) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldName, v))
}
// NameGTE applies the GTE predicate on the "name" field.
func NameGTE(v string) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldName, v))
}
// NameLT applies the LT predicate on the "name" field.
func NameLT(v string) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldName, v))
}
// NameLTE applies the LTE predicate on the "name" field.
func NameLTE(v string) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldName, v))
}
// NameContains applies the Contains predicate on the "name" field.
func NameContains(v string) predicate.Shops {
return predicate.Shops(sql.FieldContains(FieldName, v))
}
// NameHasPrefix applies the HasPrefix predicate on the "name" field.
func NameHasPrefix(v string) predicate.Shops {
return predicate.Shops(sql.FieldHasPrefix(FieldName, v))
}
// NameHasSuffix applies the HasSuffix predicate on the "name" field.
func NameHasSuffix(v string) predicate.Shops {
return predicate.Shops(sql.FieldHasSuffix(FieldName, v))
}
// NameEqualFold applies the EqualFold predicate on the "name" field.
func NameEqualFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldEqualFold(FieldName, v))
}
// NameContainsFold applies the ContainsFold predicate on the "name" field.
func NameContainsFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldContainsFold(FieldName, v))
}
// BannerEQ applies the EQ predicate on the "banner" field.
func BannerEQ(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldBanner, v))
}
// BannerNEQ applies the NEQ predicate on the "banner" field.
func BannerNEQ(v string) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldBanner, v))
}
// BannerIn applies the In predicate on the "banner" field.
func BannerIn(vs ...string) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldBanner, vs...))
}
// BannerNotIn applies the NotIn predicate on the "banner" field.
func BannerNotIn(vs ...string) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldBanner, vs...))
}
// BannerGT applies the GT predicate on the "banner" field.
func BannerGT(v string) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldBanner, v))
}
// BannerGTE applies the GTE predicate on the "banner" field.
func BannerGTE(v string) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldBanner, v))
}
// BannerLT applies the LT predicate on the "banner" field.
func BannerLT(v string) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldBanner, v))
}
// BannerLTE applies the LTE predicate on the "banner" field.
func BannerLTE(v string) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldBanner, v))
}
// BannerContains applies the Contains predicate on the "banner" field.
func BannerContains(v string) predicate.Shops {
return predicate.Shops(sql.FieldContains(FieldBanner, v))
}
// BannerHasPrefix applies the HasPrefix predicate on the "banner" field.
func BannerHasPrefix(v string) predicate.Shops {
return predicate.Shops(sql.FieldHasPrefix(FieldBanner, v))
}
// BannerHasSuffix applies the HasSuffix predicate on the "banner" field.
func BannerHasSuffix(v string) predicate.Shops {
return predicate.Shops(sql.FieldHasSuffix(FieldBanner, v))
}
// BannerIsNil applies the IsNil predicate on the "banner" field.
func BannerIsNil() predicate.Shops {
return predicate.Shops(sql.FieldIsNull(FieldBanner))
}
// BannerNotNil applies the NotNil predicate on the "banner" field.
func BannerNotNil() predicate.Shops {
return predicate.Shops(sql.FieldNotNull(FieldBanner))
}
// BannerEqualFold applies the EqualFold predicate on the "banner" field.
func BannerEqualFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldEqualFold(FieldBanner, v))
}
// BannerContainsFold applies the ContainsFold predicate on the "banner" field.
func BannerContainsFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldContainsFold(FieldBanner, v))
}
// DescriptionEQ applies the EQ predicate on the "description" field.
func DescriptionEQ(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldDescription, v))
}
// DescriptionNEQ applies the NEQ predicate on the "description" field.
func DescriptionNEQ(v string) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldDescription, v))
}
// DescriptionIn applies the In predicate on the "description" field.
func DescriptionIn(vs ...string) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldDescription, vs...))
}
// DescriptionNotIn applies the NotIn predicate on the "description" field.
func DescriptionNotIn(vs ...string) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldDescription, vs...))
}
// DescriptionGT applies the GT predicate on the "description" field.
func DescriptionGT(v string) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldDescription, v))
}
// DescriptionGTE applies the GTE predicate on the "description" field.
func DescriptionGTE(v string) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldDescription, v))
}
// DescriptionLT applies the LT predicate on the "description" field.
func DescriptionLT(v string) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldDescription, v))
}
// DescriptionLTE applies the LTE predicate on the "description" field.
func DescriptionLTE(v string) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldDescription, v))
}
// DescriptionContains applies the Contains predicate on the "description" field.
func DescriptionContains(v string) predicate.Shops {
return predicate.Shops(sql.FieldContains(FieldDescription, v))
}
// DescriptionHasPrefix applies the HasPrefix predicate on the "description" field.
func DescriptionHasPrefix(v string) predicate.Shops {
return predicate.Shops(sql.FieldHasPrefix(FieldDescription, v))
}
// DescriptionHasSuffix applies the HasSuffix predicate on the "description" field.
func DescriptionHasSuffix(v string) predicate.Shops {
return predicate.Shops(sql.FieldHasSuffix(FieldDescription, v))
}
// DescriptionIsNil applies the IsNil predicate on the "description" field.
func DescriptionIsNil() predicate.Shops {
return predicate.Shops(sql.FieldIsNull(FieldDescription))
}
// DescriptionNotNil applies the NotNil predicate on the "description" field.
func DescriptionNotNil() predicate.Shops {
return predicate.Shops(sql.FieldNotNull(FieldDescription))
}
// DescriptionEqualFold applies the EqualFold predicate on the "description" field.
func DescriptionEqualFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldEqualFold(FieldDescription, v))
}
// DescriptionContainsFold applies the ContainsFold predicate on the "description" field.
func DescriptionContainsFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldContainsFold(FieldDescription, v))
}
// RatingEQ applies the EQ predicate on the "rating" field.
func RatingEQ(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldRating, v))
}
// RatingNEQ applies the NEQ predicate on the "rating" field.
func RatingNEQ(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldRating, v))
}
// RatingIn applies the In predicate on the "rating" field.
func RatingIn(vs ...decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldRating, vs...))
}
// RatingNotIn applies the NotIn predicate on the "rating" field.
func RatingNotIn(vs ...decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldRating, vs...))
}
// RatingGT applies the GT predicate on the "rating" field.
func RatingGT(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldRating, v))
}
// RatingGTE applies the GTE predicate on the "rating" field.
func RatingGTE(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldRating, v))
}
// RatingLT applies the LT predicate on the "rating" field.
func RatingLT(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldRating, v))
}
// RatingLTE applies the LTE predicate on the "rating" field.
func RatingLTE(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldRating, v))
}
// RatingIsNil applies the IsNil predicate on the "rating" field.
func RatingIsNil() predicate.Shops {
return predicate.Shops(sql.FieldIsNull(FieldRating))
}
// RatingNotNil applies the NotNil predicate on the "rating" field.
func RatingNotNil() predicate.Shops {
return predicate.Shops(sql.FieldNotNull(FieldRating))
}
// TotalOrdersEQ applies the EQ predicate on the "total_orders" field.
func TotalOrdersEQ(v int) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldTotalOrders, v))
}
// TotalOrdersNEQ applies the NEQ predicate on the "total_orders" field.
func TotalOrdersNEQ(v int) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldTotalOrders, v))
}
// TotalOrdersIn applies the In predicate on the "total_orders" field.
func TotalOrdersIn(vs ...int) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldTotalOrders, vs...))
}
// TotalOrdersNotIn applies the NotIn predicate on the "total_orders" field.
func TotalOrdersNotIn(vs ...int) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldTotalOrders, vs...))
}
// TotalOrdersGT applies the GT predicate on the "total_orders" field.
func TotalOrdersGT(v int) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldTotalOrders, v))
}
// TotalOrdersGTE applies the GTE predicate on the "total_orders" field.
func TotalOrdersGTE(v int) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldTotalOrders, v))
}
// TotalOrdersLT applies the LT predicate on the "total_orders" field.
func TotalOrdersLT(v int) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldTotalOrders, v))
}
// TotalOrdersLTE applies the LTE predicate on the "total_orders" field.
func TotalOrdersLTE(v int) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldTotalOrders, v))
}
// TotalOrdersIsNil applies the IsNil predicate on the "total_orders" field.
func TotalOrdersIsNil() predicate.Shops {
return predicate.Shops(sql.FieldIsNull(FieldTotalOrders))
}
// TotalOrdersNotNil applies the NotNil predicate on the "total_orders" field.
func TotalOrdersNotNil() predicate.Shops {
return predicate.Shops(sql.FieldNotNull(FieldTotalOrders))
}
// PlayerCountEQ applies the EQ predicate on the "player_count" field.
func PlayerCountEQ(v int) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldPlayerCount, v))
}
// PlayerCountNEQ applies the NEQ predicate on the "player_count" field.
func PlayerCountNEQ(v int) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldPlayerCount, v))
}
// PlayerCountIn applies the In predicate on the "player_count" field.
func PlayerCountIn(vs ...int) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldPlayerCount, vs...))
}
// PlayerCountNotIn applies the NotIn predicate on the "player_count" field.
func PlayerCountNotIn(vs ...int) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldPlayerCount, vs...))
}
// PlayerCountGT applies the GT predicate on the "player_count" field.
func PlayerCountGT(v int) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldPlayerCount, v))
}
// PlayerCountGTE applies the GTE predicate on the "player_count" field.
func PlayerCountGTE(v int) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldPlayerCount, v))
}
// PlayerCountLT applies the LT predicate on the "player_count" field.
func PlayerCountLT(v int) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldPlayerCount, v))
}
// PlayerCountLTE applies the LTE predicate on the "player_count" field.
func PlayerCountLTE(v int) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldPlayerCount, v))
}
// PlayerCountIsNil applies the IsNil predicate on the "player_count" field.
func PlayerCountIsNil() predicate.Shops {
return predicate.Shops(sql.FieldIsNull(FieldPlayerCount))
}
// PlayerCountNotNil applies the NotNil predicate on the "player_count" field.
func PlayerCountNotNil() predicate.Shops {
return predicate.Shops(sql.FieldNotNull(FieldPlayerCount))
}
// CommissionTypeEQ applies the EQ predicate on the "commission_type" field.
func CommissionTypeEQ(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldCommissionType, v))
}
// CommissionTypeNEQ applies the NEQ predicate on the "commission_type" field.
func CommissionTypeNEQ(v string) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldCommissionType, v))
}
// CommissionTypeIn applies the In predicate on the "commission_type" field.
func CommissionTypeIn(vs ...string) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldCommissionType, vs...))
}
// CommissionTypeNotIn applies the NotIn predicate on the "commission_type" field.
func CommissionTypeNotIn(vs ...string) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldCommissionType, vs...))
}
// CommissionTypeGT applies the GT predicate on the "commission_type" field.
func CommissionTypeGT(v string) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldCommissionType, v))
}
// CommissionTypeGTE applies the GTE predicate on the "commission_type" field.
func CommissionTypeGTE(v string) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldCommissionType, v))
}
// CommissionTypeLT applies the LT predicate on the "commission_type" field.
func CommissionTypeLT(v string) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldCommissionType, v))
}
// CommissionTypeLTE applies the LTE predicate on the "commission_type" field.
func CommissionTypeLTE(v string) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldCommissionType, v))
}
// CommissionTypeContains applies the Contains predicate on the "commission_type" field.
func CommissionTypeContains(v string) predicate.Shops {
return predicate.Shops(sql.FieldContains(FieldCommissionType, v))
}
// CommissionTypeHasPrefix applies the HasPrefix predicate on the "commission_type" field.
func CommissionTypeHasPrefix(v string) predicate.Shops {
return predicate.Shops(sql.FieldHasPrefix(FieldCommissionType, v))
}
// CommissionTypeHasSuffix applies the HasSuffix predicate on the "commission_type" field.
func CommissionTypeHasSuffix(v string) predicate.Shops {
return predicate.Shops(sql.FieldHasSuffix(FieldCommissionType, v))
}
// CommissionTypeEqualFold applies the EqualFold predicate on the "commission_type" field.
func CommissionTypeEqualFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldEqualFold(FieldCommissionType, v))
}
// CommissionTypeContainsFold applies the ContainsFold predicate on the "commission_type" field.
func CommissionTypeContainsFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldContainsFold(FieldCommissionType, v))
}
// CommissionValueEQ applies the EQ predicate on the "commission_value" field.
func CommissionValueEQ(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldCommissionValue, v))
}
// CommissionValueNEQ applies the NEQ predicate on the "commission_value" field.
func CommissionValueNEQ(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldCommissionValue, v))
}
// CommissionValueIn applies the In predicate on the "commission_value" field.
func CommissionValueIn(vs ...decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldCommissionValue, vs...))
}
// CommissionValueNotIn applies the NotIn predicate on the "commission_value" field.
func CommissionValueNotIn(vs ...decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldCommissionValue, vs...))
}
// CommissionValueGT applies the GT predicate on the "commission_value" field.
func CommissionValueGT(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldCommissionValue, v))
}
// CommissionValueGTE applies the GTE predicate on the "commission_value" field.
func CommissionValueGTE(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldCommissionValue, v))
}
// CommissionValueLT applies the LT predicate on the "commission_value" field.
func CommissionValueLT(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldCommissionValue, v))
}
// CommissionValueLTE applies the LTE predicate on the "commission_value" field.
func CommissionValueLTE(v decimal.Decimal) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldCommissionValue, v))
}
// AllowMultiShopEQ applies the EQ predicate on the "allow_multi_shop" field.
func AllowMultiShopEQ(v bool) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldAllowMultiShop, v))
}
// AllowMultiShopNEQ applies the NEQ predicate on the "allow_multi_shop" field.
func AllowMultiShopNEQ(v bool) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldAllowMultiShop, v))
}
// AllowMultiShopIsNil applies the IsNil predicate on the "allow_multi_shop" field.
func AllowMultiShopIsNil() predicate.Shops {
return predicate.Shops(sql.FieldIsNull(FieldAllowMultiShop))
}
// AllowMultiShopNotNil applies the NotNil predicate on the "allow_multi_shop" field.
func AllowMultiShopNotNil() predicate.Shops {
return predicate.Shops(sql.FieldNotNull(FieldAllowMultiShop))
}
// AllowIndependentOrdersEQ applies the EQ predicate on the "allow_independent_orders" field.
func AllowIndependentOrdersEQ(v bool) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldAllowIndependentOrders, v))
}
// AllowIndependentOrdersNEQ applies the NEQ predicate on the "allow_independent_orders" field.
func AllowIndependentOrdersNEQ(v bool) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldAllowIndependentOrders, v))
}
// AllowIndependentOrdersIsNil applies the IsNil predicate on the "allow_independent_orders" field.
func AllowIndependentOrdersIsNil() predicate.Shops {
return predicate.Shops(sql.FieldIsNull(FieldAllowIndependentOrders))
}
// AllowIndependentOrdersNotNil applies the NotNil predicate on the "allow_independent_orders" field.
func AllowIndependentOrdersNotNil() predicate.Shops {
return predicate.Shops(sql.FieldNotNull(FieldAllowIndependentOrders))
}
// DispatchModeEQ applies the EQ predicate on the "dispatch_mode" field.
func DispatchModeEQ(v string) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldDispatchMode, v))
}
// DispatchModeNEQ applies the NEQ predicate on the "dispatch_mode" field.
func DispatchModeNEQ(v string) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldDispatchMode, v))
}
// DispatchModeIn applies the In predicate on the "dispatch_mode" field.
func DispatchModeIn(vs ...string) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldDispatchMode, vs...))
}
// DispatchModeNotIn applies the NotIn predicate on the "dispatch_mode" field.
func DispatchModeNotIn(vs ...string) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldDispatchMode, vs...))
}
// DispatchModeGT applies the GT predicate on the "dispatch_mode" field.
func DispatchModeGT(v string) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldDispatchMode, v))
}
// DispatchModeGTE applies the GTE predicate on the "dispatch_mode" field.
func DispatchModeGTE(v string) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldDispatchMode, v))
}
// DispatchModeLT applies the LT predicate on the "dispatch_mode" field.
func DispatchModeLT(v string) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldDispatchMode, v))
}
// DispatchModeLTE applies the LTE predicate on the "dispatch_mode" field.
func DispatchModeLTE(v string) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldDispatchMode, v))
}
// DispatchModeContains applies the Contains predicate on the "dispatch_mode" field.
func DispatchModeContains(v string) predicate.Shops {
return predicate.Shops(sql.FieldContains(FieldDispatchMode, v))
}
// DispatchModeHasPrefix applies the HasPrefix predicate on the "dispatch_mode" field.
func DispatchModeHasPrefix(v string) predicate.Shops {
return predicate.Shops(sql.FieldHasPrefix(FieldDispatchMode, v))
}
// DispatchModeHasSuffix applies the HasSuffix predicate on the "dispatch_mode" field.
func DispatchModeHasSuffix(v string) predicate.Shops {
return predicate.Shops(sql.FieldHasSuffix(FieldDispatchMode, v))
}
// DispatchModeEqualFold applies the EqualFold predicate on the "dispatch_mode" field.
func DispatchModeEqualFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldEqualFold(FieldDispatchMode, v))
}
// DispatchModeContainsFold applies the ContainsFold predicate on the "dispatch_mode" field.
func DispatchModeContainsFold(v string) predicate.Shops {
return predicate.Shops(sql.FieldContainsFold(FieldDispatchMode, v))
}
// AnnouncementsIsNil applies the IsNil predicate on the "announcements" field.
func AnnouncementsIsNil() predicate.Shops {
return predicate.Shops(sql.FieldIsNull(FieldAnnouncements))
}
// AnnouncementsNotNil applies the NotNil predicate on the "announcements" field.
func AnnouncementsNotNil() predicate.Shops {
return predicate.Shops(sql.FieldNotNull(FieldAnnouncements))
}
// TemplateConfigIsNil applies the IsNil predicate on the "template_config" field.
func TemplateConfigIsNil() predicate.Shops {
return predicate.Shops(sql.FieldIsNull(FieldTemplateConfig))
}
// TemplateConfigNotNil applies the NotNil predicate on the "template_config" field.
func TemplateConfigNotNil() predicate.Shops {
return predicate.Shops(sql.FieldNotNull(FieldTemplateConfig))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func CreatedAtEQ(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldCreatedAt, v))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func CreatedAtNEQ(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldCreatedAt, v))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func CreatedAtIn(vs ...time.Time) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldCreatedAt, vs...))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func CreatedAtNotIn(vs ...time.Time) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldCreatedAt, vs...))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func CreatedAtGT(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldCreatedAt, v))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func CreatedAtGTE(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldCreatedAt, v))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func CreatedAtLT(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldCreatedAt, v))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func CreatedAtLTE(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldCreatedAt, v))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func UpdatedAtEQ(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldEQ(FieldUpdatedAt, v))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func UpdatedAtNEQ(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldNEQ(FieldUpdatedAt, v))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func UpdatedAtIn(vs ...time.Time) predicate.Shops {
return predicate.Shops(sql.FieldIn(FieldUpdatedAt, vs...))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func UpdatedAtNotIn(vs ...time.Time) predicate.Shops {
return predicate.Shops(sql.FieldNotIn(FieldUpdatedAt, vs...))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func UpdatedAtGT(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldGT(FieldUpdatedAt, v))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func UpdatedAtGTE(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldGTE(FieldUpdatedAt, v))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func UpdatedAtLT(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldLT(FieldUpdatedAt, v))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func UpdatedAtLTE(v time.Time) predicate.Shops {
return predicate.Shops(sql.FieldLTE(FieldUpdatedAt, v))
}
// And groups predicates with the AND operator between them.
func And(predicates ...predicate.Shops) predicate.Shops {
return predicate.Shops(sql.AndPredicates(predicates...))
}
// Or groups predicates with the OR operator between them.
func Or(predicates ...predicate.Shops) predicate.Shops {
return predicate.Shops(sql.OrPredicates(predicates...))
}
// Not applies the not operator on the given predicate.
func Not(p predicate.Shops) predicate.Shops {
return predicate.Shops(sql.NotPredicates(p))
}
@@ -0,0 +1,514 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/shops"
"time"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/shopspring/decimal"
)
// ShopsCreate is the builder for creating a Shops entity.
type ShopsCreate struct {
config
mutation *ShopsMutation
hooks []Hook
}
// SetOwnerID sets the "owner_id" field.
func (_c *ShopsCreate) SetOwnerID(v int64) *ShopsCreate {
_c.mutation.SetOwnerID(v)
return _c
}
// SetName sets the "name" field.
func (_c *ShopsCreate) SetName(v string) *ShopsCreate {
_c.mutation.SetName(v)
return _c
}
// SetBanner sets the "banner" field.
func (_c *ShopsCreate) SetBanner(v string) *ShopsCreate {
_c.mutation.SetBanner(v)
return _c
}
// SetNillableBanner sets the "banner" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableBanner(v *string) *ShopsCreate {
if v != nil {
_c.SetBanner(*v)
}
return _c
}
// SetDescription sets the "description" field.
func (_c *ShopsCreate) SetDescription(v string) *ShopsCreate {
_c.mutation.SetDescription(v)
return _c
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableDescription(v *string) *ShopsCreate {
if v != nil {
_c.SetDescription(*v)
}
return _c
}
// SetRating sets the "rating" field.
func (_c *ShopsCreate) SetRating(v decimal.Decimal) *ShopsCreate {
_c.mutation.SetRating(v)
return _c
}
// SetNillableRating sets the "rating" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableRating(v *decimal.Decimal) *ShopsCreate {
if v != nil {
_c.SetRating(*v)
}
return _c
}
// SetTotalOrders sets the "total_orders" field.
func (_c *ShopsCreate) SetTotalOrders(v int) *ShopsCreate {
_c.mutation.SetTotalOrders(v)
return _c
}
// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableTotalOrders(v *int) *ShopsCreate {
if v != nil {
_c.SetTotalOrders(*v)
}
return _c
}
// SetPlayerCount sets the "player_count" field.
func (_c *ShopsCreate) SetPlayerCount(v int) *ShopsCreate {
_c.mutation.SetPlayerCount(v)
return _c
}
// SetNillablePlayerCount sets the "player_count" field if the given value is not nil.
func (_c *ShopsCreate) SetNillablePlayerCount(v *int) *ShopsCreate {
if v != nil {
_c.SetPlayerCount(*v)
}
return _c
}
// SetCommissionType sets the "commission_type" field.
func (_c *ShopsCreate) SetCommissionType(v string) *ShopsCreate {
_c.mutation.SetCommissionType(v)
return _c
}
// SetNillableCommissionType sets the "commission_type" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableCommissionType(v *string) *ShopsCreate {
if v != nil {
_c.SetCommissionType(*v)
}
return _c
}
// SetCommissionValue sets the "commission_value" field.
func (_c *ShopsCreate) SetCommissionValue(v decimal.Decimal) *ShopsCreate {
_c.mutation.SetCommissionValue(v)
return _c
}
// SetAllowMultiShop sets the "allow_multi_shop" field.
func (_c *ShopsCreate) SetAllowMultiShop(v bool) *ShopsCreate {
_c.mutation.SetAllowMultiShop(v)
return _c
}
// SetNillableAllowMultiShop sets the "allow_multi_shop" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableAllowMultiShop(v *bool) *ShopsCreate {
if v != nil {
_c.SetAllowMultiShop(*v)
}
return _c
}
// SetAllowIndependentOrders sets the "allow_independent_orders" field.
func (_c *ShopsCreate) SetAllowIndependentOrders(v bool) *ShopsCreate {
_c.mutation.SetAllowIndependentOrders(v)
return _c
}
// SetNillableAllowIndependentOrders sets the "allow_independent_orders" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableAllowIndependentOrders(v *bool) *ShopsCreate {
if v != nil {
_c.SetAllowIndependentOrders(*v)
}
return _c
}
// SetDispatchMode sets the "dispatch_mode" field.
func (_c *ShopsCreate) SetDispatchMode(v string) *ShopsCreate {
_c.mutation.SetDispatchMode(v)
return _c
}
// SetNillableDispatchMode sets the "dispatch_mode" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableDispatchMode(v *string) *ShopsCreate {
if v != nil {
_c.SetDispatchMode(*v)
}
return _c
}
// SetAnnouncements sets the "announcements" field.
func (_c *ShopsCreate) SetAnnouncements(v []string) *ShopsCreate {
_c.mutation.SetAnnouncements(v)
return _c
}
// SetTemplateConfig sets the "template_config" field.
func (_c *ShopsCreate) SetTemplateConfig(v map[string]interface{}) *ShopsCreate {
_c.mutation.SetTemplateConfig(v)
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *ShopsCreate) SetCreatedAt(v time.Time) *ShopsCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableCreatedAt(v *time.Time) *ShopsCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *ShopsCreate) SetUpdatedAt(v time.Time) *ShopsCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *ShopsCreate) SetNillableUpdatedAt(v *time.Time) *ShopsCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// SetID sets the "id" field.
func (_c *ShopsCreate) SetID(v int64) *ShopsCreate {
_c.mutation.SetID(v)
return _c
}
// Mutation returns the ShopsMutation object of the builder.
func (_c *ShopsCreate) Mutation() *ShopsMutation {
return _c.mutation
}
// Save creates the Shops in the database.
func (_c *ShopsCreate) Save(ctx context.Context) (*Shops, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *ShopsCreate) SaveX(ctx context.Context) *Shops {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ShopsCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ShopsCreate) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_c *ShopsCreate) defaults() {
if _, ok := _c.mutation.Rating(); !ok {
v := shops.DefaultRating
_c.mutation.SetRating(v)
}
if _, ok := _c.mutation.TotalOrders(); !ok {
v := shops.DefaultTotalOrders
_c.mutation.SetTotalOrders(v)
}
if _, ok := _c.mutation.PlayerCount(); !ok {
v := shops.DefaultPlayerCount
_c.mutation.SetPlayerCount(v)
}
if _, ok := _c.mutation.CommissionType(); !ok {
v := shops.DefaultCommissionType
_c.mutation.SetCommissionType(v)
}
if _, ok := _c.mutation.AllowMultiShop(); !ok {
v := shops.DefaultAllowMultiShop
_c.mutation.SetAllowMultiShop(v)
}
if _, ok := _c.mutation.AllowIndependentOrders(); !ok {
v := shops.DefaultAllowIndependentOrders
_c.mutation.SetAllowIndependentOrders(v)
}
if _, ok := _c.mutation.DispatchMode(); !ok {
v := shops.DefaultDispatchMode
_c.mutation.SetDispatchMode(v)
}
if _, ok := _c.mutation.Announcements(); !ok {
v := shops.DefaultAnnouncements
_c.mutation.SetAnnouncements(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := shops.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := shops.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *ShopsCreate) check() error {
if _, ok := _c.mutation.OwnerID(); !ok {
return &ValidationError{Name: "owner_id", err: errors.New(`models: missing required field "Shops.owner_id"`)}
}
if _, ok := _c.mutation.Name(); !ok {
return &ValidationError{Name: "name", err: errors.New(`models: missing required field "Shops.name"`)}
}
if v, ok := _c.mutation.Name(); ok {
if err := shops.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Shops.name": %w`, err)}
}
}
if _, ok := _c.mutation.CommissionType(); !ok {
return &ValidationError{Name: "commission_type", err: errors.New(`models: missing required field "Shops.commission_type"`)}
}
if v, ok := _c.mutation.CommissionType(); ok {
if err := shops.CommissionTypeValidator(v); err != nil {
return &ValidationError{Name: "commission_type", err: fmt.Errorf(`models: validator failed for field "Shops.commission_type": %w`, err)}
}
}
if _, ok := _c.mutation.CommissionValue(); !ok {
return &ValidationError{Name: "commission_value", err: errors.New(`models: missing required field "Shops.commission_value"`)}
}
if _, ok := _c.mutation.DispatchMode(); !ok {
return &ValidationError{Name: "dispatch_mode", err: errors.New(`models: missing required field "Shops.dispatch_mode"`)}
}
if v, ok := _c.mutation.DispatchMode(); ok {
if err := shops.DispatchModeValidator(v); err != nil {
return &ValidationError{Name: "dispatch_mode", err: fmt.Errorf(`models: validator failed for field "Shops.dispatch_mode": %w`, err)}
}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`models: missing required field "Shops.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`models: missing required field "Shops.updated_at"`)}
}
return nil
}
func (_c *ShopsCreate) sqlSave(ctx context.Context) (*Shops, error) {
if err := _c.check(); err != nil {
return nil, err
}
_node, _spec := _c.createSpec()
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
if _spec.ID.Value != _node.ID {
id := _spec.ID.Value.(int64)
_node.ID = int64(id)
}
_c.mutation.id = &_node.ID
_c.mutation.done = true
return _node, nil
}
func (_c *ShopsCreate) createSpec() (*Shops, *sqlgraph.CreateSpec) {
var (
_node = &Shops{config: _c.config}
_spec = sqlgraph.NewCreateSpec(shops.Table, sqlgraph.NewFieldSpec(shops.FieldID, field.TypeInt64))
)
if id, ok := _c.mutation.ID(); ok {
_node.ID = id
_spec.ID.Value = id
}
if value, ok := _c.mutation.OwnerID(); ok {
_spec.SetField(shops.FieldOwnerID, field.TypeInt64, value)
_node.OwnerID = value
}
if value, ok := _c.mutation.Name(); ok {
_spec.SetField(shops.FieldName, field.TypeString, value)
_node.Name = value
}
if value, ok := _c.mutation.Banner(); ok {
_spec.SetField(shops.FieldBanner, field.TypeString, value)
_node.Banner = &value
}
if value, ok := _c.mutation.Description(); ok {
_spec.SetField(shops.FieldDescription, field.TypeString, value)
_node.Description = &value
}
if value, ok := _c.mutation.Rating(); ok {
_spec.SetField(shops.FieldRating, field.TypeOther, value)
_node.Rating = value
}
if value, ok := _c.mutation.TotalOrders(); ok {
_spec.SetField(shops.FieldTotalOrders, field.TypeInt, value)
_node.TotalOrders = value
}
if value, ok := _c.mutation.PlayerCount(); ok {
_spec.SetField(shops.FieldPlayerCount, field.TypeInt, value)
_node.PlayerCount = value
}
if value, ok := _c.mutation.CommissionType(); ok {
_spec.SetField(shops.FieldCommissionType, field.TypeString, value)
_node.CommissionType = value
}
if value, ok := _c.mutation.CommissionValue(); ok {
_spec.SetField(shops.FieldCommissionValue, field.TypeOther, value)
_node.CommissionValue = value
}
if value, ok := _c.mutation.AllowMultiShop(); ok {
_spec.SetField(shops.FieldAllowMultiShop, field.TypeBool, value)
_node.AllowMultiShop = value
}
if value, ok := _c.mutation.AllowIndependentOrders(); ok {
_spec.SetField(shops.FieldAllowIndependentOrders, field.TypeBool, value)
_node.AllowIndependentOrders = value
}
if value, ok := _c.mutation.DispatchMode(); ok {
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
_node.DispatchMode = value
}
if value, ok := _c.mutation.Announcements(); ok {
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
_node.Announcements = value
}
if value, ok := _c.mutation.TemplateConfig(); ok {
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
_node.TemplateConfig = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(shops.FieldCreatedAt, field.TypeTime, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(shops.FieldUpdatedAt, field.TypeTime, value)
_node.UpdatedAt = value
}
return _node, _spec
}
// ShopsCreateBulk is the builder for creating many Shops entities in bulk.
type ShopsCreateBulk struct {
config
err error
builders []*ShopsCreate
}
// Save creates the Shops entities in the database.
func (_c *ShopsCreateBulk) Save(ctx context.Context) ([]*Shops, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Shops, len(_c.builders))
mutators := make([]Mutator, len(_c.builders))
for i := range _c.builders {
func(i int, root context.Context) {
builder := _c.builders[i]
builder.defaults()
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
mutation, ok := m.(*ShopsMutation)
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, _c.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, _c.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 && nodes[i].ID == 0 {
id := specs[i].ID.Value.(int64)
nodes[i].ID = int64(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, _c.builders[0].mutation); err != nil {
return nil, err
}
}
return nodes, nil
}
// SaveX is like Save, but panics if an error occurs.
func (_c *ShopsCreateBulk) SaveX(ctx context.Context) []*Shops {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *ShopsCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *ShopsCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
@@ -0,0 +1,88 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/shops"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ShopsDelete is the builder for deleting a Shops entity.
type ShopsDelete struct {
config
hooks []Hook
mutation *ShopsMutation
}
// Where appends a list predicates to the ShopsDelete builder.
func (_d *ShopsDelete) Where(ps ...predicate.Shops) *ShopsDelete {
_d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func (_d *ShopsDelete) Exec(ctx context.Context) (int, error) {
return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks)
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ShopsDelete) ExecX(ctx context.Context) int {
n, err := _d.Exec(ctx)
if err != nil {
panic(err)
}
return n
}
func (_d *ShopsDelete) sqlExec(ctx context.Context) (int, error) {
_spec := sqlgraph.NewDeleteSpec(shops.Table, sqlgraph.NewFieldSpec(shops.FieldID, field.TypeInt64))
if ps := _d.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec)
if err != nil && sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
_d.mutation.done = true
return affected, err
}
// ShopsDeleteOne is the builder for deleting a single Shops entity.
type ShopsDeleteOne struct {
_d *ShopsDelete
}
// Where appends a list predicates to the ShopsDelete builder.
func (_d *ShopsDeleteOne) Where(ps ...predicate.Shops) *ShopsDeleteOne {
_d._d.mutation.Where(ps...)
return _d
}
// Exec executes the deletion query.
func (_d *ShopsDeleteOne) Exec(ctx context.Context) error {
n, err := _d._d.Exec(ctx)
switch {
case err != nil:
return err
case n == 0:
return &NotFoundError{shops.Label}
default:
return nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func (_d *ShopsDeleteOne) ExecX(ctx context.Context) {
if err := _d.Exec(ctx); err != nil {
panic(err)
}
}
+527
View File
@@ -0,0 +1,527 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/shops"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// ShopsQuery is the builder for querying Shops entities.
type ShopsQuery struct {
config
ctx *QueryContext
order []shops.OrderOption
inters []Interceptor
predicates []predicate.Shops
// intermediate query (i.e. traversal path).
sql *sql.Selector
path func(context.Context) (*sql.Selector, error)
}
// Where adds a new predicate for the ShopsQuery builder.
func (_q *ShopsQuery) Where(ps ...predicate.Shops) *ShopsQuery {
_q.predicates = append(_q.predicates, ps...)
return _q
}
// Limit the number of records to be returned by this query.
func (_q *ShopsQuery) Limit(limit int) *ShopsQuery {
_q.ctx.Limit = &limit
return _q
}
// Offset to start from.
func (_q *ShopsQuery) Offset(offset int) *ShopsQuery {
_q.ctx.Offset = &offset
return _q
}
// 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 (_q *ShopsQuery) Unique(unique bool) *ShopsQuery {
_q.ctx.Unique = &unique
return _q
}
// Order specifies how the records should be ordered.
func (_q *ShopsQuery) Order(o ...shops.OrderOption) *ShopsQuery {
_q.order = append(_q.order, o...)
return _q
}
// First returns the first Shops entity from the query.
// Returns a *NotFoundError when no Shops was found.
func (_q *ShopsQuery) First(ctx context.Context) (*Shops, error) {
nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst))
if err != nil {
return nil, err
}
if len(nodes) == 0 {
return nil, &NotFoundError{shops.Label}
}
return nodes[0], nil
}
// FirstX is like First, but panics if an error occurs.
func (_q *ShopsQuery) FirstX(ctx context.Context) *Shops {
node, err := _q.First(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return node
}
// FirstID returns the first Shops ID from the query.
// Returns a *NotFoundError when no Shops ID was found.
func (_q *ShopsQuery) FirstID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil {
return
}
if len(ids) == 0 {
err = &NotFoundError{shops.Label}
return
}
return ids[0], nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func (_q *ShopsQuery) FirstIDX(ctx context.Context) int64 {
id, err := _q.FirstID(ctx)
if err != nil && !IsNotFound(err) {
panic(err)
}
return id
}
// Only returns a single Shops entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one Shops entity is found.
// Returns a *NotFoundError when no Shops entities are found.
func (_q *ShopsQuery) Only(ctx context.Context) (*Shops, error) {
nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly))
if err != nil {
return nil, err
}
switch len(nodes) {
case 1:
return nodes[0], nil
case 0:
return nil, &NotFoundError{shops.Label}
default:
return nil, &NotSingularError{shops.Label}
}
}
// OnlyX is like Only, but panics if an error occurs.
func (_q *ShopsQuery) OnlyX(ctx context.Context) *Shops {
node, err := _q.Only(ctx)
if err != nil {
panic(err)
}
return node
}
// OnlyID is like Only, but returns the only Shops ID in the query.
// Returns a *NotSingularError when more than one Shops ID is found.
// Returns a *NotFoundError when no entities are found.
func (_q *ShopsQuery) OnlyID(ctx context.Context) (id int64, err error) {
var ids []int64
if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil {
return
}
switch len(ids) {
case 1:
id = ids[0]
case 0:
err = &NotFoundError{shops.Label}
default:
err = &NotSingularError{shops.Label}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func (_q *ShopsQuery) OnlyIDX(ctx context.Context) int64 {
id, err := _q.OnlyID(ctx)
if err != nil {
panic(err)
}
return id
}
// All executes the query and returns a list of ShopsSlice.
func (_q *ShopsQuery) All(ctx context.Context) ([]*Shops, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll)
if err := _q.prepareQuery(ctx); err != nil {
return nil, err
}
qr := querierAll[[]*Shops, *ShopsQuery]()
return withInterceptors[[]*Shops](ctx, _q, qr, _q.inters)
}
// AllX is like All, but panics if an error occurs.
func (_q *ShopsQuery) AllX(ctx context.Context) []*Shops {
nodes, err := _q.All(ctx)
if err != nil {
panic(err)
}
return nodes
}
// IDs executes the query and returns a list of Shops IDs.
func (_q *ShopsQuery) IDs(ctx context.Context) (ids []int64, err error) {
if _q.ctx.Unique == nil && _q.path != nil {
_q.Unique(true)
}
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs)
if err = _q.Select(shops.FieldID).Scan(ctx, &ids); err != nil {
return nil, err
}
return ids, nil
}
// IDsX is like IDs, but panics if an error occurs.
func (_q *ShopsQuery) IDsX(ctx context.Context) []int64 {
ids, err := _q.IDs(ctx)
if err != nil {
panic(err)
}
return ids
}
// Count returns the count of the given query.
func (_q *ShopsQuery) Count(ctx context.Context) (int, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount)
if err := _q.prepareQuery(ctx); err != nil {
return 0, err
}
return withInterceptors[int](ctx, _q, querierCount[*ShopsQuery](), _q.inters)
}
// CountX is like Count, but panics if an error occurs.
func (_q *ShopsQuery) CountX(ctx context.Context) int {
count, err := _q.Count(ctx)
if err != nil {
panic(err)
}
return count
}
// Exist returns true if the query has elements in the graph.
func (_q *ShopsQuery) Exist(ctx context.Context) (bool, error) {
ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist)
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
return false, fmt.Errorf("models: check existence: %w", err)
default:
return true, nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func (_q *ShopsQuery) ExistX(ctx context.Context) bool {
exist, err := _q.Exist(ctx)
if err != nil {
panic(err)
}
return exist
}
// Clone returns a duplicate of the ShopsQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func (_q *ShopsQuery) Clone() *ShopsQuery {
if _q == nil {
return nil
}
return &ShopsQuery{
config: _q.config,
ctx: _q.ctx.Clone(),
order: append([]shops.OrderOption{}, _q.order...),
inters: append([]Interceptor{}, _q.inters...),
predicates: append([]predicate.Shops{}, _q.predicates...),
// clone intermediate query.
sql: _q.sql.Clone(),
path: _q.path,
}
}
// 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 {
// OwnerID int64 `json:"owner_id,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.Shops.Query().
// GroupBy(shops.FieldOwnerID).
// Aggregate(models.Count()).
// Scan(ctx, &v)
func (_q *ShopsQuery) GroupBy(field string, fields ...string) *ShopsGroupBy {
_q.ctx.Fields = append([]string{field}, fields...)
grbuild := &ShopsGroupBy{build: _q}
grbuild.flds = &_q.ctx.Fields
grbuild.label = shops.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 {
// OwnerID int64 `json:"owner_id,omitempty"`
// }
//
// client.Shops.Query().
// Select(shops.FieldOwnerID).
// Scan(ctx, &v)
func (_q *ShopsQuery) Select(fields ...string) *ShopsSelect {
_q.ctx.Fields = append(_q.ctx.Fields, fields...)
sbuild := &ShopsSelect{ShopsQuery: _q}
sbuild.label = shops.Label
sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan
return sbuild
}
// Aggregate returns a ShopsSelect configured with the given aggregations.
func (_q *ShopsQuery) Aggregate(fns ...AggregateFunc) *ShopsSelect {
return _q.Select().Aggregate(fns...)
}
func (_q *ShopsQuery) prepareQuery(ctx context.Context) error {
for _, inter := range _q.inters {
if inter == nil {
return fmt.Errorf("models: uninitialized interceptor (forgotten import models/runtime?)")
}
if trv, ok := inter.(Traverser); ok {
if err := trv.Traverse(ctx, _q); err != nil {
return err
}
}
}
for _, f := range _q.ctx.Fields {
if !shops.ValidColumn(f) {
return &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
}
}
if _q.path != nil {
prev, err := _q.path(ctx)
if err != nil {
return err
}
_q.sql = prev
}
return nil
}
func (_q *ShopsQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Shops, error) {
var (
nodes = []*Shops{}
_spec = _q.querySpec()
)
_spec.ScanValues = func(columns []string) ([]any, error) {
return (*Shops).scanValues(nil, columns)
}
_spec.Assign = func(columns []string, values []any) error {
node := &Shops{config: _q.config}
nodes = append(nodes, node)
return node.assignValues(columns, values)
}
for i := range hooks {
hooks[i](ctx, _spec)
}
if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil {
return nil, err
}
if len(nodes) == 0 {
return nodes, nil
}
return nodes, nil
}
func (_q *ShopsQuery) sqlCount(ctx context.Context) (int, error) {
_spec := _q.querySpec()
_spec.Node.Columns = _q.ctx.Fields
if len(_q.ctx.Fields) > 0 {
_spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique
}
return sqlgraph.CountNodes(ctx, _q.driver, _spec)
}
func (_q *ShopsQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(shops.Table, shops.Columns, sqlgraph.NewFieldSpec(shops.FieldID, field.TypeInt64))
_spec.From = _q.sql
if unique := _q.ctx.Unique; unique != nil {
_spec.Unique = *unique
} else if _q.path != nil {
_spec.Unique = true
}
if fields := _q.ctx.Fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, shops.FieldID)
for i := range fields {
if fields[i] != shops.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := _q.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := _q.ctx.Limit; limit != nil {
_spec.Limit = *limit
}
if offset := _q.ctx.Offset; offset != nil {
_spec.Offset = *offset
}
if ps := _q.order; len(ps) > 0 {
_spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return _spec
}
func (_q *ShopsQuery) sqlQuery(ctx context.Context) *sql.Selector {
builder := sql.Dialect(_q.driver.Dialect())
t1 := builder.Table(shops.Table)
columns := _q.ctx.Fields
if len(columns) == 0 {
columns = shops.Columns
}
selector := builder.Select(t1.Columns(columns...)...).From(t1)
if _q.sql != nil {
selector = _q.sql
selector.Select(selector.Columns(columns...)...)
}
if _q.ctx.Unique != nil && *_q.ctx.Unique {
selector.Distinct()
}
for _, p := range _q.predicates {
p(selector)
}
for _, p := range _q.order {
p(selector)
}
if offset := _q.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 := _q.ctx.Limit; limit != nil {
selector.Limit(*limit)
}
return selector
}
// ShopsGroupBy is the group-by builder for Shops entities.
type ShopsGroupBy struct {
selector
build *ShopsQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func (_g *ShopsGroupBy) Aggregate(fns ...AggregateFunc) *ShopsGroupBy {
_g.fns = append(_g.fns, fns...)
return _g
}
// Scan applies the selector query and scans the result into the given value.
func (_g *ShopsGroupBy) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy)
if err := _g.build.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ShopsQuery, *ShopsGroupBy](ctx, _g.build, _g, _g.build.inters, v)
}
func (_g *ShopsGroupBy) sqlScan(ctx context.Context, root *ShopsQuery, v any) error {
selector := root.sqlQuery(ctx).Select()
aggregation := make([]string, 0, len(_g.fns))
for _, fn := range _g.fns {
aggregation = append(aggregation, fn(selector))
}
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(*_g.flds)+len(_g.fns))
for _, f := range *_g.flds {
columns = append(columns, selector.C(f))
}
columns = append(columns, aggregation...)
selector.Select(columns...)
}
selector.GroupBy(selector.Columns(*_g.flds...)...)
if err := selector.Err(); err != nil {
return err
}
rows := &sql.Rows{}
query, args := selector.Query()
if err := _g.build.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
// ShopsSelect is the builder for selecting fields of Shops entities.
type ShopsSelect struct {
*ShopsQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func (_s *ShopsSelect) Aggregate(fns ...AggregateFunc) *ShopsSelect {
_s.fns = append(_s.fns, fns...)
return _s
}
// Scan applies the selector query and scans the result into the given value.
func (_s *ShopsSelect) Scan(ctx context.Context, v any) error {
ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect)
if err := _s.prepareQuery(ctx); err != nil {
return err
}
return scanWithInterceptors[*ShopsQuery, *ShopsSelect](ctx, _s.ShopsQuery, _s, _s.inters, v)
}
func (_s *ShopsSelect) sqlScan(ctx context.Context, root *ShopsQuery, v any) error {
selector := root.sqlQuery(ctx)
aggregation := make([]string, 0, len(_s.fns))
for _, fn := range _s.fns {
aggregation = append(aggregation, fn(selector))
}
switch n := len(*_s.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 := _s.driver.Query(ctx, query, args, rows); err != nil {
return err
}
defer rows.Close()
return sql.ScanSlice(rows, v)
}
@@ -0,0 +1,948 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"errors"
"fmt"
"juwan-backend/app/shop/rpc/internal/models/predicate"
"juwan-backend/app/shop/rpc/internal/models/shops"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqljson"
"entgo.io/ent/schema/field"
"github.com/shopspring/decimal"
)
// ShopsUpdate is the builder for updating Shops entities.
type ShopsUpdate struct {
config
hooks []Hook
mutation *ShopsMutation
}
// Where appends a list predicates to the ShopsUpdate builder.
func (_u *ShopsUpdate) Where(ps ...predicate.Shops) *ShopsUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetOwnerID sets the "owner_id" field.
func (_u *ShopsUpdate) SetOwnerID(v int64) *ShopsUpdate {
_u.mutation.ResetOwnerID()
_u.mutation.SetOwnerID(v)
return _u
}
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableOwnerID(v *int64) *ShopsUpdate {
if v != nil {
_u.SetOwnerID(*v)
}
return _u
}
// AddOwnerID adds value to the "owner_id" field.
func (_u *ShopsUpdate) AddOwnerID(v int64) *ShopsUpdate {
_u.mutation.AddOwnerID(v)
return _u
}
// SetName sets the "name" field.
func (_u *ShopsUpdate) SetName(v string) *ShopsUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableName(v *string) *ShopsUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetBanner sets the "banner" field.
func (_u *ShopsUpdate) SetBanner(v string) *ShopsUpdate {
_u.mutation.SetBanner(v)
return _u
}
// SetNillableBanner sets the "banner" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableBanner(v *string) *ShopsUpdate {
if v != nil {
_u.SetBanner(*v)
}
return _u
}
// ClearBanner clears the value of the "banner" field.
func (_u *ShopsUpdate) ClearBanner() *ShopsUpdate {
_u.mutation.ClearBanner()
return _u
}
// SetDescription sets the "description" field.
func (_u *ShopsUpdate) SetDescription(v string) *ShopsUpdate {
_u.mutation.SetDescription(v)
return _u
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableDescription(v *string) *ShopsUpdate {
if v != nil {
_u.SetDescription(*v)
}
return _u
}
// ClearDescription clears the value of the "description" field.
func (_u *ShopsUpdate) ClearDescription() *ShopsUpdate {
_u.mutation.ClearDescription()
return _u
}
// SetRating sets the "rating" field.
func (_u *ShopsUpdate) SetRating(v decimal.Decimal) *ShopsUpdate {
_u.mutation.SetRating(v)
return _u
}
// SetNillableRating sets the "rating" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableRating(v *decimal.Decimal) *ShopsUpdate {
if v != nil {
_u.SetRating(*v)
}
return _u
}
// ClearRating clears the value of the "rating" field.
func (_u *ShopsUpdate) ClearRating() *ShopsUpdate {
_u.mutation.ClearRating()
return _u
}
// SetTotalOrders sets the "total_orders" field.
func (_u *ShopsUpdate) SetTotalOrders(v int) *ShopsUpdate {
_u.mutation.ResetTotalOrders()
_u.mutation.SetTotalOrders(v)
return _u
}
// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableTotalOrders(v *int) *ShopsUpdate {
if v != nil {
_u.SetTotalOrders(*v)
}
return _u
}
// AddTotalOrders adds value to the "total_orders" field.
func (_u *ShopsUpdate) AddTotalOrders(v int) *ShopsUpdate {
_u.mutation.AddTotalOrders(v)
return _u
}
// ClearTotalOrders clears the value of the "total_orders" field.
func (_u *ShopsUpdate) ClearTotalOrders() *ShopsUpdate {
_u.mutation.ClearTotalOrders()
return _u
}
// SetPlayerCount sets the "player_count" field.
func (_u *ShopsUpdate) SetPlayerCount(v int) *ShopsUpdate {
_u.mutation.ResetPlayerCount()
_u.mutation.SetPlayerCount(v)
return _u
}
// SetNillablePlayerCount sets the "player_count" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillablePlayerCount(v *int) *ShopsUpdate {
if v != nil {
_u.SetPlayerCount(*v)
}
return _u
}
// AddPlayerCount adds value to the "player_count" field.
func (_u *ShopsUpdate) AddPlayerCount(v int) *ShopsUpdate {
_u.mutation.AddPlayerCount(v)
return _u
}
// ClearPlayerCount clears the value of the "player_count" field.
func (_u *ShopsUpdate) ClearPlayerCount() *ShopsUpdate {
_u.mutation.ClearPlayerCount()
return _u
}
// SetCommissionType sets the "commission_type" field.
func (_u *ShopsUpdate) SetCommissionType(v string) *ShopsUpdate {
_u.mutation.SetCommissionType(v)
return _u
}
// SetNillableCommissionType sets the "commission_type" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableCommissionType(v *string) *ShopsUpdate {
if v != nil {
_u.SetCommissionType(*v)
}
return _u
}
// SetCommissionValue sets the "commission_value" field.
func (_u *ShopsUpdate) SetCommissionValue(v decimal.Decimal) *ShopsUpdate {
_u.mutation.SetCommissionValue(v)
return _u
}
// SetNillableCommissionValue sets the "commission_value" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableCommissionValue(v *decimal.Decimal) *ShopsUpdate {
if v != nil {
_u.SetCommissionValue(*v)
}
return _u
}
// SetAllowMultiShop sets the "allow_multi_shop" field.
func (_u *ShopsUpdate) SetAllowMultiShop(v bool) *ShopsUpdate {
_u.mutation.SetAllowMultiShop(v)
return _u
}
// SetNillableAllowMultiShop sets the "allow_multi_shop" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableAllowMultiShop(v *bool) *ShopsUpdate {
if v != nil {
_u.SetAllowMultiShop(*v)
}
return _u
}
// ClearAllowMultiShop clears the value of the "allow_multi_shop" field.
func (_u *ShopsUpdate) ClearAllowMultiShop() *ShopsUpdate {
_u.mutation.ClearAllowMultiShop()
return _u
}
// SetAllowIndependentOrders sets the "allow_independent_orders" field.
func (_u *ShopsUpdate) SetAllowIndependentOrders(v bool) *ShopsUpdate {
_u.mutation.SetAllowIndependentOrders(v)
return _u
}
// SetNillableAllowIndependentOrders sets the "allow_independent_orders" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableAllowIndependentOrders(v *bool) *ShopsUpdate {
if v != nil {
_u.SetAllowIndependentOrders(*v)
}
return _u
}
// ClearAllowIndependentOrders clears the value of the "allow_independent_orders" field.
func (_u *ShopsUpdate) ClearAllowIndependentOrders() *ShopsUpdate {
_u.mutation.ClearAllowIndependentOrders()
return _u
}
// SetDispatchMode sets the "dispatch_mode" field.
func (_u *ShopsUpdate) SetDispatchMode(v string) *ShopsUpdate {
_u.mutation.SetDispatchMode(v)
return _u
}
// SetNillableDispatchMode sets the "dispatch_mode" field if the given value is not nil.
func (_u *ShopsUpdate) SetNillableDispatchMode(v *string) *ShopsUpdate {
if v != nil {
_u.SetDispatchMode(*v)
}
return _u
}
// SetAnnouncements sets the "announcements" field.
func (_u *ShopsUpdate) SetAnnouncements(v []string) *ShopsUpdate {
_u.mutation.SetAnnouncements(v)
return _u
}
// AppendAnnouncements appends value to the "announcements" field.
func (_u *ShopsUpdate) AppendAnnouncements(v []string) *ShopsUpdate {
_u.mutation.AppendAnnouncements(v)
return _u
}
// ClearAnnouncements clears the value of the "announcements" field.
func (_u *ShopsUpdate) ClearAnnouncements() *ShopsUpdate {
_u.mutation.ClearAnnouncements()
return _u
}
// SetTemplateConfig sets the "template_config" field.
func (_u *ShopsUpdate) SetTemplateConfig(v map[string]interface{}) *ShopsUpdate {
_u.mutation.SetTemplateConfig(v)
return _u
}
// ClearTemplateConfig clears the value of the "template_config" field.
func (_u *ShopsUpdate) ClearTemplateConfig() *ShopsUpdate {
_u.mutation.ClearTemplateConfig()
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ShopsUpdate) SetUpdatedAt(v time.Time) *ShopsUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// Mutation returns the ShopsMutation object of the builder.
func (_u *ShopsUpdate) Mutation() *ShopsMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ShopsUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ShopsUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ShopsUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ShopsUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ShopsUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := shops.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *ShopsUpdate) check() error {
if v, ok := _u.mutation.Name(); ok {
if err := shops.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Shops.name": %w`, err)}
}
}
if v, ok := _u.mutation.CommissionType(); ok {
if err := shops.CommissionTypeValidator(v); err != nil {
return &ValidationError{Name: "commission_type", err: fmt.Errorf(`models: validator failed for field "Shops.commission_type": %w`, err)}
}
}
if v, ok := _u.mutation.DispatchMode(); ok {
if err := shops.DispatchModeValidator(v); err != nil {
return &ValidationError{Name: "dispatch_mode", err: fmt.Errorf(`models: validator failed for field "Shops.dispatch_mode": %w`, err)}
}
}
return nil
}
func (_u *ShopsUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(shops.Table, shops.Columns, sqlgraph.NewFieldSpec(shops.FieldID, field.TypeInt64))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.OwnerID(); ok {
_spec.SetField(shops.FieldOwnerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedOwnerID(); ok {
_spec.AddField(shops.FieldOwnerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(shops.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Banner(); ok {
_spec.SetField(shops.FieldBanner, field.TypeString, value)
}
if _u.mutation.BannerCleared() {
_spec.ClearField(shops.FieldBanner, field.TypeString)
}
if value, ok := _u.mutation.Description(); ok {
_spec.SetField(shops.FieldDescription, field.TypeString, value)
}
if _u.mutation.DescriptionCleared() {
_spec.ClearField(shops.FieldDescription, field.TypeString)
}
if value, ok := _u.mutation.Rating(); ok {
_spec.SetField(shops.FieldRating, field.TypeOther, value)
}
if _u.mutation.RatingCleared() {
_spec.ClearField(shops.FieldRating, field.TypeOther)
}
if value, ok := _u.mutation.TotalOrders(); ok {
_spec.SetField(shops.FieldTotalOrders, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedTotalOrders(); ok {
_spec.AddField(shops.FieldTotalOrders, field.TypeInt, value)
}
if _u.mutation.TotalOrdersCleared() {
_spec.ClearField(shops.FieldTotalOrders, field.TypeInt)
}
if value, ok := _u.mutation.PlayerCount(); ok {
_spec.SetField(shops.FieldPlayerCount, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedPlayerCount(); ok {
_spec.AddField(shops.FieldPlayerCount, field.TypeInt, value)
}
if _u.mutation.PlayerCountCleared() {
_spec.ClearField(shops.FieldPlayerCount, field.TypeInt)
}
if value, ok := _u.mutation.CommissionType(); ok {
_spec.SetField(shops.FieldCommissionType, field.TypeString, value)
}
if value, ok := _u.mutation.CommissionValue(); ok {
_spec.SetField(shops.FieldCommissionValue, field.TypeOther, value)
}
if value, ok := _u.mutation.AllowMultiShop(); ok {
_spec.SetField(shops.FieldAllowMultiShop, field.TypeBool, value)
}
if _u.mutation.AllowMultiShopCleared() {
_spec.ClearField(shops.FieldAllowMultiShop, field.TypeBool)
}
if value, ok := _u.mutation.AllowIndependentOrders(); ok {
_spec.SetField(shops.FieldAllowIndependentOrders, field.TypeBool, value)
}
if _u.mutation.AllowIndependentOrdersCleared() {
_spec.ClearField(shops.FieldAllowIndependentOrders, field.TypeBool)
}
if value, ok := _u.mutation.DispatchMode(); ok {
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
}
if value, ok := _u.mutation.Announcements(); ok {
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedAnnouncements(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, shops.FieldAnnouncements, value)
})
}
if _u.mutation.AnnouncementsCleared() {
_spec.ClearField(shops.FieldAnnouncements, field.TypeJSON)
}
if value, ok := _u.mutation.TemplateConfig(); ok {
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
}
if _u.mutation.TemplateConfigCleared() {
_spec.ClearField(shops.FieldTemplateConfig, field.TypeJSON)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(shops.FieldUpdatedAt, field.TypeTime, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{shops.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ShopsUpdateOne is the builder for updating a single Shops entity.
type ShopsUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ShopsMutation
}
// SetOwnerID sets the "owner_id" field.
func (_u *ShopsUpdateOne) SetOwnerID(v int64) *ShopsUpdateOne {
_u.mutation.ResetOwnerID()
_u.mutation.SetOwnerID(v)
return _u
}
// SetNillableOwnerID sets the "owner_id" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableOwnerID(v *int64) *ShopsUpdateOne {
if v != nil {
_u.SetOwnerID(*v)
}
return _u
}
// AddOwnerID adds value to the "owner_id" field.
func (_u *ShopsUpdateOne) AddOwnerID(v int64) *ShopsUpdateOne {
_u.mutation.AddOwnerID(v)
return _u
}
// SetName sets the "name" field.
func (_u *ShopsUpdateOne) SetName(v string) *ShopsUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableName(v *string) *ShopsUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetBanner sets the "banner" field.
func (_u *ShopsUpdateOne) SetBanner(v string) *ShopsUpdateOne {
_u.mutation.SetBanner(v)
return _u
}
// SetNillableBanner sets the "banner" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableBanner(v *string) *ShopsUpdateOne {
if v != nil {
_u.SetBanner(*v)
}
return _u
}
// ClearBanner clears the value of the "banner" field.
func (_u *ShopsUpdateOne) ClearBanner() *ShopsUpdateOne {
_u.mutation.ClearBanner()
return _u
}
// SetDescription sets the "description" field.
func (_u *ShopsUpdateOne) SetDescription(v string) *ShopsUpdateOne {
_u.mutation.SetDescription(v)
return _u
}
// SetNillableDescription sets the "description" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableDescription(v *string) *ShopsUpdateOne {
if v != nil {
_u.SetDescription(*v)
}
return _u
}
// ClearDescription clears the value of the "description" field.
func (_u *ShopsUpdateOne) ClearDescription() *ShopsUpdateOne {
_u.mutation.ClearDescription()
return _u
}
// SetRating sets the "rating" field.
func (_u *ShopsUpdateOne) SetRating(v decimal.Decimal) *ShopsUpdateOne {
_u.mutation.SetRating(v)
return _u
}
// SetNillableRating sets the "rating" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableRating(v *decimal.Decimal) *ShopsUpdateOne {
if v != nil {
_u.SetRating(*v)
}
return _u
}
// ClearRating clears the value of the "rating" field.
func (_u *ShopsUpdateOne) ClearRating() *ShopsUpdateOne {
_u.mutation.ClearRating()
return _u
}
// SetTotalOrders sets the "total_orders" field.
func (_u *ShopsUpdateOne) SetTotalOrders(v int) *ShopsUpdateOne {
_u.mutation.ResetTotalOrders()
_u.mutation.SetTotalOrders(v)
return _u
}
// SetNillableTotalOrders sets the "total_orders" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableTotalOrders(v *int) *ShopsUpdateOne {
if v != nil {
_u.SetTotalOrders(*v)
}
return _u
}
// AddTotalOrders adds value to the "total_orders" field.
func (_u *ShopsUpdateOne) AddTotalOrders(v int) *ShopsUpdateOne {
_u.mutation.AddTotalOrders(v)
return _u
}
// ClearTotalOrders clears the value of the "total_orders" field.
func (_u *ShopsUpdateOne) ClearTotalOrders() *ShopsUpdateOne {
_u.mutation.ClearTotalOrders()
return _u
}
// SetPlayerCount sets the "player_count" field.
func (_u *ShopsUpdateOne) SetPlayerCount(v int) *ShopsUpdateOne {
_u.mutation.ResetPlayerCount()
_u.mutation.SetPlayerCount(v)
return _u
}
// SetNillablePlayerCount sets the "player_count" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillablePlayerCount(v *int) *ShopsUpdateOne {
if v != nil {
_u.SetPlayerCount(*v)
}
return _u
}
// AddPlayerCount adds value to the "player_count" field.
func (_u *ShopsUpdateOne) AddPlayerCount(v int) *ShopsUpdateOne {
_u.mutation.AddPlayerCount(v)
return _u
}
// ClearPlayerCount clears the value of the "player_count" field.
func (_u *ShopsUpdateOne) ClearPlayerCount() *ShopsUpdateOne {
_u.mutation.ClearPlayerCount()
return _u
}
// SetCommissionType sets the "commission_type" field.
func (_u *ShopsUpdateOne) SetCommissionType(v string) *ShopsUpdateOne {
_u.mutation.SetCommissionType(v)
return _u
}
// SetNillableCommissionType sets the "commission_type" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableCommissionType(v *string) *ShopsUpdateOne {
if v != nil {
_u.SetCommissionType(*v)
}
return _u
}
// SetCommissionValue sets the "commission_value" field.
func (_u *ShopsUpdateOne) SetCommissionValue(v decimal.Decimal) *ShopsUpdateOne {
_u.mutation.SetCommissionValue(v)
return _u
}
// SetNillableCommissionValue sets the "commission_value" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableCommissionValue(v *decimal.Decimal) *ShopsUpdateOne {
if v != nil {
_u.SetCommissionValue(*v)
}
return _u
}
// SetAllowMultiShop sets the "allow_multi_shop" field.
func (_u *ShopsUpdateOne) SetAllowMultiShop(v bool) *ShopsUpdateOne {
_u.mutation.SetAllowMultiShop(v)
return _u
}
// SetNillableAllowMultiShop sets the "allow_multi_shop" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableAllowMultiShop(v *bool) *ShopsUpdateOne {
if v != nil {
_u.SetAllowMultiShop(*v)
}
return _u
}
// ClearAllowMultiShop clears the value of the "allow_multi_shop" field.
func (_u *ShopsUpdateOne) ClearAllowMultiShop() *ShopsUpdateOne {
_u.mutation.ClearAllowMultiShop()
return _u
}
// SetAllowIndependentOrders sets the "allow_independent_orders" field.
func (_u *ShopsUpdateOne) SetAllowIndependentOrders(v bool) *ShopsUpdateOne {
_u.mutation.SetAllowIndependentOrders(v)
return _u
}
// SetNillableAllowIndependentOrders sets the "allow_independent_orders" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableAllowIndependentOrders(v *bool) *ShopsUpdateOne {
if v != nil {
_u.SetAllowIndependentOrders(*v)
}
return _u
}
// ClearAllowIndependentOrders clears the value of the "allow_independent_orders" field.
func (_u *ShopsUpdateOne) ClearAllowIndependentOrders() *ShopsUpdateOne {
_u.mutation.ClearAllowIndependentOrders()
return _u
}
// SetDispatchMode sets the "dispatch_mode" field.
func (_u *ShopsUpdateOne) SetDispatchMode(v string) *ShopsUpdateOne {
_u.mutation.SetDispatchMode(v)
return _u
}
// SetNillableDispatchMode sets the "dispatch_mode" field if the given value is not nil.
func (_u *ShopsUpdateOne) SetNillableDispatchMode(v *string) *ShopsUpdateOne {
if v != nil {
_u.SetDispatchMode(*v)
}
return _u
}
// SetAnnouncements sets the "announcements" field.
func (_u *ShopsUpdateOne) SetAnnouncements(v []string) *ShopsUpdateOne {
_u.mutation.SetAnnouncements(v)
return _u
}
// AppendAnnouncements appends value to the "announcements" field.
func (_u *ShopsUpdateOne) AppendAnnouncements(v []string) *ShopsUpdateOne {
_u.mutation.AppendAnnouncements(v)
return _u
}
// ClearAnnouncements clears the value of the "announcements" field.
func (_u *ShopsUpdateOne) ClearAnnouncements() *ShopsUpdateOne {
_u.mutation.ClearAnnouncements()
return _u
}
// SetTemplateConfig sets the "template_config" field.
func (_u *ShopsUpdateOne) SetTemplateConfig(v map[string]interface{}) *ShopsUpdateOne {
_u.mutation.SetTemplateConfig(v)
return _u
}
// ClearTemplateConfig clears the value of the "template_config" field.
func (_u *ShopsUpdateOne) ClearTemplateConfig() *ShopsUpdateOne {
_u.mutation.ClearTemplateConfig()
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ShopsUpdateOne) SetUpdatedAt(v time.Time) *ShopsUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// Mutation returns the ShopsMutation object of the builder.
func (_u *ShopsUpdateOne) Mutation() *ShopsMutation {
return _u.mutation
}
// Where appends a list predicates to the ShopsUpdate builder.
func (_u *ShopsUpdateOne) Where(ps ...predicate.Shops) *ShopsUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *ShopsUpdateOne) Select(field string, fields ...string) *ShopsUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Shops entity.
func (_u *ShopsUpdateOne) Save(ctx context.Context) (*Shops, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ShopsUpdateOne) SaveX(ctx context.Context) *Shops {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ShopsUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ShopsUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ShopsUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := shops.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_u *ShopsUpdateOne) check() error {
if v, ok := _u.mutation.Name(); ok {
if err := shops.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`models: validator failed for field "Shops.name": %w`, err)}
}
}
if v, ok := _u.mutation.CommissionType(); ok {
if err := shops.CommissionTypeValidator(v); err != nil {
return &ValidationError{Name: "commission_type", err: fmt.Errorf(`models: validator failed for field "Shops.commission_type": %w`, err)}
}
}
if v, ok := _u.mutation.DispatchMode(); ok {
if err := shops.DispatchModeValidator(v); err != nil {
return &ValidationError{Name: "dispatch_mode", err: fmt.Errorf(`models: validator failed for field "Shops.dispatch_mode": %w`, err)}
}
}
return nil
}
func (_u *ShopsUpdateOne) sqlSave(ctx context.Context) (_node *Shops, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(shops.Table, shops.Columns, sqlgraph.NewFieldSpec(shops.FieldID, field.TypeInt64))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`models: missing "Shops.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, shops.FieldID)
for _, f := range fields {
if !shops.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("models: invalid field %q for query", f)}
}
if f != shops.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.OwnerID(); ok {
_spec.SetField(shops.FieldOwnerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.AddedOwnerID(); ok {
_spec.AddField(shops.FieldOwnerID, field.TypeInt64, value)
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(shops.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.Banner(); ok {
_spec.SetField(shops.FieldBanner, field.TypeString, value)
}
if _u.mutation.BannerCleared() {
_spec.ClearField(shops.FieldBanner, field.TypeString)
}
if value, ok := _u.mutation.Description(); ok {
_spec.SetField(shops.FieldDescription, field.TypeString, value)
}
if _u.mutation.DescriptionCleared() {
_spec.ClearField(shops.FieldDescription, field.TypeString)
}
if value, ok := _u.mutation.Rating(); ok {
_spec.SetField(shops.FieldRating, field.TypeOther, value)
}
if _u.mutation.RatingCleared() {
_spec.ClearField(shops.FieldRating, field.TypeOther)
}
if value, ok := _u.mutation.TotalOrders(); ok {
_spec.SetField(shops.FieldTotalOrders, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedTotalOrders(); ok {
_spec.AddField(shops.FieldTotalOrders, field.TypeInt, value)
}
if _u.mutation.TotalOrdersCleared() {
_spec.ClearField(shops.FieldTotalOrders, field.TypeInt)
}
if value, ok := _u.mutation.PlayerCount(); ok {
_spec.SetField(shops.FieldPlayerCount, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedPlayerCount(); ok {
_spec.AddField(shops.FieldPlayerCount, field.TypeInt, value)
}
if _u.mutation.PlayerCountCleared() {
_spec.ClearField(shops.FieldPlayerCount, field.TypeInt)
}
if value, ok := _u.mutation.CommissionType(); ok {
_spec.SetField(shops.FieldCommissionType, field.TypeString, value)
}
if value, ok := _u.mutation.CommissionValue(); ok {
_spec.SetField(shops.FieldCommissionValue, field.TypeOther, value)
}
if value, ok := _u.mutation.AllowMultiShop(); ok {
_spec.SetField(shops.FieldAllowMultiShop, field.TypeBool, value)
}
if _u.mutation.AllowMultiShopCleared() {
_spec.ClearField(shops.FieldAllowMultiShop, field.TypeBool)
}
if value, ok := _u.mutation.AllowIndependentOrders(); ok {
_spec.SetField(shops.FieldAllowIndependentOrders, field.TypeBool, value)
}
if _u.mutation.AllowIndependentOrdersCleared() {
_spec.ClearField(shops.FieldAllowIndependentOrders, field.TypeBool)
}
if value, ok := _u.mutation.DispatchMode(); ok {
_spec.SetField(shops.FieldDispatchMode, field.TypeString, value)
}
if value, ok := _u.mutation.Announcements(); ok {
_spec.SetField(shops.FieldAnnouncements, field.TypeJSON, value)
}
if value, ok := _u.mutation.AppendedAnnouncements(); ok {
_spec.AddModifier(func(u *sql.UpdateBuilder) {
sqljson.Append(u, shops.FieldAnnouncements, value)
})
}
if _u.mutation.AnnouncementsCleared() {
_spec.ClearField(shops.FieldAnnouncements, field.TypeJSON)
}
if value, ok := _u.mutation.TemplateConfig(); ok {
_spec.SetField(shops.FieldTemplateConfig, field.TypeJSON, value)
}
if _u.mutation.TemplateConfigCleared() {
_spec.ClearField(shops.FieldTemplateConfig, field.TypeJSON)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(shops.FieldUpdatedAt, field.TypeTime, value)
}
_node = &Shops{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{shops.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}
+216
View File
@@ -0,0 +1,216 @@
// Code generated by ent, DO NOT EDIT.
package models
import (
"context"
"sync"
"entgo.io/ent/dialect"
)
// Tx is a transactional client that is created by calling Client.Tx().
type Tx struct {
config
// ShopInvitations is the client for interacting with the ShopInvitations builders.
ShopInvitations *ShopInvitationsClient
// ShopPlayers is the client for interacting with the ShopPlayers builders.
ShopPlayers *ShopPlayersClient
// Shops is the client for interacting with the Shops builders.
Shops *ShopsClient
// lazily loaded.
client *Client
clientOnce sync.Once
// ctx lives for the life of the transaction. It is
// the same context used by the underlying connection.
ctx context.Context
}
type (
// Committer is the interface that wraps the Commit method.
Committer interface {
Commit(context.Context, *Tx) error
}
// The CommitFunc type is an adapter to allow the use of ordinary
// function as a Committer. If f is a function with the appropriate
// signature, CommitFunc(f) is a Committer that calls f.
CommitFunc func(context.Context, *Tx) error
// CommitHook defines the "commit middleware". A function that gets a Committer
// and returns a Committer. For example:
//
// hook := func(next ent.Committer) ent.Committer {
// return ent.CommitFunc(func(ctx context.Context, tx *ent.Tx) error {
// // Do some stuff before.
// if err := next.Commit(ctx, tx); err != nil {
// return err
// }
// // Do some stuff after.
// return nil
// })
// }
//
CommitHook func(Committer) Committer
)
// Commit calls f(ctx, m).
func (f CommitFunc) Commit(ctx context.Context, tx *Tx) error {
return f(ctx, tx)
}
// Commit commits the transaction.
func (tx *Tx) Commit() error {
txDriver := tx.config.driver.(*txDriver)
var fn Committer = CommitFunc(func(context.Context, *Tx) error {
return txDriver.tx.Commit()
})
txDriver.mu.Lock()
hooks := append([]CommitHook(nil), txDriver.onCommit...)
txDriver.mu.Unlock()
for i := len(hooks) - 1; i >= 0; i-- {
fn = hooks[i](fn)
}
return fn.Commit(tx.ctx, tx)
}
// OnCommit adds a hook to call on commit.
func (tx *Tx) OnCommit(f CommitHook) {
txDriver := tx.config.driver.(*txDriver)
txDriver.mu.Lock()
txDriver.onCommit = append(txDriver.onCommit, f)
txDriver.mu.Unlock()
}
type (
// Rollbacker is the interface that wraps the Rollback method.
Rollbacker interface {
Rollback(context.Context, *Tx) error
}
// The RollbackFunc type is an adapter to allow the use of ordinary
// function as a Rollbacker. If f is a function with the appropriate
// signature, RollbackFunc(f) is a Rollbacker that calls f.
RollbackFunc func(context.Context, *Tx) error
// RollbackHook defines the "rollback middleware". A function that gets a Rollbacker
// and returns a Rollbacker. For example:
//
// hook := func(next ent.Rollbacker) ent.Rollbacker {
// return ent.RollbackFunc(func(ctx context.Context, tx *ent.Tx) error {
// // Do some stuff before.
// if err := next.Rollback(ctx, tx); err != nil {
// return err
// }
// // Do some stuff after.
// return nil
// })
// }
//
RollbackHook func(Rollbacker) Rollbacker
)
// Rollback calls f(ctx, m).
func (f RollbackFunc) Rollback(ctx context.Context, tx *Tx) error {
return f(ctx, tx)
}
// Rollback rollbacks the transaction.
func (tx *Tx) Rollback() error {
txDriver := tx.config.driver.(*txDriver)
var fn Rollbacker = RollbackFunc(func(context.Context, *Tx) error {
return txDriver.tx.Rollback()
})
txDriver.mu.Lock()
hooks := append([]RollbackHook(nil), txDriver.onRollback...)
txDriver.mu.Unlock()
for i := len(hooks) - 1; i >= 0; i-- {
fn = hooks[i](fn)
}
return fn.Rollback(tx.ctx, tx)
}
// OnRollback adds a hook to call on rollback.
func (tx *Tx) OnRollback(f RollbackHook) {
txDriver := tx.config.driver.(*txDriver)
txDriver.mu.Lock()
txDriver.onRollback = append(txDriver.onRollback, f)
txDriver.mu.Unlock()
}
// Client returns a Client that binds to current transaction.
func (tx *Tx) Client() *Client {
tx.clientOnce.Do(func() {
tx.client = &Client{config: tx.config}
tx.client.init()
})
return tx.client
}
func (tx *Tx) init() {
tx.ShopInvitations = NewShopInvitationsClient(tx.config)
tx.ShopPlayers = NewShopPlayersClient(tx.config)
tx.Shops = NewShopsClient(tx.config)
}
// txDriver wraps the given dialect.Tx with a nop dialect.Driver implementation.
// The idea is to support transactions without adding any extra code to the builders.
// When a builder calls to driver.Tx(), it gets the same dialect.Tx instance.
// Commit and Rollback are nop for the internal builders and the user must call one
// 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: ShopInvitations.QueryXXX(), the query will be executed
// through the driver which created this transaction.
//
// Note that txDriver is not goroutine safe.
type txDriver struct {
// the driver we started the transaction from.
drv dialect.Driver
// tx is the underlying transaction.
tx dialect.Tx
// completion hooks.
mu sync.Mutex
onCommit []CommitHook
onRollback []RollbackHook
}
// newTx creates a new transactional driver.
func newTx(ctx context.Context, drv dialect.Driver) (*txDriver, error) {
tx, err := drv.Tx(ctx)
if err != nil {
return nil, err
}
return &txDriver{tx: tx, drv: drv}, nil
}
// Tx returns the transaction wrapper (txDriver) to avoid Commit or Rollback calls
// from the internal builders. Should be called only by the internal builders.
func (tx *txDriver) Tx(context.Context) (dialect.Tx, error) { return tx, nil }
// Dialect returns the dialect of the driver we started the transaction from.
func (tx *txDriver) Dialect() string { return tx.drv.Dialect() }
// Close is a nop close.
func (*txDriver) Close() error { return nil }
// Commit is a nop commit for the internal builders.
// User must call `Tx.Commit` in order to commit the transaction.
func (*txDriver) Commit() error { return nil }
// Rollback is a nop rollback for the internal builders.
// User must call `Tx.Rollback` in order to rollback the transaction.
func (*txDriver) Rollback() error { return nil }
// Exec calls tx.Exec.
func (tx *txDriver) Exec(ctx context.Context, query string, args, v any) error {
return tx.tx.Exec(ctx, query, args, v)
}
// Query calls tx.Query.
func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error {
return tx.tx.Query(ctx, query, args, v)
}
var _ dialect.Driver = (*txDriver)(nil)
@@ -0,0 +1,102 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.9.2
// Source: shop.proto
package server
import (
"context"
"juwan-backend/app/shop/rpc/internal/logic"
"juwan-backend/app/shop/rpc/internal/svc"
"juwan-backend/app/shop/rpc/pb"
)
type ShopServiceServer struct {
svcCtx *svc.ServiceContext
pb.UnimplementedShopServiceServer
}
func NewShopServiceServer(svcCtx *svc.ServiceContext) *ShopServiceServer {
return &ShopServiceServer{
svcCtx: svcCtx,
}
}
// -----------------------shopInvitations-----------------------
func (s *ShopServiceServer) AddShopInvitations(ctx context.Context, in *pb.AddShopInvitationsReq) (*pb.AddShopInvitationsResp, error) {
l := logic.NewAddShopInvitationsLogic(ctx, s.svcCtx)
return l.AddShopInvitations(in)
}
func (s *ShopServiceServer) UpdateShopInvitations(ctx context.Context, in *pb.UpdateShopInvitationsReq) (*pb.UpdateShopInvitationsResp, error) {
l := logic.NewUpdateShopInvitationsLogic(ctx, s.svcCtx)
return l.UpdateShopInvitations(in)
}
func (s *ShopServiceServer) DelShopInvitations(ctx context.Context, in *pb.DelShopInvitationsReq) (*pb.DelShopInvitationsResp, error) {
l := logic.NewDelShopInvitationsLogic(ctx, s.svcCtx)
return l.DelShopInvitations(in)
}
func (s *ShopServiceServer) GetShopInvitationsById(ctx context.Context, in *pb.GetShopInvitationsByIdReq) (*pb.GetShopInvitationsByIdResp, error) {
l := logic.NewGetShopInvitationsByIdLogic(ctx, s.svcCtx)
return l.GetShopInvitationsById(in)
}
func (s *ShopServiceServer) SearchShopInvitations(ctx context.Context, in *pb.SearchShopInvitationsReq) (*pb.SearchShopInvitationsResp, error) {
l := logic.NewSearchShopInvitationsLogic(ctx, s.svcCtx)
return l.SearchShopInvitations(in)
}
// -----------------------shopPlayers-----------------------
func (s *ShopServiceServer) AddShopPlayers(ctx context.Context, in *pb.AddShopPlayersReq) (*pb.AddShopPlayersResp, error) {
l := logic.NewAddShopPlayersLogic(ctx, s.svcCtx)
return l.AddShopPlayers(in)
}
func (s *ShopServiceServer) UpdateShopPlayers(ctx context.Context, in *pb.UpdateShopPlayersReq) (*pb.UpdateShopPlayersResp, error) {
l := logic.NewUpdateShopPlayersLogic(ctx, s.svcCtx)
return l.UpdateShopPlayers(in)
}
func (s *ShopServiceServer) DelShopPlayers(ctx context.Context, in *pb.DelShopPlayersReq) (*pb.DelShopPlayersResp, error) {
l := logic.NewDelShopPlayersLogic(ctx, s.svcCtx)
return l.DelShopPlayers(in)
}
func (s *ShopServiceServer) GetShopPlayersById(ctx context.Context, in *pb.GetShopPlayersByIdReq) (*pb.GetShopPlayersByIdResp, error) {
l := logic.NewGetShopPlayersByIdLogic(ctx, s.svcCtx)
return l.GetShopPlayersById(in)
}
func (s *ShopServiceServer) SearchShopPlayers(ctx context.Context, in *pb.SearchShopPlayersReq) (*pb.SearchShopPlayersResp, error) {
l := logic.NewSearchShopPlayersLogic(ctx, s.svcCtx)
return l.SearchShopPlayers(in)
}
// -----------------------shops-----------------------
func (s *ShopServiceServer) AddShops(ctx context.Context, in *pb.AddShopsReq) (*pb.AddShopsResp, error) {
l := logic.NewAddShopsLogic(ctx, s.svcCtx)
return l.AddShops(in)
}
func (s *ShopServiceServer) UpdateShops(ctx context.Context, in *pb.UpdateShopsReq) (*pb.UpdateShopsResp, error) {
l := logic.NewUpdateShopsLogic(ctx, s.svcCtx)
return l.UpdateShops(in)
}
func (s *ShopServiceServer) DelShops(ctx context.Context, in *pb.DelShopsReq) (*pb.DelShopsResp, error) {
l := logic.NewDelShopsLogic(ctx, s.svcCtx)
return l.DelShops(in)
}
func (s *ShopServiceServer) GetShopsById(ctx context.Context, in *pb.GetShopsByIdReq) (*pb.GetShopsByIdResp, error) {
l := logic.NewGetShopsByIdLogic(ctx, s.svcCtx)
return l.GetShopsById(in)
}
func (s *ShopServiceServer) SearchShops(ctx context.Context, in *pb.SearchShopsReq) (*pb.SearchShopsResp, error) {
l := logic.NewSearchShopsLogic(ctx, s.svcCtx)
return l.SearchShops(in)
}
@@ -0,0 +1,49 @@
package svc
import (
"juwan-backend/app/shop/rpc/internal/config"
"juwan-backend/app/shop/rpc/internal/models"
"juwan-backend/app/snowflake/rpc/snowflake"
"juwan-backend/common/redisx"
"juwan-backend/common/snowflakex"
"juwan-backend/pkg/adapter"
"time"
"ariga.io/entcache"
"entgo.io/ent/dialect/sql"
"github.com/zeromicro/go-zero/core/logx"
)
type ServiceContext struct {
Config config.Config
Snowflake snowflake.SnowflakeServiceClient
ShopModelRW *models.Client
ShopModelRO *models.Client
}
func NewServiceContext(c config.Config) *ServiceContext {
RWConn, err := sql.Open("pgx", c.DB.Master)
if err != nil {
panic(err)
}
ROConn, err := sql.Open("pgx", c.DB.Slaves)
if err != nil {
panic(err)
}
redisCluster, err := redisx.ConnectMasterSlaveCluster(c.CacheConf, 5*time.Second)
if redisCluster == nil || err != nil {
logx.Errorf("failed to connect to Redis cluster: %v", err)
panic(err)
}
// snowflakex.NewClient(c.SnowflakeRpcConf)
RWDrv := entcache.NewDriver(RWConn, entcache.TTL(30*time.Second), entcache.Levels(adapter.NewRedisCache(redisCluster.Client)))
RODrv := entcache.NewDriver(ROConn, entcache.TTL(30*time.Second), entcache.Levels(adapter.NewRedisCache(redisCluster.Client)))
return &ServiceContext{
Config: c,
Snowflake: snowflakex.NewClient(c.SnowflakeRpcConf),
ShopModelRO: models.NewClient(models.Driver(RODrv)),
ShopModelRW: models.NewClient(models.Driver(RWDrv)),
}
}