• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang xorm.Engine类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/lunny/xorm.Engine的典型用法代码示例。如果您正苦于以下问题:Golang Engine类的具体用法?Golang Engine怎么用?Golang Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Engine类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: PrintTable

func PrintTable(engine *xorm.Engine) {
	var users []User

	engine.Find(&users)

	fmt.Printf("%+v\n", users)
}
开发者ID:GoSteelProgrammers,项目名称:talk-review-orms,代码行数:7,代码来源:query.go


示例2: Crawl

func Crawl(engine *xorm.Engine) error {
	latestIndices, err := getLatestIndices()
	if err != nil {
		return err
	}

	_, err = engine.Insert(&latestIndices.News)
	if err != nil {
		return err
	}

	news := make([]News, 0)
	for _, newsIndex := range latestIndices.News {
		content, err := getArticle(newsIndex.Id)
		if err == nil {
			news = append(news, News{newsIndex.Id, content})
		}
	}
	_, err = engine.Insert(&news)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:ZCLanner,项目名称:WebZhihuNews,代码行数:25,代码来源:crawl_news.go


示例3: 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))
}
开发者ID:popospectre,项目名称:gogs,代码行数:21,代码来源:models.go


示例4: main

func main() {
	var (
		engine *xorm.Engine
		user   *User
	)

	engine = SetupDb()

	//START CODE OMIT
	engine.Insert(&User{Id: 1, FirstName: "John", LastName: "Doe"})
	PrintTable(engine)

	user = &User{Id: 1}
	engine.Get(user)

	user.FirstName = "James"
	engine.Update(user)
	PrintTable(engine)

	engine.Delete(user)
	PrintTable(engine)
	//END CODE OMIT
}
开发者ID:GoSteelProgrammers,项目名称:talk-review-orms,代码行数:23,代码来源:crud.go


示例5: main

func main() {
	var (
		engine *xorm.Engine
	)

	engine = SetupDb()

	engine.Insert(&User{
		Id:        1,
		FirstName: "John",
		LastName:  "Doe",
		Age:       24,
	})

	engine.Insert(&User{
		Id:        2,
		FirstName: "Jane",
		LastName:  "Doe",
		Age:       52,
	})

	engine.Insert(&User{
		Id:        3,
		FirstName: "Joe",
		LastName:  "Shmoe",
		Age:       10,
	})

	//START CODE OMIT

	var users []User
	engine.Where("last_name = ? OR age < ?", "Doe", "12").OrderBy("age").Limit(2).Find(&users)
	fmt.Printf("%+v\n", users)

	//END CODE OMIT
}
开发者ID:GoSteelProgrammers,项目名称:talk-review-orms,代码行数:36,代码来源:query.go


示例6: test

func test(engine *xorm.Engine) {
	err := engine.CreateTables(u)
	if err != nil {
		fmt.Println(err)
		return
	}

	size := 500
	queue := make(chan int, size)

	for i := 0; i < size; i++ {
		go func(x int) {
			//x := i
			err := engine.Test()
			if err != nil {
				fmt.Println(err)
			} else {
				err = engine.Map(u)
				if err != nil {
					fmt.Println("Map user failed")
				} else {
					for j := 0; j < 10; j++ {
						if x+j < 2 {
							_, err = engine.Get(u)
						} else if x+j < 4 {
							users := make([]User, 0)
							err = engine.Find(&users)
						} else if x+j < 8 {
							_, err = engine.Count(u)
						} else if x+j < 16 {
							_, err = engine.Insert(&User{Name: "xlw"})
						} else if x+j < 32 {
							_, err = engine.Id(1).Delete(u)
						}
						if err != nil {
							fmt.Println(err)
							queue <- x
							return
						}
					}
					fmt.Printf("%v success!\n", x)
				}
			}
			queue <- x
		}(i)
	}

	for i := 0; i < size; i++ {
		<-queue
	}

	//conns := atomic.LoadInt32(&xorm.ConnectionNum)
	//fmt.Println("connection number:", conns)
	fmt.Println("end")
}
开发者ID:matm,项目名称:gobuild,代码行数:55,代码来源:goroutine.go


示例7: 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"]))
}
开发者ID:gezidan,项目名称:exercise,代码行数:63,代码来源:main.go


示例8: test

func test(engine *xorm.Engine) {
	err := engine.CreateTables(u)
	if err != nil {
		fmt.Println(err)
		return
	}

	engine.ShowSQL = true
	engine.Pool.SetMaxConns(5)
	size := 1000
	queue := make(chan int, size)

	for i := 0; i < size; i++ {
		go func(x int) {
			//x := i
			err := engine.Test()
			if err != nil {
				fmt.Println(err)
			} else {
				err = engine.Map(u)
				if err != nil {
					fmt.Println("Map user failed")
				} else {
					for j := 0; j < 10; j++ {
						if x+j < 2 {
							_, err = engine.Get(u)
						} else if x+j < 4 {
							users := make([]User, 0)
							err = engine.Find(&users)
						} else if x+j < 8 {
							_, err = engine.Count(u)
						} else if x+j < 16 {
							_, err = engine.Insert(&User{Name: "xlw"})
						} else if x+j < 32 {
							_, err = engine.Id(1).Delete(u)
						}
						if err != nil {
							fmt.Println(err)
							queue <- x
							return
						}
					}
					fmt.Printf("%v success!\n", x)
				}
			}
			queue <- x
		}(i)
	}

	for i := 0; i < size; i++ {
		<-queue
	}

	fmt.Println("end")
}
开发者ID:jimmykuu,项目名称:xorm,代码行数:55,代码来源:maxconnect.go


示例9: sync

func sync(engine *xorm.Engine) error {
	return engine.Sync(&SyncLoginInfo2{}, &SyncUser2{})
}
开发者ID:matm,项目名称:gobuild,代码行数:3,代码来源:sync.go



注:本文中的github.com/lunny/xorm.Engine类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang driver.Job类代码示例发布时间:2022-05-23
下一篇:
Golang xorm.NewEngine函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap