fix: 复合主键表改为单字段 id 以支持 ent 完整生成

This commit is contained in:
zetaloop
2026-04-24 07:32:52 +08:00
parent c62d743320
commit 5ad579f03c
19 changed files with 324 additions and 82 deletions
@@ -12,6 +12,7 @@ import (
"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.
@@ -79,6 +80,29 @@ func (_q *ShopPlayersQuery) FirstX(ctx context.Context) *ShopPlayers {
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.
@@ -106,6 +130,34 @@ func (_q *ShopPlayersQuery) OnlyX(ctx context.Context) *ShopPlayers {
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)
@@ -125,6 +177,27 @@ func (_q *ShopPlayersQuery) AllX(ctx context.Context) []*ShopPlayers {
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)
@@ -146,7 +219,7 @@ func (_q *ShopPlayersQuery) CountX(ctx context.Context) int {
// 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.First(ctx); {
switch _, err := _q.FirstID(ctx); {
case IsNotFound(err):
return false, nil
case err != nil:
@@ -292,7 +365,7 @@ func (_q *ShopPlayersQuery) sqlCount(ctx context.Context) (int, error) {
}
func (_q *ShopPlayersQuery) querySpec() *sqlgraph.QuerySpec {
_spec := sqlgraph.NewQuerySpec(shopplayers.Table, shopplayers.Columns, nil)
_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
@@ -301,8 +374,11 @@ func (_q *ShopPlayersQuery) querySpec() *sqlgraph.QuerySpec {
}
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 {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
if fields[i] != shopplayers.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
}
}
}
if ps := _q.predicates; len(ps) > 0 {