func LoadSQLDate(dbMap *gorp.DbMap, t interface{}, rows []map[string]interface{}) { for _, row := range rows { err := mapstructure.Decode(row, t) checkErr(err, "") err = dbMap.Insert(t) checkErr(err, "") } }
func process(metric data.Metric, dbMap *gorp.DbMap) error { log.Printf("Metric %+v", metric) now := time.Now().UTC() account := Account{Name: metric.Username, Time: now} err := dbMap.Insert(&account) if err, ok := err.(*pq.Error); ok && err.Code.Name() != PG_UNIQUE_VIOLATION_ERR { log.Fatalf("Error inserting account. ERR: %+v", err) } return nil }
func importToDB(res *ScriptOutput, name string, dbm *gorp.DbMap) error { count, err := IsImportedEquipmentInfo(name, dbm) if err != nil { return err } if count > 0 { log.Printf("skipping import: %s", name) return nil } for _, row := range res.Result { if row[0] == "工事設計認証を受けた者の氏名又は名称" { continue } t, err := time.Parse("2006-01-02", row[6]) if err != nil { continue } obj := EquipmentInfo{ CertifiedName: row[0], EquipmentType: row[1], Model: row[2], AuthNumber: row[3], RadioType: row[4], IsApplied1421: row[5], AuthDate: t, Note: row[7], File: name, } log.Printf("insert: %v", obj) if err := dbm.Insert(&obj); err != nil { if !strings.HasPrefix(err.Error(), "UNIQUE constraint failed") { return err } log.Printf("skipping insert: %s", err.Error()) } } return nil }