| | |
| | | package models |
| | | |
| | | import "github.com/astaxie/beego/orm" |
| | | import ( |
| | | "fmt" |
| | | "github.com/astaxie/beego/orm" |
| | | ) |
| | | |
| | | type UserCar struct { |
| | | Id string `orm:"pk;size(50);column(id)" json:"id"` |
| | |
| | | |
| | | func (uc *UserCar) GetByUserId(userId string) (all []UserCar,err error) { |
| | | o := orm.NewOrm() |
| | | _, err = o.Raw("select * from ? where userId=?", uc.TableName(), userId).QueryRows(&all) |
| | | _, err = o.QueryTable(uc.TableName()).Filter("userId", userId).All(&all) |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | |
| | | func (uc *UserCar) Exist(userId string, plateNo string) bool { |
| | | var list []UserCar |
| | | o := orm.NewOrm() |
| | | i,_ := o.Raw("select * from ? where userId=? and plateNo=?", uc.TableName(), userId, plateNo).QueryRows(&list) |
| | | if i > 0 && len(list) >0 { |
| | | o.Raw("select * from ? where userId=? and plateNo=?", uc.TableName(), userId, plateNo).QueryRows(&list) |
| | | if len(list) >0 { |
| | | return true |
| | | } |
| | | return false |
| | | } |
| | | |
| | | func (uc *UserCar) DeleteByUserId(userId string) (int64, error) { |
| | | func (uc *UserCar) Delete(userId string, plateNo string) (int64, error) { |
| | | o := orm.NewOrm() |
| | | result, err := o.Raw("delete from ? where userId=?", uc.TableName(), userId).Exec() |
| | | sql := fmt.Sprintf("delete from "+uc.TableName()+" where userId='%s' and plateNo='%s'", userId, plateNo) |
| | | result, err := o.Raw(sql).Exec() |
| | | if err != nil { |
| | | return 0, err |
| | | } |