當前位置: 首頁>>代碼示例>>Golang>>正文


Golang DbMap.TraceOn方法代碼示例

本文整理匯總了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))

}
開發者ID:rafadev7,項目名稱:server,代碼行數:48,代碼來源:db.go

示例2: enableLogging

func enableLogging(db *gorp.DbMap) {
	db.TraceOn("[gorp]", log.New(os.Stdout, "", log.Lmicroseconds))
}
開發者ID:joiggama,項目名稱:martini-example,代碼行數:3,代碼來源:db.go


注:本文中的github.com/coopernurse/gorp.DbMap.TraceOn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。