fix(orm): fix broken Table.Delete method (#11112)

This commit is contained in:
Aaron Craelius 2022-02-03 15:59:16 -05:00 committed by GitHub
parent e0543a3be0
commit 888548ab53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View File

@ -153,9 +153,9 @@ func (t tableImpl) doSave(writer *batchIndexCommitmentWriter, message proto.Mess
return writer.Write()
}
func (t tableImpl) Delete(context context.Context, message proto.Message) error {
func (t tableImpl) Delete(ctx context.Context, message proto.Message) error {
pk := t.PrimaryKeyCodec.GetKeyValues(message.ProtoReflect())
return t.DeleteBy(context, pk)
return t.doDelete(ctx, pk)
}
func (t tableImpl) GetIndex(fields string) Index {

View File

@ -395,6 +395,13 @@ func runTestScenario(t *testing.T, table ormtable.Table, backend ormtable.Backen
it, err = store.List(ctx, testpb.ExampleTablePrimaryKey{})
assert.NilError(t, err)
assertIteratorItems(it, 0, 2, 6, 10)
// Let's delete something directly
assert.NilError(t, store.Delete(ctx, data[0]))
it, err = store.List(ctx, testpb.ExampleTablePrimaryKey{})
assert.NilError(t, err)
assertIteratorItems(it, 2, 6, 10)
}
func TestRandomTableData(t *testing.T) {

View File

@ -1098,6 +1098,31 @@ ITERATOR 0100 -> 0101
PK testpb.ExampleTable 9/0/ -> {"u32":9,"b":true}
NEXT
VALID false
GET 0100000000047ffffffffffffffe616263 100e2203616263
PK testpb.ExampleTable 4/-2/abc -> {"u32":4,"u64":14,"str":"abc","bz":"abc","i64":-2}
ORM DELETE testpb.ExampleTable {"u32":4,"u64":14,"str":"abc","bz":"abc","i64":-2}
DEL 0100000000047ffffffffffffffe616263
DEL PK testpb.ExampleTable 4/-2/abc -> {"u32":4,"str":"abc","i64":-2}
DEL 0101000000000000000e616263
DEL ERR:EOF
DEL 010261626300000000047ffffffffffffffe
DEL IDX testpb.ExampleTable str/u32/i64 : abc/4/-2 -> 4/-2/abc
DEL 01030361626361626300000000047ffffffffffffffe
DEL IDX testpb.ExampleTable bz/str/u32/i64 : [97 98 99]/abc/4/-2 -> 4/-2/abc
ITERATOR 0100 -> 0101
VALID true
KEY 0100000000047fffffffffffffff616263 10102203616263
PK testpb.ExampleTable 4/-1/abc -> {"u32":4,"u64":16,"str":"abc","bz":"abc","i64":-1}
NEXT
VALID true
KEY 0100000000077fffffffffffffff616265 100b
PK testpb.ExampleTable 7/-1/abe -> {"u32":7,"u64":11,"str":"abe","i64":-1}
NEXT
VALID true
KEY 0100000000098000000000000000 7801
PK testpb.ExampleTable 9/0/ -> {"u32":9,"b":true}
NEXT
VALID false
CLOSE
CLOSE
CLOSE