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) return fmt.Errorf("kissorm: expected to receive a pointer to struct, but got: %T", record)
} }
it := c.db.Raw(query, params...) rows, err := c.db.DB().QueryContext(ctx, query, params...)
if it.Error != nil { if err != nil {
return it.Error return err
} }
it = it.Scan(record) defer rows.Close()
if it.Error != nil && it.Error.Error() == "record not found" {
if !rows.Next() {
return ErrRecordNotFound return ErrRecordNotFound
} }
return it.Error
return scanRows(rows, record)
} }
// QueryChunks is meant to perform queries that returns // QueryChunks is meant to perform queries that returns