mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
entc/gen: returns affected rows in delete
Summary: Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1455 Reviewed By: alexsn Differential Revision: D17396880 fbshipit-source-id: 3a3a9849b816777bd0ef94cf55b2291705a37df6
This commit is contained in:
committed by
Facebook Github Bot
parent
2b1ff377b5
commit
83d0063437
@@ -96,6 +96,7 @@ var tests = []func(*testing.T, *ent.Client){
|
||||
Sanity,
|
||||
Paging,
|
||||
Select,
|
||||
Delete,
|
||||
Relation,
|
||||
Predicate,
|
||||
AddValues,
|
||||
@@ -367,6 +368,28 @@ func AddValues(t *testing.T, client *ent.Client) {
|
||||
require.Equal(20, *cmt1.NillableInt)
|
||||
}
|
||||
|
||||
func Delete(t *testing.T, client *ent.Client) {
|
||||
require := require.New(t)
|
||||
ctx := context.Background()
|
||||
|
||||
nd := client.Node.Create().SetValue(1e3).SaveX(ctx)
|
||||
err := client.Node.DeleteOneID(nd.ID).Exec(ctx)
|
||||
require.NoError(err)
|
||||
err = client.Node.DeleteOneID(nd.ID).Exec(ctx)
|
||||
require.True(ent.IsNotFound(err))
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
client.Node.Create().SetValue(i).SaveX(ctx)
|
||||
}
|
||||
affected, err := client.Node.Delete().Where(node.ValueGT(2)).Exec(ctx)
|
||||
require.NoError(err)
|
||||
require.Equal(2, affected)
|
||||
|
||||
affected, err = client.Node.Delete().Exec(ctx)
|
||||
require.NoError(err)
|
||||
require.Equal(3, affected)
|
||||
}
|
||||
|
||||
func Relation(t *testing.T, client *ent.Client) {
|
||||
require := require.New(t)
|
||||
ctx := context.Background()
|
||||
|
||||
Reference in New Issue
Block a user