V
V
v- death2015-08-16 00:04:07
MySQL
v- death, 2015-08-16 00:04:07

Is there a mysql library for Go?

Hello. View code

db, err := sql.Open("mysql", "root:[email protected]/generais")
  if err != nil {
    panic(err.Error())
  }
  defer db.Close()
  err = db.Ping()
  if err != nil {
    panic(err.Error())
  }

  age := 27
  rows, err := db.Query("SELECT * FROM keyApi WHERE key=?", age)
  if err != nil {
    log.Fatal(err)
  }
  defer rows.Close()

  for rows.Next() {
    var name string
    if err := rows.Scan(&name); err != nil {
      log.Fatal(err)
    }
    fmt.Printf("%s is %d\n", name, age)
  }
  if err := rows.Err(); err != nil {
    log.Fatal(err)
  }

For the sake of one request... I don't like so much writing. Are there wrappers for this thing that are easy to use, like in the same php - mysqli?
Thanks to all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rikcon, 2015-08-16
@vGrabko99

https://github.com/jinzhu/gorm
Here is an ORM for you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question