entc/gen: wrap nillable fields with custom go-type with sql.nullscanner

This commit is contained in:
Ariel Mashraki
2021-04-17 10:06:10 +03:00
committed by Ariel Mashraki
parent 762e6aeff9
commit 2480b5c0ef
41 changed files with 181 additions and 95 deletions

View File

@@ -400,7 +400,7 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
s.Where(sql.InValues(group.UsersPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)

View File

@@ -400,7 +400,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
s.Where(sql.InValues(user.GroupsPrimaryKey[1], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)

View File

@@ -399,7 +399,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
s.Where(sql.InValues(user.FriendsPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)

View File

@@ -435,7 +435,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
s.Where(sql.InValues(user.FollowersPrimaryKey[1], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)
@@ -500,7 +500,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
s.Where(sql.InValues(user.FollowingPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)

View File

@@ -480,7 +480,7 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
s.Where(sql.InValues(group.UsersPrimaryKey[1], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)

View File

@@ -106,7 +106,6 @@ func (u *User) assignValues(columns []string, values []interface{}) error {
u.Name = value.String
}
case user.FieldFoods:
if value, ok := values[i].(*[]byte); !ok {
return fmt.Errorf("unexpected type %T for field foods", values[i])
} else if value != nil && len(*value) > 0 {

View File

@@ -480,7 +480,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
s.Where(sql.InValues(user.GroupsPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)

View File

@@ -400,7 +400,7 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
s.Where(sql.InValues(group.UsersPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)

View File

@@ -466,7 +466,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
s.Where(sql.InValues(user.GroupsPrimaryKey[1], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)

View File

@@ -444,7 +444,7 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
s.Where(sql.InValues(group.UsersPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)

View File

@@ -444,7 +444,7 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
s.Where(sql.InValues(pet.FriendsPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)

View File

@@ -538,7 +538,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
s.Where(sql.InValues(user.FriendsPrimaryKey[0], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)
@@ -603,7 +603,7 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
s.Where(sql.InValues(user.GroupsPrimaryKey[1], fks...))
},
ScanValues: func() [2]interface{} {
return [2]interface{}{&sql.NullInt64{}, &sql.NullInt64{}}
return [2]interface{}{new(sql.NullInt64), new(sql.NullInt64)}
},
Assign: func(out, in interface{}) error {
eout, ok := out.(*sql.NullInt64)