mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: adding singular variants of select query finishers (#594)
Signed-off-by: Alex Snast <alexsn@fb.com>
This commit is contained in:
@@ -620,6 +620,32 @@ func (ggb *GroupGroupBy) StringsX(ctx context.Context) []string {
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GroupGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = ggb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{group.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GroupGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (ggb *GroupGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := ggb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GroupGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(ggb.fields) > 1 {
|
||||
@@ -641,6 +667,32 @@ func (ggb *GroupGroupBy) IntsX(ctx context.Context) []int {
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GroupGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = ggb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{group.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GroupGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (ggb *GroupGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := ggb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GroupGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(ggb.fields) > 1 {
|
||||
@@ -662,6 +714,32 @@ func (ggb *GroupGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GroupGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = ggb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{group.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GroupGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (ggb *GroupGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := ggb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GroupGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(ggb.fields) > 1 {
|
||||
@@ -683,6 +761,32 @@ func (ggb *GroupGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ggb *GroupGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = ggb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{group.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GroupGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (ggb *GroupGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := ggb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (ggb *GroupGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := ggb.sqlQuery().Query()
|
||||
@@ -750,6 +854,32 @@ func (gs *GroupSelect) StringsX(ctx context.Context) []string {
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from selector. It is only allowed when selecting one field.
|
||||
func (gs *GroupSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = gs.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{group.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GroupSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (gs *GroupSelect) StringX(ctx context.Context) string {
|
||||
v, err := gs.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from selector. It is only allowed when selecting one field.
|
||||
func (gs *GroupSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(gs.fields) > 1 {
|
||||
@@ -771,6 +901,32 @@ func (gs *GroupSelect) IntsX(ctx context.Context) []int {
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from selector. It is only allowed when selecting one field.
|
||||
func (gs *GroupSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = gs.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{group.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GroupSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (gs *GroupSelect) IntX(ctx context.Context) int {
|
||||
v, err := gs.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from selector. It is only allowed when selecting one field.
|
||||
func (gs *GroupSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(gs.fields) > 1 {
|
||||
@@ -792,6 +948,32 @@ func (gs *GroupSelect) Float64sX(ctx context.Context) []float64 {
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from selector. It is only allowed when selecting one field.
|
||||
func (gs *GroupSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = gs.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{group.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GroupSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (gs *GroupSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := gs.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from selector. It is only allowed when selecting one field.
|
||||
func (gs *GroupSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(gs.fields) > 1 {
|
||||
@@ -813,6 +995,32 @@ func (gs *GroupSelect) BoolsX(ctx context.Context) []bool {
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from selector. It is only allowed when selecting one field.
|
||||
func (gs *GroupSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = gs.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{group.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: GroupSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (gs *GroupSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := gs.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (gs *GroupSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := gs.sqlQuery().Query()
|
||||
|
||||
@@ -620,6 +620,32 @@ func (pgb *PetGroupBy) StringsX(ctx context.Context) []string {
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from group-by. It is only allowed when querying group-by with one field.
|
||||
func (pgb *PetGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = pgb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{pet.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PetGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (pgb *PetGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := pgb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field.
|
||||
func (pgb *PetGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(pgb.fields) > 1 {
|
||||
@@ -641,6 +667,32 @@ func (pgb *PetGroupBy) IntsX(ctx context.Context) []int {
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from group-by. It is only allowed when querying group-by with one field.
|
||||
func (pgb *PetGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = pgb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{pet.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PetGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (pgb *PetGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := pgb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field.
|
||||
func (pgb *PetGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(pgb.fields) > 1 {
|
||||
@@ -662,6 +714,32 @@ func (pgb *PetGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field.
|
||||
func (pgb *PetGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = pgb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{pet.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PetGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (pgb *PetGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := pgb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field.
|
||||
func (pgb *PetGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(pgb.fields) > 1 {
|
||||
@@ -683,6 +761,32 @@ func (pgb *PetGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field.
|
||||
func (pgb *PetGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = pgb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{pet.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PetGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (pgb *PetGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := pgb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (pgb *PetGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := pgb.sqlQuery().Query()
|
||||
@@ -750,6 +854,32 @@ func (ps *PetSelect) StringsX(ctx context.Context) []string {
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from selector. It is only allowed when selecting one field.
|
||||
func (ps *PetSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = ps.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{pet.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PetSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (ps *PetSelect) StringX(ctx context.Context) string {
|
||||
v, err := ps.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from selector. It is only allowed when selecting one field.
|
||||
func (ps *PetSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(ps.fields) > 1 {
|
||||
@@ -771,6 +901,32 @@ func (ps *PetSelect) IntsX(ctx context.Context) []int {
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from selector. It is only allowed when selecting one field.
|
||||
func (ps *PetSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = ps.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{pet.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PetSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (ps *PetSelect) IntX(ctx context.Context) int {
|
||||
v, err := ps.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from selector. It is only allowed when selecting one field.
|
||||
func (ps *PetSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(ps.fields) > 1 {
|
||||
@@ -792,6 +948,32 @@ func (ps *PetSelect) Float64sX(ctx context.Context) []float64 {
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from selector. It is only allowed when selecting one field.
|
||||
func (ps *PetSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = ps.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{pet.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PetSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (ps *PetSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := ps.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from selector. It is only allowed when selecting one field.
|
||||
func (ps *PetSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(ps.fields) > 1 {
|
||||
@@ -813,6 +995,32 @@ func (ps *PetSelect) BoolsX(ctx context.Context) []bool {
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from selector. It is only allowed when selecting one field.
|
||||
func (ps *PetSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = ps.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{pet.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: PetSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (ps *PetSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := ps.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (ps *PetSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := ps.sqlQuery().Query()
|
||||
|
||||
@@ -766,6 +766,32 @@ func (ugb *UserGroupBy) StringsX(ctx context.Context) []string {
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ugb *UserGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = ugb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := ugb.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ugb *UserGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(ugb.fields) > 1 {
|
||||
@@ -787,6 +813,32 @@ func (ugb *UserGroupBy) IntsX(ctx context.Context) []int {
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ugb *UserGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = ugb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := ugb.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ugb *UserGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(ugb.fields) > 1 {
|
||||
@@ -808,6 +860,32 @@ func (ugb *UserGroupBy) Float64sX(ctx context.Context) []float64 {
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ugb *UserGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = ugb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := ugb.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ugb *UserGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(ugb.fields) > 1 {
|
||||
@@ -829,6 +907,32 @@ func (ugb *UserGroupBy) BoolsX(ctx context.Context) []bool {
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from group-by. It is only allowed when querying group-by with one field.
|
||||
func (ugb *UserGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = ugb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (ugb *UserGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := ugb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (ugb *UserGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := ugb.sqlQuery().Query()
|
||||
@@ -896,6 +1000,32 @@ func (us *UserSelect) StringsX(ctx context.Context) []string {
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = us.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (us *UserSelect) StringX(ctx context.Context) string {
|
||||
v, err := us.String(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Ints returns list of ints from selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(us.fields) > 1 {
|
||||
@@ -917,6 +1047,32 @@ func (us *UserSelect) IntsX(ctx context.Context) []int {
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = us.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (us *UserSelect) IntX(ctx context.Context) int {
|
||||
v, err := us.Int(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64s returns list of float64s from selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(us.fields) > 1 {
|
||||
@@ -938,6 +1094,32 @@ func (us *UserSelect) Float64sX(ctx context.Context) []float64 {
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = us.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (us *UserSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := us.Float64(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Bools returns list of bools from selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(us.fields) > 1 {
|
||||
@@ -959,6 +1141,32 @@ func (us *UserSelect) BoolsX(ctx context.Context) []bool {
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from selector. It is only allowed when selecting one field.
|
||||
func (us *UserSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = us.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{user.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: UserSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (us *UserSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := us.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (us *UserSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := us.sqlQuery().Query()
|
||||
|
||||
Reference in New Issue
Block a user