本文整理匯總了Golang中github.com/coopernurse/gorp.DbMap.TraceOn方法的典型用法代碼示例。如果您正苦於以下問題:Golang DbMap.TraceOn方法的具體用法?Golang DbMap.TraceOn怎麽用?Golang DbMap.TraceOn使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coopernurse/gorp.DbMap
的用法示例。
在下文中一共展示了DbMap.TraceOn方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: init
func init() {
log.Println("Connecting to database...")
// connect to db using standard Go database/sql API
// use whatever database/sql driver you wish
dbopen, err := sql.Open("mysql", dbuser+":"+dbpass+"@/"+dbname+"?charset=utf8&parseTime=true")
if err != nil {
panic(err.Error()) // Just for example purpose. You should use proper error handling instead of panic
}
//defer db.Close() // I DUNNO IF IT WORKS HERE, LETS TEST
dialect := gorp.MySQLDialect{"InnoDB", "UTF8"}
// construct a gorp DbMap
dbmap := gorp.DbMap{Db: dbopen, Dialect: dialect}
log.Println("Database connected!")
// Adding schemes to my ORM
dbmap.AddTableWithName(User{}, "user").SetKeys(false, "userid")
dbmap.AddTableWithName(Profile{}, "profile").SetKeys(false, "profileid")
dbmap.AddTableWithName(Pic{}, "pic").SetKeys(false, "picid")
dbmap.AddTableWithName(Token{}, "token").SetKeys(false, "tokenid", "userid")
dbmap.AddTableWithName(Category{}, "category").SetKeys(false, "categoryid")
dbmap.AddTableWithName(Image{}, "image").SetKeys(false, "imageid")
dbmap.AddTableWithName(Url{}, "url").SetKeys(false, "urlid")
dbmap.AddTableWithName(Content{}, "content").SetKeys(false, "contentid")
dbmap.AddTableWithName(FullContent{}, "fullcontent").SetKeys(false, "contentid")
dbmap.AddTableWithName(ContentLike{}, "contentlike").SetKeys(false, "contentid", "userid")
dbmap.AddTableWithName(Access{}, "access").SetKeys(false, "accessid")
// Adding to local vairable
db = &dbmap
log.Println("Start routine to create the default values of our datas...")
checkAndCreateDefaultPic(db)
checkAndCreateDefaultImage(db)
checkAndCreateAnonymousUser(db)
checkAndCreateCategories(db)
log.Println("All default values has been created.")
dbmap.TraceOn("[SQL]", log.New(os.Stdout, "[DB]", log.Lmicroseconds))
}
示例2: enableLogging
func enableLogging(db *gorp.DbMap) {
db.TraceOn("[gorp]", log.New(os.Stdout, "", log.Lmicroseconds))
}