Remove gorm dependency from QueryOne()

pull/2/head
Vinícius Garcia 2020-11-22 22:34:24 -03:00
parent cdad1673f0
commit 13bd087cee
1 changed files with 8 additions and 6 deletions

View File

@ -101,15 +101,17 @@ func (c Client) QueryOne(
return fmt.Errorf("kissorm: expected to receive a pointer to struct, but got: %T", record)
}
it := c.db.Raw(query, params...)
if it.Error != nil {
return it.Error
rows, err := c.db.DB().QueryContext(ctx, query, params...)
if err != nil {
return err
}
it = it.Scan(record)
if it.Error != nil && it.Error.Error() == "record not found" {
defer rows.Close()
if !rows.Next() {
return ErrRecordNotFound
}
return it.Error
return scanRows(rows, record)
}
// QueryChunks is meant to perform queries that returns