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) | |
} |
Thank you for posting this. Useful
I stopped using Go a long time ago and had to google how to create a connection, I found my own Gist. LOL.
I stopped using Go a long time ago and had to google how to create a connection, I found my own Gist. LOL.
Can you please explain the 2nd argument of db, err := sqlx.Connect("mysql", "test:test@(localhost:3306)/test")
sqlx.Connect("mysql", "test:test@(localhost:3306)/test")
Hope this helps:
sqlx.Connect("dbType", "dbUser:dbPassword@(dbURL:PORT)/dbName")
…On Mon, May 24, 2021 at 10:42 AM Chetan Giradkar ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
I stopped using Go a long time ago and had to google how to create a
connection, I found my own Gist. LOL.
Can you please explain the 2nd argument of db, err :=
sqlx.Connect("mysql", "test:test@(localhost:3306)/test")
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/562a36d9bda596002efa#gistcomment-3755108>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAOEIERIZTFOO6ALSUVGKWDTPJXXRANCNFSM4JTUJLGA>
.
--
Thanks!
Blia Xiong
***@***.***
I stopped using Go a long time ago and had to google how to create a connection, I found my own Gist. LOL.
huh... what?? hahahahaha
thanks for useful information
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. This information was really helpful.