mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
DeleteView from Frame
This commit is contained in:
parent
fec7413f96
commit
748b034aa8
2 changed files with 51 additions and 0 deletions
20
frame.go
20
frame.go
|
|
@ -509,6 +509,26 @@ func (f *Frame) newView(path, name string) *View {
|
|||
return view
|
||||
}
|
||||
|
||||
// DeleteView removes a view from the frame.
|
||||
func (f *Frame) DeleteView(name string) error {
|
||||
view := f.views[name]
|
||||
if view == nil {
|
||||
return ErrInvalidView
|
||||
}
|
||||
|
||||
// TODO capture errors lower down in this method
|
||||
_ = view.Close()
|
||||
|
||||
// Delete view directory.
|
||||
if err := os.RemoveAll(view.Path()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
delete(f.views, name)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetBit sets a bit on a view within the frame.
|
||||
func (f *Frame) SetBit(name string, rowID, colID uint64, t *time.Time) (changed bool, err error) {
|
||||
// Validate view name.
|
||||
|
|
|
|||
|
|
@ -307,3 +307,34 @@ func TestFrame_RowLabelValidation(t *testing.T) {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
// Ensure frame can open and retrieve a view.
|
||||
func TestFrame_DeleteView(t *testing.T) {
|
||||
f := test.MustOpenFrame()
|
||||
defer f.Close()
|
||||
|
||||
// Create view.
|
||||
view, err := f.CreateViewIfNotExists("v")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if view == nil {
|
||||
t.Fatal("expected view")
|
||||
}
|
||||
|
||||
err = f.DeleteView("v")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if f.View("v") != nil {
|
||||
t.Fatal("view still exists in frame")
|
||||
}
|
||||
|
||||
// // Retrieve existing view.
|
||||
view2, err := f.CreateViewIfNotExists("v")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
} else if view == view2 {
|
||||
t.Fatal("failed to create new view")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue