(t *testing.T)
| 1090 | } |
| 1091 | |
| 1092 | func TestInsert(t *testing.T) { |
| 1093 | b := &sqlBuilder{t: newTemplateWithUtils(&testTemplate)} |
| 1094 | assert := assert.New(t) |
| 1095 | |
| 1096 | assert.Equal( |
| 1097 | `INSERT INTO "artist" VALUES ($1, $2), ($3, $4), ($5, $6)`, |
| 1098 | b.InsertInto("artist"). |
| 1099 | Values(10, "Ryuichi Sakamoto"). |
| 1100 | Values(11, "Alondra de la Parra"). |
| 1101 | Values(12, "Haruki Murakami"). |
| 1102 | String(), |
| 1103 | ) |
| 1104 | |
| 1105 | assert.Equal( |
| 1106 | `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`, |
| 1107 | b.InsertInto("artist").Values(map[string]string{"id": "12", "name": "Chavela Vargas"}).String(), |
| 1108 | ) |
| 1109 | |
| 1110 | assert.Equal( |
| 1111 | `INSERT INTO "artist" ("id", "name") VALUES ($1, $2) RETURNING "id"`, |
| 1112 | b.InsertInto("artist").Values(map[string]string{"id": "12", "name": "Chavela Vargas"}).Returning("id").String(), |
| 1113 | ) |
| 1114 | |
| 1115 | assert.Equal( |
| 1116 | `INSERT INTO "artist" ("id", "name") VALUES ($1, $2) RETURNING "id"`, |
| 1117 | b.InsertInto("artist").Values(map[string]string{"id": "12", "name": "Chavela Vargas"}).Amend(func(query string) string { |
| 1118 | return query + ` RETURNING "id"` |
| 1119 | }).String(), |
| 1120 | ) |
| 1121 | |
| 1122 | assert.Equal( |
| 1123 | `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`, |
| 1124 | b.InsertInto("artist").Values(map[string]interface{}{"name": "Chavela Vargas", "id": 12}).String(), |
| 1125 | ) |
| 1126 | |
| 1127 | assert.Equal( |
| 1128 | `INSERT INTO "artist" ("id", "name") VALUES ($1, $2)`, |
| 1129 | b.InsertInto("artist").Values(struct { |
| 1130 | ID int `db:"id"` |
| 1131 | Name string `db:"name"` |
| 1132 | }{12, "Chavela Vargas"}).String(), |
| 1133 | ) |
| 1134 | |
| 1135 | { |
| 1136 | type artistStruct struct { |
| 1137 | ID int `db:"id,omitempty"` |
| 1138 | Name string `db:"name,omitempty"` |
| 1139 | } |
| 1140 | |
| 1141 | assert.Equal( |
| 1142 | `INSERT INTO "artist" ("id", "name") VALUES ($1, $2), ($3, $4), ($5, $6)`, |
| 1143 | b.InsertInto("artist"). |
| 1144 | Values(artistStruct{12, "Chavela Vargas"}). |
| 1145 | Values(artistStruct{13, "Alondra de la Parra"}). |
| 1146 | Values(artistStruct{14, "Haruki Murakami"}). |
| 1147 | String(), |
| 1148 | ) |
| 1149 | } |
nothing calls this directly
no test coverage detected