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

Golang orm.Ormer类代码示例

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

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



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

示例1: TestToken

func TestToken(t *testing.T) {
	tokenTest := &models.Token{"token1", "writeToken", "readToken"}
	var o orm.Ormer = orm.NewOrm()
	result := []orm.ParamsList{}

	Convey("Check save token", t, func() {
		success := tokenTest.Save()
		So(success, ShouldEqual, nil)
	})

	Convey("Check write token", t, func() {

		r, _ := o.Raw("select write_token from token where document_id = ?", tokenTest.DocumentId).ValuesList(&result)
		_ = r
		e := result[0][0]
		So(e, ShouldEqual, tokenTest.WriteToken)
	})

	Convey("Check read token", t, func() {

		r, _ := o.Raw("select read_token from token where document_id = ?", tokenTest.DocumentId).ValuesList(&result)
		_ = r
		e := result[0][0]
		So(e, ShouldEqual, tokenTest.ReadToken)
	})

}
开发者ID:eraserxp,项目名称:coedit,代码行数:27,代码来源:testToken_test.go


示例2: NumOfRows

func NumOfRows(o orm.Ormer, sql string) (int64, error) {
	type tableRows struct {
		Rows int64
	}
	var rows tableRows
	if err := o.Raw(sql).QueryRow(&rows); err != nil {
		return 0, err
	}
	return rows.Rows, nil
}
开发者ID:naokij,项目名称:gotalk,代码行数:10,代码来源:utils.go


示例3: invalidateVerification

func invalidateVerification(verification *Verification, o orm.Ormer) int {
	verification.Expire = 0
	_, err := o.Update(verification)
	if err == nil {
		return 0
	} else {
		beego.Warning("CheckVerifyCode, Update expire fail: ", err)
		return utils.ERROR_CODE_SYSTEM_ERROR
	}
}
开发者ID:Piasy,项目名称:BeegoTDDBootStrap,代码行数:10,代码来源:verification.go


示例4: LoadToMySQL

func (c *CSVDataFile) LoadToMySQL(o orm.Ormer) error {
	sql := fmt.Sprintf(`load data infile '%s' into table %s FIELDS TERMINATED BY '%s' ENCLOSED BY '"' (%s)`, c.File, c.Table, string(c.FieldsTerminatedBy), strings.Join(c.Fields, ", "))
	//fmt.Println(sql)
	_, err := o.Raw(sql).Exec()
	if err != nil {
		c.hasImportError = true
		return fmt.Errorf("datafile %s: %s", c.File, err.Error())
	}
	return nil
}
开发者ID:naokij,项目名称:gotalk,代码行数:10,代码来源:csvdatafile.go


示例5: execUpdate

func execUpdate(o orm.Ormer, sql string, params ...interface{}) error {
	p, err := o.Raw(sql).Prepare()
	if err != nil {
		return err
	}
	defer p.Close()
	_, err = p.Exec(params...)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:vmware,项目名称:harbor,代码行数:12,代码来源:dao_test.go


示例6: RunPreImportMySQLSettings

func RunPreImportMySQLSettings(o orm.Ormer) {
	const sql = `/*!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @[email protected]@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 */;`
	var cmds = strings.Split(sql, "\n")
	for _, cmd := range cmds {
		if _, err := o.Raw(cmd).Exec(); err != nil {
			fmt.Println("PreImportSettings: ", err)
		}
	}
}
开发者ID:naokij,项目名称:gotalk,代码行数:12,代码来源:utils.go


示例7: Map2InsertSql

func Map2InsertSql(o orm.Ormer, table string, data map[string]interface{}) error {
	var values []interface{}
	var keys []string
	var valuesPlaceHolders []string
	for k, v := range data {
		valuesPlaceHolders = append(valuesPlaceHolders, "? ")
		keys = append(keys, fmt.Sprintf("`%s`", k))
		values = append(values, v) //
	}
	sql := fmt.Sprintf("INSERT INTO `%s` (%s) VALUES(%s)", table, strings.Join(keys, ","), strings.Join(valuesPlaceHolders, ","))
	_, err := o.Raw(sql, values...).Exec()
	if err != nil {
		return err
	}
	return nil
}
开发者ID:naokij,项目名称:gotalk,代码行数:16,代码来源:utils.go


示例8: createAgent

func createAgent(m map[string]interface{}, o orm.Ormer, h *models.House) {
	photo := models.Photo{}
	photo.Url = m["avatar"].(string)
	o.Insert(&photo)

	agent := models.Agent{
		Name:          m["name"].(string),
		Phone:         m["phone"].(string),
		AverageRating: float32(m["averageRating"].(float64)),
		NumRates:      m["numRates"].(int),
		RecentSales:   m["recentSales"].(int),
		House:         h,
		Avatar:        &photo,
	}
	o.Insert(&agent)
}
开发者ID:quannguyen89,项目名称:beego_api_demo,代码行数:16,代码来源:main.go


示例9: TestCreateDoc

func TestCreateDoc(t *testing.T) {
	var o orm.Ormer = orm.NewOrm()
	docNew := &models.Documents{"testid", "test_content", "D", "[email protected]"}
	// Only pass t into top-level Convey calls
	err := docNew.Save()
	if err == nil {
		fmt.Println("***************************************")
	}
	Convey("Test Create Doc in database", t, func() {
		var lists []orm.ParamsList

		num, _ := o.Raw(" select Id from documents where id = ?", "testid").ValuesList(&lists)

		num = num + 1
		So(lists[0][0], ShouldEqual, "testid")
	})
}
开发者ID:eraserxp,项目名称:coedit,代码行数:17,代码来源:createDoc_test.go


示例10: InsertWithScope

func (this UserService) InsertWithScope(tr orm.Ormer, u *user.User) error {
	u.PasswordSalt = GetUserSalt()

	if !utils.IsEmail(u.Email) {
		return errors.New("invalid email")
	}

	beego.Info(setting.SystemAdminEmails)

	if strings.Index(setting.SystemAdminEmails, u.Email) >= 0 {
		u.IsSystemAccount = true
		beego.Info(setting.SystemAdminEmails)
	}
	if _, err := tr.Insert(u); err != nil {
		return err
	}
	return nil
}
开发者ID:thanzen,项目名称:identity,代码行数:18,代码来源:userservice.go


示例11: insertEvent

func insertEvent(q orm.Ormer, eve *coommonModel.Event) (res interface{}, err error) {
	var status int
	if status = 0; eve.Status == "OK" {
		status = 1
	}
	sqltemplete := `INSERT INTO events (
		event_caseId,
		step,
		cond,
		status,
		timestamp
	) VALUES(?,?,?,?,?)`
	res, err = q.Raw(
		sqltemplete,
		eve.Id,
		eve.CurrentStep,
		fmt.Sprintf("%v %v %v", eve.LeftValue, eve.Operator(), eve.RightValue()),
		status,
		time.Unix(eve.EventTime, 0),
	).Exec()
	return
}
开发者ID:donh,项目名称:alarm,代码行数:22,代码来源:event_operation.go


示例12: createHouse

func createHouse(m map[string]interface{}, o orm.Ormer) *models.House {
	location := models.Location{}
	locationData := m["location"].([]float32)
	location.Latitude = locationData[0]
	location.Longtitude = locationData[1]
	o.Insert(&location)

	thumbnail := models.Photo{}
	thumbnail.Url = m["thumbnail"].(string)
	o.Insert(&thumbnail)

	house := models.House{
		Address:     m["address"].(string),
		HouseType:   m["houseType"].(string),
		Price:       m["price"].(int),
		Properties:  m["properties"].(string),
		PublishFrom: m["publishFrom"].(int),
		Description: m["description"].(string),
		Location:    &location,
		Thumbnail:   &thumbnail,
	}
	o.Insert(&house)
	return &house
}
开发者ID:quannguyen89,项目名称:beego_api_demo,代码行数:24,代码来源:main.go


示例13: InsertUsersWithScope

func (this RoleService) InsertUsersWithScope(tr orm.Ormer, r *user.Role, users ...*user.User) error {
	_, err := tr.QueryM2M(r, "Users").Add(users)
	return err
}
开发者ID:thanzen,项目名称:identity,代码行数:4,代码来源:roleservice.go


示例14: seed

func seed(o orm.Ormer) {
	arr := [10]map[string]interface{}{}
	arr[0] = map[string]interface{}{
		"address":     "589 Coleridge Ave, Hanoi, Vietnam",
		"houseType":   "House for sale",
		"price":       8950000,
		"properties":  "3 bds, 3.5 ba, 4464 sqft, 0.28 ac lot, Built 1997",
		"publishFrom": 104,
		"thumbnail":   "http://photos2.zillowstatic.com/p_g/ISpxm1nzj9y1xo1000000000.jpg",
		"location":    []float32{21.009326, 105.857682},
		"description": "Custom designed home on a large lot in the Old Palo Alto neighborhood. Vaulted ceilings and large windows fill the home with natural light. Clean lines and craftsman details create a bond between the shingle-style neighborhood and contemporary style. Three level home, with basement. Possibility to create a fourth bedroom on either the ground floor or at the basement level.",
	}
	arr[1] = map[string]interface{}{
		"address":     "1565 Webster St,  Hanoi, Vietnam",
		"houseType":   "House for sale",
		"price":       6950000,
		"properties":  "3 bds, 3.5 ba, 4464 sqft, 0.28 ac lot, Built 1997",
		"publishFrom": 200,
		"thumbnail":   "http://photos3.zillowstatic.com/p_g/ISxzt2p00tw62m1000000000.jpg",
		"location":    []float32{21.009356, 105.855442},
		"description": "Custom designed home on a large lot in the Old Palo Alto neighborhood. Vaulted ceilings and large windows fill the home with natural light. Clean lines and craftsman details create a bond between the shingle-style neighborhood and contemporary style. Three level home, with basement. Possibility to create a fourth bedroom on either the ground floor or at the basement level.",
	}
	arr[2] = map[string]interface{}{
		"address":     "1061 Alma Street, Hanoi, Vietnam",
		"houseType":   "Make me move",
		"price":       550000,
		"properties":  "3 bds, 3.5 ba, 4464 sqft, 0.28 ac lot, Built 1997",
		"publishFrom": 222,
		"thumbnail":   "http://photos3.zillowstatic.com/p_g/IS5mozylseymxd1000000000.jpg",
		"location":    []float32{21.011072, 105.842455},
		"description": "Custom designed home on a large lot in the Old Palo Alto neighborhood. Vaulted ceilings and large windows fill the home with natural light. Clean lines and craftsman details create a bond between the shingle-style neighborhood and contemporary style. Three level home, with basement. Possibility to create a fourth bedroom on either the ground floor or at the basement level.",
	}
	arr[3] = map[string]interface{}{
		"address":     "589 Coleridge Ave, Hanoi, Vietnam",
		"houseType":   "House for sale",
		"price":       1250000,
		"properties":  "3 bds, 3.5 ba, 4464 sqft, 0.28 ac lot, Built 1997",
		"publishFrom": 204,
		"thumbnail":   "http://photos2.zillowstatic.com/p_g/ISpxm1nzj9y1xo1000000000.jpg",
		"location":    []float32{21.027816, 105.852268},
		"description": "Custom designed home on a large lot in the Old Palo Alto neighborhood. Vaulted ceilings and large windows fill the home with natural light. Clean lines and craftsman details create a bond between the shingle-style neighborhood and contemporary style. Three level home, with basement. Possibility to create a fourth bedroom on either the ground floor or at the basement level.",
	}
	arr[4] = map[string]interface{}{
		"address":     "589 Coleridge Ave, Hanoi, Vietnam",
		"houseType":   "House for sale",
		"price":       1250000,
		"properties":  "3 bds, 3.5 ba, 4464 sqft, 0.28 ac lot, Built 1997",
		"publishFrom": 204,
		"thumbnail":   "http://photos3.zillowstatic.com/p_g/ISxzt2p00tw62m1000000000.jpg",
		"location":    []float32{21.054544, 105.820344},
		"description": "Custom designed home on a large lot in the Old Palo Alto neighborhood. Vaulted ceilings and large windows fill the home with natural light. Clean lines and craftsman details create a bond between the shingle-style neighborhood and contemporary style. Three level home, with basement. Possibility to create a fourth bedroom on either the ground floor or at the basement level.",
	}
	arr[5] = map[string]interface{}{
		"address":     "589 Coleridge Ave, Hanoi, Vietnam",
		"houseType":   "House for sale",
		"price":       1250000,
		"properties":  "3 bds, 3.5 ba, 4464 sqft, 0.28 ac lot, Built 1997",
		"publishFrom": 204,
		"thumbnail":   "http://photos3.zillowstatic.com/p_g/IS5mozylseymxd1000000000.jpg",
		"location":    []float32{21.042675, 105.791481},
		"description": "Custom designed home on a large lot in the Old Palo Alto neighborhood. Vaulted ceilings and large windows fill the home with natural light. Clean lines and craftsman details create a bond between the shingle-style neighborhood and contemporary style. Three level home, with basement. Possibility to create a fourth bedroom on either the ground floor or at the basement level.",
	}
	arr[6] = map[string]interface{}{
		"address":     "589 Coleridge Ave, Hanoi, Vietnam",
		"houseType":   "House for sale",
		"price":       1250000,
		"properties":  "3 bds, 3.5 ba, 4464 sqft, 0.28 ac lot, Built 1997",
		"publishFrom": 204,
		"thumbnail":   "http://photos2.zillowstatic.com/p_g/ISpxm1nzj9y1xo1000000000.jpg",
		"location":    []float32{21.028501, 105.782255},
		"description": "Custom designed home on a large lot in the Old Palo Alto neighborhood. Vaulted ceilings and large windows fill the home with natural light. Clean lines and craftsman details create a bond between the shingle-style neighborhood and contemporary style. Three level home, with basement. Possibility to create a fourth bedroom on either the ground floor or at the basement level.",
	}
	arr[7] = map[string]interface{}{
		"address":     "589 Coleridge Ave, Hanoi, Vietnam",
		"houseType":   "House for sale",
		"price":       1250000,
		"properties":  "3 bds, 3.5 ba, 4464 sqft, 0.28 ac lot, Built 1997",
		"publishFrom": 204,
		"thumbnail":   "http://photos3.zillowstatic.com/p_g/IS5mozylseymxd1000000000.jpg",
		"location":    []float32{21.028309, 105.790856},
		"description": "Custom designed home on a large lot in the Old Palo Alto neighborhood. Vaulted ceilings and large windows fill the home with natural light. Clean lines and craftsman details create a bond between the shingle-style neighborhood and contemporary style. Three level home, with basement. Possibility to create a fourth bedroom on either the ground floor or at the basement level.",
	}
	arr[8] = map[string]interface{}{
		"address":     "589 Coleridge Ave, Hanoi, Vietnam",
		"houseType":   "House for sale",
		"price":       1250000,
		"properties":  "3 bds, 3.5 ba, 4464 sqft, 0.28 ac lot, Built 1997",
		"publishFrom": 204,
		"thumbnail":   "http://photos2.zillowstatic.com/p_g/ISpxm1nzj9y1xo1000000000.jpg",
		"location":    []float32{21.027705, 105.811117},
		"description": "Custom designed home on a large lot in the Old Palo Alto neighborhood. Vaulted ceilings and large windows fill the home with natural light. Clean lines and craftsman details create a bond between the shingle-style neighborhood and contemporary style. Three level home, with basement. Possibility to create a fourth bedroom on either the ground floor or at the basement level.",
	}
	arr[9] = map[string]interface{}{
		"address":     "589 Coleridge Ave, Hanoi, Vietnam",
		"houseType":   "House for sale",
		"price":       1250000,
		"properties":  "3 bds, 3.5 ba, 4464 sqft, 0.28 ac lot, Built 1997",
		"publishFrom": 204,
		"thumbnail":   "http://photos3.zillowstatic.com/p_g/ISxzt2p00tw62m1000000000.jpg",
		"location":    []float32{21.019992, 105.814706},
//.........这里部分代码省略.........
开发者ID:quannguyen89,项目名称:beego_api_demo,代码行数:101,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang orm.QuerySeter类代码示例发布时间:2022-05-24
下一篇:
Golang orm.RunSyncdb函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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