Rename the Get function to Find

This change was made based on a suggestion from
Raí Tamarindo (raitamarindo@gmail.com)
pull/2/head
Vinícius Garcia 2020-09-11 19:03:06 -03:00
parent 67cedb1f81
commit 387c2cdd74
2 changed files with 7 additions and 6 deletions

View File

@ -19,9 +19,10 @@ func NewClient(tableName string) Client {
}
}
// Get one instance from the database, the input struct
// must be passed by reference.
func (c Client) Get(
// Find one instance from the database, the input struct
// must be passed by reference and the query should
// return only one result.
func (c Client) Find(
ctx context.Context,
item interface{},
query string,

View File

@ -16,7 +16,7 @@ type User struct {
CreatedAt time.Time
}
func TestGet(t *testing.T) {
func TestFind(t *testing.T) {
err := createTable()
if err != nil {
t.Fatal("could not create test table!")
@ -32,7 +32,7 @@ func TestGet(t *testing.T) {
tableName: "users",
}
u := User{}
err := c.Get(ctx, &u, `SELECT * FROM users WHERE id=1;`)
err := c.Find(ctx, &u, `SELECT * FROM users WHERE id=1;`)
assert.Equal(t, err, nil)
assert.Equal(t, User{}, u)
})
@ -51,7 +51,7 @@ func TestGet(t *testing.T) {
tableName: "users",
}
u := User{}
err = c.Get(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)