@@ -68,7 +68,7 @@ func (w Writer) Insert(values []string, schema schema.Schema, tableName string)
68
68
var sb strings.Builder
69
69
valuesLength := len (values )
70
70
71
- // we are creating a string for the insert template like: $1, $2, $3
71
+ // Generate placeholder string. e.g. $1, $2, $3
72
72
for i := 1 ; i < valuesLength + 1 ; i ++ {
73
73
74
74
sb .WriteRune ('$' )
@@ -80,13 +80,15 @@ func (w Writer) Insert(values []string, schema schema.Schema, tableName string)
80
80
}
81
81
}
82
82
83
+ // Build the INSERT statement
83
84
statement := fmt .Sprintf (`INSERT INTO "%s" VALUES (%s);` , tableName , sb .String ())
84
85
85
86
var valuesGeneric = make ([]interface {}, len (values ))
86
87
for i , value := range values {
87
88
valuesGeneric [i ] = value
88
89
}
89
90
91
+ // Execute the statement
90
92
_ , err = w .db .Exec (statement , valuesGeneric ... )
91
93
92
94
if nil != err {
@@ -96,6 +98,7 @@ func (w Writer) Insert(values []string, schema schema.Schema, tableName string)
96
98
return err
97
99
}
98
100
101
+ // getSQLColumnType converts types.BasicKind values to corresponding postgresql column types
99
102
func (w Writer ) getSQLColumnType (goType types.BasicKind ) (result string ) {
100
103
101
104
switch goType {
@@ -115,6 +118,8 @@ func (w Writer) getSQLColumnType(goType types.BasicKind) (result string) {
115
118
result = "DOUBLE"
116
119
case types .String :
117
120
result = "TEXT"
121
+ default :
122
+ panic (fmt .Sprintf ("unsupported golang type: %d" , goType ))
118
123
}
119
124
120
125
return result
0 commit comments