Created
April 3, 2018 00:46
-
-
Save andizzle/39a93a9d95b50ab93134bd8ba429fb0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
"time" | |
) | |
func main() { | |
nextWeekStart := time.Now() | |
nextWeekEnd := time.Now().Add(152 * time.Hour) | |
// TODO: insert shifts for shift swap tests | |
shiftA := map[string]interface{}{ | |
"id": 1, | |
"company_id": "008df52e-4167-4791-8460-a6f4ec6cde17", | |
"owner_id": "008df52e-5ced-0b75-11ca-6a011caf1f47", | |
"accepted_id": "ef118257-c4bc-48e5-b580-021b843054e6", | |
"position_id": "d2df8485-7c2a-449a-8bf8-41ff974f6e3b", | |
"skill_set_id": 42, | |
"privacy": "private", | |
"rate": 3000, | |
"slots": 1, | |
"slots_used": 1, | |
"start_at": nextWeekStart, | |
"end_at": nextWeekEnd, | |
"start_at_utc": nextWeekStart.UTC(), | |
"end_at_utc": nextWeekEnd.UTC(), | |
"published": "published", | |
} | |
shiftB := map[string]interface{}{ | |
"id": 2, | |
"company_id": "008df52e-4167-4791-8460-a6f4ec6cde17", | |
"owner_id": "008df52e-5ced-0b75-11ca-6a011caf1f47", | |
"accepted_id": "ef118257-c4bc-48e5-b580-021b843054e6", | |
"position_id": "d2df8485-7c2a-449a-8bf8-41ff974f6e3b", | |
"skill_set_id": 42, | |
"privacy": "private", | |
"rate": 3000, | |
"slots": 1, | |
"slots_used": 1, | |
"start_at": nextWeekStart, | |
"end_at": nextWeekEnd, | |
"start_at_utc": nextWeekStart.UTC(), | |
"end_at_utc": nextWeekEnd.UTC(), | |
"published": "published", | |
} | |
shifts := []map[string]interface{}{shiftA, shiftB} | |
var colAdded bool | |
cols := []string{} | |
placeholders := []string{} | |
vals := []interface{}{} | |
for _, shift := range shifts { | |
for key, val := range shift { | |
if !colAdded { | |
cols = append(cols, key) | |
vals = append(vals, val) | |
} | |
} | |
placeholders = append(placeholders, fmt.Sprintf("(%s)", strings.Trim(strings.Repeat("?,", len(shift)), ","))) | |
colAdded = true | |
} | |
columns := strings.Join(cols, ",") | |
stmt := fmt.Sprintf("INSERT INTO shifts (%s) VALUES %s", columns, strings.Join(placeholders, ",")) | |
fmt.Println(stmt) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment