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:
@@ -525,6 +525,32 @@ func (cgb *CardGroupBy) 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 (cgb *CardGroupBy) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = cgb.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{card.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: CardGroupBy.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (cgb *CardGroupBy) StringX(ctx context.Context) string {
|
||||
v, err := cgb.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 (cgb *CardGroupBy) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(cgb.fields) > 1 {
|
||||
@@ -546,6 +572,32 @@ func (cgb *CardGroupBy) 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 (cgb *CardGroupBy) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = cgb.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{card.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: CardGroupBy.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (cgb *CardGroupBy) IntX(ctx context.Context) int {
|
||||
v, err := cgb.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 (cgb *CardGroupBy) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(cgb.fields) > 1 {
|
||||
@@ -567,6 +619,32 @@ func (cgb *CardGroupBy) 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 (cgb *CardGroupBy) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = cgb.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{card.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: CardGroupBy.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (cgb *CardGroupBy) Float64X(ctx context.Context) float64 {
|
||||
v, err := cgb.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 (cgb *CardGroupBy) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(cgb.fields) > 1 {
|
||||
@@ -588,6 +666,32 @@ func (cgb *CardGroupBy) 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 (cgb *CardGroupBy) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = cgb.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{card.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: CardGroupBy.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (cgb *CardGroupBy) BoolX(ctx context.Context) bool {
|
||||
v, err := cgb.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (cgb *CardGroupBy) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := cgb.sqlQuery().Query()
|
||||
@@ -655,6 +759,32 @@ func (cs *CardSelect) StringsX(ctx context.Context) []string {
|
||||
return v
|
||||
}
|
||||
|
||||
// String returns a single string from selector. It is only allowed when selecting one field.
|
||||
func (cs *CardSelect) String(ctx context.Context) (_ string, err error) {
|
||||
var v []string
|
||||
if v, err = cs.Strings(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{card.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: CardSelect.Strings returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// StringX is like String, but panics if an error occurs.
|
||||
func (cs *CardSelect) StringX(ctx context.Context) string {
|
||||
v, err := cs.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 (cs *CardSelect) Ints(ctx context.Context) ([]int, error) {
|
||||
if len(cs.fields) > 1 {
|
||||
@@ -676,6 +806,32 @@ func (cs *CardSelect) IntsX(ctx context.Context) []int {
|
||||
return v
|
||||
}
|
||||
|
||||
// Int returns a single int from selector. It is only allowed when selecting one field.
|
||||
func (cs *CardSelect) Int(ctx context.Context) (_ int, err error) {
|
||||
var v []int
|
||||
if v, err = cs.Ints(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{card.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: CardSelect.Ints returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IntX is like Int, but panics if an error occurs.
|
||||
func (cs *CardSelect) IntX(ctx context.Context) int {
|
||||
v, err := cs.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 (cs *CardSelect) Float64s(ctx context.Context) ([]float64, error) {
|
||||
if len(cs.fields) > 1 {
|
||||
@@ -697,6 +853,32 @@ func (cs *CardSelect) Float64sX(ctx context.Context) []float64 {
|
||||
return v
|
||||
}
|
||||
|
||||
// Float64 returns a single float64 from selector. It is only allowed when selecting one field.
|
||||
func (cs *CardSelect) Float64(ctx context.Context) (_ float64, err error) {
|
||||
var v []float64
|
||||
if v, err = cs.Float64s(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{card.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: CardSelect.Float64s returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Float64X is like Float64, but panics if an error occurs.
|
||||
func (cs *CardSelect) Float64X(ctx context.Context) float64 {
|
||||
v, err := cs.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 (cs *CardSelect) Bools(ctx context.Context) ([]bool, error) {
|
||||
if len(cs.fields) > 1 {
|
||||
@@ -718,6 +900,32 @@ func (cs *CardSelect) BoolsX(ctx context.Context) []bool {
|
||||
return v
|
||||
}
|
||||
|
||||
// Bool returns a single bool from selector. It is only allowed when selecting one field.
|
||||
func (cs *CardSelect) Bool(ctx context.Context) (_ bool, err error) {
|
||||
var v []bool
|
||||
if v, err = cs.Bools(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(v) {
|
||||
case 1:
|
||||
return v[0], nil
|
||||
case 0:
|
||||
err = &NotFoundError{card.Label}
|
||||
default:
|
||||
err = fmt.Errorf("ent: CardSelect.Bools returned %d results when one was expected", len(v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// BoolX is like Bool, but panics if an error occurs.
|
||||
func (cs *CardSelect) BoolX(ctx context.Context) bool {
|
||||
v, err := cs.Bool(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (cs *CardSelect) sqlScan(ctx context.Context, v interface{}) error {
|
||||
rows := &sql.Rows{}
|
||||
query, args := cs.sqlQuery().Query()
|
||||
|
||||
@@ -518,6 +518,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 {
|
||||
@@ -539,6 +565,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 {
|
||||
@@ -560,6 +612,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 {
|
||||
@@ -581,6 +659,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()
|
||||
@@ -648,6 +752,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 {
|
||||
@@ -669,6 +799,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 {
|
||||
@@ -690,6 +846,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 {
|
||||
@@ -711,6 +893,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