@@ -3,7 +3,7 @@ package main
33import (
44 "strings"
55
6- cool "github.com/StirlingMarketingGroup/cool-mysql"
6+ mysql "github.com/StirlingMarketingGroup/cool-mysql"
77)
88
99// the mysql lib we're using, cool mysql, lets us define a
@@ -18,8 +18,8 @@ type column struct {
1818 PrimaryKey bool
1919}
2020
21- func getTableColumns (db * cool .Database , tableName string ) ([]* column , error ) {
22- var columns []* column
21+ func getTableColumns (db * mysql .Database , tableName string ) ([]column , error ) {
22+ var columns []column
2323
2424 // we need to check to see if the db supports generated columns
2525 // if it doesn't, our query to get column info will fail
@@ -47,7 +47,7 @@ func getTableColumns(db *cool.Database, tableName string) ([]*column, error) {
4747 return nil , err
4848 }
4949
50- var primaryKeys []* struct {
50+ var primaryKeys []struct {
5151 ColumnName string `mysql:"Column_name"`
5252 }
5353 err = db .Select (& primaryKeys , "show index from`" + tableName + "`where`Key_name`='PRIMARY'" , 0 )
@@ -60,7 +60,8 @@ func getTableColumns(db *cool.Database, tableName string) ([]*column, error) {
6060 primaryKeysSet [pk .ColumnName ] = struct {}{}
6161 }
6262
63- for _ , c := range columns {
63+ for i := range columns {
64+ c := & columns [i ]
6465 if _ , ok := primaryKeysSet [c .ColumnName ]; ok {
6566 c .PrimaryKey = true
6667 }
@@ -69,11 +70,11 @@ func getTableColumns(db *cool.Database, tableName string) ([]*column, error) {
6970 return columns , nil
7071}
7172
72- func quoteColumns (columns []* column ) string {
73+ func quoteColumns (columns []column ) string {
7374 return quoteColumnsPrefix (columns , "" )
7475}
7576
76- func quoteColumnsPrefix (columns []* column , prefix string ) string {
77+ func quoteColumnsPrefix (columns []column , prefix string ) string {
7778 // this is our string builder for quoted column names,
7879 // which will be used in our select statement
7980 columnsQuotedBld := new (strings.Builder )
@@ -92,10 +93,18 @@ func quoteColumnsPrefix(columns []*column, prefix string) string {
9293 return columnsQuotedBld .String ()
9394}
9495
95- func columnsSet (columns []* column ) map [string ]struct {} {
96+ func columnsSet (columns []column ) map [string ]struct {} {
9697 set := make (map [string ]struct {}, len (columns ))
9798 for _ , c := range columns {
9899 set [c .ColumnName ] = struct {}{}
99100 }
100101 return set
101102}
103+
104+ func columnNames (columns []column ) []string {
105+ names := make ([]string , len (columns ))
106+ for i , c := range columns {
107+ names [i ] = c .ColumnName
108+ }
109+ return names
110+ }
0 commit comments