mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
examples: regenerate examples (#296)
This commit is contained in:
@@ -28,7 +28,7 @@ type User struct {
|
||||
Edges struct {
|
||||
// Spouse holds the value of the spouse edge.
|
||||
Spouse *User
|
||||
}
|
||||
} `json:"edges"`
|
||||
user_spouse_id *int
|
||||
}
|
||||
|
||||
|
||||
@@ -82,8 +82,8 @@ func (uc *UserCreate) SaveX(ctx context.Context) *User {
|
||||
|
||||
func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
var (
|
||||
u = &User{config: uc.config}
|
||||
spec = &sqlgraph.CreateSpec{
|
||||
u = &User{config: uc.config}
|
||||
_spec = &sqlgraph.CreateSpec{
|
||||
Table: user.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
@@ -92,7 +92,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
}
|
||||
)
|
||||
if value := uc.age; value != nil {
|
||||
spec.Fields = append(spec.Fields, &sqlgraph.FieldSpec{
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: *value,
|
||||
Column: user.FieldAge,
|
||||
@@ -100,7 +100,7 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
u.Age = *value
|
||||
}
|
||||
if value := uc.name; value != nil {
|
||||
spec.Fields = append(spec.Fields, &sqlgraph.FieldSpec{
|
||||
_spec.Fields = append(_spec.Fields, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: *value,
|
||||
Column: user.FieldName,
|
||||
@@ -124,15 +124,15 @@ func (uc *UserCreate) sqlSave(ctx context.Context) (*User, error) {
|
||||
for k, _ := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
spec.Edges = append(spec.Edges, edge)
|
||||
_spec.Edges = append(_spec.Edges, edge)
|
||||
}
|
||||
if err := sqlgraph.CreateNode(ctx, uc.driver, spec); err != nil {
|
||||
if err := sqlgraph.CreateNode(ctx, uc.driver, _spec); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
id := spec.ID.Value.(int64)
|
||||
id := _spec.ID.Value.(int64)
|
||||
u.ID = int(id)
|
||||
return u, nil
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func (ud *UserDelete) ExecX(ctx context.Context) int {
|
||||
}
|
||||
|
||||
func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
spec := &sqlgraph.DeleteSpec{
|
||||
_spec := &sqlgraph.DeleteSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: user.Table,
|
||||
ID: &sqlgraph.FieldSpec{
|
||||
@@ -53,13 +53,13 @@ func (ud *UserDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
},
|
||||
}
|
||||
if ps := ud.predicates; len(ps) > 0 {
|
||||
spec.Predicate = func(selector *sql.Selector) {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return sqlgraph.DeleteNodes(ctx, ud.driver, spec)
|
||||
return sqlgraph.DeleteNodes(ctx, ud.driver, _spec)
|
||||
}
|
||||
|
||||
// UserDeleteOne is the builder for deleting a single User entity.
|
||||
|
||||
@@ -295,15 +295,15 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
var (
|
||||
nodes []*User
|
||||
withFKs = uq.withFKs
|
||||
spec = uq.querySpec()
|
||||
_spec = uq.querySpec()
|
||||
)
|
||||
if uq.withSpouse != nil {
|
||||
withFKs = true
|
||||
}
|
||||
if withFKs {
|
||||
spec.Node.Columns = append(spec.Node.Columns, user.ForeignKeys...)
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, user.ForeignKeys...)
|
||||
}
|
||||
spec.ScanValues = func() []interface{} {
|
||||
_spec.ScanValues = func() []interface{} {
|
||||
node := &User{config: uq.config}
|
||||
nodes = append(nodes, node)
|
||||
values := node.scanValues()
|
||||
@@ -312,14 +312,14 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
}
|
||||
return values
|
||||
}
|
||||
spec.Assign = func(values ...interface{}) error {
|
||||
_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 {
|
||||
if err := sqlgraph.QueryNodes(ctx, uq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -352,8 +352,8 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
spec := uq.querySpec()
|
||||
return sqlgraph.CountNodes(ctx, uq.driver, spec)
|
||||
_spec := uq.querySpec()
|
||||
return sqlgraph.CountNodes(ctx, uq.driver, _spec)
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
@@ -365,7 +365,7 @@ func (uq *UserQuery) sqlExist(ctx context.Context) (bool, error) {
|
||||
}
|
||||
|
||||
func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
spec := &sqlgraph.QuerySpec{
|
||||
_spec := &sqlgraph.QuerySpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: user.Table,
|
||||
Columns: user.Columns,
|
||||
@@ -378,26 +378,26 @@ func (uq *UserQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
Unique: true,
|
||||
}
|
||||
if ps := uq.predicates; len(ps) > 0 {
|
||||
spec.Predicate = func(selector *sql.Selector) {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := uq.limit; limit != nil {
|
||||
spec.Limit = *limit
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := uq.offset; offset != nil {
|
||||
spec.Offset = *offset
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := uq.order; len(ps) > 0 {
|
||||
spec.Order = func(selector *sql.Selector) {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return spec
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (uq *UserQuery) sqlQuery() *sql.Selector {
|
||||
|
||||
@@ -116,7 +116,7 @@ func (uu *UserUpdate) ExecX(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
spec := &sqlgraph.UpdateSpec{
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: user.Table,
|
||||
Columns: user.Columns,
|
||||
@@ -127,28 +127,28 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
},
|
||||
}
|
||||
if ps := uu.predicates; len(ps) > 0 {
|
||||
spec.Predicate = func(selector *sql.Selector) {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value := uu.age; value != nil {
|
||||
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: *value,
|
||||
Column: user.FieldAge,
|
||||
})
|
||||
}
|
||||
if value := uu.addage; value != nil {
|
||||
spec.Fields.Add = append(spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: *value,
|
||||
Column: user.FieldAge,
|
||||
})
|
||||
}
|
||||
if value := uu.name; value != nil {
|
||||
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: *value,
|
||||
Column: user.FieldName,
|
||||
@@ -168,7 +168,7 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
},
|
||||
},
|
||||
}
|
||||
spec.Edges.Clear = append(spec.Edges.Clear, edge)
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uu.spouse; len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -187,9 +187,9 @@ func (uu *UserUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
for k, _ := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
spec.Edges.Add = append(spec.Edges.Add, edge)
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, spec); err != nil {
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, uu.driver, _spec); err != nil {
|
||||
if cerr, ok := isSQLConstraintError(err); ok {
|
||||
err = cerr
|
||||
}
|
||||
@@ -291,7 +291,7 @@ func (uuo *UserUpdateOne) ExecX(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
spec := &sqlgraph.UpdateSpec{
|
||||
_spec := &sqlgraph.UpdateSpec{
|
||||
Node: &sqlgraph.NodeSpec{
|
||||
Table: user.Table,
|
||||
Columns: user.Columns,
|
||||
@@ -303,21 +303,21 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
},
|
||||
}
|
||||
if value := uuo.age; value != nil {
|
||||
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: *value,
|
||||
Column: user.FieldAge,
|
||||
})
|
||||
}
|
||||
if value := uuo.addage; value != nil {
|
||||
spec.Fields.Add = append(spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
_spec.Fields.Add = append(_spec.Fields.Add, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeInt,
|
||||
Value: *value,
|
||||
Column: user.FieldAge,
|
||||
})
|
||||
}
|
||||
if value := uuo.name; value != nil {
|
||||
spec.Fields.Set = append(spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||
Type: field.TypeString,
|
||||
Value: *value,
|
||||
Column: user.FieldName,
|
||||
@@ -337,7 +337,7 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
},
|
||||
},
|
||||
}
|
||||
spec.Edges.Clear = append(spec.Edges.Clear, edge)
|
||||
_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
|
||||
}
|
||||
if nodes := uuo.spouse; len(nodes) > 0 {
|
||||
edge := &sqlgraph.EdgeSpec{
|
||||
@@ -356,12 +356,12 @@ func (uuo *UserUpdateOne) sqlSave(ctx context.Context) (u *User, err error) {
|
||||
for k, _ := range nodes {
|
||||
edge.Target.Nodes = append(edge.Target.Nodes, k)
|
||||
}
|
||||
spec.Edges.Add = append(spec.Edges.Add, edge)
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
u = &User{config: uuo.config}
|
||||
spec.Assign = u.assignValues
|
||||
spec.ScanValues = u.scanValues()
|
||||
if err = sqlgraph.UpdateNode(ctx, uuo.driver, spec); err != 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user