rozman50

Untitled

Jul 23rd, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. package main
  2.  
  3. // go get github.com/go-sql-driver/mysql
  4. // go get syreclabs.com/go/faker
  5. // https://godoc.org/syreclabs.com/go/faker
  6.  
  7.  
  8. import (
  9. "database/sql"
  10. "fmt"
  11. _ "github.com/go-sql-driver/mysql"
  12. "syreclabs.com/go/faker"
  13. _ "syreclabs.com/go/faker"
  14. )
  15.  
  16. func main() {
  17.  
  18. // The database is called testDb
  19. db, err := sql.Open("mysql", "root:@tcp(127.0.0.1:3306)/perf")
  20.  
  21. // if there is an error opening the connection, handle it
  22. if err != nil {
  23. panic(err.Error())
  24. }
  25.  
  26. // defer the close till after the main function has finished
  27. // executing
  28. defer db.Close()
  29.  
  30. //for i := 0; i < 100000; i++ {
  31. // insertUsers(db)
  32. //}
  33.  
  34.  
  35. insertDeletedImage(db)
  36. //for i := 0; i < 1000000; i++ {
  37. // _ = insertPersons(db)
  38. // //r2 := insertAddress(db)
  39. // //insertAddressPerson(r1, r2, db)
  40. //}
  41. }
  42.  
  43. func insertDeletedImage(db *sql.DB) {
  44.  
  45. for i := 312960; i < 2000000; i++ {
  46. _,_ = db.Exec("INSERT INTO perf.deletedimages (image_id) values(?)", i);
  47. }
  48. }
  49.  
  50. func insertUsers(db *sql.DB) {
  51. _,_ = db.Exec("INSERT into rentacar.users (username, email, password) values(?, ?, ?)", faker.Name().FirstName(), faker.Internet().Email(), "$2a$10$ioTAqdrN1BIhwgwsuhmLJeGbuBe0ZUgdjwmAqB7z9dJHhbACR.ESe")
  52. }
  53.  
  54. func insertPersons(db *sql.DB) (complaintID int64) {
  55. row,err:= db.Exec("INSERT INTO perf.persons (firstname, lastname, emso, birthcity, birthday, phonenumber) " +
  56. "VALUES(?,?,?,?,?,?);", faker.Name().FirstName(), faker.Name().LastName(),faker.Number().Between(10000, 99999), faker.Address().City(), faker.Date().Birthday(5, 95), faker.PhoneNumber().PhoneNumber())
  57. if err != nil {
  58. fmt.Print(err.Error())
  59. }
  60. complaintID, _ = row.LastInsertId()
  61. return
  62. }
  63.  
  64. func insertAddress(db *sql.DB) (addressID int64) {
  65. row,err := db.Exec("INSERT INTO rentacar.addresses (name, `number`, city, post, postcode, country_id) " +
  66. "VALUES(?,?,?,?,?,?);", faker.Address().StreetAddress(), faker.Address().BuildingNumber(), faker.Address().State(), faker.Address().State(), faker.Address().Postcode(), faker.Number().Between(1, 40))
  67. if err != nil {
  68. fmt.Print(err.Error())
  69. }
  70. addressID, _ = row.LastInsertId()
  71. return
  72. }
  73.  
  74. func insertAddressPerson(id1 int64, id2 int64, db *sql.DB) {
  75. _, err := db.Exec("INSERT INTO rentacar.personsaddresses (person_id, address_id) VALUES(?,?);",id1, id2)
  76. if err != nil {
  77. fmt.Print(err.Error())
  78. }
  79. }
Add Comment
Please, Sign In to add comment