本文整理匯總了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
}