Created
December 31, 2014 06:25
-
-
Save bliaxiong/562a36d9bda596002efa to your computer and use it in GitHub Desktop.
Go mysql sqlx example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
_ "github.com/go-sql-driver/mysql" | |
"github.com/jmoiron/sqlx" | |
"log" | |
) | |
type User struct { | |
Id int | |
First, Last, Email string | |
} | |
func main() { | |
db, err := sqlx.Connect("mysql", "test:test@(localhost:3306)/test") | |
if err != nil { | |
log.Fatalln(err) | |
} | |
user := []User{} | |
db.Select(&user, "select * from users") | |
log.Println("users...") | |
log.Println(user) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for useful information