Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- // go get github.com/go-sql-driver/mysql
- // go get syreclabs.com/go/faker
- // https://godoc.org/syreclabs.com/go/faker
- import (
- "database/sql"
- "fmt"
- _ "github.com/go-sql-driver/mysql"
- "syreclabs.com/go/faker"
- _ "syreclabs.com/go/faker"
- )
- func main() {
- // The database is called testDb
- db, err := sql.Open("mysql", "root:@tcp(127.0.0.1:3306)/perf")
- // if there is an error opening the connection, handle it
- if err != nil {
- panic(err.Error())
- }
- // defer the close till after the main function has finished
- // executing
- defer db.Close()
- //for i := 0; i < 100000; i++ {
- // insertUsers(db)
- //}
- insertDeletedImage(db)
- //for i := 0; i < 1000000; i++ {
- // _ = insertPersons(db)
- // //r2 := insertAddress(db)
- // //insertAddressPerson(r1, r2, db)
- //}
- }
- func insertDeletedImage(db *sql.DB) {
- for i := 312960; i < 2000000; i++ {
- _,_ = db.Exec("INSERT INTO perf.deletedimages (image_id) values(?)", i);
- }
- }
- func insertUsers(db *sql.DB) {
- _,_ = db.Exec("INSERT into rentacar.users (username, email, password) values(?, ?, ?)", faker.Name().FirstName(), faker.Internet().Email(), "$2a$10$ioTAqdrN1BIhwgwsuhmLJeGbuBe0ZUgdjwmAqB7z9dJHhbACR.ESe")
- }
- func insertPersons(db *sql.DB) (complaintID int64) {
- row,err:= db.Exec("INSERT INTO perf.persons (firstname, lastname, emso, birthcity, birthday, phonenumber) " +
- "VALUES(?,?,?,?,?,?);", faker.Name().FirstName(), faker.Name().LastName(),faker.Number().Between(10000, 99999), faker.Address().City(), faker.Date().Birthday(5, 95), faker.PhoneNumber().PhoneNumber())
- if err != nil {
- fmt.Print(err.Error())
- }
- complaintID, _ = row.LastInsertId()
- return
- }
- func insertAddress(db *sql.DB) (addressID int64) {
- row,err := db.Exec("INSERT INTO rentacar.addresses (name, `number`, city, post, postcode, country_id) " +
- "VALUES(?,?,?,?,?,?);", faker.Address().StreetAddress(), faker.Address().BuildingNumber(), faker.Address().State(), faker.Address().State(), faker.Address().Postcode(), faker.Number().Between(1, 40))
- if err != nil {
- fmt.Print(err.Error())
- }
- addressID, _ = row.LastInsertId()
- return
- }
- func insertAddressPerson(id1 int64, id2 int64, db *sql.DB) {
- _, err := db.Exec("INSERT INTO rentacar.personsaddresses (person_id, address_id) VALUES(?,?);",id1, id2)
- if err != nil {
- fmt.Print(err.Error())
- }
- }
Add Comment
Please, Sign In to add comment