本文整理汇总了Golang中github.com/lunny/xorm.Engine.Sync方法的典型用法代码示例。如果您正苦于以下问题:Golang Engine.Sync方法的具体用法?Golang Engine.Sync怎么用?Golang Engine.Sync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/lunny/xorm.Engine
的用法示例。
在下文中一共展示了Engine.Sync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewTestEngine
func NewTestEngine(x *xorm.Engine) (err error) {
switch DbCfg.Type {
case "mysql":
x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%[email protected](%s)/%s?charset=utf8",
DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name))
case "postgres":
x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode))
// case "sqlite3":
// os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
// x, err = xorm.NewEngine("sqlite3", DbCfg.Path)
default:
return fmt.Errorf("Unknown database type: %s", DbCfg.Type)
}
if err != nil {
return fmt.Errorf("models.init(fail to conntect database): %v", err)
}
return x.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
new(Action), new(Access), new(Issue), new(Comment))
}
示例2: main
func main() {
//runtime.GOMAXPROCS(2)
// load config
var err error
cfg, err := config.Load("config.ini")
if err != nil {
fmt.Println(err)
return
}
cfgs := cfg.Map()
// create Orm
var orm *xorm.Engine
orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%v:%[email protected]%v/%v?charset=utf8",
cfgs["dbuser"], cfgs["dbpasswd"], cfgs["dbhost"], cfgs["dbname"]))
if err != nil {
fmt.Println(err)
return
}
orm.ShowSQL, _ = cfg.GetBool("showSql")
orm.ShowDebug, _ = cfg.GetBool("showDebug")
err = orm.Sync(&User{}, &Question{},
&QuestionFollow{}, &UserFollow{}, &Answer{}, &AnswerUp{},
&QuestionComment{}, &AnswerComment{}, &Tag{}, &QuestionTag{},
&Message{}, &Topic{}, &QuestionTopic{}, &TopicFollow{}, &News{})
if err != nil {
fmt.Println(err)
return
}
server := xweb.MainServer()
app := xweb.RootApp()
app.SetConfig("Orm", orm)
if useCache, _ := cfg.GetBool("useCache"); useCache {
server.Info("using orm cache system ...")
cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
orm.SetDefaultCacher(cacher)
}
// add actions
xweb.AddAction(&HomeAction{})
xweb.AutoAction(&ExerciseAction{}, &QuestionAction{}, &NewsAction{})
xweb.AddAction(&UserAction{})
// add login filter
loginFilter := xweb.NewLoginFilter(app, USER_ID_TAG, "/login")
loginFilter.AddAnonymousUrls("/", "/exercise", "/exercise/compile",
"/news", "/login", "/about", "/register")
app.AddFilter(loginFilter)
// add func or var app scope
app.AddTmplVar("AppVer", func() string {
return "v" + APP_VER
})
// run the web server
xweb.Run(fmt.Sprintf("%v:%v", cfgs["address"], cfgs["port"]))
}
示例3: sync
func sync(engine *xorm.Engine) error {
return engine.Sync(&SyncLoginInfo2{}, &SyncUser2{})
}