updated deps; regen ent
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
// Code generated by entc, DO NOT EDIT.
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
|
||||
@@ -21,16 +20,15 @@ import (
|
||||
// MatchQuery is the builder for querying Match entities.
|
||||
type MatchQuery struct {
|
||||
config
|
||||
limit *int
|
||||
offset *int
|
||||
unique *bool
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
predicates []predicate.Match
|
||||
// eager-loading edges.
|
||||
limit *int
|
||||
offset *int
|
||||
unique *bool
|
||||
order []OrderFunc
|
||||
fields []string
|
||||
predicates []predicate.Match
|
||||
withStats *MatchPlayerQuery
|
||||
withPlayers *PlayerQuery
|
||||
modifiers []func(s *sql.Selector)
|
||||
modifiers []func(*sql.Selector)
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
@@ -337,17 +335,18 @@ func (mq *MatchQuery) WithPlayers(opts ...func(*PlayerQuery)) *MatchQuery {
|
||||
// GroupBy(match.FieldShareCode).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (mq *MatchQuery) GroupBy(field string, fields ...string) *MatchGroupBy {
|
||||
group := &MatchGroupBy{config: mq.config}
|
||||
group.fields = append([]string{field}, fields...)
|
||||
group.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
grbuild := &MatchGroupBy{config: mq.config}
|
||||
grbuild.fields = append([]string{field}, fields...)
|
||||
grbuild.path = func(ctx context.Context) (prev *sql.Selector, err error) {
|
||||
if err := mq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return mq.sqlQuery(ctx), nil
|
||||
}
|
||||
return group
|
||||
grbuild.label = match.Label
|
||||
grbuild.flds, grbuild.scan = &grbuild.fields, grbuild.Scan
|
||||
return grbuild
|
||||
}
|
||||
|
||||
// Select allows the selection one or more fields/columns for the given query,
|
||||
@@ -362,10 +361,12 @@ func (mq *MatchQuery) GroupBy(field string, fields ...string) *MatchGroupBy {
|
||||
// client.Match.Query().
|
||||
// Select(match.FieldShareCode).
|
||||
// Scan(ctx, &v)
|
||||
//
|
||||
func (mq *MatchQuery) Select(fields ...string) *MatchSelect {
|
||||
mq.fields = append(mq.fields, fields...)
|
||||
return &MatchSelect{MatchQuery: mq}
|
||||
selbuild := &MatchSelect{MatchQuery: mq}
|
||||
selbuild.label = match.Label
|
||||
selbuild.flds, selbuild.scan = &mq.fields, selbuild.Scan
|
||||
return selbuild
|
||||
}
|
||||
|
||||
func (mq *MatchQuery) prepareQuery(ctx context.Context) error {
|
||||
@@ -384,7 +385,7 @@ func (mq *MatchQuery) prepareQuery(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mq *MatchQuery) sqlAll(ctx context.Context) ([]*Match, error) {
|
||||
func (mq *MatchQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Match, error) {
|
||||
var (
|
||||
nodes = []*Match{}
|
||||
_spec = mq.querySpec()
|
||||
@@ -394,119 +395,127 @@ func (mq *MatchQuery) sqlAll(ctx context.Context) ([]*Match, error) {
|
||||
}
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
|
||||
node := &Match{config: mq.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.scanValues(columns)
|
||||
return (*Match).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []interface{}) error {
|
||||
if len(nodes) == 0 {
|
||||
return fmt.Errorf("ent: Assign called without calling ScanValues")
|
||||
}
|
||||
node := nodes[len(nodes)-1]
|
||||
node := &Match{config: mq.config}
|
||||
nodes = append(nodes, node)
|
||||
node.Edges.loadedTypes = loadedTypes
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
if len(mq.modifiers) > 0 {
|
||||
_spec.Modifiers = mq.modifiers
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, mq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
if query := mq.withStats; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uint64]*Match)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
nodes[i].Edges.Stats = []*MatchPlayer{}
|
||||
}
|
||||
query.Where(predicate.MatchPlayer(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(match.StatsColumn, fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
if err := mq.loadStats(ctx, query, nodes,
|
||||
func(n *Match) { n.Edges.Stats = []*MatchPlayer{} },
|
||||
func(n *Match, e *MatchPlayer) { n.Edges.Stats = append(n.Edges.Stats, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.MatchStats
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`unexpected foreign-key "match_stats" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
node.Edges.Stats = append(node.Edges.Stats, n)
|
||||
}
|
||||
}
|
||||
|
||||
if query := mq.withPlayers; query != nil {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
ids := make(map[uint64]*Match, len(nodes))
|
||||
for _, node := range nodes {
|
||||
ids[node.ID] = node
|
||||
fks = append(fks, node.ID)
|
||||
node.Edges.Players = []*Player{}
|
||||
}
|
||||
var (
|
||||
edgeids []uint64
|
||||
edges = make(map[uint64][]*Match)
|
||||
)
|
||||
_spec := &sqlgraph.EdgeQuerySpec{
|
||||
Edge: &sqlgraph.EdgeSpec{
|
||||
Inverse: true,
|
||||
Table: match.PlayersTable,
|
||||
Columns: match.PlayersPrimaryKey,
|
||||
},
|
||||
Predicate: func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(match.PlayersPrimaryKey[1], fks...))
|
||||
},
|
||||
ScanValues: func() [2]interface{} {
|
||||
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
|
||||
},
|
||||
Assign: func(out, in interface{}) error {
|
||||
eout, ok := out.(*sql.NullInt64)
|
||||
if !ok || eout == nil {
|
||||
return fmt.Errorf("unexpected id value for edge-out")
|
||||
}
|
||||
ein, ok := in.(*sql.NullInt64)
|
||||
if !ok || ein == nil {
|
||||
return fmt.Errorf("unexpected id value for edge-in")
|
||||
}
|
||||
outValue := uint64(eout.Int64)
|
||||
inValue := uint64(ein.Int64)
|
||||
node, ok := ids[outValue]
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected node id in edges: %v", outValue)
|
||||
}
|
||||
if _, ok := edges[inValue]; !ok {
|
||||
edgeids = append(edgeids, inValue)
|
||||
}
|
||||
edges[inValue] = append(edges[inValue], node)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
if err := sqlgraph.QueryEdges(ctx, mq.driver, _spec); err != nil {
|
||||
return nil, fmt.Errorf(`query edges "players": %w`, err)
|
||||
}
|
||||
query.Where(player.IDIn(edgeids...))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
if err := mq.loadPlayers(ctx, query, nodes,
|
||||
func(n *Match) { n.Edges.Players = []*Player{} },
|
||||
func(n *Match, e *Player) { n.Edges.Players = append(n.Edges.Players, e) }); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := edges[n.ID]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf(`unexpected "players" node returned %v`, n.ID)
|
||||
}
|
||||
for i := range nodes {
|
||||
nodes[i].Edges.Players = append(nodes[i].Edges.Players, n)
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (mq *MatchQuery) loadStats(ctx context.Context, query *MatchPlayerQuery, nodes []*Match, init func(*Match), assign func(*Match, *MatchPlayer)) error {
|
||||
fks := make([]driver.Value, 0, len(nodes))
|
||||
nodeids := make(map[uint64]*Match)
|
||||
for i := range nodes {
|
||||
fks = append(fks, nodes[i].ID)
|
||||
nodeids[nodes[i].ID] = nodes[i]
|
||||
if init != nil {
|
||||
init(nodes[i])
|
||||
}
|
||||
}
|
||||
|
||||
return nodes, nil
|
||||
query.Where(predicate.MatchPlayer(func(s *sql.Selector) {
|
||||
s.Where(sql.InValues(match.StatsColumn, fks...))
|
||||
}))
|
||||
neighbors, err := query.All(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
fk := n.MatchStats
|
||||
node, ok := nodeids[fk]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected foreign-key "match_stats" returned %v for node %v`, fk, n.ID)
|
||||
}
|
||||
assign(node, n)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (mq *MatchQuery) loadPlayers(ctx context.Context, query *PlayerQuery, nodes []*Match, init func(*Match), assign func(*Match, *Player)) error {
|
||||
edgeIDs := make([]driver.Value, len(nodes))
|
||||
byID := make(map[uint64]*Match)
|
||||
nids := make(map[uint64]map[*Match]struct{})
|
||||
for i, node := range nodes {
|
||||
edgeIDs[i] = node.ID
|
||||
byID[node.ID] = node
|
||||
if init != nil {
|
||||
init(node)
|
||||
}
|
||||
}
|
||||
query.Where(func(s *sql.Selector) {
|
||||
joinT := sql.Table(match.PlayersTable)
|
||||
s.Join(joinT).On(s.C(player.FieldID), joinT.C(match.PlayersPrimaryKey[0]))
|
||||
s.Where(sql.InValues(joinT.C(match.PlayersPrimaryKey[1]), edgeIDs...))
|
||||
columns := s.SelectedColumns()
|
||||
s.Select(joinT.C(match.PlayersPrimaryKey[1]))
|
||||
s.AppendSelect(columns...)
|
||||
s.SetDistinct(false)
|
||||
})
|
||||
if err := query.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
neighbors, err := query.sqlAll(ctx, func(_ context.Context, spec *sqlgraph.QuerySpec) {
|
||||
assign := spec.Assign
|
||||
values := spec.ScanValues
|
||||
spec.ScanValues = func(columns []string) ([]interface{}, error) {
|
||||
values, err := values(columns[1:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return append([]interface{}{new(sql.NullInt64)}, values...), nil
|
||||
}
|
||||
spec.Assign = func(columns []string, values []interface{}) error {
|
||||
outValue := uint64(values[0].(*sql.NullInt64).Int64)
|
||||
inValue := uint64(values[1].(*sql.NullInt64).Int64)
|
||||
if nids[inValue] == nil {
|
||||
nids[inValue] = map[*Match]struct{}{byID[outValue]: struct{}{}}
|
||||
return assign(columns[1:], values[1:])
|
||||
}
|
||||
nids[inValue][byID[outValue]] = struct{}{}
|
||||
return nil
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, n := range neighbors {
|
||||
nodes, ok := nids[n.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf(`unexpected "players" node returned %v`, n.ID)
|
||||
}
|
||||
for kn := range nodes {
|
||||
assign(kn, n)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (mq *MatchQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
@@ -621,6 +630,7 @@ func (mq *MatchQuery) Modify(modifiers ...func(s *sql.Selector)) *MatchSelect {
|
||||
// MatchGroupBy is the group-by builder for Match entities.
|
||||
type MatchGroupBy struct {
|
||||
config
|
||||
selector
|
||||
fields []string
|
||||
fns []AggregateFunc
|
||||
// intermediate query (i.e. traversal path).
|
||||
@@ -644,209 +654,6 @@ func (mgb *MatchGroupBy) Scan(ctx context.Context, v interface{}) error {
|
||||
return mgb.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (mgb *MatchGroupBy) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := mgb.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (mgb *MatchGroupBy) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(mgb.fields) > 1 {
|
||||
return nil, errors.New("ent: MatchGroupBy.Strings is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := mgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (mgb *MatchGroupBy) StringsX(ctx context.Context) []string {
|
||||
v, err := mgb.Strings(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (mgb *MatchGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = mgb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{match.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: MatchGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (mgb *MatchGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := mgb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (mgb *MatchGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(mgb.fields) > 1 {
|
||||
return nil, errors.New("ent: MatchGroupBy.Ints is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := mgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (mgb *MatchGroupBy) IntsX(ctx context.Context) []int {
|
||||
v, err := mgb.Ints(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (mgb *MatchGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = mgb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{match.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: MatchGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (mgb *MatchGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := mgb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (mgb *MatchGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(mgb.fields) > 1 {
|
||||
return nil, errors.New("ent: MatchGroupBy.Float64s is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := mgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (mgb *MatchGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := mgb.Float64s(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (mgb *MatchGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = mgb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{match.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: MatchGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (mgb *MatchGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := mgb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (mgb *MatchGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(mgb.fields) > 1 {
|
||||
return nil, errors.New("ent: MatchGroupBy.Bools is not achievable when grouping more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := mgb.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (mgb *MatchGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
v, err := mgb.Bools(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from a group-by query.
|
||||
// It is only allowed when executing a group-by query with one field.
|
||||
func (mgb *MatchGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = mgb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{match.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: MatchGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (mgb *MatchGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := mgb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (mgb *MatchGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
for _, f := range mgb.fields {
|
||||
if !match.ValidColumn(f) {
|
||||
@@ -888,6 +695,7 @@ func (mgb *MatchGroupBy) sqlQuery() *sql.Selector {
|
||||
// MatchSelect is the builder for selecting fields of Match entities.
|
||||
type MatchSelect struct {
|
||||
*MatchQuery
|
||||
selector
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
}
|
||||
@@ -901,201 +709,6 @@ func (ms *MatchSelect) Scan(ctx context.Context, v interface{}) error {
|
||||
return ms.sqlScan(ctx, v)
|
||||
}
|
||||
|
||||
// ScanX is like Scan, but panics if an error occurs.
|
||||
func (ms *MatchSelect) ScanX(ctx context.Context, v interface{}) {
|
||||
if err := ms.Scan(ctx, v); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Strings returns list of strings from a selector. It is only allowed when selecting one field.
|
||||
func (ms *MatchSelect) Strings(ctx context.Context) ([]string, error) {
|
||||
if len(ms.fields) > 1 {
|
||||
return nil, errors.New("ent: MatchSelect.Strings is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []string
|
||||
if err := ms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// StringsX is like Strings, but panics if an error occurs.
|
||||
func (ms *MatchSelect) StringsX(ctx context.Context) []string {
|
||||
v, err := ms.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 (ms *MatchSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = ms.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{match.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: MatchSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (ms *MatchSelect) StringX(ctx context.Context) string {
|
||||
v, err := ms.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 (ms *MatchSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(ms.fields) > 1 {
|
||||
return nil, errors.New("ent: MatchSelect.Ints is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []int
|
||||
if err := ms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// IntsX is like Ints, but panics if an error occurs.
|
||||
func (ms *MatchSelect) IntsX(ctx context.Context) []int {
|
||||
v, err := ms.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 (ms *MatchSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = ms.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{match.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: MatchSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (ms *MatchSelect) IntX(ctx context.Context) int {
|
||||
v, err := ms.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 (ms *MatchSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(ms.fields) > 1 {
|
||||
return nil, errors.New("ent: MatchSelect.Float64s is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []float64
|
||||
if err := ms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// Float64sX is like Float64s, but panics if an error occurs.
|
||||
func (ms *MatchSelect) Float64sX(ctx context.Context) []float64 {
|
||||
v, err := ms.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 (ms *MatchSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = ms.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{match.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: MatchSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (ms *MatchSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := ms.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 (ms *MatchSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(ms.fields) > 1 {
|
||||
return nil, errors.New("ent: MatchSelect.Bools is not achievable when selecting more than 1 field")
|
||||
}
|
||||
var v []bool
|
||||
if err := ms.Scan(ctx, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BoolsX is like Bools, but panics if an error occurs.
|
||||
func (ms *MatchSelect) BoolsX(ctx context.Context) []bool {
|
||||
v, err := ms.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 (ms *MatchSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = ms.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{match.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: MatchSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (ms *MatchSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := ms.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (ms *MatchSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := ms.sql.Query()
|
||||
|
Reference in New Issue
Block a user