本文整理汇总了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))
}