fix: don't log empty sql responses as errors
This commit is contained in:
@@ -85,10 +85,11 @@ func (r sqlRepository) queryOne(sq Sqlizer, response interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = r.ormer.Raw(query, args...).QueryRow(response)
|
err = r.ormer.Raw(query, args...).QueryRow(response)
|
||||||
r.logSQL(query, args, err, 1)
|
|
||||||
if err == orm.ErrNoRows {
|
if err == orm.ErrNoRows {
|
||||||
|
r.logSQL(query, args, nil, 1)
|
||||||
return model.ErrNotFound
|
return model.ErrNotFound
|
||||||
}
|
}
|
||||||
|
r.logSQL(query, args, err, 1)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,26 +99,19 @@ func (r sqlRepository) queryAll(sq Sqlizer, response interface{}) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c, err := r.ormer.Raw(query, args...).QueryRows(response)
|
c, err := r.ormer.Raw(query, args...).QueryRows(response)
|
||||||
r.logSQL(query, args, err, c)
|
|
||||||
if err == orm.ErrNoRows {
|
if err == orm.ErrNoRows {
|
||||||
|
r.logSQL(query, args, nil, c)
|
||||||
return model.ErrNotFound
|
return model.ErrNotFound
|
||||||
}
|
}
|
||||||
|
r.logSQL(query, args, nil, c)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r sqlRepository) exists(existsQuery SelectBuilder) (bool, error) {
|
func (r sqlRepository) exists(existsQuery SelectBuilder) (bool, error) {
|
||||||
existsQuery = existsQuery.Columns("count(*) as count").From(r.tableName)
|
existsQuery = existsQuery.Columns("count(*) as exist").From(r.tableName)
|
||||||
var res struct{ Count int64 }
|
var res struct{ Exist int64 }
|
||||||
query, args, err := existsQuery.ToSql()
|
err := r.queryOne(existsQuery, &res)
|
||||||
if err != nil {
|
return res.Exist > 0, err
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
err = r.ormer.Raw(query, args...).QueryRow(&res)
|
|
||||||
if err == orm.ErrNoRows {
|
|
||||||
err = nil
|
|
||||||
}
|
|
||||||
r.logSQL(query, args, err, res.Count)
|
|
||||||
return res.Count > 0, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r sqlRepository) count(countQuery SelectBuilder, options ...model.QueryOptions) (int64, error) {
|
func (r sqlRepository) count(countQuery SelectBuilder, options ...model.QueryOptions) (int64, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user