本文整理汇总了Golang中github.com/coopernurse/gorp.DbMap.SelectOne方法的典型用法代码示例。如果您正苦于以下问题:Golang DbMap.SelectOne方法的具体用法?Golang DbMap.SelectOne怎么用?Golang DbMap.SelectOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coopernurse/gorp.DbMap
的用法示例。
在下文中一共展示了DbMap.SelectOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetRateById
func (r Rate) GetRateById(Db *gorp.DbMap, id int64) Rate {
Db.SelectOne(&r, "select * from Rate where Id = ?", id)
if r.Id != 0 {
r.Votes = r.GetVotes(Db)
}
return r
}
示例2: UserGet
func UserGet(ren render.Render, params martini.Params, dbmap *gorp.DbMap, s sessions.Session) {
var usr User
log.Println(params)
err := dbmap.SelectOne(&usr, "SELECT * from users WHERE id = $1", s.Get("userId"))
PanicIf(err)
ren.JSON(200, usr)
}
示例3: FindArticleWithReadReceipts
func FindArticleWithReadReceipts(dbmap *gorp.DbMap, id int64) (*Article, error) {
var a Article
err := dbmap.SelectOne(&a, "select * from articles where id = $1", id)
a.AddReadReceipts(dbmap)
return &a, err
}
示例4: GetBySlug
func GetBySlug(db *gorp.DbMap, slug string) (WikiPage, bool) {
w := WikiPage{}
err := db.SelectOne(&w, "select * from WikiPage where Title = ?", slug)
if err != nil {
return w, false
}
return w, true
}
示例5: GetRate
func (r Rate) GetRate(Db *gorp.DbMap, itemType int64, itemId int64) Rate {
if r.Id != 0 {
return r
}
Db.SelectOne(&r, "select * from Rate where ItemId = ? and ItemType = ?",
itemId, itemType)
r.Votes = r.GetVotes(Db)
return r
}
示例6: CheckPhone
func CheckPhone(db *gorp.DbMap, phone string) (User, error) {
var user = User{}
db.SelectOne(&user, "select * from User where Phone = ? limit 1",
phone)
if user.Id != 0 {
return user, errors.New("User found")
}
return user, nil
}
示例7: GetAddr
func GetAddr(db *gorp.DbMap, addr string) (Address, error) {
var a Address
var err error
db.SelectOne(&a, "select * from Address where RawText = ?", addr)
if a.Id == 0 || a.RawText == "" {
err = errors.New(ErrorNotFound)
}
return a, err
}
示例8: GetAddrById
func GetAddrById(db *gorp.DbMap, id int64) (Address, error) {
var a Address
var err error
db.SelectOne(&a, "select * from Address where Id = ?", id)
if a.Id == 0 || a.RawText == "" {
err = errors.New(ErrorNotFound)
}
return a, err
}
示例9: GetGoodsById
func GetGoodsById(gid string, dbmap *gorp.DbMap) (GoodInfo, error) {
var ginfo GoodInfo
err := dbmap.SelectOne(&ginfo, "SELECT * FROM GOODS WHERE G_ID=?", gid)
if err != nil {
glog.V(1).Infof("[DEBUG:] Search goods by id:%v fail:%v", gid, err)
return ginfo, err
}
return ginfo, nil
}
示例10: PlayerInit
func PlayerInit(playerId int, gameId string, gs GameService, ws *websocket.Conn, db *gorp.DbMap) error {
log.Printf("Player is connected: %#v", playerId)
game, _, err := gs.GetGame(db, gameId, playerId)
if err != nil {
log.Printf("Couldn't get player and/or game")
return err
}
if game.State == "start" {
log.Printf("Player %#v rejoining game in play", playerId)
board, err := getBoard(gameId, db)
if err != nil {
log.Printf("Can't get TTT board: %#v", err)
return err
}
log.Printf("Got board, getting nicer one: %#v", board)
niceBoard, err := board.getBoard()
if err != nil {
log.Printf("Unable to get nice board: %#v", err)
return err
}
log.Printf("Got board for player %#v: %#v", playerId, board)
// There may not be a board yet so just try and send it
ws.WriteJSON(Message{
"type": "update",
"state": game.State,
"board": niceBoard,
})
} else {
ws.WriteJSON(Message{
"type": "update",
"state": game.State,
"board": nil,
})
}
// check to make sure this player has a turn row
turn := TicTacToe_Turn{}
err = db.SelectOne(&turn, "select * from tictactoe_turn where game=? and player=?", gameId, playerId)
if err != nil {
turn.Game = gameId
turn.Player = playerId
turn.Move = -1
err = db.Insert(&turn)
if err != nil {
log.Printf("Unable to insert initial turn row: %#v", err)
return err
}
}
gs.SendHost(gameId, Message{"type": "join"})
return nil
}
示例11: Authenticate
func Authenticate(user *User, dbmap *gorp.DbMap) bool {
var db_user User
err := dbmap.SelectOne(&db_user, "SELECT * FROM CUSTOMER WHERE CUS_TEL=?", user.PhoneNumber)
//count,err := dbmap.SelectInt("SELECT count(*) FROM CUSTOMER WHERE CUS_TEL=?",user.PhoneNumber)
if err != nil {
return false
}
glog.V(4).Infof("User Info:%v", db_user)
return user.Password == db_user.Password
}
示例12: GetNearestStation
func (ph *Station) GetNearestStation(dbMap *gorp.DbMap, latitudeF, longitudeF float64) error {
latitude := strconv.FormatFloat(latitudeF, 'f', 6, 64)
longitude := strconv.FormatFloat(longitudeF, 'f', 6, 64)
err := dbMap.SelectOne(ph, "SELECT * FROM station_info WHERE ( 3959 * acos( cos( radians('"+latitude+"') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('"+longitude+"') ) + sin( radians('"+latitude+"') ) * sin( radians( latitude ) ) ) ) < '300' ORDER BY ( 3959 * acos( cos( radians('"+latitude+"') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians('"+longitude+"') ) + sin( radians('"+latitude+"') ) * sin( radians( latitude ) ) ) ) ASC LIMIT 0, 1")
// err = dbMap.SelectOne(ph, "SELECT * FROM station_info WHERE station_code = ?", 2)
if err != nil {
return err
}
return nil
}
示例13: MustGet
func MustGet(db *gorp.DbMap, name string) (Tag, bool) {
t := Tag{}
exist := false
if tagExist(db, name) {
db.SelectOne(&t, "select * from Tag where Title = ?", name)
exist = true
} else {
t, _ = createTag(db, Tag{Title: name})
}
return t, exist
}
示例14: getStationDetails
func getStationDetails(dbMap *gorp.DbMap, code string) PathReturnFormat {
var station model.Station
err := dbMap.SelectOne(&station, "SELECT * FROM station_info WHERE station_code = ?", code)
if err != nil {
fmt.Println("error retreiving station info")
}
var pathReturnFormat PathReturnFormat
pathReturnFormat.Lat = station.Latitude
pathReturnFormat.Long = station.Longitude
pathReturnFormat.Name = station.StationName
return pathReturnFormat
}
示例15: Login
func Login(r *http.Request, render render.Render, db *gorp.DbMap, s sessions.Session) {
user := User{}
email, password := r.FormValue("email"), r.FormValue("password")
err := db.SelectOne(&user, "Select * from users where email=? ", email)
//tmp_pass, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
//err := db.QueryRow("select id, password from users where email=$1", email).Scan(&userId, &dbPasswd)
if err != nil || bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password)) != nil {
render.HTML(400, "404", "")
}
s.Set("userId", user.Id)
render.HTML(200, "dashboard", "")
}