Merge pull request #260 from facebookincubator/sqlgraph/query

entc/gen: remove FromRows decoding
This commit is contained in:
Ariel Mashraki
2019-12-24 10:37:30 +02:00
committed by GitHub
26 changed files with 2 additions and 971 deletions

File diff suppressed because one or more lines are too long

View File

@@ -7,44 +7,6 @@ in the LICENSE file in the root directory of this source tree.
{{ define "dialect/sql/decode/one" }}
{{ $receiver := $.Receiver }}
// FromRows scans the sql response data into {{ $.Name }}.
func ({{ $receiver }} *{{ $.Name }}) FromRows(rows *sql.Rows) error {
{{- $scan := print "scan" $receiver }}
var {{ $scan }} struct {
ID {{ if $.ID.IsString }}int{{ else }}{{ $.ID.Type }}{{ end }}
{{ range $_, $f := $.Fields }}
{{- $f.StructField }} {{ $f.NullType }}
{{ end }}
}
// the order here should be the same as in the `{{ $.Package }}.Columns`.
if err := rows.Scan(
&{{ $scan }}.ID,
{{- range $_, $f := $.Fields }}
&{{ $scan }}.{{ $f.StructField }},
{{- end }}
); err != nil {
return err
}
{{ $receiver }}.ID = {{ if $.ID.IsString }}strconv.Itoa({{ $scan }}.ID){{ else }}{{ $scan }}.ID{{ end }}
{{- range $_, $f := $.Fields }}
{{- if $f.IsJSON }}
if value := {{ $scan }}.{{ $f.StructField }}; len(value) > 0 {
if err := json.Unmarshal(value, &{{ $receiver }}.{{ $f.StructField }}); err != nil {
return fmt.Errorf("unmarshal field {{ $f.Name }}: %v", err)
}
}
{{- else if $f.Nillable }}
if {{ $scan }}.{{ $f.StructField }}.Valid {
{{ $receiver }}.{{ $f.StructField }} = new({{ $f.Type }})
*{{ $receiver }}.{{ $f.StructField }} = {{ printf "%s.%s" $scan $f.StructField | $f.NullTypeField }}
}
{{- else }}
{{ $receiver }}.{{ $f.StructField }} = {{ printf "%s.%s" $scan $f.StructField | $f.NullTypeField }}
{{- end }}
{{- end }}
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*{{ $.Name }}) scanValues() []interface{} {
return []interface{} {
@@ -115,19 +77,4 @@ func ({{ $receiver }} *{{ $.Name }}) assignValues(values ...interface{}) error {
{{- end }}
{{ define "dialect/sql/decode/many" }}
{{ $receiver := $.Receiver }}
{{ $slice := $.Scope.Slice }}
// FromRows scans the sql response data into {{ $slice }}.
func ({{ $receiver }} *{{ $slice }}) FromRows(rows *sql.Rows) error {
for rows.Next() {
{{- $scan := print "scan" $receiver }}
{{ $scan }} := &{{ $.Name }}{}
if err := {{ $scan }}.FromRows(rows); err != nil {
return err
}
*{{ $receiver }} = append(*{{ $receiver }}, {{ $scan }})
}
return nil
}
{{ end }}

View File

@@ -21,21 +21,6 @@ type User struct {
ID int `json:"id,omitempty"`
}
// FromRows scans the sql response data into User.
func (u *User) FromRows(rows *sql.Rows) error {
var scanu struct {
ID int
}
// the order here should be the same as in the `user.Columns`.
if err := rows.Scan(
&scanu.ID,
); err != nil {
return err
}
u.ID = scanu.ID
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues() []interface{} {
return []interface{}{
@@ -88,18 +73,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

@@ -10,7 +10,6 @@ import (
"fmt"
"strings"
"github.com/facebookincubator/ent/dialect/sql"
"github.com/facebookincubator/ent/entc/integration/customid/ent/blob"
"github.com/google/uuid"
)
@@ -24,24 +23,6 @@ type Blob struct {
UUID uuid.UUID `json:"uuid,omitempty"`
}
// FromRows scans the sql response data into Blob.
func (b *Blob) FromRows(rows *sql.Rows) error {
var scanb struct {
ID uuid.UUID
UUID uuid.UUID
}
// the order here should be the same as in the `blob.Columns`.
if err := rows.Scan(
&scanb.ID,
&scanb.UUID,
); err != nil {
return err
}
b.ID = scanb.ID
b.UUID = scanb.UUID
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Blob) scanValues() []interface{} {
return []interface{}{
@@ -102,18 +83,6 @@ func (b *Blob) String() string {
// Blobs is a parsable slice of Blob.
type Blobs []*Blob
// FromRows scans the sql response data into Blobs.
func (b *Blobs) FromRows(rows *sql.Rows) error {
for rows.Next() {
scanb := &Blob{}
if err := scanb.FromRows(rows); err != nil {
return err
}
*b = append(*b, scanb)
}
return nil
}
func (b Blobs) config(cfg config) {
for _i := range b {
b[_i].config = cfg

View File

@@ -21,21 +21,6 @@ type Group struct {
ID int `json:"id,omitempty"`
}
// FromRows scans the sql response data into Group.
func (gr *Group) FromRows(rows *sql.Rows) error {
var scangr struct {
ID int
}
// the order here should be the same as in the `group.Columns`.
if err := rows.Scan(
&scangr.ID,
); err != nil {
return err
}
gr.ID = scangr.ID
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Group) scanValues() []interface{} {
return []interface{}{
@@ -93,18 +78,6 @@ func (gr *Group) String() string {
// Groups is a parsable slice of Group.
type Groups []*Group
// FromRows scans the sql response data into Groups.
func (gr *Groups) FromRows(rows *sql.Rows) error {
for rows.Next() {
scangr := &Group{}
if err := scangr.FromRows(rows); err != nil {
return err
}
*gr = append(*gr, scangr)
}
return nil
}
func (gr Groups) config(cfg config) {
for _i := range gr {
gr[_i].config = cfg

View File

@@ -21,21 +21,6 @@ type User struct {
ID int `json:"id,omitempty"`
}
// FromRows scans the sql response data into User.
func (u *User) FromRows(rows *sql.Rows) error {
var scanu struct {
ID int
}
// the order here should be the same as in the `user.Columns`.
if err := rows.Scan(
&scanu.ID,
); err != nil {
return err
}
u.ID = scanu.ID
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues() []interface{} {
return []interface{}{
@@ -93,18 +78,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

@@ -34,33 +34,6 @@ type Card struct {
StaticField string `json:"boring,omitempty"`
}
// FromRows scans the sql response data into Card.
func (c *Card) FromRows(rows *sql.Rows) error {
var scanc struct {
ID int
CreateTime sql.NullTime
UpdateTime sql.NullTime
Number sql.NullString
Name sql.NullString
}
// the order here should be the same as in the `card.Columns`.
if err := rows.Scan(
&scanc.ID,
&scanc.CreateTime,
&scanc.UpdateTime,
&scanc.Number,
&scanc.Name,
); err != nil {
return err
}
c.ID = strconv.Itoa(scanc.ID)
c.CreateTime = scanc.CreateTime.Time
c.UpdateTime = scanc.UpdateTime.Time
c.Number = scanc.Number.String
c.Name = scanc.Name.String
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Card) scanValues() []interface{} {
return []interface{}{
@@ -156,18 +129,6 @@ func (c *Card) id() int {
// 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

@@ -28,33 +28,6 @@ type Comment struct {
NillableInt *int `json:"nillable_int,omitempty"`
}
// FromRows scans the sql response data into Comment.
func (c *Comment) FromRows(rows *sql.Rows) error {
var scanc struct {
ID int
UniqueInt sql.NullInt64
UniqueFloat sql.NullFloat64
NillableInt sql.NullInt64
}
// the order here should be the same as in the `comment.Columns`.
if err := rows.Scan(
&scanc.ID,
&scanc.UniqueInt,
&scanc.UniqueFloat,
&scanc.NillableInt,
); err != nil {
return err
}
c.ID = strconv.Itoa(scanc.ID)
c.UniqueInt = int(scanc.UniqueInt.Int64)
c.UniqueFloat = scanc.UniqueFloat.Float64
if scanc.NillableInt.Valid {
c.NillableInt = new(int)
*c.NillableInt = int(scanc.NillableInt.Int64)
}
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Comment) scanValues() []interface{} {
return []interface{}{
@@ -140,18 +113,6 @@ func (c *Comment) id() int {
// Comments is a parsable slice of Comment.
type Comments []*Comment
// FromRows scans the sql response data into Comments.
func (c *Comments) FromRows(rows *sql.Rows) error {
for rows.Next() {
scanc := &Comment{}
if err := scanc.FromRows(rows); err != nil {
return err
}
*c = append(*c, scanc)
}
return nil
}
func (c Comments) config(cfg config) {
for _i := range c {
c[_i].config = cfg

View File

@@ -56,87 +56,6 @@ type FieldType struct {
State fieldtype.State `json:"state,omitempty"`
}
// FromRows scans the sql response data into FieldType.
func (ft *FieldType) FromRows(rows *sql.Rows) error {
var scanft struct {
ID int
Int sql.NullInt64
Int8 sql.NullInt64
Int16 sql.NullInt64
Int32 sql.NullInt64
Int64 sql.NullInt64
OptionalInt sql.NullInt64
OptionalInt8 sql.NullInt64
OptionalInt16 sql.NullInt64
OptionalInt32 sql.NullInt64
OptionalInt64 sql.NullInt64
NillableInt sql.NullInt64
NillableInt8 sql.NullInt64
NillableInt16 sql.NullInt64
NillableInt32 sql.NullInt64
NillableInt64 sql.NullInt64
ValidateOptionalInt32 sql.NullInt64
State sql.NullString
}
// the order here should be the same as in the `fieldtype.Columns`.
if err := rows.Scan(
&scanft.ID,
&scanft.Int,
&scanft.Int8,
&scanft.Int16,
&scanft.Int32,
&scanft.Int64,
&scanft.OptionalInt,
&scanft.OptionalInt8,
&scanft.OptionalInt16,
&scanft.OptionalInt32,
&scanft.OptionalInt64,
&scanft.NillableInt,
&scanft.NillableInt8,
&scanft.NillableInt16,
&scanft.NillableInt32,
&scanft.NillableInt64,
&scanft.ValidateOptionalInt32,
&scanft.State,
); err != nil {
return err
}
ft.ID = strconv.Itoa(scanft.ID)
ft.Int = int(scanft.Int.Int64)
ft.Int8 = int8(scanft.Int8.Int64)
ft.Int16 = int16(scanft.Int16.Int64)
ft.Int32 = int32(scanft.Int32.Int64)
ft.Int64 = scanft.Int64.Int64
ft.OptionalInt = int(scanft.OptionalInt.Int64)
ft.OptionalInt8 = int8(scanft.OptionalInt8.Int64)
ft.OptionalInt16 = int16(scanft.OptionalInt16.Int64)
ft.OptionalInt32 = int32(scanft.OptionalInt32.Int64)
ft.OptionalInt64 = scanft.OptionalInt64.Int64
if scanft.NillableInt.Valid {
ft.NillableInt = new(int)
*ft.NillableInt = int(scanft.NillableInt.Int64)
}
if scanft.NillableInt8.Valid {
ft.NillableInt8 = new(int8)
*ft.NillableInt8 = int8(scanft.NillableInt8.Int64)
}
if scanft.NillableInt16.Valid {
ft.NillableInt16 = new(int16)
*ft.NillableInt16 = int16(scanft.NillableInt16.Int64)
}
if scanft.NillableInt32.Valid {
ft.NillableInt32 = new(int32)
*ft.NillableInt32 = int32(scanft.NillableInt32.Int64)
}
if scanft.NillableInt64.Valid {
ft.NillableInt64 = new(int64)
*ft.NillableInt64 = scanft.NillableInt64.Int64
}
ft.ValidateOptionalInt32 = int32(scanft.ValidateOptionalInt32.Int64)
ft.State = fieldtype.State(scanft.State.String)
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*FieldType) scanValues() []interface{} {
return []interface{}{
@@ -346,18 +265,6 @@ func (ft *FieldType) id() int {
// FieldTypes is a parsable slice of FieldType.
type FieldTypes []*FieldType
// FromRows scans the sql response data into FieldTypes.
func (ft *FieldTypes) FromRows(rows *sql.Rows) error {
for rows.Next() {
scanft := &FieldType{}
if err := scanft.FromRows(rows); err != nil {
return err
}
*ft = append(*ft, scanft)
}
return nil
}
func (ft FieldTypes) config(cfg config) {
for _i := range ft {
ft[_i].config = cfg

View File

@@ -30,36 +30,6 @@ type File struct {
Group string `json:"group,omitempty"`
}
// FromRows scans the sql response data into File.
func (f *File) FromRows(rows *sql.Rows) error {
var scanf struct {
ID int
Size sql.NullInt64
Name sql.NullString
User sql.NullString
Group sql.NullString
}
// the order here should be the same as in the `file.Columns`.
if err := rows.Scan(
&scanf.ID,
&scanf.Size,
&scanf.Name,
&scanf.User,
&scanf.Group,
); err != nil {
return err
}
f.ID = strconv.Itoa(scanf.ID)
f.Size = int(scanf.Size.Int64)
f.Name = scanf.Name.String
if scanf.User.Valid {
f.User = new(string)
*f.User = scanf.User.String
}
f.Group = scanf.Group.String
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*File) scanValues() []interface{} {
return []interface{}{
@@ -163,18 +133,6 @@ func (f *File) id() int {
// Files is a parsable slice of File.
type Files []*File
// FromRows scans the sql response data into Files.
func (f *Files) FromRows(rows *sql.Rows) error {
for rows.Next() {
scanf := &File{}
if err := scanf.FromRows(rows); err != nil {
return err
}
*f = append(*f, scanf)
}
return nil
}
func (f Files) config(cfg config) {
for _i := range f {
f[_i].config = cfg

View File

@@ -24,24 +24,6 @@ type FileType struct {
Name string `json:"name,omitempty"`
}
// FromRows scans the sql response data into FileType.
func (ft *FileType) FromRows(rows *sql.Rows) error {
var scanft struct {
ID int
Name sql.NullString
}
// the order here should be the same as in the `filetype.Columns`.
if err := rows.Scan(
&scanft.ID,
&scanft.Name,
); err != nil {
return err
}
ft.ID = strconv.Itoa(scanft.ID)
ft.Name = scanft.Name.String
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*FileType) scanValues() []interface{} {
return []interface{}{
@@ -113,18 +95,6 @@ func (ft *FileType) id() int {
// FileTypes is a parsable slice of FileType.
type FileTypes []*FileType
// FromRows scans the sql response data into FileTypes.
func (ft *FileTypes) FromRows(rows *sql.Rows) error {
for rows.Next() {
scanft := &FileType{}
if err := scanft.FromRows(rows); err != nil {
return err
}
*ft = append(*ft, scanft)
}
return nil
}
func (ft FileTypes) config(cfg config) {
for _i := range ft {
ft[_i].config = cfg

View File

@@ -33,39 +33,6 @@ type Group struct {
Name string `json:"name,omitempty"`
}
// FromRows scans the sql response data into Group.
func (gr *Group) FromRows(rows *sql.Rows) error {
var scangr struct {
ID int
Active sql.NullBool
Expire sql.NullTime
Type sql.NullString
MaxUsers sql.NullInt64
Name sql.NullString
}
// the order here should be the same as in the `group.Columns`.
if err := rows.Scan(
&scangr.ID,
&scangr.Active,
&scangr.Expire,
&scangr.Type,
&scangr.MaxUsers,
&scangr.Name,
); err != nil {
return err
}
gr.ID = strconv.Itoa(scangr.ID)
gr.Active = scangr.Active.Bool
gr.Expire = scangr.Expire.Time
if scangr.Type.Valid {
gr.Type = new(string)
*gr.Type = scangr.Type.String
}
gr.MaxUsers = int(scangr.MaxUsers.Int64)
gr.Name = scangr.Name.String
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Group) scanValues() []interface{} {
return []interface{}{
@@ -187,18 +154,6 @@ func (gr *Group) id() int {
// Groups is a parsable slice of Group.
type Groups []*Group
// FromRows scans the sql response data into Groups.
func (gr *Groups) FromRows(rows *sql.Rows) error {
for rows.Next() {
scangr := &Group{}
if err := scangr.FromRows(rows); err != nil {
return err
}
*gr = append(*gr, scangr)
}
return nil
}
func (gr Groups) config(cfg config) {
for _i := range gr {
gr[_i].config = cfg

View File

@@ -26,27 +26,6 @@ type GroupInfo struct {
MaxUsers int `json:"max_users,omitempty"`
}
// FromRows scans the sql response data into GroupInfo.
func (gi *GroupInfo) FromRows(rows *sql.Rows) error {
var scangi struct {
ID int
Desc sql.NullString
MaxUsers sql.NullInt64
}
// the order here should be the same as in the `groupinfo.Columns`.
if err := rows.Scan(
&scangi.ID,
&scangi.Desc,
&scangi.MaxUsers,
); err != nil {
return err
}
gi.ID = strconv.Itoa(scangi.ID)
gi.Desc = scangi.Desc.String
gi.MaxUsers = int(scangi.MaxUsers.Int64)
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*GroupInfo) scanValues() []interface{} {
return []interface{}{
@@ -126,18 +105,6 @@ func (gi *GroupInfo) id() int {
// GroupInfos is a parsable slice of GroupInfo.
type GroupInfos []*GroupInfo
// FromRows scans the sql response data into GroupInfos.
func (gi *GroupInfos) FromRows(rows *sql.Rows) error {
for rows.Next() {
scangi := &GroupInfo{}
if err := scangi.FromRows(rows); err != nil {
return err
}
*gi = append(*gi, scangi)
}
return nil
}
func (gi GroupInfos) config(cfg config) {
for _i := range gi {
gi[_i].config = cfg

View File

@@ -22,21 +22,6 @@ type Item struct {
ID string `json:"id,omitempty"`
}
// FromRows scans the sql response data into Item.
func (i *Item) FromRows(rows *sql.Rows) error {
var scani struct {
ID int
}
// the order here should be the same as in the `item.Columns`.
if err := rows.Scan(
&scani.ID,
); err != nil {
return err
}
i.ID = strconv.Itoa(scani.ID)
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Item) scanValues() []interface{} {
return []interface{}{
@@ -95,18 +80,6 @@ func (i *Item) id() int {
// Items is a parsable slice of Item.
type Items []*Item
// FromRows scans the sql response data into Items.
func (i *Items) FromRows(rows *sql.Rows) error {
for rows.Next() {
scani := &Item{}
if err := scani.FromRows(rows); err != nil {
return err
}
*i = append(*i, scani)
}
return nil
}
func (i Items) config(cfg config) {
for _i := range i {
i[_i].config = cfg

View File

@@ -24,24 +24,6 @@ type Node struct {
Value int `json:"value,omitempty"`
}
// FromRows scans the sql response data into Node.
func (n *Node) FromRows(rows *sql.Rows) error {
var scann struct {
ID int
Value sql.NullInt64
}
// the order here should be the same as in the `node.Columns`.
if err := rows.Scan(
&scann.ID,
&scann.Value,
); err != nil {
return err
}
n.ID = strconv.Itoa(scann.ID)
n.Value = int(scann.Value.Int64)
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Node) scanValues() []interface{} {
return []interface{}{
@@ -118,18 +100,6 @@ func (n *Node) id() int {
// Nodes is a parsable slice of Node.
type Nodes []*Node
// FromRows scans the sql response data into Nodes.
func (n *Nodes) FromRows(rows *sql.Rows) error {
for rows.Next() {
scann := &Node{}
if err := scann.FromRows(rows); err != nil {
return err
}
*n = append(*n, scann)
}
return nil
}
func (n Nodes) config(cfg config) {
for _i := range n {
n[_i].config = cfg

View File

@@ -24,24 +24,6 @@ type Pet struct {
Name string `json:"name,omitempty"`
}
// FromRows scans the sql response data into Pet.
func (pe *Pet) FromRows(rows *sql.Rows) error {
var scanpe struct {
ID int
Name sql.NullString
}
// the order here should be the same as in the `pet.Columns`.
if err := rows.Scan(
&scanpe.ID,
&scanpe.Name,
); err != nil {
return err
}
pe.ID = strconv.Itoa(scanpe.ID)
pe.Name = scanpe.Name.String
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Pet) scanValues() []interface{} {
return []interface{}{
@@ -118,18 +100,6 @@ func (pe *Pet) id() int {
// Pets is a parsable slice of Pet.
type Pets []*Pet
// FromRows scans the sql response data into Pets.
func (pe *Pets) FromRows(rows *sql.Rows) error {
for rows.Next() {
scanpe := &Pet{}
if err := scanpe.FromRows(rows); err != nil {
return err
}
*pe = append(*pe, scanpe)
}
return nil
}
func (pe Pets) config(cfg config) {
for _i := range pe {
pe[_i].config = cfg

View File

@@ -34,39 +34,6 @@ type User struct {
Password string `graphql:"-" json:"-"`
}
// 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
Last sql.NullString
Nickname sql.NullString
Phone sql.NullString
Password sql.NullString
}
// the order here should be the same as in the `user.Columns`.
if err := rows.Scan(
&scanu.ID,
&scanu.Age,
&scanu.Name,
&scanu.Last,
&scanu.Nickname,
&scanu.Phone,
&scanu.Password,
); err != nil {
return err
}
u.ID = strconv.Itoa(scanu.ID)
u.Age = int(scanu.Age.Int64)
u.Name = scanu.Name.String
u.Last = scanu.Last.String
u.Nickname = scanu.Nickname.String
u.Phone = scanu.Phone.String
u.Password = scanu.Password.String
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues() []interface{} {
return []interface{}{
@@ -227,18 +194,6 @@ func (u *User) id() int {
// 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

@@ -23,24 +23,6 @@ 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 uint64
Name sql.NullString
}
// the order here should be the same as in the `user.Columns`.
if err := rows.Scan(
&scanu.ID,
&scanu.Name,
); err != nil {
return err
}
u.ID = scanu.ID
u.Name = scanu.Name.String
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues() []interface{} {
return []interface{}{
@@ -116,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

@@ -36,63 +36,6 @@ type User struct {
Strings []string `json:"strings,omitempty"`
}
// FromRows scans the sql response data into User.
func (u *User) FromRows(rows *sql.Rows) error {
var scanu struct {
ID int
URL []byte
Raw []byte
Dirs []byte
Ints []byte
Floats []byte
Strings []byte
}
// the order here should be the same as in the `user.Columns`.
if err := rows.Scan(
&scanu.ID,
&scanu.URL,
&scanu.Raw,
&scanu.Dirs,
&scanu.Ints,
&scanu.Floats,
&scanu.Strings,
); err != nil {
return err
}
u.ID = scanu.ID
if value := scanu.URL; len(value) > 0 {
if err := json.Unmarshal(value, &u.URL); err != nil {
return fmt.Errorf("unmarshal field url: %v", err)
}
}
if value := scanu.Raw; len(value) > 0 {
if err := json.Unmarshal(value, &u.Raw); err != nil {
return fmt.Errorf("unmarshal field raw: %v", err)
}
}
if value := scanu.Dirs; len(value) > 0 {
if err := json.Unmarshal(value, &u.Dirs); err != nil {
return fmt.Errorf("unmarshal field dirs: %v", err)
}
}
if value := scanu.Ints; len(value) > 0 {
if err := json.Unmarshal(value, &u.Ints); err != nil {
return fmt.Errorf("unmarshal field ints: %v", err)
}
}
if value := scanu.Floats; len(value) > 0 {
if err := json.Unmarshal(value, &u.Floats); err != nil {
return fmt.Errorf("unmarshal field floats: %v", err)
}
}
if value := scanu.Strings; len(value) > 0 {
if err := json.Unmarshal(value, &u.Strings); err != nil {
return fmt.Errorf("unmarshal field strings: %v", err)
}
}
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues() []interface{} {
return []interface{}{
@@ -211,18 +154,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

@@ -35,42 +35,6 @@ type User struct {
State user.State `json:"state,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
Nickname sql.NullString
Address sql.NullString
Renamed sql.NullString
Blob []byte
State sql.NullString
}
// the order here should be the same as in the `user.Columns`.
if err := rows.Scan(
&scanu.ID,
&scanu.Age,
&scanu.Name,
&scanu.Nickname,
&scanu.Address,
&scanu.Renamed,
&scanu.Blob,
&scanu.State,
); err != nil {
return err
}
u.ID = scanu.ID
u.Age = int32(scanu.Age.Int64)
u.Name = scanu.Name.String
u.Nickname = scanu.Nickname.String
u.Address = scanu.Address.String
u.Renamed = scanu.Renamed.String
u.Blob = scanu.Blob
u.State = user.State(scanu.State.String)
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues() []interface{} {
return []interface{}{
@@ -179,18 +143,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

@@ -21,21 +21,6 @@ type Group struct {
ID int `json:"id,omitempty"`
}
// FromRows scans the sql response data into Group.
func (gr *Group) FromRows(rows *sql.Rows) error {
var scangr struct {
ID int
}
// the order here should be the same as in the `group.Columns`.
if err := rows.Scan(
&scangr.ID,
); err != nil {
return err
}
gr.ID = scangr.ID
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Group) scanValues() []interface{} {
return []interface{}{
@@ -88,18 +73,6 @@ func (gr *Group) String() string {
// Groups is a parsable slice of Group.
type Groups []*Group
// FromRows scans the sql response data into Groups.
func (gr *Groups) FromRows(rows *sql.Rows) error {
for rows.Next() {
scangr := &Group{}
if err := scangr.FromRows(rows); err != nil {
return err
}
*gr = append(*gr, scangr)
}
return nil
}
func (gr Groups) config(cfg config) {
for _i := range gr {
gr[_i].config = cfg

View File

@@ -21,21 +21,6 @@ type Pet struct {
ID int `json:"id,omitempty"`
}
// FromRows scans the sql response data into Pet.
func (pe *Pet) FromRows(rows *sql.Rows) error {
var scanpe struct {
ID int
}
// the order here should be the same as in the `pet.Columns`.
if err := rows.Scan(
&scanpe.ID,
); err != nil {
return err
}
pe.ID = scanpe.ID
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Pet) scanValues() []interface{} {
return []interface{}{
@@ -88,18 +73,6 @@ func (pe *Pet) String() string {
// Pets is a parsable slice of Pet.
type Pets []*Pet
// FromRows scans the sql response data into Pets.
func (pe *Pets) FromRows(rows *sql.Rows) error {
for rows.Next() {
scanpe := &Pet{}
if err := scanpe.FromRows(rows); err != nil {
return err
}
*pe = append(*pe, scanpe)
}
return nil
}
func (pe Pets) config(cfg config) {
for _i := range pe {
pe[_i].config = cfg

View File

@@ -39,48 +39,6 @@ type User struct {
State user.State `json:"state,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
Nickname sql.NullString
Phone sql.NullString
Buffer []byte
Title sql.NullString
NewName sql.NullString
Blob []byte
State sql.NullString
}
// the order here should be the same as in the `user.Columns`.
if err := rows.Scan(
&scanu.ID,
&scanu.Age,
&scanu.Name,
&scanu.Nickname,
&scanu.Phone,
&scanu.Buffer,
&scanu.Title,
&scanu.NewName,
&scanu.Blob,
&scanu.State,
); err != nil {
return err
}
u.ID = scanu.ID
u.Age = int(scanu.Age.Int64)
u.Name = scanu.Name.String
u.Nickname = scanu.Nickname.String
u.Phone = scanu.Phone.String
u.Buffer = scanu.Buffer
u.Title = scanu.Title.String
u.NewName = scanu.NewName.String
u.Blob = scanu.Blob
u.State = user.State(scanu.State.String)
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues() []interface{} {
return []interface{}{
@@ -205,18 +163,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

@@ -23,24 +23,6 @@ type Group struct {
MaxUsers int `json:"max_users,omitempty"`
}
// FromRows scans the sql response data into Group.
func (gr *Group) FromRows(rows *sql.Rows) error {
var scangr struct {
ID int
MaxUsers sql.NullInt64
}
// the order here should be the same as in the `group.Columns`.
if err := rows.Scan(
&scangr.ID,
&scangr.MaxUsers,
); err != nil {
return err
}
gr.ID = scangr.ID
gr.MaxUsers = int(scangr.MaxUsers.Int64)
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Group) scanValues() []interface{} {
return []interface{}{
@@ -101,18 +83,6 @@ func (gr *Group) String() string {
// Groups is a parsable slice of Group.
type Groups []*Group
// FromRows scans the sql response data into Groups.
func (gr *Groups) FromRows(rows *sql.Rows) error {
for rows.Next() {
scangr := &Group{}
if err := scangr.FromRows(rows); err != nil {
return err
}
*gr = append(*gr, scangr)
}
return nil
}
func (gr Groups) config(cfg config) {
for _i := range gr {
gr[_i].config = cfg

View File

@@ -26,30 +26,6 @@ type Pet struct {
LicensedAt *time.Time `json:"licensed_at,omitempty"`
}
// FromRows scans the sql response data into Pet.
func (pe *Pet) FromRows(rows *sql.Rows) error {
var scanpe struct {
ID int
Age sql.NullInt64
LicensedAt sql.NullTime
}
// the order here should be the same as in the `pet.Columns`.
if err := rows.Scan(
&scanpe.ID,
&scanpe.Age,
&scanpe.LicensedAt,
); err != nil {
return err
}
pe.ID = scanpe.ID
pe.Age = int(scanpe.Age.Int64)
if scanpe.LicensedAt.Valid {
pe.LicensedAt = new(time.Time)
*pe.LicensedAt = scanpe.LicensedAt.Time
}
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*Pet) scanValues() []interface{} {
return []interface{}{
@@ -126,18 +102,6 @@ func (pe *Pet) String() string {
// Pets is a parsable slice of Pet.
type Pets []*Pet
// FromRows scans the sql response data into Pets.
func (pe *Pets) FromRows(rows *sql.Rows) error {
for rows.Next() {
scanpe := &Pet{}
if err := scanpe.FromRows(rows); err != nil {
return err
}
*pe = append(*pe, scanpe)
}
return nil
}
func (pe Pets) config(cfg config) {
for _i := range pe {
pe[_i].config = cfg

View File

@@ -23,24 +23,6 @@ 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
Name sql.NullString
}
// the order here should be the same as in the `user.Columns`.
if err := rows.Scan(
&scanu.ID,
&scanu.Name,
); err != nil {
return err
}
u.ID = scanu.ID
u.Name = scanu.Name.String
return nil
}
// scanValues returns the types for scanning values from sql.Rows.
func (*User) scanValues() []interface{} {
return []interface{}{
@@ -111,18 +93,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