Example #1
0
func TestRemove(t *testing.T) {
	setup(t)

	p1 := &Person{Name: "John", Age: 9}
	p2 := &Person{Name: "Sarah", Age: 27}
	p3 := &Person{Name: "James", Age: 11}
	p4 := &Person{Name: "Monika", Age: 12}
	people := []*Person{p1, p2, p3, p4}

	for _, p := range people {
		if err := rebecca.Save(p); err != nil {
			t.Fatal(err)
		}
	}

	if err := rebecca.Remove(p3); err != nil {
		t.Fatal(err)
	}

	expected := []Person{*p1, *p2, *p4}
	actual := []Person{}
	if err := rebecca.All(&actual); err != nil {
		t.Fatal(err)
	}

	if !reflect.DeepEqual(actual, expected) {
		t.Errorf("Expected %+v to equal %+v", actual, expected)
	}
}
Example #2
0
func ExampleRemove() {
	type Person struct {
		// ...
	}

	// First lets find person with primary key = 25
	person := &Person{}
	if err := rebecca.Get(25, person); err != nil {
		panic(err)
	}

	// And then, lets remove it
	if err := rebecca.Remove(person); err != nil {
		panic(err)
	}

	// At this point person with primary key = 25 was removed from database.
}