examples: regenerate assets

Closes #261
This commit is contained in:
Ariel Mashraki
2019-12-25 11:21:04 +02:00
parent d586492147
commit 1f2cb87cee
60 changed files with 1755 additions and 1739 deletions

View File

@@ -12,6 +12,7 @@ import (
"time"
"github.com/facebookincubator/ent/dialect/sql"
"github.com/facebookincubator/ent/examples/o2o2types/ent/card"
)
// Card is the model entity for the Card schema.
@@ -25,24 +26,37 @@ type Card struct {
Number string `json:"number,omitempty"`
}
// FromRows scans the sql response data into Card.
func (c *Card) FromRows(rows *sql.Rows) error {
var scanc struct {
ID int
Expired sql.NullTime
Number sql.NullString
// scanValues returns the types for scanning values from sql.Rows.
func (*Card) scanValues() []interface{} {
return []interface{}{
&sql.NullInt64{},
&sql.NullTime{},
&sql.NullString{},
}
// the order here should be the same as in the `card.Columns`.
if err := rows.Scan(
&scanc.ID,
&scanc.Expired,
&scanc.Number,
); err != nil {
return err
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Card fields.
func (c *Card) assignValues(values ...interface{}) error {
if m, n := len(values), len(card.Columns); m != n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
value, ok := values[0].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
c.ID = int(value.Int64)
values = values[1:]
if value, ok := values[0].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field expired", values[0])
} else if value.Valid {
c.Expired = value.Time
}
if value, ok := values[1].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field number", values[1])
} else if value.Valid {
c.Number = value.String
}
c.ID = scanc.ID
c.Expired = scanc.Expired.Time
c.Number = scanc.Number.String
return nil
}
@@ -85,18 +99,6 @@ func (c *Card) String() string {
// Cards is a parsable slice of Card.
type Cards []*Card
// FromRows scans the sql response data into Cards.
func (c *Cards) FromRows(rows *sql.Rows) error {
for rows.Next() {
scanc := &Card{}
if err := scanc.FromRows(rows); err != nil {
return err
}
*c = append(*c, scanc)
}
return nil
}
func (c Cards) config(cfg config) {
for _i := range c {
c[_i].config = cfg

View File

@@ -17,6 +17,7 @@ import (
"github.com/facebookincubator/ent/examples/o2o2types/ent/card"
"github.com/facebookincubator/ent/examples/o2o2types/ent/predicate"
"github.com/facebookincubator/ent/examples/o2o2types/ent/user"
"github.com/facebookincubator/ent/schema/field"
)
// CardQuery is the builder for querying Card entities.
@@ -278,45 +279,31 @@ func (cq *CardQuery) Select(field string, fields ...string) *CardSelect {
}
func (cq *CardQuery) sqlAll(ctx context.Context) ([]*Card, error) {
rows := &sql.Rows{}
selector := cq.sqlQuery()
if unique := cq.unique; len(unique) == 0 {
selector.Distinct()
var (
nodes []*Card
spec = cq.querySpec()
)
spec.ScanValues = func() []interface{} {
node := &Card{config: cq.config}
nodes = append(nodes, node)
return node.scanValues()
}
query, args := selector.Query()
if err := cq.driver.Query(ctx, query, args, rows); err != nil {
spec.Assign = func(values ...interface{}) error {
if len(nodes) == 0 {
return fmt.Errorf("ent: Assign called without calling ScanValues")
}
node := nodes[len(nodes)-1]
return node.assignValues(values...)
}
if err := sqlgraph.QueryNodes(ctx, cq.driver, spec); err != nil {
return nil, err
}
defer rows.Close()
var cs Cards
if err := cs.FromRows(rows); err != nil {
return nil, err
}
cs.config(cq.config)
return cs, nil
return nodes, nil
}
func (cq *CardQuery) sqlCount(ctx context.Context) (int, error) {
rows := &sql.Rows{}
selector := cq.sqlQuery()
unique := []string{card.FieldID}
if len(cq.unique) > 0 {
unique = cq.unique
}
selector.Count(sql.Distinct(selector.Columns(unique...)...))
query, args := selector.Query()
if err := cq.driver.Query(ctx, query, args, rows); err != nil {
return 0, err
}
defer rows.Close()
if !rows.Next() {
return 0, errors.New("ent: no rows found")
}
var n int
if err := rows.Scan(&n); err != nil {
return 0, fmt.Errorf("ent: failed reading count: %v", err)
}
return n, nil
spec := cq.querySpec()
return sqlgraph.CountNodes(ctx, cq.driver, spec)
}
func (cq *CardQuery) sqlExist(ctx context.Context) (bool, error) {
@@ -327,6 +314,42 @@ func (cq *CardQuery) sqlExist(ctx context.Context) (bool, error) {
return n > 0, nil
}
func (cq *CardQuery) querySpec() *sqlgraph.QuerySpec {
spec := &sqlgraph.QuerySpec{
Node: &sqlgraph.NodeSpec{
Table: card.Table,
Columns: card.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: card.FieldID,
},
},
From: cq.sql,
Unique: true,
}
if ps := cq.predicates; len(ps) > 0 {
spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := cq.limit; limit != nil {
spec.Limit = *limit
}
if offset := cq.offset; offset != nil {
spec.Offset = *offset
}
if ps := cq.order; len(ps) > 0 {
spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return spec
}
func (cq *CardQuery) sqlQuery() *sql.Selector {
builder := sql.Dialect(cq.driver.Dialect())
t1 := builder.Table(card.Table)
@@ -598,7 +621,7 @@ func (cs *CardSelect) sqlScan(ctx context.Context, v interface{}) error {
}
func (cs *CardSelect) sqlQuery() sql.Querier {
view := "card_view"
return sql.Dialect(cs.driver.Dialect()).
Select(cs.fields...).From(cs.sql.As(view))
selector := cs.sql
selector.Select(selector.Columns(cs.fields...)...)
return selector
}

View File

@@ -9,7 +9,6 @@ package ent
import (
"context"
"errors"
"fmt"
"time"
"github.com/facebookincubator/ent/dialect/sql"
@@ -314,33 +313,8 @@ func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (c *Card, err error) {
spec.Edges.Add = append(spec.Edges.Add, edge)
}
c = &Card{config: cuo.config}
spec.ScanTypes = []interface{}{
&sql.NullInt64{},
&sql.NullTime{},
&sql.NullString{},
}
spec.Assign = func(values ...interface{}) error {
if m, n := len(values), len(spec.ScanTypes); m != n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
value, ok := values[0].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
c.ID = int(value.Int64)
values = values[1:]
if value, ok := values[0].(*sql.NullTime); !ok {
return fmt.Errorf("unexpected type %T for field expired", values[0])
} else if value.Valid {
c.Expired = value.Time
}
if value, ok := values[1].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field number", values[1])
} else if value.Valid {
c.Number = value.String
}
return nil
}
spec.Assign = c.assignValues
spec.ScanValues = c.scanValues()
if err = sqlgraph.UpdateNode(ctx, cuo.driver, spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
err = cerr

View File

@@ -11,6 +11,7 @@ import (
"strings"
"github.com/facebookincubator/ent/dialect/sql"
"github.com/facebookincubator/ent/examples/o2o2types/ent/user"
)
// User is the model entity for the User schema.
@@ -24,24 +25,37 @@ type User struct {
Name string `json:"name,omitempty"`
}
// FromRows scans the sql response data into User.
func (u *User) FromRows(rows *sql.Rows) error {
var scanu struct {
ID int
Age sql.NullInt64
Name sql.NullString
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues() []interface{} {
return []interface{}{
&sql.NullInt64{},
&sql.NullInt64{},
&sql.NullString{},
}
// the order here should be the same as in the `user.Columns`.
if err := rows.Scan(
&scanu.ID,
&scanu.Age,
&scanu.Name,
); err != nil {
return err
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the User fields.
func (u *User) assignValues(values ...interface{}) error {
if m, n := len(values), len(user.Columns); m != n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
value, ok := values[0].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
u.ID = int(value.Int64)
values = values[1:]
if value, ok := values[0].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field age", values[0])
} else if value.Valid {
u.Age = int(value.Int64)
}
if value, ok := values[1].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[1])
} else if value.Valid {
u.Name = value.String
}
u.ID = scanu.ID
u.Age = int(scanu.Age.Int64)
u.Name = scanu.Name.String
return nil
}
@@ -84,18 +98,6 @@ func (u *User) String() string {
// Users is a parsable slice of User.
type Users []*User
// FromRows scans the sql response data into Users.
func (u *Users) FromRows(rows *sql.Rows) error {
for rows.Next() {
scanu := &User{}
if err := scanu.FromRows(rows); err != nil {
return err
}
*u = append(*u, scanu)
}
return nil
}
func (u Users) config(cfg config) {
for _i := range u {
u[_i].config = cfg

View File

@@ -17,6 +17,7 @@ import (
"github.com/facebookincubator/ent/examples/o2o2types/ent/card"
"github.com/facebookincubator/ent/examples/o2o2types/ent/predicate"
"github.com/facebookincubator/ent/examples/o2o2types/ent/user"
"github.com/facebookincubator/ent/schema/field"
)
// UserQuery is the builder for querying User entities.
@@ -278,45 +279,31 @@ func (uq *UserQuery) Select(field string, fields ...string) *UserSelect {
}
func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
rows := &sql.Rows{}
selector := uq.sqlQuery()
if unique := uq.unique; len(unique) == 0 {
selector.Distinct()
var (
nodes []*User
spec = uq.querySpec()
)
spec.ScanValues = func() []interface{} {
node := &User{config: uq.config}
nodes = append(nodes, node)
return node.scanValues()
}
query, args := selector.Query()
if err := uq.driver.Query(ctx, query, args, rows); err != nil {
spec.Assign = func(values ...interface{}) error {
if len(nodes) == 0 {
return fmt.Errorf("ent: Assign called without calling ScanValues")
}
node := nodes[len(nodes)-1]
return node.assignValues(values...)
}
if err := sqlgraph.QueryNodes(ctx, uq.driver, spec); err != nil {
return nil, err
}
defer rows.Close()
var us Users
if err := us.FromRows(rows); err != nil {
return nil, err
}
us.config(uq.config)
return us, nil
return nodes, nil
}
func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) {
rows := &sql.Rows{}
selector := uq.sqlQuery()
unique := []string{user.FieldID}
if len(uq.unique) > 0 {
unique = uq.unique
}
selector.Count(sql.Distinct(selector.Columns(unique...)...))
query, args := selector.Query()
if err := uq.driver.Query(ctx, query, args, rows); err != nil {
return 0, err
}
defer rows.Close()
if !rows.Next() {
return 0, errors.New("ent: no rows found")
}
var n int
if err := rows.Scan(&n); err != nil {
return 0, fmt.Errorf("ent: failed reading count: %v", err)
}
return n, nil
spec := uq.querySpec()
return sqlgraph.CountNodes(ctx, uq.driver, spec)
}
func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) {
@@ -327,6 +314,42 @@ func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) {
return n > 0, nil
}
func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec {
spec := &sqlgraph.QuerySpec{
Node: &sqlgraph.NodeSpec{
Table: user.Table,
Columns: user.Columns,
ID: &sqlgraph.FieldSpec{
Type: field.TypeInt,
Column: user.FieldID,
},
},
From: uq.sql,
Unique: true,
}
if ps := uq.predicates; len(ps) > 0 {
spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if limit := uq.limit; limit != nil {
spec.Limit = *limit
}
if offset := uq.offset; offset != nil {
spec.Offset = *offset
}
if ps := uq.order; len(ps) > 0 {
spec.Order = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
return spec
}
func (uq *UserQuery) sqlQuery() *sql.Selector {
builder := sql.Dialect(uq.driver.Dialect())
t1 := builder.Table(user.Table)
@@ -598,7 +621,7 @@ func (us *UserSelect) sqlScan(ctx context.Context, v interface{}) error {
}
func (us *UserSelect) sqlQuery() sql.Querier {
view := "user_view"
return sql.Dialect(us.driver.Dialect()).
Select(us.fields...).From(us.sql.As(view))
selector := us.sql
selector.Select(selector.Columns(us.fields...)...)
return selector
}

View File

@@ -9,7 +9,6 @@ package ent
import (
"context"
"errors"
"fmt"
"github.com/facebookincubator/ent/dialect/sql"
"github.com/facebookincubator/ent/dialect/sql/sqlgraph"
@@ -361,33 +360,8 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
spec.Edges.Add = append(spec.Edges.Add, edge)
}
u = &User{config: uuo.config}
spec.ScanTypes = []interface{}{
&sql.NullInt64{},
&sql.NullInt64{},
&sql.NullString{},
}
spec.Assign = func(values ...interface{}) error {
if m, n := len(values), len(spec.ScanTypes); m != n {
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
}
value, ok := values[0].(*sql.NullInt64)
if !ok {
return fmt.Errorf("unexpected type %T for field id", value)
}
u.ID = int(value.Int64)
values = values[1:]
if value, ok := values[0].(*sql.NullInt64); !ok {
return fmt.Errorf("unexpected type %T for field age", values[0])
} else if value.Valid {
u.Age = int(value.Int64)
}
if value, ok := values[1].(*sql.NullString); !ok {
return fmt.Errorf("unexpected type %T for field name", values[1])
} else if value.Valid {
u.Name = value.String
}
return nil
}
spec.Assign = u.assignValues
spec.ScanValues = u.scanValues()
if err = sqlgraph.UpdateNode(ctx, uuo.driver, spec); err != nil {
if cerr, ok := isSQLConstraintError(err); ok {
err = cerr