本文整理汇总了Golang中github.com/astaxie/beego/orm.NewOrm函数的典型用法代码示例。如果您正苦于以下问题:Golang NewOrm函数的具体用法?Golang NewOrm怎么用?Golang NewOrm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewOrm函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: AddTopic
func AddTopic(uid, name, content, pic, nid, fid string) error {
nidNum, err := strconv.ParseInt(nid, 10, 64)
if err != nil {
return err
}
fidNum, _ := strconv.ParseInt(fid, 10, 64)
o := orm.NewOrm()
topic := &Topic{
Uid: uid,
Nid: nidNum,
Fid: fidNum,
Name: name,
Content: content,
Pic: pic,
Created: time.Now(),
Updated: time.Now(),
}
//判断是否是子串,如果是就更新父串的Update时间
if fidNum != 0 {
beego.Info("qwe:")
otmp := orm.NewOrm()
qst := otmp.QueryTable("topic")
tf := new(Topic)
err = qst.Filter("id", fidNum).One(tf)
tf.Updated = time.Now()
otmp.Update(tf)
}
_, err = o.Insert(topic)
return err
}
开发者ID:sllt,项目名称:ac,代码行数:31,代码来源:model.go
示例2: TrashProblem
// put problem into trash
func (this *Problem) TrashProblem(id int) error {
o := orm.NewOrm()
ob := orm.NewOrm()
var pro Problem
var prob ProblemBank
var err error
var num int64
if id > 0 {
// read from problem
pro.Id = id
err = o.Read(&pro, "Id")
if err != nil {
return err
}
// read from problem bank
prob.Id = pro.Pbid
err = ob.Read(&prob, "Id")
if err == nil {
prob.Status = "deleted"
ob.Update(&prob)
}
num, err = o.Delete(&pro)
} else {
return errors.New("at least one valid param")
}
if num == 0 {
return errors.New("no row to delete")
}
return err
}
开发者ID:jango2015,项目名称:ojsite,代码行数:36,代码来源:problem.go
示例3: CreateNewPublish
//@param streamId
//@param streamTitle
//@return publishId if err==nil and pubilshId==nil, not allow taken
//streamId can only be taken once a time
func CreateNewPublish(userId int, streamId, streamTitle string, streamQuality, streamOrientation int) (publishId string, err error) {
timestamp := time.Now().Unix()
orm.NewOrm().QueryTable("LiveVideo").Filter("StreamId", streamId).Filter("EndTime", 0).Update(orm.Params{
"EndTime": timestamp,
})
publishId = utils.Md5Hash(fmt.Sprintf("%s:%s:%d", streamId, streamTitle, timestamp))
user := User{Id: userId}
newPublish := LiveVideo{
User: &user,
PublishId: publishId,
Title: streamTitle,
StreamId: streamId,
Quality: streamQuality,
Orientation: streamOrientation,
StartTime: timestamp,
}
_, cErr := orm.NewOrm().Insert(&newPublish)
if cErr != nil {
err = cErr
return
}
return
}
开发者ID:qiniudemo,项目名称:qiniu-live-server,代码行数:30,代码来源:live_video.go
示例4: PutAdminInTeam
func PutAdminInTeam(tid int64, uids string) error {
if uids == "" {
return nil
}
uidArr := strings.Split(uids, ",")
for i := 0; i < len(uidArr); i++ {
uid := uidArr[i]
if uid == "" {
continue
}
id, err := strconv.Atoi(uid)
if err != nil {
return err
}
_, err = orm.NewOrm().Raw("insert into rel_team_user(tid,uid,is_admin) values(?, ?, 1)", tid, id).Exec()
if err != nil {
_, err = orm.NewOrm().Raw("update rel_team_user set is_admin = 1 where tid=? and uid=?", tid, id).Exec()
if err != nil {
return err
}
}
}
return nil
}
开发者ID:Liuyanglong,项目名称:uic,代码行数:28,代码来源:team.go
示例5: SaveMiniUIData
func SaveMiniUIData(ModelName string, data string, diy interface{}) (err error) {
//TODO:加入修改删除时的身份判断。只能修改删除自己创建的。加filter
beego.Debug("SaveMiniUIData(ModelName = [%#v], data = [%#v], diy = [%#v])\n", ModelName, data, diy)
//根据名称获取Model
reflecty, _ := ModelCache.Get(ModelName)
//得到实例
reflectx := reflecty()
//整理为可识别格式
var dataList DataList
json.Unmarshal([]byte(data), &dataList)
//按struct 遍历得到定义,及得到的值
for _, SingleItem := range dataList.List {
state := SingleItem["_state"]
beego.Debug("state是", state)
if state == nil || state == "" {
state = "modified"
beego.Debug("state改为默认的", state)
}
if state != "" {
Params := make(orm.Params)
//格式化miniui过来的时间,得到修改过的字段放到m中
err = MiniUIDataUpdate(reflectx, SingleItem, Params, state.(string), diy)
if err != nil {
beego.Error("MiniUIDataUpdate", err)
}
//beego.Debug("更新参数",Params)
switch state {
case "modified":
pk := GetModelPk(reflectx)
//获取表名,要求必须有TableName方法
if tablenameMC := reflect.ValueOf(reflectx).MethodByName("TableName"); tablenameMC.IsValid() {
tablename := tablenameMC.Call(nil)[0].Interface().(string)
//fmt.Println("dddd",tablename.Interface().(string))
//orm.NewOrm().QueryTable(reflect.TypeOf(reflectx).Elem().Name()).Filter(pk, SingleItem[pk]).Update(Params)
beego.Debug("更新参数", Params)
count, err := orm.NewOrm().QueryTable(tablename).Filter(pk, SingleItem[pk]).Update(Params)
beego.Debug("更新参数", count, err, Params)
} else {
beego.Error("获取表名,要求必须有TableName方法")
return errors.New(fmt.Sprintf("获取表名,要求必须有TableName方法"))
}
case "added":
_, err = orm.NewOrm().Insert(reflectx)
case "removed":
_, err = orm.NewOrm().Delete(reflectx)
}
}
}
return err
}
开发者ID:dongjun111111,项目名称:notes,代码行数:60,代码来源:MiniUiOrm.go
示例6: SetSession
func SetSession(userId int, sessionId string) (err error) {
var session Session
qs := orm.NewOrm().QueryTable("Session").Filter("UserId", userId)
qErr := qs.Limit(1).One(&session)
if qErr != nil {
if qErr != orm.ErrNoRows {
err = errors.New(fmt.Sprintf("set session error, %s", qErr.Error()))
return
}
}
if session.Id != 0 {
session.SessionId = sessionId
_, uErr := orm.NewOrm().Update(&session, "SessionId")
if uErr != nil {
err = errors.New(fmt.Sprintf("update session error, %s", uErr.Error()))
return
}
} else {
session.UserId = userId
session.SessionId = sessionId
_, cErr := orm.NewOrm().Insert(&session)
if cErr != nil {
err = errors.New(fmt.Sprintf("create session error, %s", cErr.Error()))
return
}
}
return
}
开发者ID:qiniudemo,项目名称:qiniu-live-server,代码行数:28,代码来源:session.go
示例7: Insert
func (m *User) Insert() error {
id := m.Id
//fmt.Println("id...")
//fmt.Println(m.Id)
//orm.Debug = true
m.Rands = GetUserSalt()
if _, err := orm.NewOrm().Insert(m); err != nil {
return err
}
fmt.Println(m.Email)
fmt.Println(m.Id)
o := orm.NewOrm()
o.QueryTable("user").Filter("email", m.Email).Update(orm.Params{
"id": id,
})
//fmt.Printf("Affected Num: %s, %s", num, err)
return nil
}
开发者ID:EPICPaaS,项目名称:wetalk,代码行数:27,代码来源:auth.go
示例8: SaveOrUpdate
//同一个agent的结果保存20条记录,滚动覆盖记录
func (monitor *Monitor) SaveOrUpdate() error {
count, err := orm.NewOrm().QueryTable(new(Monitor)).Filter("AgentId", monitor.AgentId).Count()
if err != nil {
beego.Error("Count Monitor error : %s", err)
return err
}
if count < utils.Monitor_Agent_Size {
return monitor.Save()
}
var _monitor Monitor
//选取同一个agent_id 的最早update的记录
err = orm.NewOrm().QueryTable(new(Monitor)).Filter("AgentId", monitor.AgentId).OrderBy("Updated").Limit(1).One(&_monitor)
if err == orm.ErrNoRows {
return monitor.Save()
}
if err == nil {
monitor.Id = _monitor.Id
return monitor.Update()
}
return err
}
开发者ID:alex8023,项目名称:citycloud.cf-deploy-ui,代码行数:28,代码来源:ops_monitor.go
示例9: Load
func (resourcesPools *ResourcesPools) Load() error {
errors := orm.NewOrm().Read(resourcesPools, "Id")
if errors != nil {
beego.Error("Read ResourcesPools error : %s", errors)
_, err := orm.NewOrm().Insert(resourcesPools)
if err != nil {
beego.Error("Insert ResourcesPools error %s ", err)
}
}
return errors
}
开发者ID:alex8023,项目名称:citycloud.cf-deploy-ui,代码行数:12,代码来源:cloudfoundry.go
示例10: CreateTable
func CreateTable() {
name := "default" //数据库别名
force := false //不强制建数据库
verbose := true //打印建表过程
err := orm.RunSyncdb(name, force, verbose) //建表
if err != nil {
beego.Error(err)
}
exit := orm.NewOrm().QueryTable("user").Filter("username", "admin").Exist()
if !exit {
user := User{Username: "admin", Password: "admin"}
orm.NewOrm().Insert(&user)
}
}
开发者ID:wuwenbao,项目名称:GoWebSSH,代码行数:14,代码来源:base.go
示例11: Delete
func (m *Post) Delete() error {
if m.Tags != "" {
o := orm.NewOrm()
oldtags := strings.Split(strings.Trim(m.Tags, ","), ",")
//标签统计-1
o.QueryTable(&Tag{}).Filter("name__in", oldtags).Update(orm.Params{"count": orm.ColValue(orm.Col_Minus, 1)})
//删掉tag_post表的记录
o.QueryTable(&TagPost{}).Filter("postid", m.Id).Delete()
}
if _, err := orm.NewOrm().Delete(m); err != nil {
return err
}
return nil
}
开发者ID:ShinichR,项目名称:myBlog,代码行数:14,代码来源:post.go
示例12: Load
func (netWork *NetWork) Load() error {
queryOneErr := orm.NewOrm().QueryTable(netWork).One(netWork, "Id")
if queryOneErr != nil {
beego.Error("Query One failed %s", queryOneErr)
}
errors := orm.NewOrm().Read(netWork, "Id")
if errors != nil {
beego.Error("Read NetWork error : %s", errors)
_, err := orm.NewOrm().Insert(netWork)
if err != nil {
beego.Error("Insert NetWork error %s ", err)
}
}
return errors
}
开发者ID:alex8023,项目名称:citycloud.cf-deploy-ui,代码行数:15,代码来源:microbosh.go
示例13: AcceptProblem
// 通过problem
// id bank中的ID
func (this *ProblemBank) AcceptProblem(id int) error {
o := orm.NewOrm()
var prob ProblemBank
var err error
prob.Id = id
// read problem in problem bank
err = o.Read(&prob, "Id")
if err != nil {
return err
}
// create problem
var pro Problem
op := orm.NewOrm()
pro.Title = prob.Title
pro.Pbid = prob.Id
pro.Type = prob.Type
pro.Description = prob.Description
pro.PreCode = prob.PreCode
pro.IoData = prob.IoData
pro.Tags = prob.Tags
pro.Level = "public"
log.Blueln("[problem copy from bank to list]")
log.Blueln(pro)
// insert into problem
pid, err := op.Insert(&pro)
if err != nil {
return err
} else if pid == 0 {
return errors.New("insert error, id is 0.")
}
// update problem bank
prob.Status = "ok"
_, err = o.Update(&prob)
if err != nil {
return err
} else {
return nil
}
}
开发者ID:jango2015,项目名称:ojsite,代码行数:50,代码来源:problem_bank.go
示例14: UpdateUser
// TODO return more detailed error number
// NOTE: this will do a fully update, so the user must be read from DB, and then update its field
func UpdateUser(user *User) int {
o := orm.NewOrm()
err := o.Begin()
if err != nil {
beego.Warning("UpdateUser fail: ", err)
return utils.ERROR_CODE_SYSTEM_ERROR
}
var errNum int
for i := 0; i < DB_UNIQUE_CONFLICT_TRY; i++ {
user.UpdateAt = utils.GetTimeMillis()
errNum = updateUserInternal(&o, user)
if errNum == 0 {
break
}
time.Sleep(1 * time.Millisecond)
}
if errNum > 0 {
o.Rollback()
return errNum
} else {
err = o.Commit()
if err != nil {
beego.Warning("UpdateUser fail: commit fail ", err)
o.Rollback()
return utils.ERROR_CODE_SYSTEM_ERROR
}
}
return 0
}
开发者ID:Piasy,项目名称:BeegoTDDBootStrap,代码行数:33,代码来源:user.go
示例15: VerifyUserByPhone
func VerifyUserByPhone(phone *string, secret string) (*User, int) {
utils.AssertNotEmptyString(phone)
o := orm.NewOrm()
user := User{Phone: phone}
err := o.Read(&user, "Phone")
if err != nil {
return nil, utils.ERROR_CODE_USERS_USER_NOT_EXISTS
}
if utils.Secret2Password("phone:"+*phone, secret) != user.Password {
return nil, utils.ERROR_CODE_TOKENS_PASSWORD_MISMATCH
}
for i := 0; i < DB_UNIQUE_CONFLICT_TRY; i++ {
user.Token = utils.GenToken()
user.UpdateAt = utils.GetTimeMillis()
_, err = o.Update(&user)
if err == nil {
return &user, 0
}
time.Sleep(1 * time.Millisecond)
}
beego.Warning("VerifyUser, update token fail: ", err)
return nil, utils.ERROR_CODE_SYSTEM_ERROR
}
开发者ID:Piasy,项目名称:BeegoTDDBootStrap,代码行数:27,代码来源:user.go
示例16: GetAllCategories
func GetAllCategories() ([]*Category, error) {
o := orm.NewOrm()
cates := make([]*Category, 0)
qs := o.QueryTable("category")
_, err := qs.All(&cates)
return cates, err
}
开发者ID:cwen-coder,项目名称:cwengo.com,代码行数:7,代码来源:category.go
示例17: DeleteReply
func DeleteReply(rid string) error {
ridNum, err := strconv.ParseInt(rid, 10, 64)
if err != nil {
return err
}
o := orm.NewOrm()
var tidNum int64
reply := &Comment{Id: ridNum}
if o.Read(reply) == nil {
tidNum = reply.Tid
_, err = o.Delete(reply)
if err != nil {
return err
}
}
replies := make([]*Comment, 0)
qs := o.QueryTable("comment")
_, err = qs.Filter("tid", tidNum).OrderBy("-created").All(&replies)
if err != nil {
return err
}
topic := &Topic{Id: tidNum}
if o.Read(topic) == nil {
topic.ReplyTime = replies[0].Created
topic.ReplyCount = int64(len(replies))
_, err = o.Update(topic)
}
return err
}
开发者ID:443752009,项目名称:go-web-foundation,代码行数:33,代码来源:models.go
示例18: AddReply
func AddReply(tid, nickname, content string) error {
tidNum, err := strconv.ParseInt(tid, 10, 64)
if err != nil {
return err
}
reply := &Comment{
Tid: tidNum,
Name: nickname,
Content: content,
Created: time.Now(),
}
o := orm.NewOrm()
_, err = o.Insert(reply)
if err != nil {
return err
}
topic := &Topic{Id: tidNum}
if o.Read(topic) == nil {
topic.ReplyTime = time.Now()
topic.ReplyCount++
_, err = o.Update(topic)
}
return err
}
开发者ID:443752009,项目名称:go-web-foundation,代码行数:26,代码来源:models.go
示例19: DeleteTopic
func DeleteTopic(tid string) error {
tidNum, err := strconv.ParseInt(tid, 10, 64)
if err != nil {
return err
}
o := orm.NewOrm()
var oldCate string
topic := &Topic{Id: tidNum}
if o.Read(topic) == nil {
oldCate = topic.Category
_, err = o.Delete(topic)
if err != nil {
return err
}
}
if len(oldCate) > 0 {
cate := new(Category)
qs := o.QueryTable("category")
err = qs.Filter("title", topic.Category).One(cate)
if err == nil {
cate.TopicCount--
_, err = o.Update(cate)
}
}
return err
}
开发者ID:443752009,项目名称:go-web-foundation,代码行数:29,代码来源:models.go
示例20: GetFileList
// 文件列表
// page 页码
// numPerPage 每页条数
// 返回值:
// []orm.Params 文章
// bool 是否有下一页
// int 总页数
// error 错误
func GetFileList(page int, numPerPage int) ([]orm.Params, bool, int, error) {
// numPerPage := 6
sql1 := "select * from file order by time desc limit ?," + fmt.Sprintf("%d", numPerPage)
sql2 := "select count(*) as number from file"
var maps, maps2 []orm.Params
o := orm.NewOrm()
num, err := o.Raw(sql1, numPerPage*(page-1)).Values(&maps)
o.Raw(sql2).Values(&maps2)
number, _ := strconv.Atoi(maps2[0]["number"].(string))
var addFlag int
if 0 == (number % numPerPage) {
addFlag = 0
} else {
addFlag = 1
}
pages := number/numPerPage + addFlag
var flagNextPage bool
if pages == page {
flagNextPage = false
} else {
flagNextPage = true
}
if err == nil && num > 0 {
return maps, flagNextPage, pages, nil
} else {
return nil, false, pages, err
}
}
开发者ID:dw250100785,项目名称:blog-1,代码行数:41,代码来源:file.go
注:本文中的github.com/astaxie/beego/orm.NewOrm函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论