// 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 }
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 }