diff --git a/kiss_orm.go b/kiss_orm.go index b042390..fdb2e45 100644 --- a/kiss_orm.go +++ b/kiss_orm.go @@ -12,7 +12,6 @@ import ( // ORMProvider describes the public behavior of this ORM type ORMProvider interface { Find(ctx context.Context, item interface{}, query string, params ...interface{}) error - GetByID(ctx context.Context, item interface{}, id interface{}) error Insert(ctx context.Context, items ...interface{}) error Delete(ctx context.Context, ids ...interface{}) error Update(ctx context.Context, items ...interface{}) error @@ -138,20 +137,6 @@ func (c Client) QueryNext( return false, c.db.ScanRows(it.rows, item) } -// GetByID recovers a single entity from the database by the ID field. -func (c Client) GetByID( - ctx context.Context, - item interface{}, - id interface{}, -) error { - it := c.db.Raw(fmt.Sprintf("select * from %s where id = ?", c.tableName), id) - if it.Error != nil { - return it.Error - } - it = it.Scan(item) - return it.Error -} - // Insert one or more instances on the database // // If the original instances have been passed by reference diff --git a/kiss_orm_test.go b/kiss_orm_test.go index ef2f71d..5fd4581 100644 --- a/kiss_orm_test.go +++ b/kiss_orm_test.go @@ -59,50 +59,6 @@ func TestFind(t *testing.T) { }) } -func TestGetByID(t *testing.T) { - err := createTable() - if err != nil { - t.Fatal("could not create test table!") - } - - t.Run("should return 0 results correctly", func(t *testing.T) { - db := connectDB(t) - defer db.Close() - - ctx := context.Background() - c := Client{ - db: db, - tableName: "users", - } - u := User{} - err := c.GetByID(ctx, &u, 999) - assert.NotEqual(t, nil, err) - assert.Equal(t, User{}, u) - }) - - t.Run("should return a user correctly", func(t *testing.T) { - db := connectDB(t) - defer db.Close() - - bia := &User{ - Name: "Bia", - } - db.Create(&bia) - - ctx := context.Background() - c := Client{ - db: db, - tableName: "users", - } - result := User{} - err = c.GetByID(ctx, &result, bia.ID) - - assert.Equal(t, err, nil) - assert.Equal(t, "Bia", result.Name) - assert.Equal(t, bia.ID, result.ID) - }) -} - func TestInsert(t *testing.T) { err := createTable() if err != nil { @@ -233,7 +189,9 @@ func TestUpdate(t *testing.T) { assert.Equal(t, err, nil) result := User{} - err = c.GetByID(ctx, &result, u.ID) + it := c.db.Raw("SELECT * FROM users WHERE id=?", u.ID) + it.Scan(&result) + it.Close() assert.Equal(t, err, nil) assert.Equal(t, "Thay", result.Name)