From 25e00fdad64bda689597d918e0e3a8d2ae8d6f45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Fri, 11 Sep 2020 19:06:36 -0300 Subject: [PATCH] Add feature of escaping params to Find function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change was made based on a suggestion from RaĆ­ Tamarindo (raitamarindo@gmail.com) --- postgres.go | 3 ++- postgres_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/postgres.go b/postgres.go index 42c3e43..65bd5ab 100644 --- a/postgres.go +++ b/postgres.go @@ -26,8 +26,9 @@ func (c Client) Find( ctx context.Context, item interface{}, query string, + params ...interface{}, ) error { - it := c.db.Raw(query) + it := c.db.Raw(query, params...) it.Scan(item) return it.Error } diff --git a/postgres_test.go b/postgres_test.go index ef022bc..cc31d78 100644 --- a/postgres_test.go +++ b/postgres_test.go @@ -51,7 +51,7 @@ func TestFind(t *testing.T) { tableName: "users", } u := User{} - err = c.Find(ctx, &u, `SELECT * FROM users WHERE name='Bia';`) + err = c.Find(ctx, &u, `SELECT * FROM users WHERE name=?;`, "Bia") assert.Equal(t, err, nil) assert.Equal(t, "Bia", u.Name)