Skip to content

Commit

Permalink
fixed flaw with delete
Browse files Browse the repository at this point in the history
  • Loading branch information
ax4w committed Nov 13, 2023
1 parent 8e5ba2a commit abf16dd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
test
Social
benchmark
concurrent
5 changes: 3 additions & 2 deletions gorageTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,12 @@ func (g *GorageTable) Delete() {
for _, i := range g.Rows {
if compareRows(o, i) {
if idx > len(realTable.Rows) {

realTable.Unlock()
return
}
if idx+1 > len(realTable.Rows) {
realTable.Rows = append(realTable.Rows[idx:])
if idx == len(realTable.Rows) {
realTable.Rows = append(realTable.Rows[:idx-1])
} else {
realTable.Rows = append(realTable.Rows[:idx], realTable.Rows[idx+1:]...)
}
Expand Down
36 changes: 36 additions & 0 deletions gorage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,39 @@ func TestRemoveColumn(t *testing.T) {
}
g.Save()
}

func TestComplete(t *testing.T) {
if fileExists("./Social") {
err := os.Remove("./Social")
if err != nil {
t.Fatalf("Error removing old test file")
return
}
}
gorage := CreateNewGorage("./Social", false, false)
userTable := gorage.CreateTable("User")
if userTable == nil {
return
}
userTable.
AddColumn("Name", STRING).
AddColumn("Handle", STRING).
AddColumn("Age", INT)
gorage.Save()

userTable.Insert([]interface{}{"Emily", "@Emily", 20})
userTable.Insert([]interface{}{"Emily", "@Emily_Backup", 20})
userTable.Insert([]interface{}{"Carl", "@Carl", 23})

gorage.Save()

userTable.
Where(":Handle == '@Emily'").
Update(map[string]interface{}{
"Name": "Emily MLG",
})

gorage.Save()
userTable.Where(":Handle == '@Emily_Backup' || :Name == 'Carl'").Delete()
gorage.Save()
}

0 comments on commit abf16dd

Please sign in to comment.