From 13bd087cee4525e6a1a97991b3f6652b49c70754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Sun, 22 Nov 2020 22:34:24 -0300 Subject: [PATCH] Remove gorm dependency from QueryOne() --- kiss_orm.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/kiss_orm.go b/kiss_orm.go index a0b6803..aa96bcc 100644 --- a/kiss_orm.go +++ b/kiss_orm.go @@ -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