Skip to content

Instantly share code, notes, and snippets.

@anidotnet
Created March 19, 2014 05:55
Show Gist options
  • Save anidotnet/9636189 to your computer and use it in GitHub Desktop.
Save anidotnet/9636189 to your computer and use it in GitHub Desktop.
MySQL test
package main
import (
"log"
"upper.io/db"
_ "upper.io/db/mysql"
)
var settings = db.Settings{
Host: "localhost", // MySQL server IP or name.
Database: "blog", // Database name.
User: "root", // Optional user name.
Password: "*******", // Optional user password.
}
type Test struct {
firstName string `field:"firstname"`
lastName string `field:"lastname"`
}
func main() {
sess, err := db.Open("mysql", settings)
if err != nil {
panic(err.Error())
}
col, err := sess.Collection("test")
log.Println(col.Name())
col.Append(Test{
"abcd",
"xyz",
})
sess.Close()
if err != nil {
panic(err.Error())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment