本文整理汇总了Golang中github.com/jackc/pgx.ConnPool.QueryRow方法的典型用法代码示例。如果您正苦于以下问题:Golang ConnPool.QueryRow方法的具体用法?Golang ConnPool.QueryRow怎么用?Golang ConnPool.QueryRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jackc/pgx.ConnPool
的用法示例。
在下文中一共展示了ConnPool.QueryRow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FindModel
func FindModel(model models.Model, db *pgx.ConnPool, tx *pgx.Tx, where string, fields ...string) error {
fieldNames, fieldValues := model.Fields(fields...)
query := SqlSelect(model.TableName(), fieldNames)
where = fmt.Sprintf(" WHERE %s = ? %s", model.PrimaryName(), where)
query = FormateToPQuery(query + where)
args := []interface{}{model.PrimaryValue()}
var err error
if tx != nil {
err = tx.QueryRow(query, args...).Scan(fieldValues...)
} else {
err = db.QueryRow(query, args...).Scan(fieldValues...)
}
if err == pgx.ErrNoRows {
return models.ErrNotFound
}
if err != nil {
return err
}
return nil
}
示例2: updateOrCreateModel
func updateOrCreateModel(model models.Model, db *pgx.ConnPool, tx *pgx.Tx, isNew, isRemove bool, where string, fields ...string) error {
if isNew {
model.BeforeCreate()
}
if isRemove {
model.BeforeDelete()
}
model.BeforeSave()
fieldNames, fieldValues := model.Fields(fields...)
var query string = SqlUpdate(model.TableName(), fieldNames)
if isNew {
query = SqlInsert(model.TableName(), fieldNames)
}
where = fmt.Sprintf(" WHERE %[1]s = ? %[2]s RETURNING %[1]s", model.PrimaryName(), where)
if isNew {
where = fmt.Sprintf(" RETURNING %s", model.PrimaryName())
} else {
fieldValues = append(fieldValues, model.PrimaryValue())
}
query = FormateToPQuery(query + where)
var err error
if tx != nil {
err = tx.QueryRow(query, fieldValues...).Scan(model.Maps()[model.PrimaryName()])
} else {
err = db.QueryRow(query, fieldValues...).Scan(model.Maps()[model.PrimaryName()])
}
if err != nil {
return err
}
return nil
}
示例3: poolPrepareUseAndDeallocate
func poolPrepareUseAndDeallocate(pool *pgx.ConnPool, actionNum int) error {
psName := fmt.Sprintf("poolPreparedStatement%d", actionNum)
_, err := pool.Prepare(psName, "select $1::text")
if err != nil {
return err
}
var s string
err = pool.QueryRow(psName, "hello").Scan(&s)
if err != nil {
return err
}
if s != "hello" {
return fmt.Errorf("Prepared statement did not return expected value: %v", s)
}
return pool.Deallocate(psName)
}