Skip to content

Instantly share code, notes, and snippets.

@q45
Created January 21, 2016 00:19
Show Gist options
  • Select an option

  • Save q45/a79232def1b8e1d0cd56 to your computer and use it in GitHub Desktop.

Select an option

Save q45/a79232def1b8e1d0cd56 to your computer and use it in GitHub Desktop.
// digital ocean creds
// db, err := sql.Open("mysql", "root:@/theory_mysql")
databaseURL := os.Getenv("DATABASE_URL")
fmt.Println(databaseURL)
db, err := sql.Open("mysql", databaseURL)
fmt.Println(databaseURL)
if err != nil {
fmt.Println("error opening theory database")
}
defer db.Close()
// db, err := sql.Open("postgres", "user=q dbname=theory password=root45 sslmode=disable")
// if err != nil {
// fmt.Printf("Error connecting to postgres: %v\n", err)
// }
// fmt.Println("Successfully connected to the database")
//check and make sure struct is populated
// statement := `"insert into theory (address, city, email_address, first_name, last_name, profile_id, state, status, value, zipcode, type) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)"`, item.Address, item.City, item.EmailAddress, item.FirstName, item.LastName, item.ProfileID, item.State, item.Status, item.Value, item.Zipcode, item.Type
// stmt, err := db.Prepare(statement)
// if err != nil {
// fmt.Printf("Error creating item %v\n", err)
// return err
// }
fmt.Printf("StartTime: %v\n", time.Now())
fmt.Println("Please do this")
res, err := db.Exec("insert into transactions VALUES(?,?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", item.ID, item.PrintCode, item.FirstName, item.LastName, item.Address, item.City, item.State, item.Zipcode, item.EmailAddress, item.ProfileID, item.Status, item.Value, item.Type)
// res, err := db.Exec("insert into theory VALUES($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)", item.Address, item.City, item.EmailAddress, item.FirstName, item.LastName, item.ProfileID, item.State, item.Status, item.Value, item.Zipcode, item.Type)
if err != nil || res == nil {
fmt.Printf("Error writing to database: %+v\n", err)
}
fmt.Println("RES from Query")
fmt.Println(res)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment