本文整理汇总了Golang中github.com/jmoiron/sqlx.Tx.QueryRowx方法的典型用法代码示例。如果您正苦于以下问题:Golang Tx.QueryRowx方法的具体用法?Golang Tx.QueryRowx怎么用?Golang Tx.QueryRowx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/jmoiron/sqlx.Tx
的用法示例。
在下文中一共展示了Tx.QueryRowx方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DoesExist
// DoesExist check if database exist with a name and an owner
func (d *Database) DoesExist(tx *sqlx.Tx) (exists bool, err error) {
exists = false
err = tx.QueryRowx("SELECT id FROM \"database\" WHERE name = $1 AND owner = $2", d.Name, d.Owner).Scan(&d.Id)
switch {
case err == sql.ErrNoRows:
return exists, nil
case err != nil:
return exists, errors.New("database::DoesExist: " + err.Error())
}
return true, nil
}
示例2: statisticsPanel
func (app *Application) statisticsPanel(tx *sqlx.Tx) (map[string]interface{}, error) {
var (
totalParts int64
totalStock int64
emptyParts int64
totalPlaces int64
totalCategories int64
)
row := tx.QueryRowx(`SELECT COUNT(*), SUM(amount) FROM 'part_view'`)
if err := row.Scan(&totalParts, &totalStock); err != nil {
return nil, err
}
row = tx.QueryRowx(`SELECT COUNT(*) FROM 'part_view' WHERE "amount" = 0`)
if err := row.Scan(&emptyParts); err != nil {
return nil, err
}
row = tx.QueryRowx(`SELECT COUNT(*) FROM 'place'`)
if err := row.Scan(&totalPlaces); err != nil {
return nil, err
}
row = tx.QueryRowx(`SELECT COUNT(*) FROM 'category'`)
if err := row.Scan(&totalCategories); err != nil {
return nil, err
}
return map[string]interface{}{
"TotalParts": totalParts,
"TotalStock": totalStock,
"EmptyParts": emptyParts,
"TotalPlaces": totalPlaces,
"TotalCategories": totalCategories,
}, nil
}