diff --git a/orm/model/ormtable/table_impl.go b/orm/model/ormtable/table_impl.go index 7923aad74d..41696fde68 100644 --- a/orm/model/ormtable/table_impl.go +++ b/orm/model/ormtable/table_impl.go @@ -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 { diff --git a/orm/model/ormtable/table_test.go b/orm/model/ormtable/table_test.go index 8eb7d19241..f8ae712f03 100644 --- a/orm/model/ormtable/table_test.go +++ b/orm/model/ormtable/table_test.go @@ -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) { diff --git a/orm/model/ormtable/testdata/test_scenario.golden b/orm/model/ormtable/testdata/test_scenario.golden index 15a8cb7fd1..57010bfea4 100644 --- a/orm/model/ormtable/testdata/test_scenario.golden +++ b/orm/model/ormtable/testdata/test_scenario.golden @@ -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